Class PriorityServiceLoader<S>
- java.lang.Object
- 
- org.jboss.resteasy.spi.PriorityServiceLoader<S>
 
- 
- All Implemented Interfaces:
- Iterable<S>
 
 public class PriorityServiceLoader<S> extends Object implements Iterable<S> A service loader which loads classes aggressively sorting the implementations by the value in the Priorityannotation. If the implementation does not include the annotationInteger.MAX_VALUEis used for the priority. The instances themselves are lazily created.
 ConstructorIf a constructor function is used the argument passed to the function is the resolved type. The function is free to construct the type however it sees fit.Example: PriorityServiceLoader.load(Service.class, (service) -> { try { return service.getConstructor(String.class).newInstance("init value"); } catch (Exception e) { throw new RuntimeException(e); } });- Since:
- 6.1
- Author:
- James R. Perkins
- See Also:
- ServiceLoader
 
- 
- 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<S>first()If there are services available the first one is returned.Set<Class<S>>getTypes()Returns the types found for this service.Iterator<S>iterator()Optional<S>last()If there are services available the last one is returned.static <S> PriorityServiceLoader<S>load(Class<S> type)Creates a new service loader for the type.static <S> PriorityServiceLoader<S>load(Class<S> type, ClassLoader cl)Creates a new service loader for the type and class loader.static <S> PriorityServiceLoader<S>load(Class<S> type, ClassLoader cl, Function<Class<? extends S>,S> constructor)Creates a new service loader for the type and class loader.static <S> PriorityServiceLoader<S>load(Class<S> type, Function<Class<? extends S>,S> constructor)Creates a new service loader for the type.StringtoString()- 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface java.lang.IterableforEach, spliterator
 
- 
 
- 
- 
- 
Method Detail- 
loadpublic static <S> PriorityServiceLoader<S> load(Class<S> type) Creates a new service loader for the type.To resolve the class loader this first attempts to get the current threads context class loader. If that is nullthe services class loader is used. Finally if the class loader from the service isnullthen the system class loader is used.- Parameters:
- type- the type to load the services for
- Returns:
- a new service loader
- Throws:
- SecurityException- if the security manager is enabled there is a security issue loading the class or retrieving the class loader
 
 - 
loadpublic static <S> PriorityServiceLoader<S> load(Class<S> type, Function<Class<? extends S>,S> constructor) Creates a new service loader for the type.To resolve the class loader this first attempts to get the current threads context class loader. If that is nullthe services class loader is used. Finally if the class loader from the service isnullthen the system class loader is used.- Parameters:
- type- the type to load the services for
- constructor- an optional constructor used to construct the type
- Returns:
- a new service loader
- Throws:
- SecurityException- if the security manager is enabled there is a security issue loading the class or retrieving the class loader
 
 - 
loadpublic static <S> PriorityServiceLoader<S> load(Class<S> type, ClassLoader cl) Creates a new service loader for the type and class loader.- Parameters:
- type- the type to load the services for
- cl- the class loader used to load the found services
- Returns:
- a new service loader
- Throws:
- SecurityException- if the security manager is enabled and there is a security issue loading the class
 
 - 
loadpublic static <S> PriorityServiceLoader<S> load(Class<S> type, ClassLoader cl, Function<Class<? extends S>,S> constructor) Creates a new service loader for the type and class loader.- Parameters:
- type- the type to load the services for
- cl- the class loader used to load the found services
- constructor- an optional constructor used to construct the type
- Returns:
- a new service loader
- Throws:
- SecurityException- if the security manager is enabled and there is a security issue loading the class
 
 - 
firstpublic Optional<S> first() If there are services available the first one is returned.- Returns:
- the first service or an empty optional
- Throws:
- SecurityException- if the security manager is enabled and there is a security error instantiating the object
 
 - 
lastpublic Optional<S> last() If there are services available the last one is returned.- Returns:
- the last service or an empty optional
- Throws:
- SecurityException- if the security manager is enabled and there is a security error instantiating the object
 
 - 
getTypespublic Set<Class<S>> getTypes() Returns the types found for this service.Note if accessed before the iterator the types are not actually constructed. - Returns:
- the types found for this service
 
 - 
iteratorpublic Iterator<S> iterator() - Specified by:
- iteratorin interface- Iterable<S>
- Throws:
- SecurityException- if the security manager is enabled and there is a security error instantiating the object
 
 
- 
 
-