public class TLcdServiceLoader<S> extends Object implements 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 Services mechanism documentation.
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(Class<S> service)
Creates a new service loader that can load services of the given class.
|
Iterator<S> |
iterator()
Returns an iterator that lazily loads services of the service loaders' service class (see
getInstance(Class) ). |
String |
toString()
Returns a
String describing this service loader. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public 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).
public static <S> TLcdServiceLoader<S> getInstance(Class<S> service)
TLcdServiceLoader.iterator()
.service
- the class describing the service