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


Java ServiceTracker類代碼示例

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


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

示例1: start

import org.osgi.util.tracker.ServiceTracker; //導入依賴的package包/類
@Override
public void start(BundleContext context) throws Exception {
    randomNumberServiceTracker = new ServiceTracker<>(context, RandomNumberGenerator.class.getName(), null);
    randomNumberServiceTracker.open();
    serviceReference = randomNumberServiceTracker.getServiceReference();
    if (serviceReference != null) {
        final RandomNumberGenerator service = context.getService(serviceReference);
        if (service != null) {
            log.info("############ tracked random: {} with service {}", service.generateNumber(), service);
        } else {
            log.info("############# no tracked random because service is null");
        }
    } else {
        log.info("############# no tracked random because serviceReference is null");
    }

}
 
開發者ID:L7R7,項目名稱:magic-bundle,代碼行數:18,代碼來源:Activator.java

示例2: createDataSourceTracker

import org.osgi.util.tracker.ServiceTracker; //導入依賴的package包/類
private ServiceTracker<?, ?> createDataSourceTracker(PersistenceProvider provider) {
     if (usesDataSource()) {
     	synchronized (this) {
	driver = "Pre Configured DataSource";
}
         if (!usesDataSourceService()) {
             LOGGER.warn("Persistence unit " + persistenceUnit.getPersistenceUnitName() + " refers to a non OSGi service DataSource");
             return null;
         }
         DataSourceTracker dsTracker = new DataSourceTracker(containerContext, this, 
         		DataSourceTracker.getDsName(persistenceUnit));
         return dsTracker;
     } else if (usesDSF()) {
     	String jdbcClass = DSFTracker.getDriverName(persistenceUnit);
     	synchronized (this) {
	driver = jdbcClass;
}
DSFTracker dsfTracker = new DSFTracker(containerContext, this, 
         		jdbcClass);
         return dsfTracker;
     } else {
         LOGGER.debug("Persistence unit " + getPUName() + " does not refer a DataSource. "
                      +"It can only be used with EntityManagerFactoryBuilder.");
         return null;
     }
 }
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:27,代碼來源:AriesEntityManagerFactoryBuilder.java

示例3: 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

示例4: ManualHandlerImpl

import org.osgi.util.tracker.ServiceTracker; //導入依賴的package包/類
public ManualHandlerImpl ( final String configurationId, final EventProcessor eventProcessor, final ObjectPoolTracker<MasterItem> poolTracker, final int priority, final ServiceTracker<ConfigurationAdministrator, ConfigurationAdministrator> caTracker )
{
    super ( configurationId, poolTracker, priority, caTracker, ManualHandlerFactoryImpl.FACTORY_ID, ManualHandlerFactoryImpl.FACTORY_ID );
    this.id = configurationId;
    this.eventProcessor = eventProcessor;

    this.attrActive = getPrefixed ( "active", Activator.getStringInterner () ); //$NON-NLS-1$
    this.attrUser = getPrefixed ( "user", Activator.getStringInterner () ); //$NON-NLS-1$
    this.attrReason = getPrefixed ( "reason", Activator.getStringInterner () ); //$NON-NLS-1$
    this.attrValue = getPrefixed ( "value", Activator.getStringInterner () ); //$NON-NLS-1$

    this.attrValueOriginal = getPrefixed ( "value.original", Activator.getStringInterner () ); //$NON-NLS-1$
    this.attrErrorOriginal = getPrefixed ( "error.original", Activator.getStringInterner () ); //$NON-NLS-1$
    this.attrTimestampOriginal = getPrefixed ( "timestamp.original", Activator.getStringInterner () ); //$NON-NLS-1$

    this.attrErrorCountOriginal = getPrefixed ( "error.count.original", Activator.getStringInterner () ); //$NON-NLS-1$
    this.attrErrorItemsOriginal = getPrefixed ( "error.items.original", Activator.getStringInterner () ); //$NON-NLS-1$
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:19,代碼來源:ManualHandlerImpl.java

示例5: ScriptMonitor

import org.osgi.util.tracker.ServiceTracker; //導入依賴的package包/類
public ScriptMonitor ( final String id, final String factoryId, final Executor executor, final BundleContext context, final Interner<String> stringInterner, final EventProcessor eventProcessor, final ObjectPoolTracker<DataSource> dataSourcePoolTracker, final ObjectPoolTracker<MasterItem> masterItemPoolTracker, final ServiceTracker<ConfigurationAdministrator, ConfigurationAdministrator> caTracker )
{
    super ( id, factoryId, executor, context, stringInterner, eventProcessor );
    this.executor = executor;

    this.prefix = stringInterner.intern ( factoryId + ". " + id ); //$NON-NLS-1$

    this.classLoader = getClass ().getClassLoader ();

    this.monitorStateInjector = new MonitorStateInjector ( stringInterner );
    this.monitorStateInjector.setPrefix ( this.prefix );

    this.handler = new InjectMasterHandler ( id, masterItemPoolTracker, 0, caTracker, this.prefix, factoryId );
    this.listener = new MultiDataSourceListener ( dataSourcePoolTracker ) {

        @Override
        protected void handleChange ( final Map<String, DataSourceHandler> sources )
        {
            ScriptMonitor.this.handleChange ( sources );
        }
    };
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:23,代碼來源:ScriptMonitor.java

示例6: before

import org.osgi.util.tracker.ServiceTracker; //導入依賴的package包/類
@Before
public void before() throws Exception {
    assertAllBundlesResolved();

    // Track ArtifactInstaller service ONLY from bundle org.osc.installer
    Bundle installerBundle = findBundle("osc-installer");
    Filter artifactInstallerTrackerFilter = FrameworkUtil.createFilter(String.format("(&(objectClass=%s)(service.bundleid=%d))", ArtifactInstaller.class.getName(), installerBundle.getBundleId()));
    this.artifactInstallerTracker = new ServiceTracker<>(this.bundleContext, artifactInstallerTrackerFilter, null);
    this.artifactInstallerTracker.open();

    // Wait up to 5 seconds for ArtifactInstaller to appear
    ArtifactInstaller artifactInstaller = this.artifactInstallerTracker.waitForService(5000);
    if (artifactInstaller == null) {
        fail("ArtifactInstaller service not available within 5 seconds");
    }

    this.fwkInstallerTracker = new ServiceTracker<>(this.bundleContext, FrameworkInstaller.class, null);
    this.fwkInstallerTracker.open();
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:20,代碼來源:InstallerIntegrationTest.java

示例7: 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

示例8: testWrap

import org.osgi.util.tracker.ServiceTracker; //導入依賴的package包/類
@Test
public void testWrap() throws Exception {
    final ServiceRegistration<?> serviceReg = mockServiceRegistration();
    OsgiRegistrationUtil.wrap(serviceReg).close();
    verify(serviceReg).unregister();

    final BundleTracker<?> tracker = mock(BundleTracker.class);
    doNothing().when(tracker).close();
    OsgiRegistrationUtil.wrap(tracker).close();
    verify(tracker).close();

    final ServiceTracker<?, ?> sTracker = mock(ServiceTracker.class);
    doNothing().when(sTracker).close();
    OsgiRegistrationUtil.wrap(sTracker).close();
    verify(sTracker).close();
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:17,代碼來源:OsgiRegistrationUtilTest.java

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: getHTTPClientFactory

import org.osgi.util.tracker.ServiceTracker; //導入依賴的package包/類
@Override
public HTTPClientFactory getHTTPClientFactory(final ConnectionInstanceData instanceData) {
    final ServiceTracker proxyServiceTracker = TFSCommonUIClientPlugin.getDefault().getProxyServiceTracker();

    if (proxyServiceTracker.getService() != null) {
        if (log.isDebugEnabled()) {
            log.debug("IProxyService is available, returning an EclipseHttpClientFactory"); //$NON-NLS-1$
        }

        return new ProxyServiceHTTPClientFactory(instanceData, proxyServiceTracker);
    }

    if (log.isDebugEnabled()) {
        log.debug("IProxyService is not available, returning a LegacyHttpClientFactory"); //$NON-NLS-1$
    }

    return new LegacyHTTPClientFactory(instanceData);
}
 
開發者ID:Microsoft,項目名稱:team-explorer-everywhere,代碼行數:19,代碼來源:UIClientConnectionAdvisor.java


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