+
+ private Long availableSince;
+
+ // Readiness
+ private boolean nodeAvailable = false;
+ private boolean userAdminAvailable = false;
+ private boolean httpExpected = false;
+ private boolean httpAvailable = false;
+
+ public CmsDeployment() {
+ ServiceReference<NodeState> nodeStateSr = bc.getServiceReference(NodeState.class);
+ if (nodeStateSr == null)
+ throw new CmsException("No node state available");
+
+ NodeState nodeState = bc.getService(nodeStateSr);
+ deployConfig = new DeployConfig(nodeState.isClean());
+ httpExpected = deployConfig.getProps(KernelConstants.JETTY_FACTORY_PID, "default") != null;
+
+ initTrackers();
+ }
+
+ private void initTrackers() {
+ new PrepareHttpStc().open();
+ new RepositoryContextStc().open();
+ new ServiceTracker<UserAdmin, UserAdmin>(bc, UserAdmin.class, null) {
+ @Override
+ public UserAdmin addingService(ServiceReference<UserAdmin> reference) {
+ userAdminAvailable = true;
+ checkReadiness();
+ return super.addingService(reference);
+ }
+ }.open();
+ }
+
+ public void shutdown() {
+ deployConfig.save();
+ }
+
+ private void checkReadiness() {
+ if (nodeAvailable && userAdminAvailable && (httpExpected ? httpAvailable : true)) {
+ availableSince = System.currentTimeMillis();
+ long jvmUptime = ManagementFactory.getRuntimeMXBean().getUptime();
+ log.info("## ARGEO CMS AVAILABLE in " + (jvmUptime / 1000) + "." + (jvmUptime % 1000) + "s ##");
+ long begin = bc.getService(bc.getServiceReference(NodeState.class)).getAvailableSince();
+ long initDuration = System.currentTimeMillis() - begin;
+ if (log.isTraceEnabled())
+ log.trace("Kernel initialization took " + initDuration + "ms");
+ directorsCut(initDuration);
+ }
+ }
+
+ final private void directorsCut(long initDuration) {
+ // final long ms = 128l + (long) (Math.random() * 128d);
+ long ms = initDuration / 100;
+ log.info("Spend " + ms + "ms" + " reflecting on the progress brought to mankind" + " by Free Software...");
+ long beginNano = System.nanoTime();
+ try {
+ Thread.sleep(ms, 0);
+ } catch (InterruptedException e) {
+ // silent
+ }
+ long durationNano = System.nanoTime() - beginNano;
+ final double M = 1000d * 1000d;
+ double sleepAccuracy = ((double) durationNano) / (ms * M);
+ if (log.isDebugEnabled())
+ log.debug("Sleep accuracy: " + String.format("%.2f", 100 - (sleepAccuracy * 100 - 100)) + " %");
+ }
+
+ private void prepareNodeRepository(Repository deployedNodeRepository) {
+ if (availableSince != null) {
+ throw new CmsException("Deployment is already available");
+ }