]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms/src/org/argeo/cms/internal/kernel/Kernel.java
1 package org
.argeo
.cms
.internal
.kernel
;
4 * Argeo CMS Kernel. Responsible for :
7 * <li>provisioning</li>
10 * <li>local and remote file systems access</li>
16 //implements KernelHeader, KernelConstants {
18 // * SERVICE REFERENCES
20 // // private ServiceReference<ConfigurationAdmin> configurationAdmin;
21 // private final ServiceTracker<ConfigurationAdmin, ConfigurationAdmin> configurationAdmin;
22 // private final ServiceTracker<LogReaderService, LogReaderService> logReaderService;
23 // private final ServiceTracker<HttpService, HttpService> httpService;
24 // private final ConditionalPermissionAdmin permissionAdmin;
26 // * REGISTERED SERVICES
28 // private ServiceRegistration<ArgeoLogger> loggerReg;
29 // private ServiceRegistration<TransactionManager> tmReg;
30 // private ServiceRegistration<UserTransaction> utReg;
31 // private ServiceRegistration<TransactionSynchronizationRegistry> tsrReg;
32 // private ServiceRegistration<?> repositoryReg;
33 // private ServiceRegistration<RepositoryFactory> repositoryFactoryReg;
34 // private ServiceRegistration<UserAdmin> userAdminReg;
37 // * SERVICES IMPLEMENTATIONS
39 // private NodeLogger logger;
40 // private BitronixTransactionManager transactionManager;
41 // private BitronixTransactionSynchronizationRegistry transactionSynchronizationRegistry;
42 // private NodeRepositoryFactory repositoryFactory;
43 // private Repository repository;
44 // private NodeUserAdmin userAdmin;
47 // private final BundleContext bc;// = Activator.getBundleContext();
48 // private final NodeSecurity nodeSecurity;
50 // private final static Log log = LogFactory.getLog(Kernel.class);
51 // ThreadGroup threadGroup = new ThreadGroup(Kernel.class.getSimpleName());
52 // private DataHttp dataHttp;
53 // private NodeHttp nodeHttp;
54 // private KernelThread kernelThread;
56 // private Locale defaultLocale = null;
57 // private List<Locale> locales = null;
60 // // KernelUtils.logFrameworkProperties(log);
61 // nodeSecurity = new NodeSecurity();
62 // bc = FrameworkUtil.getBundle(getClass()).getBundleContext();
63 // configurationAdmin = new ServiceTracker<ConfigurationAdmin, ConfigurationAdmin>(bc, ConfigurationAdmin.class,
64 // new PrepareStc<ConfigurationAdmin>());
65 // configurationAdmin.open();
66 // logReaderService = new ServiceTracker<LogReaderService, LogReaderService>(bc, LogReaderService.class,
67 // new PrepareStc<LogReaderService>());
68 // logReaderService.open();
69 // httpService = new ServiceTracker<HttpService, HttpService>(bc, HttpService.class, new PrepareHttpStc());
70 // httpService.open();
72 // permissionAdmin = bc.getService(bc.getServiceReference(ConditionalPermissionAdmin.class));
76 // * PACKAGE RESTRICTED INTERFACE
78 // Subject getKernelSubject() {
79 // return nodeSecurity.getKernelSubject();
86 // final void init() {
87 // Subject.doAs(nodeSecurity.getKernelSubject(), new PrivilegedAction<Void>() {
89 // public Void run() {
96 // private void doInit() {
97 // long begin = System.currentTimeMillis();
98 // // Use CMS bundle classloader
99 // ClassLoader currentContextCl = Thread.currentThread().getContextClassLoader();
100 // Thread.currentThread().setContextClassLoader(Kernel.class.getClassLoader());
102 // // Listen to service publication (also ours)
103 // // bc.addServiceListener(Kernel.this);
105 // if (nodeSecurity.isFirstInit())
108 // defaultLocale = new Locale(getFrameworkProp(NodeConstants.I18N_DEFAULT_LOCALE, ENGLISH.getLanguage()));
109 // locales = asLocaleList(getFrameworkProp(NodeConstants.I18N_LOCALES));
111 // // ServiceTracker<LogReaderService, LogReaderService>
112 // // logReaderService = new ServiceTracker<LogReaderService,
113 // // LogReaderService>(
114 // // bc, LogReaderService.class, null);
115 // // logReaderService.open();
116 // logger = new NodeLogger(logReaderService.getService());
117 // // logReaderService.close();
119 // if (isMaintenance())
120 // maintenanceInit();
123 // } catch (Throwable e) {
124 // log.error("Cannot initialize Argeo CMS", e);
125 // throw new ArgeoException("Cannot initialize", e);
127 // Thread.currentThread().setContextClassLoader(currentContextCl);
128 // // FIXME better manage lifecycle.
130 // new LoginContext(LOGIN_CONTEXT_KERNEL, nodeSecurity.getKernelSubject()).logout();
131 // } catch (LoginException e) {
132 // e.printStackTrace();
136 // long jvmUptime = ManagementFactory.getRuntimeMXBean().getUptime();
137 // log.info("## ARGEO CMS UP in " + (jvmUptime / 1000) + "." + (jvmUptime % 1000) + "s ##");
138 // long initDuration = System.currentTimeMillis() - begin;
139 // if (log.isTraceEnabled())
140 // log.trace("Kernel initialization took " + initDuration + "ms");
141 // directorsCut(initDuration);
144 // private void normalInit() {
145 // ConfigurationAdmin conf = findConfigurationAdmin();
148 // initWebServer(conf);
149 // // ServiceReference<ExtendedHttpService> sr =
150 // // bc.getServiceReference(ExtendedHttpService.class);
151 // // if (sr != null)
152 // // addHttpService(sr);
154 // // log.warn("No http service found");
156 // // Initialise services
157 // initTransactionManager();
159 // RepositoryServiceFactory jrsf = new RepositoryServiceFactory();
160 // String[] clazzes = { ManagedServiceFactory.class.getName() };
161 // Hashtable<String, String> serviceProps = new Hashtable<String, String>();
162 // serviceProps.put(Constants.SERVICE_PID, ArgeoJcrConstants.JACKRABBIT_REPO_FACTORY_PID);
163 // bc.registerService(clazzes, jrsf, serviceProps);
166 // Configuration nodeConf = conf.createFactoryConfiguration(ArgeoJcrConstants.JACKRABBIT_REPO_FACTORY_PID);
167 // // Configuration nodeConf =
168 // // conf.getConfiguration(ArgeoJcrConstants.REPO_PID_NODE);
169 // if (nodeConf.getProperties() == null) {
170 // Dictionary<String, Object> props = getNodeConfigFromFrameworkProperties();
171 // if (props == null) {
172 // // TODO interactive configuration
173 // if (log.isDebugEnabled())
174 // log.debug("No argeo.node.repo.type=localfs|h2|postgresql|memory"
175 // + " property defined, entering interactive mode...");
178 // // props.put(ConfigurationAdmin.SERVICE_FACTORYPID,
179 // // ArgeoJcrConstants.JACKRABBIT_REPO_FACTORY_PID);
180 // props.put(Constants.SERVICE_PID, ArgeoJcrConstants.REPO_PID_NODE);
181 // nodeConf.update(props);
183 // } catch (IOException e) {
184 // throw new CmsException("Cannot get configuration", e);
187 // // ManagedJackrabbitRepository nodeRepo = new
188 // // ManagedJackrabbitRepository();
189 // // String[] clazzes = { ManagedService.class.getName(),
190 // // Repository.class.getName(),
191 // // JackrabbitRepository.class.getName() };
192 // // Hashtable<String, String> serviceProps = new Hashtable<String,
194 // // serviceProps.put(Constants.SERVICE_PID,
195 // // ArgeoJcrConstants.REPO_PID_NODE);
196 // // serviceProps.put(ArgeoJcrConstants.JCR_REPOSITORY_ALIAS,
197 // // ArgeoJcrConstants.ALIAS_NODE);
198 // // repositoryReg = bc.registerService(clazzes, nodeRepo, serviceProps);
199 // // nodeRepo.waitForInit();
201 // ServiceTracker<JackrabbitRepository, JackrabbitRepository> jackrabbitSt = new ServiceTracker<>(bc,
202 // JackrabbitRepository.class, new ServiceTrackerCustomizer<JackrabbitRepository, JackrabbitRepository>() {
205 // public JackrabbitRepository addingService(ServiceReference<JackrabbitRepository> reference) {
206 // JackrabbitRepository nodeRepo = bc.getService(reference);
208 // // JackrabbitDataModel(bc).prepareDataModel(nodeRepo);
209 // prepareDataModel(KernelUtils.openAdminSession(nodeRepo));
211 // // repository = (JackrabbitRepository)
212 // // bc.getService(repositoryReg.getReference());
213 // repository = new HomeRepository(nodeRepo);
214 // Hashtable<String, String> regProps = new Hashtable<String, String>();
215 // regProps.put(ArgeoJcrConstants.JCR_REPOSITORY_ALIAS, ArgeoJcrConstants.ALIAS_NODE);
216 // repositoryReg = (ServiceRegistration<? extends Repository>) bc.registerService(Repository.class,
217 // repository, regProps);
219 // // if (repository == null)
220 // // repository = new NodeRepository();
221 // if (repositoryFactory == null) {
222 // repositoryFactory = new NodeRepositoryFactory();
223 // // repositoryFactory.setBundleContext(bc);
224 // repositoryFactoryReg = bc.registerService(RepositoryFactory.class, repositoryFactory, null);
226 // userAdmin = new NodeUserAdmin(transactionManager, repository);
227 // userAdminReg = bc.registerService(UserAdmin.class, userAdmin, userAdmin.currentState());
232 // public void modifiedService(ServiceReference<JackrabbitRepository> reference,
233 // JackrabbitRepository service) {
237 // public void removedService(ServiceReference<JackrabbitRepository> reference,
238 // JackrabbitRepository service) {
241 // jackrabbitSt.open();
243 // // new JackrabbitDataModel(bc).prepareDataModel(nodeRepo);
244 // // prepareDataModel(nodeRepo);
246 // // repository = (JackrabbitRepository)
247 // // bc.getService(repositoryReg.getReference());
249 // //// if (repository == null)
250 // //// repository = new NodeRepository();
251 // // if (repositoryFactory == null) {
252 // // repositoryFactory = new OsgiJackrabbitRepositoryFactory();
253 // // repositoryFactory.setBundleContext(bc);
255 // // userAdmin = new NodeUserAdmin(transactionManager, repository);
258 // UserUi userUi = new UserUi();
259 // Hashtable<String, String> props = new Hashtable<String, String>();
260 // props.put("contextName", "user");
261 // bc.registerService(ApplicationConfiguration.class, userUi, props);
263 // // Bundle rapWorkbenchBundle =
264 // // findBundle("org.eclipse.rap.ui.workbench");
265 // // if (rapWorkbenchBundle != null)
267 // // Class<?> clss = rapWorkbenchBundle
268 // // .loadClass("org.eclipse.rap.ui.internal.servlet.WorkbenchApplicationConfiguration");
270 // // Hashtable<String, String> rapWorkbenchProps = new Hashtable<String,
272 // // rapWorkbenchProps.put("contextName", "ui");
273 // // ApplicationConfiguration workbenchApplicationConfiguration =
274 // // (ApplicationConfiguration) clss
275 // // .newInstance();
276 // // bc.registerService(ApplicationConfiguration.class,
277 // // workbenchApplicationConfiguration,
278 // // rapWorkbenchProps);
279 // // } catch (Exception e) {
280 // // log.error("Cannot initalize RAP workbench", e);
284 //// kernelThread = new KernelThread(this);
285 //// kernelThread.setContextClassLoader(Kernel.class.getClassLoader());
286 //// kernelThread.start();
288 // // Publish services to OSGi
292 // private Dictionary<String, Object> getNodeConfigFromFrameworkProperties() {
293 // String repoType = KernelUtils.getFrameworkProp(NodeConstants.NODE_REPO_PROP_PREFIX + RepoConf.type.name());
294 // if (repoType == null)
297 // Hashtable<String, Object> props = new Hashtable<String, Object>();
298 // for (RepoConf repoConf : RepoConf.values()) {
299 // String value = KernelUtils.getFrameworkProp(NodeConstants.NODE_REPO_PROP_PREFIX + repoConf.name());
300 // if (value != null)
301 // props.put(repoConf.name(), value);
306 // /** Session is logged out. */
307 // private void prepareDataModel(Session adminSession) {
309 // Set<String> processed = new HashSet<String>();
310 // bundles: for (Bundle bundle : bc.getBundles()) {
311 // BundleWiring wiring = bundle.adapt(BundleWiring.class);
312 // if (wiring == null) {
313 // if (log.isTraceEnabled())
314 // log.error("No wiring for " + bundle.getSymbolicName());
317 // processWiring(adminSession, wiring, processed);
320 // JcrUtils.logoutQuietly(adminSession);
324 // private void processWiring(Session adminSession, BundleWiring wiring, Set<String> processed) {
325 // // recursively process requirements first
326 // List<BundleWire> requiredWires = wiring.getRequiredWires(CMS_DATA_MODEL_NAMESPACE);
327 // for (BundleWire wire : requiredWires) {
328 // processWiring(adminSession, wire.getProviderWiring(), processed);
329 // // registerCnd(adminSession, wire.getCapability(), processed);
331 // List<BundleCapability> capabilities = wiring.getCapabilities(CMS_DATA_MODEL_NAMESPACE);
332 // for (BundleCapability capability : capabilities) {
333 // registerCnd(adminSession, capability, processed);
337 // private void registerCnd(Session adminSession, BundleCapability capability, Set<String> processed) {
338 // Map<String, Object> attrs = capability.getAttributes();
339 // String name = attrs.get(DataModelNamespace.CAPABILITY_NAME_ATTRIBUTE).toString();
340 // if (processed.contains(name)) {
341 // if (log.isTraceEnabled())
342 // log.trace("Data model " + name + " has already been processed");
345 // String path = attrs.get(DataModelNamespace.CAPABILITY_CND_ATTRIBUTE).toString();
346 // URL url = capability.getRevision().getBundle().getResource(path);
347 // try (Reader reader = new InputStreamReader(url.openStream())) {
348 // CndImporter.registerNodeTypes(reader, adminSession, true);
349 // processed.add(name);
350 // if (log.isDebugEnabled())
351 // log.debug("Registered CND " + url);
352 // } catch (Exception e) {
353 // throw new CmsException("Cannot read cnd " + url, e);
356 // Hashtable<String, Object> properties = new Hashtable<>();
357 // properties.put(ArgeoJcrConstants.JCR_REPOSITORY_ALIAS, name);
358 // bc.registerService(Repository.class, adminSession.getRepository(), properties);
359 // if (log.isDebugEnabled())
360 // log.debug("Published data model " + name);
363 // private boolean isMaintenance() {
364 // String startLevel = KernelUtils.getFrameworkProp("osgi.startLevel");
365 // if (startLevel == null)
367 // int bundleStartLevel = bc.getBundle().adapt(BundleStartLevel.class).getStartLevel();
368 // // int frameworkStartLevel =
369 // // bc.getBundle(0).adapt(BundleStartLevel.class)
370 // // .getStartLevel();
371 // int frameworkStartLevel = Integer.parseInt(startLevel);
372 // // int frameworkStartLevel = bc.getBundle(0)
373 // // .adapt(FrameworkStartLevel.class).getStartLevel();
374 // return bundleStartLevel == frameworkStartLevel;
377 // private void maintenanceInit() {
378 // log.info("## MAINTENANCE ##");
379 // // bc.addServiceListener(Kernel.this);
380 // initWebServer(null);
381 // MaintenanceUi maintenanceUi = new MaintenanceUi();
382 // Hashtable<String, String> props = new Hashtable<String, String>();
383 // props.put("contextName", "maintenance");
384 // bc.registerService(ApplicationConfiguration.class, maintenanceUi, props);
387 // private void firstInit() {
388 // log.info("## FIRST INIT ##");
389 // String nodeInit = getFrameworkProp(NodeConstants.NODE_INIT);
390 // if (nodeInit == null)
391 // nodeInit = "../../init";
392 // if (nodeInit.startsWith("http")) {
393 // // remoteFirstInit(nodeInit);
397 // if (nodeInit.startsWith("."))
398 // initDir = KernelUtils.getExecutionDir(nodeInit);
400 // initDir = new File(nodeInit);
401 // // TODO also uncompress archives
402 // if (initDir.exists())
404 // FileUtils.copyDirectory(initDir, getOsgiInstanceDir(), new FileFilter() {
407 // public boolean accept(File pathname) {
408 // if (pathname.getName().equals(".svn") || pathname.getName().equals(".git"))
413 // log.info("CMS initialized from " + initDir.getCanonicalPath());
414 // } catch (IOException e) {
415 // throw new CmsException("Cannot initialize from " + initDir, e);
419 // // private void remoteFirstInit(String uri) {
421 // // repository = new NodeRepository();
422 // // repositoryFactory = new OsgiJackrabbitRepositoryFactory();
423 // // Repository remoteRepository =
424 // // ArgeoJcrUtils.getRepositoryByUri(repositoryFactory, uri);
425 // // Session remoteSession = remoteRepository.login(new
426 // // SimpleCredentials("root", "demo".toCharArray()), "main");
427 // // Session localSession = this.repository.login();
428 // // // FIXME register node type
430 // // // CndImporter.registerNodeTypes(null, localSession);
431 // // ByteArrayOutputStream out = new ByteArrayOutputStream();
432 // // remoteSession.exportSystemView("/", out, true, false);
433 // // ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
434 // // localSession.importXML("/", in,
435 // // ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW);
436 // // // JcrUtils.copy(remoteSession.getRootNode(),
437 // // // localSession.getRootNode());
438 // // } catch (Exception e) {
439 // // throw new CmsException("Cannot first init from " + uri, e);
443 // /** Can be null */
444 // private ConfigurationAdmin findConfigurationAdmin() {
445 // // configurationAdmin =
446 // // bc.getServiceReference(ConfigurationAdmin.class);
447 // // if (configurationAdmin == null) {
450 // // return bc.getService(configurationAdmin);
451 // return configurationAdmin.getService();
454 // /** Can be null */
455 // Bundle findBundle(String symbolicName) {
456 // for (Bundle b : bc.getBundles())
457 // if (b.getSymbolicName().equals(symbolicName))
462 // private void initTransactionManager() {
463 // bitronix.tm.Configuration tmConf = TransactionManagerServices.getConfiguration();
464 // tmConf.setServerId(getFrameworkProp(FRAMEWORK_UUID));
466 // // File tmBaseDir = new File(getFrameworkProp(TRANSACTIONS_HOME,
467 // // getOsgiInstancePath(DIR_TRANSACTIONS)));
468 // Bundle bitronixBundle = FrameworkUtil.getBundle(bitronix.tm.Configuration.class);
469 // File tmBaseDir = bitronixBundle.getDataFile(DIR_TRANSACTIONS);
470 // // File tmBaseDir = bc.getDataFile(DIR_TRANSACTIONS);
471 // File tmDir1 = new File(tmBaseDir, "btm1");
473 // tmConf.setLogPart1Filename(new File(tmDir1, tmDir1.getName() + ".tlog").getAbsolutePath());
474 // File tmDir2 = new File(tmBaseDir, "btm2");
476 // tmConf.setLogPart2Filename(new File(tmDir2, tmDir2.getName() + ".tlog").getAbsolutePath());
477 // transactionManager = getTransactionManager();
478 // transactionSynchronizationRegistry = getTransactionSynchronizationRegistry();
481 // private void initWebServer(final ConfigurationAdmin conf) {
482 // String httpPort = getFrameworkProp("org.osgi.service.http.port");
483 // String httpsPort = getFrameworkProp("org.osgi.service.http.port.secure");
485 // if (httpPort != null || httpsPort != null) {
486 // final Hashtable<String, Object> jettyProps = new Hashtable<String, Object>();
487 // if (httpPort != null) {
488 // jettyProps.put(JettyConstants.HTTP_PORT, httpPort);
489 // jettyProps.put(JettyConstants.HTTP_ENABLED, true);
491 // if (httpsPort != null) {
492 // jettyProps.put(JettyConstants.HTTPS_PORT, httpsPort);
493 // jettyProps.put(JettyConstants.HTTPS_ENABLED, true);
494 // jettyProps.put(JettyConstants.SSL_KEYSTORETYPE, "PKCS12");
495 // jettyProps.put(JettyConstants.SSL_KEYSTORE,
496 // nodeSecurity.getHttpServerKeyStore().getCanonicalPath());
497 // jettyProps.put(JettyConstants.SSL_PASSWORD, "changeit");
498 // jettyProps.put(JettyConstants.SSL_WANTCLIENTAUTH, true);
500 // if (conf != null) {
501 // // TODO make filter more generic
502 // String filter = "(" + JettyConstants.HTTP_PORT + "=" + httpPort + ")";
503 // if (conf.listConfigurations(filter) != null)
505 // Configuration jettyConf = conf.createFactoryConfiguration(JETTY_FACTORY_PID, null);
506 // jettyConf.update(jettyProps);
509 // JettyConfigurator.startServer("default", jettyProps);
512 // } catch (Exception e) {
513 // throw new CmsException("Cannot initialize web server on " + httpPortsMsg(httpPort, httpsPort), e);
517 // private void publish() {
520 // loggerReg = bc.registerService(ArgeoLogger.class, logger, null);
522 // tmReg = bc.registerService(TransactionManager.class, transactionManager, null);
523 // utReg = bc.registerService(UserTransaction.class, transactionManager, null);
524 // tsrReg = bc.registerService(TransactionSynchronizationRegistry.class, transactionSynchronizationRegistry, null);
526 // // userAdminReg = bc.registerService(UserAdmin.class, userAdmin,
527 // // userAdmin.currentState());
529 // // Hashtable<String, String> regProps = new Hashtable<String, String>();
530 // // regProps.put(ArgeoJcrConstants.JCR_REPOSITORY_ALIAS,
531 // // ArgeoJcrConstants.ALIAS_NODE);
532 // // repositoryReg = (ServiceRegistration<? extends Repository>)
533 // // bc.registerService(Repository.class, repository,
535 // // repositoryFactoryReg = bc.registerService(RepositoryFactory.class,
536 // // repositoryFactory, null);
540 // long begin = System.currentTimeMillis();
543 // kernelThread.destroyAndJoin();
545 // if (dataHttp != null)
546 // dataHttp.destroy();
547 // if (nodeHttp != null)
548 // nodeHttp.destroy();
549 // if (userAdmin != null)
550 // userAdmin.destroy();
551 // // if (repository != null)
552 // // repository.shutdown();
553 // if (transactionManager != null)
554 // transactionManager.shutdown();
556 // // bc.removeServiceListener(this);
558 // // Clean hanging threads from Jackrabbit
559 // TransientFileFactory.shutdown();
561 // // Clean hanging Gogo shell thread
562 // new GogoShellKiller().start();
564 // nodeSecurity.destroy();
565 // long duration = System.currentTimeMillis() - begin;
566 // log.info("## ARGEO CMS DOWN in " + (duration / 1000) + "." + (duration % 1000) + "s ##");
569 // private void unpublish() {
570 // userAdminReg.unregister();
571 // repositoryFactoryReg.unregister();
572 // repositoryReg.unregister();
573 // tmReg.unregister();
574 // utReg.unregister();
575 // tsrReg.unregister();
576 // loggerReg.unregister();
580 // // public void serviceChanged(ServiceEvent event) {
581 // // ServiceReference<?> sr = event.getServiceReference();
582 // // Object service = bc.getService(sr);
583 // // if (service instanceof Repository) {
584 // // Object jcrRepoAlias =
585 // // sr.getProperty(ArgeoJcrConstants.JCR_REPOSITORY_ALIAS);
586 // // if (jcrRepoAlias != null) {// JCR repository
587 // // String alias = jcrRepoAlias.toString();
588 // // Repository repository = (Repository) bc.getService(sr);
589 // // Map<String, Object> props = new HashMap<String, Object>();
590 // // for (String key : sr.getPropertyKeys())
591 // // props.put(key, sr.getProperty(key));
592 // // if (ServiceEvent.REGISTERED == event.getType()) {
594 // // // repositoryFactory.register(repository, props);
595 // // dataHttp.registerRepositoryServlets(alias, repository);
596 // // } catch (Exception e) {
597 // // throw new CmsException("Could not publish JCR repository " + alias, e);
599 // // } else if (ServiceEvent.UNREGISTERING == event.getType()) {
600 // // // repositoryFactory.unregister(repository, props);
601 // // dataHttp.unregisterRepositoryServlets(alias);
605 // // // else if (service instanceof ExtendedHttpService) {
606 // // // if (ServiceEvent.REGISTERED == event.getType()) {
607 // // // addHttpService(sr);
608 // // // } else if (ServiceEvent.UNREGISTERING == event.getType()) {
609 // // // dataHttp.destroy();
610 // // // dataHttp = null;
615 // private HttpService addHttpService(ServiceReference<HttpService> sr) {
616 // // for (String key : sr.getPropertyKeys())
617 // // log.debug(key + "=" + sr.getProperty(key));
618 // HttpService httpService = bc.getService(sr);
619 // // TODO find constants
620 // Object httpPort = sr.getProperty("http.port");
621 // Object httpsPort = sr.getProperty("https.port");
622 // dataHttp = new DataHttp(httpService);
623 // nodeHttp = new NodeHttp(httpService, bc);
624 // if (log.isDebugEnabled())
625 // log.debug(httpPortsMsg(httpPort, httpsPort));
626 // return httpService;
629 // private String httpPortsMsg(Object httpPort, Object httpsPort) {
630 // return "HTTP " + httpPort + (httpsPort != null ? " - HTTPS " + httpsPort : "");
634 // public Locale getDefaultLocale() {
635 // return defaultLocale;
638 // /** Can be null. */
640 // public List<Locale> getLocales() {
644 // final private static void directorsCut(long initDuration) {
645 // // final long ms = 128l + (long) (Math.random() * 128d);
646 // long ms = initDuration / 100;
647 // log.info("Spend " + ms + "ms" + " reflecting on the progress brought to mankind" + " by Free Software...");
648 // long beginNano = System.nanoTime();
650 // Thread.sleep(ms, 0);
651 // } catch (InterruptedException e) {
654 // long durationNano = System.nanoTime() - beginNano;
655 // final double M = 1000d * 1000d;
656 // double sleepAccuracy = ((double) durationNano) / (ms * M);
657 // if (log.isDebugEnabled())
658 // log.debug("Sleep accuracy: " + String.format("%.2f", 100 - (sleepAccuracy * 100 - 100)) + " %");
661 // private class PrepareStc<T> implements ServiceTrackerCustomizer<T, T> {
664 // public T addingService(ServiceReference<T> reference) {
665 // T service = bc.getService(reference);
666 // System.out.println("addingService " + service);
671 // public void modifiedService(ServiceReference<T> reference, T service) {
672 // System.out.println("modifiedService " + service);
676 // public void removedService(ServiceReference<T> reference, T service) {
677 // System.out.println("removedService " + service);
682 // private class PrepareHttpStc implements ServiceTrackerCustomizer<HttpService, HttpService> {
685 // public HttpService addingService(ServiceReference<HttpService> reference) {
686 // HttpService httpService = addHttpService(reference);
687 // return httpService;
691 // public void modifiedService(ServiceReference<HttpService> reference, HttpService service) {
695 // public void removedService(ServiceReference<HttpService> reference, HttpService service) {
696 // dataHttp.destroy();
702 // /** Workaround for blocking Gogo shell by system shutdown. */
703 // private class GogoShellKiller extends Thread {
705 // public GogoShellKiller() {
706 // super("Gogo shell killer");
711 // public void run() {
712 // ThreadGroup rootTg = getRootThreadGroup(null);
713 // Thread gogoShellThread = findGogoShellThread(rootTg);
714 // if (gogoShellThread == null)
716 // while (getNonDaemonCount(rootTg) > 2) {
718 // Thread.sleep(100);
719 // } catch (InterruptedException e) {
723 // gogoShellThread = findGogoShellThread(rootTg);
724 // if (gogoShellThread == null)
730 // private static ThreadGroup getRootThreadGroup(ThreadGroup tg) {
732 // tg = Thread.currentThread().getThreadGroup();
733 // if (tg.getParent() == null)
736 // return getRootThreadGroup(tg.getParent());
739 // private static int getNonDaemonCount(ThreadGroup rootThreadGroup) {
740 // Thread[] threads = new Thread[rootThreadGroup.activeCount()];
741 // rootThreadGroup.enumerate(threads);
742 // int nonDameonCount = 0;
743 // for (Thread t : threads)
744 // if (t != null && !t.isDaemon())
746 // return nonDameonCount;
749 // private static Thread findGogoShellThread(ThreadGroup rootThreadGroup) {
750 // Thread[] threads = new Thread[rootThreadGroup.activeCount()];
751 // rootThreadGroup.enumerate(threads, true);
752 // for (Thread thread : threads) {
753 // if (thread.getName().equals("Gogo shell"))