-// private void registerWorkbench(final WorkbenchApplicationConfiguration wac) {
-// new Thread("Worbench Launcher") {
-// public void run() {
-// Hashtable<String, String> props = new Hashtable<String, String>();
-// props.put(ApplicationLauncher.PROPERTY_CONTEXT_NAME, "ui");
-// workbenchReg = bundleContext.registerService(
-// ApplicationConfiguration.class, wac, props);
-// }
-// }.start();
-// }
-
- private void directorsCut() {
- final long ms = 128l + (long) (Math.random() * 128d);
+ @Override
+ public void serviceChanged(ServiceEvent event) {
+ ServiceReference<?> sr = event.getServiceReference();
+ Object jcrRepoAlias = sr
+ .getProperty(ArgeoJcrConstants.JCR_REPOSITORY_ALIAS);
+ if (jcrRepoAlias != null) {// JCR repository
+ String alias = jcrRepoAlias.toString();
+ Repository repository = (Repository) bundleContext.getService(sr);
+ Map<String, Object> props = new HashMap<String, Object>();
+ for (String key : sr.getPropertyKeys())
+ props.put(key, sr.getProperty(key));
+ if (ServiceEvent.REGISTERED == event.getType()) {
+ try {
+ repositoryFactory.register(repository, props);
+ nodeHttp.registerRepositoryServlets(alias, repository);
+ } catch (Exception e) {
+ throw new CmsException("Could not publish JCR repository "
+ + alias, e);
+ }
+ } else if (ServiceEvent.UNREGISTERING == event.getType()) {
+ repositoryFactory.unregister(repository, props);
+ nodeHttp.unregisterRepositoryServlets(alias);
+ }
+ }
+
+ }
+
+ private ExtendedHttpService waitForHttpService() {
+ final ServiceTracker<ExtendedHttpService, ExtendedHttpService> st = new ServiceTracker<ExtendedHttpService, ExtendedHttpService>(
+ bundleContext, ExtendedHttpService.class, null);
+ st.open();
+ ExtendedHttpService httpService;
+ try {
+ httpService = st.waitForService(1000);
+ } catch (InterruptedException e) {
+ httpService = null;
+ }
+
+ if (httpService == null)
+ throw new CmsException("Could not find "
+ + ExtendedHttpService.class + " service.");
+ return httpService;
+ }
+
+ final private static void directorsCut(long initDuration) {
+ // final long ms = 128l + (long) (Math.random() * 128d);
+ long ms = initDuration / 100;