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


Java ServiceTracker.open方法代碼示例

本文整理匯總了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");
    }
}
 
開發者ID:VisuFlow,項目名稱:visuflow-plugin,代碼行數:31,代碼來源:ServiceUtil.java

示例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;
}
 
開發者ID:liferay,項目名稱:liferay-blade-samples,代碼行數:25,代碼來源:UseJNDI.java

示例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;
}
 
開發者ID:liferay,項目名稱:liferay-blade-samples,代碼行數:27,代碼來源:UseJDBC.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: 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

示例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();
    }
  }
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:27,代碼來源:BootstrapListener.java

示例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;
}
 
開發者ID:SK-HOLDINGS-CC,項目名稱:NEXCORE-UML-Modeler,代碼行數:20,代碼來源:Activator.java

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

示例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();
}
 
開發者ID:nateyolles,項目名稱:publick-sling-blog,代碼行數:23,代碼來源:OsgiConfigurationServiceImpl.java

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

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

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

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

示例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);
}

  }
 
開發者ID:aroog,項目名稱:code,代碼行數:16,代碼來源:Activator.java

示例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;
	}
}
 
開發者ID:csierra,項目名稱:osgi-jaxrs-extracted,代碼行數:40,代碼來源:BusServiceTrackerCustomizer.java


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