本文整理汇总了Java中org.osgi.util.tracker.ServiceTracker.getService方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceTracker.getService方法的具体用法?Java ServiceTracker.getService怎么用?Java ServiceTracker.getService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.osgi.util.tracker.ServiceTracker
的用法示例。
在下文中一共展示了ServiceTracker.getService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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();
}
示例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: 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);
}
示例5: 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();
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: 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);
}
示例10: logInternal
import org.osgi.util.tracker.ServiceTracker; //导入方法依赖的package包/类
private static void logInternal(int level, String msg, Throwable ex) {
boolean failedToGetLog = false;
try {
ServiceTracker<ExtendedLogService, ExtendedLogService> logTracker
= Activator.getLogTracker();
if (logTracker == null) {
failedToGetLog = true;
throw new IllegalStateException("logTracker is null");
}
ExtendedLogService logService = logTracker.getService();
if (logService == null) {
failedToGetLog = true;
throw new IllegalStateException("logService is null");
}
Logger logger = logService.getLogger(EQUINOX_LOGGER);
if (logger == null) {
failedToGetLog = true;
throw new IllegalStateException("logger is null");
}
logger.log(level, msg, ex);
} catch (Exception exLog) {
if (failedToGetLog) {
System.err.println("LogService not found! Logging to stdout.");
} else {
System.err.println("ERROR while trying to log!");
exLog.printStackTrace(System.err);
}
System.err.println("Attempted to log:");
System.err.println("Message: " + msg);
System.err.println("Exception: ");
if (ex != null) {
ex.printStackTrace(System.err);
}
System.err.println();
}
}
示例11: activate
import org.osgi.util.tracker.ServiceTracker; //导入方法依赖的package包/类
@Activate
void activate(BundleContext bundleContext) {
ServiceTracker logServiceTracker = new ServiceTracker(bundleContext, LogService.class.getName(), null);
logServiceTracker.open();
LogService logService = (LogService) logServiceTracker.getService();
if(logService != null)
logService.log(LogService.LOG_INFO, "[" + this.getClass().getName() + "] Testing the logServiceWritter!");
}
示例12: activate
import org.osgi.util.tracker.ServiceTracker; //导入方法依赖的package包/类
@Activate
void activate(BundleContext bundleContext) {
ServiceTracker logServiceTracker = new ServiceTracker(bundleContext, LogService.class.getName(), null);
logServiceTracker.open();
LogService logService = (LogService) logServiceTracker.getService();
ServiceReference ref = bundleContext.getServiceReference(org.osgi.service.log.LogReaderService.class.getName());
if (ref != null)
{
org.osgi.service.log.LogReaderService reader = (org.osgi.service.log.LogReaderService)bundleContext.getService(ref);
reader.addLogListener(new LogListenerImpl(logService));
}
}
示例13: 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;
}
}
示例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) {
// MotherFacade.setInstance((OGraphFacade) service);
}
}
示例15: getNotNull
import org.osgi.util.tracker.ServiceTracker; //导入方法依赖的package包/类
public static <S, T> T getNotNull(ServiceTracker<S, T> serviceTracker) {
T service = serviceTracker.getService();
if (service == null)
throw new IllegalStateException("Service is null");
return service;
}