]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsStateImpl.java
1 package org
.argeo
.cms
.internal
.runtime
;
3 import java
.net
.InetAddress
;
5 import java
.net
.UnknownHostException
;
8 import javax
.security
.auth
.login
.Configuration
;
10 import org
.argeo
.api
.cms
.CmsLog
;
11 import org
.argeo
.api
.cms
.CmsState
;
12 import org
.argeo
.api
.uuid
.UuidFactory
;
13 import org
.argeo
.cms
.auth
.ident
.IdentClient
;
16 * Implementation of a {@link CmsState}, initialising the required services.
18 public class CmsStateImpl
implements CmsState
{
19 private final static CmsLog log
= CmsLog
.getLog(CmsStateImpl
.class);
22 private Long availableSince
;
25 // private final boolean cleanState;
26 private String hostname
;
28 private UuidFactory uuidFactory
;
31 // Runtime.getRuntime().addShutdownHook(new CmsShutdown());
37 if (log
.isTraceEnabled())
38 log
.trace("CMS State started");
40 // String stateUuidStr = KernelUtils.getFrameworkProp(Constants.FRAMEWORK_UUID);
41 // this.uuid = UUID.fromString(stateUuidStr);
42 this.uuid
= uuidFactory
.timeUUID();
43 // this.cleanState = stateUuid.equals(frameworkUuid);
45 this.hostname
= InetAddress
.getLocalHost().getHostName();
46 } catch (UnknownHostException e
) {
47 log
.error("Cannot set hostname: " + e
);
50 availableSince
= System
.currentTimeMillis();
51 if (log
.isDebugEnabled())
52 // log.debug("## CMS starting... stateUuid=" + this.stateUuid + (cleanState ? "
53 // (clean state) " : " "));
54 log
.debug("## CMS starting... (" + uuid
+ ")");
59 } catch (RuntimeException e
) {
60 log
.error("## FATAL: CMS activator failed", e
);
64 private void initSecurity() {
65 if (System
.getProperty(KernelConstants
.JAAS_CONFIG_PROP
) == null) {
66 String jaasConfig
= KernelConstants
.JAAS_CONFIG
;
67 URL url
= getClass().getResource(jaasConfig
);
68 // System.setProperty(KernelConstants.JAAS_CONFIG_PROP,
69 // url.toExternalForm());
70 KernelUtils
.setJaasConfiguration(url
);
72 // explicitly load JAAS configuration
73 Configuration
.getConfiguration();
77 if (log
.isDebugEnabled())
78 log
.debug("CMS stopping... (" + this.uuid
+ ")");
80 long duration
= ((System
.currentTimeMillis() - availableSince
) / 1000) / 60;
81 log
.info("## ARGEO CMS STOPPED after " + (duration
/ 60) + "h " + (duration
% 60) + "min uptime ##");
85 public Long
getAvailableSince() {
86 return availableSince
;
92 public String
getHostname() {
97 public UUID
getUuid() {
101 public void setUuidFactory(UuidFactory uuidFactory
) {
102 this.uuidFactory
= uuidFactory
;
108 public static IdentClient
getIdentClient(String remoteAddr
) {
109 if (!IdentClient
.isDefaultAuthdPassphraseFileAvailable())
111 // TODO make passphrase more configurable
112 return new IdentClient(remoteAddr
);