public class TLcdServiceLoader<S>
extends java.lang.Object
implements java.lang.Iterable<S>
Service loader, similar to the JRE ServiceLoader
, but supporting priorities.
More specifically, this class reads and instantiates service objects from META-INF/services.
The difference with the JRE implementation is that it also retrieves priorities from the
service (from the runtime LcdService
annotation), and sorts the services accordingly.
For more information, refer to the developer's guide Chapter on adding data formats.
Instances of this class are not safe for use by multiple concurrent threads.
As a result of this, there are no special requirements enforced on the service objects that are registered in the registry. They don't need to be thread safe.
For example it is perfectly valid to annotate a non thread-safe model decoder with the @LcdService
annotation.
TLcdServiceAnnotationProcessor
,
LcdService
Modifier and Type | Method and Description |
---|---|
static <S> TLcdServiceLoader<S> |
getInstance(java.lang.Class<S> service)
Creates a new service loader that can load services of the given class.
|
java.util.Iterator<S> |
iterator()
Returns an iterator that lazily loads services of the service loaders' service class (see
getInstance(Class) ). |
java.lang.String |
toString()
Returns a
String describing this service loader. |
public java.util.Iterator<S> iterator()
Returns an iterator that lazily loads services of the service loaders' service class (see
getInstance(Class)
).
Because services are instantiated when calling the returned Iterator
, it is
possible that it throws a ServiceConfigurationError
. This can
happen for example when the described service is not assignable to the service class, or if
it can not be instantiated (e.g. when it has no empty constructor).
iterator
in interface java.lang.Iterable<S>
public static <S> TLcdServiceLoader<S> getInstance(java.lang.Class<S> service)
TLcdServiceLoader.iterator()
.service
- the class describing the servicepublic java.lang.String toString()
String
describing this service loader.toString
in class java.lang.Object
String
describing this service loader.