use of org.osgi.framework.launch.Framework in project guice by google.
the class OSGiContainerTest method testGuiceWorksInOSGiContainer.
//This test may fail if it is not run from ant, or if it is not run after ant has
//compiled & built jars. This is because the test is validating that the Guice jar
//is properly setup to load in an OSGi container
public void testGuiceWorksInOSGiContainer() throws Throwable {
// ask framework to clear cache on startup
Properties properties = new Properties();
properties.setProperty("org.osgi.framework.storage", BUILD_TEST_DIR + "/bundle.cache");
properties.setProperty("org.osgi.framework.storage.clean", "onFirstInit");
// test each available OSGi framework in turn
Iterator<FrameworkFactory> f = ServiceRegistry.lookupProviders(FrameworkFactory.class);
while (f.hasNext()) {
Framework framework = f.next().newFramework(properties);
framework.start();
BundleContext systemContext = framework.getBundleContext();
// load all the necessary bundles and start the OSGi test bundle
/*if[AOP]*/
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/aopalliance.jar");
/*end[AOP]*/
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/javax.inject.jar");
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/guava.jar");
systemContext.installBundle("reference:file:" + GUICE_JAR);
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/osgitests.jar").start();
framework.stop();
}
}
use of org.osgi.framework.launch.Framework in project roboguice by roboguice.
the class OSGiContainerTest method testGuiceWorksInOSGiContainer.
//This test may fail if it is not run from ant, or if it is not run after ant has
//compiled & built jars. This is because the test is validating that the Guice jar
//is properly setup to load in an OSGi container
public void testGuiceWorksInOSGiContainer() throws Throwable {
// ask framework to clear cache on startup
Properties properties = new Properties();
properties.setProperty("org.osgi.framework.storage", BUILD_TEST_DIR + "/bundle.cache");
properties.setProperty("org.osgi.framework.storage.clean", "onFirstInit");
// test each available OSGi framework in turn
Iterator<FrameworkFactory> f = ServiceRegistry.lookupProviders(FrameworkFactory.class);
while (f.hasNext()) {
Framework framework = f.next().newFramework(properties);
framework.start();
BundleContext systemContext = framework.getBundleContext();
// load all the necessary bundles and start the OSGi test bundle
/*if[AOP]*/
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/aopalliance.jar");
/*end[AOP]*/
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/javax.inject.jar");
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/guava.jar");
systemContext.installBundle("reference:file:" + GUICE_JAR);
systemContext.installBundle("reference:file:" + BUILD_TEST_DIR + "/osgitests.jar").start();
framework.stop();
}
}
use of org.osgi.framework.launch.Framework in project karaf by apache.
the class MainLockingTest method testLostMasterLock.
@Test
public void testLostMasterLock() throws Exception {
File basedir = new File(getClass().getClassLoader().getResource("foo").getPath()).getParentFile();
File home = new File(basedir, "test-karaf-home");
File data = new File(home, "data");
Utils.deleteDirectory(data);
String[] args = new String[0];
System.setProperty("karaf.home", home.toString());
System.setProperty("karaf.data", data.toString());
System.setProperty("karaf.framework.factory", "org.apache.felix.framework.FrameworkFactory");
System.setProperty("karaf.lock", "true");
System.setProperty("karaf.lock.delay", "1000");
System.setProperty("karaf.lock.class", "org.apache.karaf.main.MockLock");
Main main = new Main(args);
main.launch();
Framework framework = main.getFramework();
String activatorName = TimeoutShutdownActivator.class.getName().replace('.', '/') + ".class";
Bundle bundle = framework.getBundleContext().installBundle("foo", TinyBundles.bundle().set(Constants.BUNDLE_ACTIVATOR, TimeoutShutdownActivator.class.getName()).add(activatorName, getClass().getClassLoader().getResourceAsStream(activatorName)).build(withBnd()));
bundle.start();
FrameworkStartLevel sl = framework.adapt(FrameworkStartLevel.class);
MockLock lock = (MockLock) main.getLock();
Assert.assertEquals(100, sl.getStartLevel());
// simulate losing a lock
lock.setIsAlive(false);
lock.setLock(false);
// lets wait until the start level change is complete
lock.waitForLock();
Assert.assertEquals(1, sl.getStartLevel());
Thread.sleep(1000);
// get lock back
lock.setIsAlive(true);
lock.setLock(true);
Thread.sleep(1000);
// exit framework + lock loop
main.destroy();
}
use of org.osgi.framework.launch.Framework in project karaf by apache.
the class MainStartTest method testAutoStart.
@Test
public void testAutoStart() throws Exception {
File basedir = new File(getClass().getClassLoader().getResource("foo").getPath()).getParentFile();
File home = new File(basedir, "test-karaf-home");
// generate an unique folder name to avoid conflict with folder created by other unit tests (KARAF-2558)
File data = new File(home, "data" + System.currentTimeMillis());
String[] args = new String[0];
System.setProperty("karaf.home", home.toString());
System.setProperty("karaf.data", data.toString());
main = new Main(args);
main.launch();
Framework framework = main.getFramework();
Bundle[] bundles = framework.getBundleContext().getBundles();
Assert.assertEquals(3, bundles.length);
// Give the framework some time to start the bundles
Thread.sleep(1000);
Bundle bundle1 = framework.getBundleContext().getBundle("mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.api/1.0.0");
Assert.assertEquals(Bundle.ACTIVE, bundle1.getState());
Bundle bundle2 = framework.getBundleContext().getBundle("pax-url-mvn.jar");
Assert.assertEquals(Bundle.ACTIVE, bundle2.getState());
}
use of org.osgi.framework.launch.Framework in project sling by apache.
the class Sling method destroy.
/**
* Destroys this servlet by shutting down the OSGi framework and hence the
* delegatee servlet if one is set at all.
*/
public final void destroy() {
if (framework != null) {
// get a private copy of the reference and remove the class ref
Framework myFramework;
synchronized (this) {
myFramework = framework;
framework = null;
}
// shutdown the Felix container
if (myFramework != null) {
logger.log(Logger.LOG_INFO, "Shutting down Apache Sling");
try {
myFramework.stop();
myFramework.waitForStop(0);
} catch (BundleException be) {
// may be thrown by stop, log but continue
logger.log(Logger.LOG_ERROR, "Failure initiating Framework Shutdown", be);
} catch (InterruptedException ie) {
// may be thrown by waitForStop, log but continue
logger.log(Logger.LOG_ERROR, "Interrupted while waiting for the Framework Termination", ie);
}
logger.log(Logger.LOG_INFO, "Apache Sling stopped");
}
}
}
Aggregations