Class TLcdServiceLoader<S>

java.lang.Object
com.luciad.util.service.TLcdServiceLoader<S>
All Implemented Interfaces:
Iterable<S>

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.

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 Details

    • iterator

      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).

      Specified by:
      iterator in interface Iterable<S>
      Returns:
      an iterator that lazily loads services
    • getInstance

      public static <S> TLcdServiceLoader<S> getInstance(Class<S> service)
      Creates a new service loader that can load services of the given class. Services can be retrieved by calling TLcdServiceLoader.iterator().
      Parameters:
      service - the class describing the service
      Returns:
      a new service loader that can load services of the given class.
    • toString

      public String toString()
      Returns a String describing this service loader.
      Overrides:
      toString in class Object
      Returns:
      a String describing this service loader.