Java Code Examples for org.osgi.framework.launch.Framework#stop()

The following examples show how to use org.osgi.framework.launch.Framework#stop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestOsgi.java    From sensorhub with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void test2InstallBundle() throws Exception
{
    Framework fw = getFramework();
    fw.start();
    
    // install bundle w/o dependency
    Bundle newBundle = installBundle(fw, getClass().getResource("/test-nodep.jar").toString(), "org.sensorhub.test");
            
    // attempt to start it
    newBundle.start();
    assertEquals("Bundle should be in ACTIVE state", Bundle.ACTIVE, newBundle.getState());
    
    fw.stop();
    fw.waitForStop(0);
}
 
Example 2
Source File: TestOsgi.java    From sensorhub with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void test3BundleDependencies() throws Exception
{
    Framework fw = getFramework();
    fw.start();
    
    assertEquals("Wrong number of loaded bundles", 1, fw.getBundleContext().getBundles().length);
    
    // install 1st bundle
    installBundle(fw, getClass().getResource("/test-nodep.jar").toString(), "org.sensorhub.test");
    
    // install 2nd bundle
    Bundle bundle2 = installBundle(fw, getClass().getResource("/test-withdep.jar").toString(), "org.sensorhub.test2");
    
    bundle2.start();
    assertEquals("Bundle " + bundle2.getSymbolicName() + " should be in ACTIVE state", Bundle.ACTIVE, bundle2.getState());
    
    fw.stop();
    fw.waitForStop(0);
}
 
Example 3
Source File: EmbeddedFelixFramework.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static void stopFramework(Framework framework) throws RuntimeException {
    try {
        if (framework != null) {
            framework.stop();
            framework.waitForStop(0);
        }
    } catch (BundleException | InterruptedException e) {
        throw Exceptions.propagate(e);
    }
}
 
Example 4
Source File: TestOsgi.java    From sensorhub with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void test1StartStopFramework() throws Exception
{
    Framework fw = getFramework();
    fw.start();
    Thread.sleep(500);
    fw.stop();
    fw.waitForStop(0);
}
 
Example 5
Source File: SimpleLSResourceResolverTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void testOSGIBundle () throws BundleException
{
  LSInput aRes;

  // Initializing Apache Felix as OSGI container is required to get the
  // "bundle" URL protocol installed correctly
  // Otherwise the first call would end up as a "file" resource ;-)
  final Framework aOSGI = new FrameworkFactory ().newFramework (new HashMap <String, String> ());
  aOSGI.start ();
  try
  {
    // Bundle 0 is the org.apache.felix.framework bundle
    final Bundle b = aOSGI.getBundleContext ().getBundle (0);
    assertNotNull (b);
    assertEquals (Bundle.ACTIVE, b.getState ());

    // No leading slash is important as the ClassLoader is used!
    assertNotNull (b.getResource ("org/apache/felix/framework/util/Util.class"));

    final LSResourceResolver aRR = new SimpleLSResourceResolver ();

    // No class loader
    aRes = aRR.resolveResource (XMLConstants.W3C_XML_SCHEMA_NS_URI,
                                null,
                                null,
                                "../Felix.class",
                                "bundle://0.0:1/org/apache/felix/framework/util/Util.class");
    assertTrue (aRes instanceof ResourceLSInput);
    final IHasInputStream aISP = ((ResourceLSInput) aRes).getInputStreamProvider ();
    assertTrue (aISP instanceof URLResource);
    // Path maybe a "jar:file:" resource
    assertTrue (((URLResource) aISP).getPath ().endsWith ("org/apache/felix/framework/Felix.class"));
  }
  finally
  {
    aOSGI.stop ();
  }
}