Properties props = new Properties();
props.load(new FileInputStream(args[0]));
Util.substVars(props);
PrintStream out = new PrintStream(new FileOutputStream(args[1], true));
long t0 = System.currentTimeMillis();
Framework f = null;
for (FrameworkFactory ff : ServiceLoader.load(FrameworkFactory.class)) {
f = ff.newFramework(props);
System.out.println("framework = " + f);
break;
}
if (f == null) {
throw new RuntimeException("no OSGi framework in classpath");
}
long t1 = System.currentTimeMillis();
logger.logp(Level.INFO, "BundleProvisioner", "main", "timeTaken to locate OSGi framework = {0} ms",
new Object[]{t1 - t0});
f.init();
long t2 = System.currentTimeMillis();
logger.logp(Level.INFO, "BundleProvisioner", "main", "timeTaken to initialize OSGi framework = {0} ms",
new Object[]{t2 - t1});
BundleProvisioner bundleProvisioner = new BundleProvisioner(f.getBundleContext(), props);
bundleProvisioner.installBundles();
long t3 = System.currentTimeMillis();
logger.logp(Level.INFO, "BundleProvisioner", "main", "timeTaken to finish installation of bundles = {0} ms",
new Object[]{t3 - t2});
int installed = bundleProvisioner.getNoOfInstalledBundles();
int updated = bundleProvisioner.getNoOfUpdatedBundles();
int uninstalled = bundleProvisioner.getNoOfUninstalledBundles();
System.out.printf("installed %d, updated = %d, uninstalled = %d\n", installed, updated, uninstalled);
if (bundleProvisioner.hasAnyThingChanged()) {
System.out.println("Refreshing framework");
bundleProvisioner.refresh();
}
bundleProvisioner.startBundles();
f.start();
long t4 = System.currentTimeMillis();
logger.logp(Level.INFO, "BundleProvisioner", "main", "time taken to finish starting bundles = {0} ms",
new Object[]{t4 - t3});
logger.logp(Level.INFO, "BundleProvisioner", "main", "total time taken to start = {0}", new Object[]{t4-t0});
if (args.length == 3 && args[2].equalsIgnoreCase("wait-before-stopping")) {
System.out.println("Hit enter to continue");
System.in.read(); //
}
f.stop();
f.waitForStop(0);
long t5 = System.currentTimeMillis();
logger.logp(Level.INFO, "BundleProvisioner", "main", "time taken to stop = {0} ms", new Object[]{t5 - t4});
logger.logp(Level.INFO, "BundleProvisioner", "main", "Total time taken = {0}", new Object[]{t5-t0});
out.printf("%d,%d,%d,%d,%d,%d,%d\n", t1-t0, t2-t1, t3-t2, t4-t3, t4-t0, t5-t4, t5-t0);
}