public static <T> T findService(Class<T> serviceClass) { Iterator<T> services = ServiceLoader.load(serviceClass, serviceClass.getClassLoader()).iterator(); while (services.hasNext()) { try { return services.next(); } catch (ServiceConfigurationError e) { logger.log(Level.DEBUG, e.getLocalizedMessage()); } } return null; }
public static <T> T findService(Class<T> serviceClass, Matcher<T> matcher) { List<T> matches = new LinkedList<>(); Iterator<T> services = ServiceLoader.load(serviceClass, serviceClass.getClassLoader()).iterator(); while (services.hasNext()) { try { T service = services.next(); if (matcher.matches(service)) { matches.add(service); } } catch (ServiceConfigurationError e) { logger.log(Level.DEBUG, e.getLocalizedMessage()); } } if (matches.size() > 1) { logger.log(Level.WARN, messages.multipleServicesFound(serviceClass, matcher, matches)); } return !matches.isEmpty() ? matches.get(0) : null; }
public boolean hasNext() { try { return iterator.hasNext(); } catch(ServiceConfigurationError sce) { log.error("proc.bad.config.file", sce.getLocalizedMessage()); throw new Abort(sce); } catch (Throwable t) { throw new Abort(t); } }
public boolean hasNext() { try { return iterator.hasNext(); } catch(ServiceConfigurationError sce) { log.error("proc.bad.config.file", sce.getLocalizedMessage()); throw new Abort(sce); } catch (Throwable t) { throw new Abort(t); } }
public Processor next() { try { return iterator.next(); } catch (ServiceConfigurationError sce) { log.error("proc.bad.config.file", sce.getLocalizedMessage()); throw new Abort(sce); } catch (Throwable t) { throw new Abort(t); } }
public Processor next() { try { return iterator.next(); } catch (ServiceConfigurationError sce) { log.error("proc.bad.config.file", sce.getLocalizedMessage()); throw new Abort(sce); } catch (Throwable t) { throw new Abort(t); } }
/** * Loads commands via {@link ServiceLoader} from {@link ClassPathLoader}. * * @since 8.1 */ private void loadPluginCommands() { final Iterator<CommandMarker> iterator = ServiceLoader.load(CommandMarker.class, ClassPathLoader.getLatest().asClassLoader()).iterator(); while (iterator.hasNext()) { try { final CommandMarker commandMarker = iterator.next(); try { add(commandMarker); } catch (Exception e) { logWrapper.warning("Could not load Command from: " + commandMarker.getClass() + " due to " + e.getLocalizedMessage(), e); // continue } } catch (ServiceConfigurationError e) { logWrapper.severe("Could not load Command: " + e.getLocalizedMessage(), e); // continue } } }
managerMap.put( manager.getClass(), manager ); } catch ( ServiceConfigurationError e ) { LOG.warn( "A resource manager was not available. Error was {}", e.getLocalizedMessage() ); LOG.trace( "Stack trace:", e );
@Override public boolean hasNext() { try { return internalHasNext(); } catch(ServiceConfigurationError sce) { log.error("proc.bad.config.file", sce.getLocalizedMessage()); throw new Abort(sce); } catch (Throwable t) { throw new Abort(t); } }
@Override public Processor next() { try { return internalNext(); } catch (ServiceConfigurationError sce) { log.error("proc.bad.config.file", sce.getLocalizedMessage()); throw new Abort(sce); } catch (Throwable t) { throw new Abort(t); } }