1 package org
.argeo
.cms
.internal
.kernel
;
3 import java
.lang
.management
.ManagementFactory
;
5 import javax
.jcr
.RepositoryFactory
;
7 import org
.apache
.commons
.logging
.Log
;
8 import org
.apache
.commons
.logging
.LogFactory
;
9 import org
.apache
.jackrabbit
.util
.TransientFileFactory
;
10 import org
.argeo
.ArgeoException
;
11 import org
.argeo
.jackrabbit
.OsgiJackrabbitRepositoryFactory
;
12 import org
.argeo
.security
.core
.InternalAuthentication
;
13 import org
.osgi
.framework
.BundleContext
;
14 import org
.springframework
.security
.core
.context
.SecurityContextHolder
;
17 * Argeo CMS Kernel. Responsible for :
20 * <li>provisioning</li>
21 * <li>transaction</li>
23 * <li>local and remote file systems access</li>
28 private final static Log log
= LogFactory
.getLog(Kernel
.class);
29 // private static final String PROP_WORKBENCH_AUTOSTART =
30 // "org.eclipse.rap.workbenchAutostart";
32 private final BundleContext bundleContext
;
34 private JackrabbitNode node
;
35 private RepositoryFactory repositoryFactory
;
36 private NodeSecurity nodeSecurity
;
37 private NodeHttp nodeHttp
;
39 Kernel(BundleContext bundleContext
) {
40 this.bundleContext
= bundleContext
;
44 ClassLoader currentContextCl
= Thread
.currentThread()
45 .getContextClassLoader();
46 // We use the CMS bundle classloader during initialization
47 Thread
.currentThread().setContextClassLoader(
48 Kernel
.class.getClassLoader());
50 long begin
= System
.currentTimeMillis();
51 InternalAuthentication initAuth
= new InternalAuthentication(
52 KernelConstants
.DEFAULT_SECURITY_KEY
);
53 SecurityContextHolder
.getContext().setAuthentication(initAuth
);
56 node
= new JackrabbitNode(bundleContext
);
57 repositoryFactory
= new OsgiJackrabbitRepositoryFactory();
58 nodeSecurity
= new NodeSecurity(bundleContext
, node
);
59 nodeHttp
= new NodeHttp(bundleContext
, node
, nodeSecurity
);
61 // Publish services to OSGi
62 nodeSecurity
.publish();
64 bundleContext
.registerService(RepositoryFactory
.class,
65 repositoryFactory
, null);
67 } catch (Exception e
) {
68 log
.error("Cannot initialize Argeo CMS", e
);
69 throw new ArgeoException("Cannot initialize", e
);
71 Thread
.currentThread().setContextClassLoader(currentContextCl
);
74 long jvmUptime
= ManagementFactory
.getRuntimeMXBean().getUptime();
75 log
.info("## ARGEO CMS UP in " + (jvmUptime
/ 1000) + "."
76 + (jvmUptime
% 1000) + "s ##");
77 long initDuration
= System
.currentTimeMillis() - begin
;
78 if (log
.isTraceEnabled())
79 log
.trace("Kernel initialization took " + initDuration
+ "ms");
80 directorsCut(initDuration
);
84 long begin
= System
.currentTimeMillis();
87 nodeSecurity
.destroy();
90 // Clean hanging threads from Jackrabbit
91 TransientFileFactory
.shutdown();
93 long duration
= System
.currentTimeMillis() - begin
;
94 log
.info("## ARGEO CMS DOWN in " + (duration
/ 1000) + "."
95 + (duration
% 1000) + "s ##");
98 private void directorsCut(long initDuration
) {
99 // final long ms = 128l + (long) (Math.random() * 128d);
100 long ms
= initDuration
/ 10;
101 log
.info("Spend " + ms
+ "ms"
102 + " reflecting on the progress brought to mankind"
103 + " by Free Software...");
104 long beginNano
= System
.nanoTime();
107 } catch (InterruptedException e
) {
110 long durationNano
= System
.nanoTime() - beginNano
;
111 final double M
= 1000d
* 1000d
;
112 double sleepAccuracy
= ((double) durationNano
) / (ms
* M
);
113 if (log
.isDebugEnabled())
114 log
.debug("Sleep accuracy: "
115 + String
.format("%.2f", sleepAccuracy
* 100) + " %");