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


Java ServiceTracker.close方法代碼示例

本文整理匯總了Java中org.osgi.util.tracker.ServiceTracker.close方法的典型用法代碼示例。如果您正苦於以下問題:Java ServiceTracker.close方法的具體用法?Java ServiceTracker.close怎麽用?Java ServiceTracker.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.osgi.util.tracker.ServiceTracker的用法示例。


在下文中一共展示了ServiceTracker.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: close

import org.osgi.util.tracker.ServiceTracker; //導入方法依賴的package包/類
public void close() {
	boolean unregister = false;
	ServiceTracker<?, ?> toClose;
	synchronized (this) {
		closed = true;
		unregister = true;
		toClose = tracker;
	}
	
	if(unregister) {
		try {
			configReg.unregister();
		} catch (Exception e) {
			LOGGER.debug("Exception on unregister", e);
		}
	}
	
	if (toClose != null) {
		toClose.close();
	}
	
	closeEMF();
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:24,代碼來源:AriesEntityManagerFactoryBuilder.java

示例2: getService

import org.osgi.util.tracker.ServiceTracker; //導入方法依賴的package包/類
/**
 * Looks up an OSGi service. If the service is not yet available, this method will wait for 60 seconds for the service to become available. If the service
 * does not appear in this period, a ServiceException is thrown.
 *
 * @param serviceClass
 *            The service interface of the service to look up
 * @param timeoutInMillis
 *            The amount of time in milliseconds to wait for the service to become available
 * @return an implementation of the given service interface
 * @throws a
 *             ServiceException, if the service couldn't be found in the OSGi service registry
 */
public static <T> T getService(Class<T> serviceClass, long timeoutInMillis) {
    BundleContext ctx = FrameworkUtil.getBundle(ServiceUtil.class).getBundleContext();
    ServiceTracker<T, T> tracker = new ServiceTracker<>(ctx, serviceClass, null);
    tracker.open();
    T service = null;
    try {
        service = tracker.waitForService(timeoutInMillis);
    } catch (InterruptedException e) {
        throw new ServiceException("Interrupted while waiting for the service " + serviceClass.getName(), e);
    }

    tracker.close();
    if (service != null) {
        return service;
    } else {
        throw new ServiceException("Service " + serviceClass.getName() + " not available");
    }
}
 
開發者ID:VisuFlow,項目名稱:visuflow-plugin,代碼行數:31,代碼來源:ServiceUtil.java

示例3: getRegions

import org.osgi.util.tracker.ServiceTracker; //導入方法依賴的package包/類
public static List<Region> getRegions() {
	BundleContext bundleContext = FrameworkUtil.getBundle(
		UseJNDI.class).getBundleContext();

	ServiceTracker<RegionLocalService, RegionLocalService> tracker =
		new ServiceTracker<>(bundleContext, RegionLocalService.class, null);

	tracker.open();

	RegionLocalService regionLocalService = tracker.getService();

	try {
		List<Region> regions = regionLocalService.getRegions(
			0, getRegionsCount());

		return regions;
	}
	catch (Exception e) {
		e.printStackTrace();
	}

	tracker.close();

	return null;
}
 
開發者ID:liferay,項目名稱:liferay-blade-samples,代碼行數:26,代碼來源:UseJNDI.java

示例4: useJNDI

import org.osgi.util.tracker.ServiceTracker; //導入方法依賴的package包/類
public static void useJNDI() {
	BundleContext bundleContext = FrameworkUtil.getBundle(
		UseJNDI.class).getBundleContext();

	ServiceTracker<RegionLocalService, RegionLocalService> tracker =
		new ServiceTracker<>(bundleContext, RegionLocalService.class, null);

	tracker.open();

	RegionLocalService regionLocalService = tracker.getService();

	try {
		regionLocalService.useJNDI();
	}
	catch (Exception e) {
		e.printStackTrace();
	}

	tracker.close();
}
 
開發者ID:liferay,項目名稱:liferay-blade-samples,代碼行數:21,代碼來源:UseJNDI.java

示例5: getCountries

import org.osgi.util.tracker.ServiceTracker; //導入方法依賴的package包/類
public static List<Country> getCountries() {
	BundleContext bundleContext = FrameworkUtil.getBundle(
		UseJDBC.class).getBundleContext();

	ServiceTracker<CountryLocalService, CountryLocalService> tracker =
		new ServiceTracker<>(
			bundleContext, CountryLocalService.class, null);

	tracker.open();

	CountryLocalService countryLocalService = tracker.getService();

	try {
		List<Country> countries = countryLocalService.getCountries(
			0, getCountriesCount());

		return countries;
	}
	catch (Exception e) {
		e.printStackTrace();
	}

	tracker.close();

	return null;
}
 
開發者ID:liferay,項目名稱:liferay-blade-samples,代碼行數:27,代碼來源:UseJDBC.java

示例6: getCountriesCount

import org.osgi.util.tracker.ServiceTracker; //導入方法依賴的package包/類
public static int getCountriesCount() {
	BundleContext bundleContext = FrameworkUtil.getBundle(
		UseJDBC.class).getBundleContext();

	ServiceTracker<CountryLocalService, CountryLocalService> tracker =
		new ServiceTracker<>(
			bundleContext, CountryLocalService.class, null);

	tracker.open();

	CountryLocalService countryLocalService = tracker.getService();

	try {
		int regionsCount = countryLocalService.getCountriesCount();

		return regionsCount;
	}
	catch (Exception e) {
		e.printStackTrace();
	}

	tracker.close();

	return 0;
}
 
開發者ID:liferay,項目名稱:liferay-blade-samples,代碼行數:26,代碼來源:UseJDBC.java

示例7: useJDBC

import org.osgi.util.tracker.ServiceTracker; //導入方法依賴的package包/類
public static void useJDBC() {
	BundleContext bundleContext = FrameworkUtil.getBundle(
		UseJDBC.class).getBundleContext();

	ServiceTracker<CountryLocalService, CountryLocalService> tracker =
		new ServiceTracker<>(
			bundleContext, CountryLocalService.class, null);

	tracker.open();

	CountryLocalService countryLocalService = tracker.getService();

	try {
		countryLocalService.useJDBC();
	}
	catch (Exception e) {
		e.printStackTrace();
	}

	tracker.close();
}
 
開發者ID:liferay,項目名稱:liferay-blade-samples,代碼行數:22,代碼來源:UseJDBC.java

示例8: getRegionsCount

import org.osgi.util.tracker.ServiceTracker; //導入方法依賴的package包/類
public static int getRegionsCount() {
	BundleContext bundleContext = FrameworkUtil.getBundle(
		UseJNDI.class).getBundleContext();

	ServiceTracker<RegionLocalService, RegionLocalService> tracker =
		new ServiceTracker<>(bundleContext, RegionLocalService.class, null);

	tracker.open();

	RegionLocalService regionLocalService = tracker.getService();

	try {
		int regionsCount = regionLocalService.getRegionsCount();

		return regionsCount;
	}
	catch (Exception e) {
		e.printStackTrace();
	}

	tracker.close();

	return 0;
}
 
開發者ID:liferay,項目名稱:liferay-blade-samples,代碼行數:25,代碼來源:UseJNDI.java

示例9: installNexusEdition

import org.osgi.util.tracker.ServiceTracker; //導入方法依賴的package包/類
private static void installNexusEdition(final BundleContext ctx, @Nullable final String editionName)
    throws Exception
{
  if (editionName != null && editionName.length() > 0) {
    final ServiceTracker<?, FeaturesService> tracker = new ServiceTracker<>(ctx, FeaturesService.class, null);
    tracker.open();
    try {
      FeaturesService featuresService = tracker.waitForService(1000);
      Feature editionFeature = featuresService.getFeature(editionName);

      log.info("Installing: {}", editionFeature);

      // edition might already be installed in the cache; if so then skip installation
      if (!featuresService.isInstalled(editionFeature)) {
        // avoid auto-refreshing bundles as that could trigger unwanted restart/lifecycle events
        EnumSet<Option> options = EnumSet.of(NoAutoRefreshBundles, NoAutoRefreshManagedBundles);
        featuresService.installFeature(editionFeature.getId(), options);
      }

      log.info("Installed: {}", editionFeature);
    }
    finally {
      tracker.close();
    }
  }
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:27,代碼來源:BootstrapListener.java

示例10: waitForService

import org.osgi.util.tracker.ServiceTracker; //導入方法依賴的package包/類
/**
 * Wait for an OSGi service to become active.
 *
 * @param serviceImpl The service implementation class
 * @param timeout The length of time to wait for the service
 */
private void waitForService(Class serviceImpl, long timeout) {
    Class serviceInterface = serviceImpl.getInterfaces()[0];
    BundleContext bundleContext = FrameworkUtil.getBundle(serviceInterface).getBundleContext();
    ServiceReference factoryRef = bundleContext.getServiceReference(serviceInterface.getName());

    ServiceTracker serviceTracker = new ServiceTracker(bundleContext, factoryRef, null);
    serviceTracker.open();

    try {
        serviceTracker.waitForService(timeout);
    } catch (InterruptedException e) {
        LOGGER.error("Could not get service", e);
    }

    serviceTracker.close();
}
 
開發者ID:nateyolles,項目名稱:publick-sling-blog,代碼行數:23,代碼來源:OsgiConfigurationServiceImpl.java

示例11: unbindRegistry

import org.osgi.util.tracker.ServiceTracker; //導入方法依賴的package包/類
private synchronized void unbindRegistry(Registry service) {
  ServiceTracker tracker = trackers.remove(service);
  if (tracker != null) {
    tracker.close();
  }

  RegistryWatcher watcher = watchers.remove(service);
  if (watcher != null) {
    watcher.destroy();
  }

  ServiceRegistration[] regs = serviceRegs.remove(service);
  if (regs != null) {
    for (ServiceRegistration reg : regs) {
      reg.unregister();
    }
  }
}
 
開發者ID:mcculls,項目名稱:osgi-in-action,代碼行數:19,代碼來源:Activator.java

示例12: shutdown

import org.osgi.util.tracker.ServiceTracker; //導入方法依賴的package包/類
public static void shutdown() {
    ServiceTracker<?, ?> toClose;
    synchronized (HibernateUtil.class) {
        toClose = tracker;
        tracker = null;
    }
    if(toClose != null) {
        toClose.close();
    }
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:11,代碼來源:HibernateUtil.java

示例13: testErrorHandling

import org.osgi.util.tracker.ServiceTracker; //導入方法依賴的package包/類
/**
 * While it may appear that this test is doing nothing, what it is doing is
 * testing what happens when the OSGi framework is shutdown while the
 * Spring/OSGi extender is deadlocked. If all goes well, the test will
 * gracefully end. If not, it will hang for quite a while.
 */
public void testErrorHandling() throws Exception {
	Resource errorResource = getLocator().locateArtifact("org.eclipse.gemini.blueprint.iandt", "deadlock",
		getSpringDMVersion());
	assertNotNull("bundle resource exists", errorResource);
	Bundle errorBundle = bundleContext.installBundle(errorResource.getURL().toExternalForm());
	assertNotNull("bundle exists", errorBundle);
	errorBundle.start();
	StringBuilder filter = new StringBuilder();

	filter.append("(&");
	filter.append("(").append(Constants.OBJECTCLASS).append("=").append(
		AbstractRefreshableApplicationContext.class.getName()).append(")");
	filter.append("(").append(ConfigurableOsgiBundleApplicationContext.APPLICATION_CONTEXT_SERVICE_PROPERTY_NAME);
	filter.append("=").append("org.eclipse.gemini.blueprint.iandt.deadlock").append(")");
	filter.append(")");
	ServiceTracker tracker = new ServiceTracker(bundleContext, bundleContext.createFilter(filter.toString()), null);

	try {
		tracker.open();

		AbstractRefreshableApplicationContext appContext = (AbstractRefreshableApplicationContext) tracker.waitForService(3000);
		assertNull("Deadlock context should not be published", appContext);
	}
	finally {
		tracker.close();
	}
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:34,代碼來源:DeadlockHandlingTest.java

示例14: removedService

import org.osgi.util.tracker.ServiceTracker; //導入方法依賴的package包/類
@Override
public void removedService(
	ServiceReference<Object> reference,
	ServiceTracker<CXFJaxRsServiceRegistrator, ?> serviceTracker) {

	serviceTracker.close();

	_bundleContext.ungetService(reference);
}
 
開發者ID:csierra,項目名稱:osgi-jaxrs-extracted,代碼行數:10,代碼來源:ServicesServiceTrackerCustomizer.java

示例15: removedService

import org.osgi.util.tracker.ServiceTracker; //導入方法依賴的package包/類
@Override
public void removedService(
	ServiceReference<Bus> serviceReference,
	Collection<ServiceTracker<?, ?>> serviceTrackers) {

	_bundleContext.ungetService(serviceReference);

	for (ServiceTracker<?, ?> serviceTracker : serviceTrackers) {
		serviceTracker.close();
	}
}
 
開發者ID:csierra,項目名稱:osgi-jaxrs-extracted,代碼行數:12,代碼來源:BusServiceTrackerCustomizer.java


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