本文整理匯總了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;
}