private <C extends Pluggable> Iterable<C> instancesOf(Class<C> clazz, boolean atLeastOne)
{
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Iterator<C> serviceLoaderIterator = ServiceLoader.load(clazz, classLoader).iterator();
List<C> serviceImplementations = new ArrayList<C>();
while(serviceLoaderIterator.hasNext())
{
C next = serviceLoaderIterator.next();
if(!isDisabled(clazz, next) && isAvailable(next))
{
serviceImplementations.add(next);
}
}
if(atLeastOne && serviceImplementations.isEmpty())
{
throw new ServerScopedRuntimeException("At least one implementation of " + clazz + " expected");
}
LOGGER.debug("Found {} implementations of {}", serviceImplementations.size(), clazz);
return serviceImplementations;
}