1 package org
.argeo
.cms
.internal
.kernel
;
3 import javax
.jcr
.RepositoryFactory
;
5 import org
.apache
.commons
.logging
.Log
;
6 import org
.apache
.commons
.logging
.LogFactory
;
7 import org
.apache
.jackrabbit
.util
.TransientFileFactory
;
8 import org
.argeo
.ArgeoException
;
9 import org
.argeo
.jackrabbit
.OsgiJackrabbitRepositoryFactory
;
10 import org
.argeo
.security
.core
.InternalAuthentication
;
11 import org
.osgi
.framework
.BundleContext
;
12 import org
.springframework
.security
.core
.context
.SecurityContextHolder
;
15 * Argeo CMS Kernel. Responsible for :
18 * <li>provisioning</li>
19 * <li>transaction</li>
21 * <li>local and remote file systems access</li>
26 private final static Log log
= LogFactory
.getLog(Kernel
.class);
27 // private static final String PROP_WORKBENCH_AUTOSTART = "org.eclipse.rap.workbenchAutostart";
29 private final BundleContext bundleContext
;
31 private JackrabbitNode node
;
32 private RepositoryFactory repositoryFactory
;
33 private NodeSecurity nodeSecurity
;
34 private NodeHttp nodeHttp
;
36 Kernel(BundleContext bundleContext
) {
37 this.bundleContext
= bundleContext
;
41 long begin
= System
.currentTimeMillis();
42 InternalAuthentication initAuth
= new InternalAuthentication(
43 KernelConstants
.DEFAULT_SECURITY_KEY
);
44 SecurityContextHolder
.getContext().setAuthentication(initAuth
);
47 node
= new JackrabbitNode(bundleContext
);
48 repositoryFactory
= new OsgiJackrabbitRepositoryFactory();
49 nodeSecurity
= new NodeSecurity(bundleContext
, node
);
50 nodeHttp
= new NodeHttp(bundleContext
, node
, nodeSecurity
);
52 // Publish services to OSGi
53 nodeSecurity
.publish();
55 bundleContext
.registerService(RepositoryFactory
.class,
56 repositoryFactory
, null);
58 } catch (Exception e
) {
59 log
.error("Cannot initialize Argeo CMS", e
);
60 throw new ArgeoException("Cannot initialize", e
);
63 long duration
= System
.currentTimeMillis() - begin
;
64 log
.info("## ARGEO CMS UP in " + (duration
/ 1000) + "."
65 + (duration
% 1000) + "s ##");
70 long begin
= System
.currentTimeMillis();
73 nodeSecurity
.destroy();
76 // Clean hanging threads from Jackrabbit
77 TransientFileFactory
.shutdown();
79 long duration
= System
.currentTimeMillis() - begin
;
80 log
.info("## ARGEO CMS DOWN in " + (duration
/ 1000) + "."
81 + (duration
% 1000) + "s ##");
84 // private void registerWorkbench(final WorkbenchApplicationConfiguration wac) {
85 // new Thread("Worbench Launcher") {
86 // public void run() {
87 // Hashtable<String, String> props = new Hashtable<String, String>();
88 // props.put(ApplicationLauncher.PROPERTY_CONTEXT_NAME, "ui");
89 // workbenchReg = bundleContext.registerService(
90 // ApplicationConfiguration.class, wac, props);
95 private void directorsCut() {
96 final long ms
= 128l + (long) (Math
.random() * 128d
);
97 log
.info("Spend " + ms
+ "ms"
98 + " reflecting on the progress brought to mankind"
99 + " by Free Software...");
100 long beginNano
= System
.nanoTime();
103 } catch (InterruptedException e
) {
106 long durationNano
= System
.nanoTime() - beginNano
;
107 final double M
= 1000d
* 1000d
;
108 double sleepAccuracy
= ((double) durationNano
) / (ms
* M
);
109 if (log
.isDebugEnabled())
110 log
.debug("Sleep accuracy: "
111 + String
.format("%.2f", sleepAccuracy
* 100) + " %");