use of org.osgi.framework.launch.Framework in project Payara by payara.
the class BundleProvisioner method main.
/**
* A simple main method to test this class
*
* @param args
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) throws Exception {
logger.log(INFO, STARTING_BUNDLEPROVISIONER);
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 framework = null;
for (FrameworkFactory frameworkFactory : ServiceLoader.load(FrameworkFactory.class)) {
framework = frameworkFactory.newFramework((Hashtable) props);
System.out.println("framework = " + framework);
break;
}
if (framework == null) {
throw new RuntimeException("no OSGi framework in classpath");
}
long t1 = System.currentTimeMillis();
logger.log(Level.INFO, LogFacade.OSGI_LOCATE_TIME, (t1 - t0));
framework.init();
long t2 = System.currentTimeMillis();
logger.log(Level.INFO, LogFacade.OSGI_INIT_TIME, (t2 - t1));
BundleProvisioner bundleProvisioner = createBundleProvisioner(framework.getBundleContext(), props);
bundleProvisioner.installBundles();
long t3 = System.currentTimeMillis();
logger.log(Level.INFO, LogFacade.BUNDLE_INSTALLATION_TIME, (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();
framework.start();
long t4 = System.currentTimeMillis();
logger.log(Level.INFO, LogFacade.BUNDLE_STARTING_TIME, (t4 - t3));
logger.log(Level.INFO, LogFacade.TOTAL_START_TIME, (t4 - t0));
if (args.length == 3 && args[2].equalsIgnoreCase("wait-before-stopping")) {
System.out.println("Hit enter to continue");
//
System.in.read();
}
framework.stop();
framework.waitForStop(0);
long t5 = System.currentTimeMillis();
logger.log(Level.INFO, LogFacade.BUNDLE_STOP_TIME, (t5 - t4));
logger.log(Level.INFO, LogFacade.TOTAL_TIME, (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);
}
Aggregations