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
.argeo
.ArgeoException
;
8 import org
.argeo
.jackrabbit
.OsgiJackrabbitRepositoryFactory
;
9 import org
.argeo
.security
.core
.InternalAuthentication
;
10 import org
.osgi
.framework
.BundleContext
;
11 import org
.springframework
.security
.core
.context
.SecurityContextHolder
;
14 * Argeo CMS Kernel. Responsible for :
17 * <li>provisioning</li>
18 * <li>transaction</li>
20 * <li>local and remote file systems access</li>
25 private final static Log log
= LogFactory
.getLog(Kernel
.class);
26 // private static final String PROP_WORKBENCH_AUTOSTART = "org.eclipse.rap.workbenchAutostart";
28 private final BundleContext bundleContext
;
30 private JackrabbitNode node
;
31 private RepositoryFactory repositoryFactory
;
32 private NodeSecurity nodeSecurity
;
33 private NodeHttp nodeHttp
;
35 Kernel(BundleContext bundleContext
) {
36 this.bundleContext
= bundleContext
;
40 long begin
= System
.currentTimeMillis();
41 InternalAuthentication initAuth
= new InternalAuthentication(
42 KernelConstants
.DEFAULT_SECURITY_KEY
);
43 SecurityContextHolder
.getContext().setAuthentication(initAuth
);
46 node
= new JackrabbitNode(bundleContext
);
47 repositoryFactory
= new OsgiJackrabbitRepositoryFactory();
48 nodeSecurity
= new NodeSecurity(bundleContext
, node
);
49 nodeHttp
= new NodeHttp(bundleContext
, node
, nodeSecurity
);
51 // Publish services to OSGi
52 nodeSecurity
.publish();
54 bundleContext
.registerService(RepositoryFactory
.class,
55 repositoryFactory
, null);
57 } catch (Exception e
) {
58 log
.error("Cannot initialize Argeo CMS", e
);
59 throw new ArgeoException("Cannot initialize", e
);
62 long duration
= System
.currentTimeMillis() - begin
;
63 log
.info("## ARGEO CMS UP in " + (duration
/ 1000) + "."
64 + (duration
% 1000) + "s ##");
69 long begin
= System
.currentTimeMillis();
72 nodeSecurity
.destroy();
75 long duration
= System
.currentTimeMillis() - begin
;
76 log
.info("## ARGEO CMS DOWN in " + (duration
/ 1000) + "."
77 + (duration
% 1000) + "s ##");
80 // private void registerWorkbench(final WorkbenchApplicationConfiguration wac) {
81 // new Thread("Worbench Launcher") {
82 // public void run() {
83 // Hashtable<String, String> props = new Hashtable<String, String>();
84 // props.put(ApplicationLauncher.PROPERTY_CONTEXT_NAME, "ui");
85 // workbenchReg = bundleContext.registerService(
86 // ApplicationConfiguration.class, wac, props);
91 private void directorsCut() {
92 final long ms
= 128l + (long) (Math
.random() * 128d
);
93 log
.info("Spend " + ms
+ "ms"
94 + " reflecting on the progress brought to mankind"
95 + " by Free Software...");
96 long beginNano
= System
.nanoTime();
99 } catch (InterruptedException e
) {
102 long durationNano
= System
.nanoTime() - beginNano
;
103 final double M
= 1000d
* 1000d
;
104 double sleepAccuracy
= ((double) durationNano
) / (ms
* M
);
105 if (log
.isDebugEnabled())
106 log
.debug("Sleep accuracy: "
107 + String
.format("%.2f", sleepAccuracy
* 100) + " %");