use of cucumber.api.osgi.ServiceNotFoundException in project cucumber-jvm by cucumber.
the class OsgiObjectFactory method getService.
private Object getService(Class<?> type, long timeout, String filter) {
final String serviceName = type.getName() + " " + filter;
try {
final long tryUntil = System.currentTimeMillis() + timeout;
Object service = null;
search: while (service == null) {
final Collection<?> serviceReferences = bundleContext.getServiceReferences(type, filter.isEmpty() ? null : filter);
for (Object serviceReference : serviceReferences) {
service = bundleContext.getService((ServiceReference<?>) serviceReference);
break search;
}
if (tryUntil < System.currentTimeMillis())
break;
Thread.sleep(20);
}
if (service == null)
throw new ServiceNotFoundException(serviceName);
return service;
} catch (InvalidSyntaxException e) {
throw new IllegalArgumentException(e);
} catch (InterruptedException e) {
throw new TimeoutException(serviceName);
}
}
Aggregations