本文整理汇总了Java中org.osgi.util.tracker.ServiceTracker.open方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceTracker.open方法的具体用法?Java ServiceTracker.open怎么用?Java ServiceTracker.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.osgi.util.tracker.ServiceTracker
的用法示例。
在下文中一共展示了ServiceTracker.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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");
}
}
示例2: 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;
}
示例3: 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;
}
示例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();
}
示例5: 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;
}
示例6: 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();
}
}
}
示例7: createServiceTracker
import org.osgi.util.tracker.ServiceTracker; //导入方法依赖的package包/类
public synchronized ServiceTracker createServiceTracker(final Class<?> c) {
ServiceTracker serviceTracker = new ServiceTracker(context, c.getName(), null);
serviceTracker.open();
long s = System.currentTimeMillis();
while (serviceTracker.getService() == null) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {}
if (System.currentTimeMillis() - s > 5000) {
if (serviceTracker.getService() == null) {
System.err.println(c.getName() + " 서비스를 사용 할 수 없습니다.");
}
break;
}
}
return serviceTracker;
}
示例8: check
import org.osgi.util.tracker.ServiceTracker; //导入方法依赖的package包/类
/**
* Check, and if needed, construct a service tracker for a specific object given a specific filter.
*
* @param current The current service tracker provider. May result to a null value
* @param clz The tracker class
* @param setter The setter to store the tracker back
*/
private static <T> void check(Supplier<ServiceTracker<T, T>> current, Class<T> clz,
Consumer<ServiceTracker<T, T>> setter) {
ServiceTracker<T, T> thisTracker = current.get();
if (thisTracker == null) {
final BundleContext bundleContext = FacesHelper.context();
if (bundleContext != null) {
String filterSpec = FacesHelper.getFilter();
String filter = "(" + Constants.OBJECTCLASS + "=" + clz.getName() + ")";
if (filterSpec != null) {
filter = "(&" + filter + filterSpec + ")";
}
try {
thisTracker = new ServiceTracker<>(bundleContext,
FrameworkUtil.createFilter(filter), null);
thisTracker.open();
} catch (Exception exc) {
exc.printStackTrace();
}
setter.accept(thisTracker);
}
}
}
示例9: 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();
}
示例10: testExtendedLogReaderServiceAvailable
import org.osgi.util.tracker.ServiceTracker; //导入方法依赖的package包/类
public void testExtendedLogReaderServiceAvailable() throws Exception {
Framework f = IntegrationTest.findFramework();
BundleContext bc = f.getBundleContext();
ServiceTracker logReaderTracker = new ServiceTracker(bc, ExtendedLogReaderService.class.getName(), null);
logReaderTracker.open();
LogReaderService logReader = (ExtendedLogReaderService) logReaderTracker.getService();
assertNotNull(logReader);
}
示例11: 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();
}
}
示例12: Activator
import org.osgi.util.tracker.ServiceTracker; //导入方法依赖的package包/类
/**
* The constructor
*/
public Activator() {
proxyTracker = new ServiceTracker(FrameworkUtil.getBundle(
this.getClass()).getBundleContext(),
IProxyService.class.getName(), null);
proxyTracker.open();
}
示例13: create
import org.osgi.util.tracker.ServiceTracker; //导入方法依赖的package包/类
/**
* Creates an instance.
*
* @param serviceInterface
* the service interface
* @param context
* the BundleContext
* @param filter
* the OSGi service filter
* @return new WaitingServiceTracker instance
*/
public static <T> WaitingServiceTracker<T> create(@Nonnull final Class<T> serviceInterface,
@Nonnull final BundleContext context, @Nonnull final String filter) {
String newFilter = String.format("(&(%s=%s)%s)", Constants.OBJECTCLASS, serviceInterface.getName(), filter);
try {
ServiceTracker<T, ?> tracker = new ServiceTracker<>(context, context.createFilter(newFilter), null);
tracker.open();
return new WaitingServiceTracker<>(serviceInterface, tracker);
} catch (final InvalidSyntaxException e) {
throw new IllegalArgumentException(String.format("Invalid OSGi filter %s", newFilter), e);
}
}
示例14: trackService
import org.osgi.util.tracker.ServiceTracker; //导入方法依赖的package包/类
private void trackService(BundleContext bc) {
ServiceTracker serviceTracker = new ServiceTracker(bc, "oog.common.OGraphFacade", null);
// Be sure to call open() before getService()
serviceTracker.open();
Object service = serviceTracker.getService();
if(service instanceof OGraphFacade) {
facade = (OGraphFacade) service;
}
// Service not yet registered, so register it!
else {
registerService(bc);
}
}
示例15: addingService
import org.osgi.util.tracker.ServiceTracker; //导入方法依赖的package包/类
@Override
public Collection<ServiceTracker<?, ?>>
addingService(ServiceReference<Bus> serviceReference) {
Bus bus = _bundleContext.getService(serviceReference);
try {
ServiceTracker<Application,?> applicationTracker =
new ServiceTracker<>(_bundleContext, getApplicationFilter(),
new ApplicationServiceTrackerCustomizer(
_bundleContext, bus));
applicationTracker.open();
ServiceTracker<Object, ?> singletonsServiceTracker =
new ServiceTracker<>(_bundleContext, getSingletonsFilter(),
new SingletonServiceTrackerCustomizer(_bundleContext, bus));
singletonsServiceTracker.open();
ServiceTracker<Object, ?> filtersAndInterceptorsServiceTracker =
new ServiceTracker<>(_bundleContext, getFiltersFilter(),
new FiltersAndInterceptorsServiceTrackerCustomizer(
_bundleContext));
filtersAndInterceptorsServiceTracker.open();
return Arrays.asList(applicationTracker, singletonsServiceTracker,
filtersAndInterceptorsServiceTracker);
}
catch (InvalidSyntaxException ise) {
throw new RuntimeException(ise);
}
catch (Exception e) {
_bundleContext.ungetService(serviceReference);
throw e;
}
}