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
.eclipse
.rap
.rwt
.application
.ApplicationConfiguration
;
11 import org
.osgi
.framework
.BundleContext
;
12 import org
.osgi
.framework
.ServiceRegistration
;
13 import org
.springframework
.security
.core
.context
.SecurityContextHolder
;
16 * Argeo CMS Kernel. Responsible for :
19 * <li>provisioning</li>
20 * <li>transaction</li>
22 * <li>local and remote file systems access</li>
27 private final static Log log
= LogFactory
.getLog(Kernel
.class);
28 // private static final String PROP_WORKBENCH_AUTOSTART = "org.eclipse.rap.workbenchAutostart";
30 private final BundleContext bundleContext
;
32 private JackrabbitNode node
;
33 private RepositoryFactory repositoryFactory
;
34 private NodeSecurity nodeSecurity
;
35 private NodeHttp nodeHttp
;
37 private ServiceRegistration
<ApplicationConfiguration
> workbenchReg
;
39 Kernel(BundleContext bundleContext
) {
40 this.bundleContext
= bundleContext
;
44 long begin
= System
.currentTimeMillis();
45 InternalAuthentication initAuth
= new InternalAuthentication(
46 KernelConstants
.DEFAULT_SECURITY_KEY
);
47 SecurityContextHolder
.getContext().setAuthentication(initAuth
);
50 node
= new JackrabbitNode(bundleContext
);
51 repositoryFactory
= new OsgiJackrabbitRepositoryFactory();
52 nodeSecurity
= new NodeSecurity(bundleContext
, node
);
53 nodeHttp
= new NodeHttp(bundleContext
, node
, nodeSecurity
);
55 // Publish services to OSGi
56 nodeSecurity
.publish();
58 bundleContext
.registerService(RepositoryFactory
.class,
59 repositoryFactory
, null);
62 // if ("false".equals(bundleContext
63 // .getProperty(PROP_WORKBENCH_AUTOSTART))) {
64 // WorkbenchApplicationConfiguration wac = new WorkbenchApplicationConfiguration();
65 // registerWorkbench(wac);
67 } catch (Exception e
) {
68 log
.error("Cannot initialize Argeo CMS", e
);
69 throw new ArgeoException("Cannot initialize", e
);
72 long duration
= System
.currentTimeMillis() - begin
;
73 log
.info("## ARGEO CMS UP in " + (duration
/ 1000) + "."
74 + (duration
% 1000) + "s ##");
79 long begin
= System
.currentTimeMillis();
82 workbenchReg
.unregister();
85 nodeSecurity
.destroy();
88 long duration
= System
.currentTimeMillis() - begin
;
89 log
.info("## ARGEO CMS DOWN in " + (duration
/ 1000) + "."
90 + (duration
% 1000) + "s ##");
93 // private void registerWorkbench(final WorkbenchApplicationConfiguration wac) {
94 // new Thread("Worbench Launcher") {
95 // public void run() {
96 // Hashtable<String, String> props = new Hashtable<String, String>();
97 // props.put(ApplicationLauncher.PROPERTY_CONTEXT_NAME, "ui");
98 // workbenchReg = bundleContext.registerService(
99 // ApplicationConfiguration.class, wac, props);
104 private void directorsCut() {
105 final long ms
= 128l + (long) (Math
.random() * 128d
);
106 log
.info("Spend " + ms
+ "ms"
107 + " reflecting on the progress brought to mankind"
108 + " by Free Software...");
109 long beginNano
= System
.nanoTime();
112 } catch (InterruptedException e
) {
115 long durationNano
= System
.nanoTime() - beginNano
;
116 final double M
= 1000d
* 1000d
;
117 double sleepAccuracy
= ((double) durationNano
) / (ms
* M
);
118 if (log
.isDebugEnabled())
119 log
.debug("Sleep accuracy: "
120 + String
.format("%.2f", sleepAccuracy
* 100) + " %");