当前位置: 首页>>代码示例>>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;未经允许,请勿转载。