本文整理汇总了Java中org.osgi.framework.Bundle.stop方法的典型用法代码示例。如果您正苦于以下问题:Java Bundle.stop方法的具体用法?Java Bundle.stop怎么用?Java Bundle.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.osgi.framework.Bundle
的用法示例。
在下文中一共展示了Bundle.stop方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stopAndUninstallBundles
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
/**
* Stops and un-installs the current bundle.
*/
public void stopAndUninstallBundles() {
// --- Get a copy of loaded bundles -----
Vector<Bundle> bundlesToRemove = new Vector<>(this.getBundleVector());
for (Bundle bundle: bundlesToRemove) {
try {
// --- Remove, if active --------
if (bundle.getState()==Bundle.ACTIVE) {
bundle.stop();
bundle.uninstall();
}
// --- Remove from vector -------
this.getBundleVector().remove(bundle);
if (this.debug) System.out.println("=> - " + bundle.getSymbolicName() + " stoped & uninstalled");
} catch (BundleException bEx) {
bEx.printStackTrace();
}
}
}
示例2: checkAndTakeDownService
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
private void checkAndTakeDownService(String beanName, Class<?> type, String bundleSymName) throws Exception {
ServiceReference ref = bundleContext.getServiceReference(type.getName());
Object service = bundleContext.getService(ref);
Assert.isInstanceOf(type, service);
Bundle dependency = OsgiBundleUtils.findBundleBySymbolicName(bundleContext, bundleSymName);
// stop dependency bundle -> no importer -> exporter goes down
dependency.stop();
}
示例3: doServiceTestOn
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
protected void doServiceTestOn(String beanName, Class<?> type) throws Exception {
ServiceReference ref = bundleContext.getServiceReference(type.getName());
Object service = bundleContext.getService(ref);
Assert.isInstanceOf(type, service);
assertSame(applicationContext.getBean(beanName), service);
Bundle dependency = getDependencyBundle();
// stop bundle (and thus the exposed service)
dependency.stop();
// check if map is still published
assertNull("exported for " + beanName + " should have been unpublished", ref.getBundle());
// double check the service space
assertNull(beanName + " service should be unregistered", bundleContext.getServiceReference(type.getName()));
dependency.start();
waitOnContextCreation(DEP_SYN_NAME);
// the old reference remains invalid
assertNull("the reference should remain invalid", ref.getBundle());
// but the service should be back again
assertSame(applicationContext.getBean(beanName), service);
}
示例4: reload
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
@Override
protected void reload(Module m) throws IOException {
try {
Bundle b = findBundle(m.getCodeNameBase());
b.stop();
fakeOneModule(m, b);
} catch (BundleException ex) {
throw new IOException(ex);
}
}
示例5: testCallGetResourceOnADifferentBundleRetrievedThroughBundleEvent
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
public void testCallGetResourceOnADifferentBundleRetrievedThroughBundleEvent() throws Exception {
String EXTRA_BUNDLE = "org.apache.servicemix.bundles.spring-core";
Bundle[] bundles = bundleContext.getBundles();
Bundle bundle = null;
for (int i = 1; bundle == null && i < bundles.length; i++) {
String location = bundles[i].getLocation();
if (location != null && location.contains(EXTRA_BUNDLE))
bundle = bundles[i];
}
assertNotNull("no bundle found", bundle);
final Bundle sampleBundle = bundle;
final boolean[] listenerCalled = new boolean[] { false };
// register listener
bundleContext.addBundleListener(new SynchronousBundleListener() {
public void bundleChanged(BundleEvent event) {
// call getResource
event.getBundle().getResource(LOCATION);
// call getResources
try {
event.getBundle().getResources(LOCATION);
} catch (IOException e) {
throw new RuntimeException(e);
}
listenerCalled[0] = true;
}
});
// update
sampleBundle.stop();
assertTrue("bundle listener hasn't been called", listenerCalled[0]);
}
示例6: testTwoExportersWithTheSameImporter
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
public void testTwoExportersWithTheSameImporter() throws Exception {
// check that both exporters go down one mandatory goes down
ServiceReference exporterARef = bundleContext.getServiceReference(Map.class.getName());
ServiceReference exporterBRef = bundleContext.getServiceReference(SimpleBean.class.getName());
Bundle dependency = getDependencyBundle();
dependency.stop();
// check if services are still published
assertNull("exportedA should have been unpublished", exporterARef.getBundle());
assertNull("exportedB should have been unpublished", exporterBRef.getBundle());
// double check the service space
assertNull("exporterA service should be unregistered", bundleContext.getServiceReference(Map.class.getName()));
assertNull("exporterB service should be unregistered", bundleContext.getServiceReference(SimpleBean.class
.getName()));
dependency.start();
waitOnContextCreation(DEP_SYN_NAME);
// the old reference remains invalid
assertNull("the reference should remain invalid", exporterARef.getBundle());
assertNull("the reference should remain invalid", exporterBRef.getBundle());
assertNotNull(bundleContext.getServiceReference(Map.class.getName()));
assertNotNull(bundleContext.getServiceReference(SimpleBean.class.getName()));
}
示例7: testServiceListener
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
public void testServiceListener() throws Exception {
assertEquals("Expected initial binding of service", 1, MyListener.BOUND_COUNT);
assertEquals("Unexpected initial unbinding of service", 0, MyListener.UNBOUND_COUNT);
Bundle simpleServiceBundle = OsgiBundleUtils.findBundleBySymbolicName(bundleContext,
"org.eclipse.gemini.blueprint.iandt.simpleservice");
assertNotNull("Cannot find the simple service bundle", simpleServiceBundle);
simpleServiceBundle.stop();
while (simpleServiceBundle.getState() == Bundle.STOPPING) {
Thread.sleep(100);
}
assertEquals("Expected one binding of service", 1, MyListener.BOUND_COUNT);
assertTrue("Expected only one unbinding of service", MyListener.UNBOUND_COUNT < 2);
assertEquals("Expected unbinding of service not seen", 1, MyListener.UNBOUND_COUNT);
logger.debug("about to restart simple service");
simpleServiceBundle.start();
waitOnContextCreation("org.eclipse.gemini.blueprint.iandt.simpleservice");
// wait some more to let the listener binding propagate
Thread.sleep(1000);
logger.debug("simple service succesfully restarted");
assertTrue("Expected only two bindings of service", MyListener.BOUND_COUNT < 3);
assertEquals("Expected binding of service not seen", 2, MyListener.BOUND_COUNT);
assertEquals("Unexpected unbinding of service", 1, MyListener.UNBOUND_COUNT);
}
示例8: testBehaviour
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
public void testBehaviour() throws Exception {
String bundleId = "org.eclipse.gemini.blueprint.iandt, sync-wait-bundle,"
+ getSpringDMVersion();
// locate bundle
String tailBundleId = "org.eclipse.gemini.blueprint.iandt, sync-tail-bundle,"
+ getSpringDMVersion();
// start bundle first (no dependency)
Bundle bundle = installBundle(bundleId);
bundle.start();
assertTrue("bundle " + bundle + "should have started", OsgiBundleUtils.isBundleActive(bundle));
// start bundle dependency
Bundle tailBundle = installBundle(tailBundleId);
tailBundle.start();
assertTrue("bundle " + tailBundle + "hasn't been fully started", OsgiBundleUtils.isBundleActive(tailBundle));
// check appCtx hasn't been published
assertContextServiceIs(bundle, false, 500);
// check the dependency ctx
assertContextServiceIs(tailBundle, true, 500);
// restart the bundle (to catch the tail)
bundle.stop();
bundle.start();
// check appCtx has been published
assertContextServiceIs(bundle, true, 500);
}
示例9: testReferenceProxyLifecycle
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
public void testReferenceProxyLifecycle() throws Exception {
MyService reference = ServiceReferer.serviceReference;
assertNotNull("reference not initialized", reference);
assertNotNull("no value specified in the reference", reference.stringValue());
Bundle simpleServiceBundle = OsgiBundleUtils.findBundleBySymbolicName(bundleContext,
"org.eclipse.gemini.blueprint.iandt.simpleservice");
assertNotNull("Cannot find the simple service bundle", simpleServiceBundle);
System.out.println("stopping bundle");
simpleServiceBundle.stop();
while (simpleServiceBundle.getState() == Bundle.STOPPING) {
System.out.println("waiting for bundle to stop");
Thread.sleep(10);
}
System.out.println("bundle stopped");
// Service should be unavailable
try {
reference.stringValue();
fail("ServiceUnavailableException should have been thrown!");
}
catch (ServiceUnavailableException e) {
// Expected
}
System.out.println("starting bundle");
simpleServiceBundle.start();
waitOnContextCreation("org.eclipse.gemini.blueprint.iandt.simpleservice");
System.out.println("bundle started");
// Service should be running
assertNotNull(reference.stringValue());
}
示例10: getOrder
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
private List<Bundle> getOrder(Bundle... bundles) throws BundleException {
List<Bundle> list = new ArrayList<>(bundles.length);
list.addAll(asList(bundles));
List<Bundle> result = new ArrayList<>();
while (!list.isEmpty()) {
result.addAll(ShutdownSorter.getBundles(list));
for (Bundle bundle : result) {
bundle.stop();
}
}
return result;
}
示例11: testLifecycle
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
public void testLifecycle() throws Exception {
assertNotSame("Guinea pig has already been shutdown", "true",
System.getProperty("org.eclipse.gemini.blueprint.iandt.lifecycle.GuineaPig.close"));
assertEquals("Guinea pig didn't startup", "true",
System.getProperty("org.eclipse.gemini.blueprint.iandt.lifecycle.GuineaPig.startUp"));
Bundle[] bundles = bundleContext.getBundles();
Bundle testBundle = null;
for (int i = 0; i < bundles.length; i++) {
if ("org.eclipse.gemini.blueprint.iandt.lifecycle".equals(bundles[i].getSymbolicName())) {
testBundle = bundles[i];
break;
}
}
assertNotNull("Could not find the test bundle", testBundle);
StringBuilder filter = new StringBuilder();
filter.append("(&");
filter.append("(").append(Constants.OBJECTCLASS).append("=").append(ApplicationContext.class.getName()).append(")");
filter.append("(").append(ConfigurableOsgiBundleApplicationContext.APPLICATION_CONTEXT_SERVICE_PROPERTY_NAME);
filter.append("=").append(testBundle.getSymbolicName()).append(")");
filter.append(")");
logger.info("Creating filter = " + filter);
/*
[org.springframework.beans.factory.DisposableBean,
org.eclipse.gemini.blueprint.context.DelegatedExecutionOsgiBundleApplicationContext,
org.eclipse.gemini.blueprint.context.ConfigurableOsgiBundleApplicationContext,
org.springframework.context.ConfigurableApplicationContext,
org.springframework.context.ApplicationContext,
org.springframework.context.Lifecycle,
org.springframework.beans.factory.ListableBeanFactory,
org.springframework.beans.factory.HierarchicalBeanFactory,
org.springframework.context.MessageSource,
org.springframework.context.ApplicationEventPublisher,
org.springframework.core.io.support.ResourcePatternResolver,
org.springframework.beans.factory.BeanFactory,
org.springframework.core.io.ResourceLoader]
*/
// ServiceTracker tracker = new ServiceTracker(bundleContext, bundleContext.createFilter(filter.toString()), null);
// ServiceTracker tracker = new ServiceTracker(testBundle.getBundleContext(), testBundle.getBundleContext().createFilter(filter.toString()), null);
// tracker.open();
try {
// logger.info("All Services");
// ServiceReference[] refs = bundleContext.getAllServiceReferences(ApplicationContext.class.getName(), null);
// printServiceRefs(refs);
// logger.info("Visible Services from local context");
// refs = bundleContext.getServiceReferences(null, filter.toString());
// printServiceRefs(refs);
// logger.info("Visible Services from test client context");
// refs = testBundle.getBundleContext().getServiceReferences(null, filter.toString());
// printServiceRefs(refs);
//
// logger.info("tracking count = " + tracker.getTrackingCount());
// AbstractRefreshableApplicationContext appContext = (AbstractRefreshableApplicationContext) tracker.waitForService(50000);
// logger.info("tracking count = " + tracker.getTrackingCount());
// AbstractRefreshableApplicationContext appContext = (AbstractRefreshableApplicationContext) tracker.getService();
ServiceReference[] refs = bundleContext.getServiceReferences((String)null, filter.toString());
assertEquals("Should have a single service matched", 1, refs.length);
AbstractRefreshableApplicationContext appContext = (AbstractRefreshableApplicationContext)bundleContext.getService(refs[0]);
assertNotNull("test application context", appContext);
assertTrue("application context is active", appContext.isActive());
testBundle.stop();
while (testBundle.getState() == Bundle.STOPPING) {
Thread.sleep(10);
}
assertEquals("Guinea pig didn't shutdown", "true",
System.getProperty("org.eclipse.gemini.blueprint.iandt.lifecycle.GuineaPig.close"));
assertFalse("application context is inactive", appContext.isActive());
} finally {
// tracker.close();
}
}
示例12: testDependencies
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
public void testDependencies() throws Exception {
// Simple Service bundle (provides the base package + 1 service)
Bundle simpleServiceBundle = bundleContext.installBundle(getLocator().locateArtifact(
"org.eclipse.gemini.blueprint.iandt", "simple.service", getSpringDMVersion()).getURL().toExternalForm());
assertNotNull("Cannot find the simple service bundle", simpleServiceBundle);
assertNotSame("simple service bundle is in the activated state!", new Integer(Bundle.ACTIVE), new Integer(
simpleServiceBundle.getState()));
startDependency(simpleServiceBundle);
// Identical Simple Service bundle (+1 service)
Bundle simpleServiceDuplicateBundle = bundleContext.installBundle(getLocator().locateArtifact(
"org.eclipse.gemini.blueprint.iandt", "simple.service.identical", getSpringDMVersion()).getURL().toExternalForm());
assertNotNull("Cannot find the simple service duplicate bundle", simpleServiceDuplicateBundle);
assertNotSame("simple service 2 bundle is in the activated state!", new Integer(Bundle.ACTIVE), new Integer(
simpleServiceDuplicateBundle.getState()));
startDependency(simpleServiceDuplicateBundle);
ServiceReference[] refs = bundleContext.getServiceReferences(DEPENDENT_CLASS_NAME, null);
assertEquals(2, refs.length);
MyService service1 = (MyService) bundleContext.getService(refs[0]);
MyService service2 = (MyService) bundleContext.getService(refs[1]);
assertNotNull(service1);
assertNotNull(service2);
String msg1 = service1.stringValue();
String msg2 = service2.stringValue();
String jmsg = "Bond. James Bond.";
String cmsg = "Connery. Sean Connery #1";
System.out.println(msg1);
System.out.println(msg2);
assertNotSame(msg1, msg2);
assertTrue(msg1.equals(jmsg) || msg1.equals(cmsg));
assertTrue(msg2.equals(jmsg) || msg2.equals(cmsg));
bundleContext.ungetService(refs[0]);
bundleContext.ungetService(refs[1]);
// Uninstall duplicate 1
simpleServiceDuplicateBundle.uninstall();
// stop base bundle so that the package is still around but its service
// is not
simpleServiceBundle.stop();
// Install something subtley different
simpleServiceDuplicateBundle = bundleContext.installBundle(getLocator().locateArtifact(
"org.eclipse.gemini.blueprint.iandt", "simple.service.2.identical", getSpringDMVersion()).getURL().toExternalForm());
assertNotNull("Cannot find the simple service duplicate 2 bundle", simpleServiceDuplicateBundle);
startDependency(simpleServiceDuplicateBundle);
refs = bundleContext.getServiceReferences(DEPENDENT_CLASS_NAME, null);
assertEquals(1, refs.length);
service1 = (MyService) bundleContext.getService(refs[0]);
assertNotNull(service1);
msg1 = service1.stringValue();
System.out.println(msg1);
assertTrue(msg1.equals("Dalton. Timothy Dalton #1"));
}
示例13: onTearDown
import org.osgi.framework.Bundle; //导入方法依赖的package包/类
protected void onTearDown() throws Exception {
Bundle bnd = getDependencyBundle();
bnd.stop();
OsgiServiceUtils.unregisterService(mandatory);
OsgiServiceUtils.unregisterService(optional);
}