Class TLcdServiceLoader<S>
- All Implemented Interfaces:
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.
Thread safety
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.
- Since:
- 2013.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <S> TLcdServiceLoader
<S> getInstance
(Class<S> service) Creates a new service loader that can load services of the given class.iterator()
Returns an iterator that lazily loads services of the service loaders' service class (seegetInstance(Class)
).toString()
Returns aString
describing this service loader.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
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 aServiceConfigurationError
. 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). -
getInstance
Creates a new service loader that can load services of the given class. Services can be retrieved by callingTLcdServiceLoader.iterator()
.- Parameters:
service
- the class describing the service- Returns:
- a new service loader that can load services of the given class.
-
toString
Returns aString
describing this service loader.
-