當前位置: 首頁>>代碼示例>>Java>>正文


Java Bundle.stop方法代碼示例

本文整理匯總了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();
		}
	}
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:24,代碼來源:ProjectBundleLoader.java

示例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();
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:10,代碼來源:CollectionImporterTest.java

示例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);
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:23,代碼來源:MultipleExportersDependingOnOneImporterTest.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:Netigso.java

示例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]);
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:39,代碼來源:CallingResourceOnDifferentBundlesTest.java

示例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()));
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:28,代碼來源:MultipleExportersDependingOnOneImporterTest.java

示例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);
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:30,代碼來源:ServiceListenerTest.java

示例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);
	}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:34,代碼來源:SyncWaitWithoutDependencyTest.java

示例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());
	}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:39,代碼來源:ReferenceProxyTest.java

示例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;
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:14,代碼來源:BlueprintShutdownSorterTest.java

示例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();
        }
    }
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:82,代碼來源:LifecycleTest.java

示例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"));
	}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:69,代碼來源:DuplicateClassTest.java

示例13: onTearDown

import org.osgi.framework.Bundle; //導入方法依賴的package包/類
protected void onTearDown() throws Exception {
	Bundle bnd = getDependencyBundle();
	bnd.stop();
	OsgiServiceUtils.unregisterService(mandatory);
	OsgiServiceUtils.unregisterService(optional);
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:7,代碼來源:ExporterWithOptionalAndMandatoryImportersTest.java


注:本文中的org.osgi.framework.Bundle.stop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。