Class ServiceManager<S>

java.lang.Object
org.proto4j.swing.ServiceManager<S>

public final class ServiceManager<S>
extends java.lang.Object
The basic class for managing a set of services (Thread-Safe).

As part of its initialization, the ServiceManager class will attempt to load available S classes by using:

  • Service providers of the org.proto4j.swing.laf.LAFProvider class, that are loaded via the ServiceLoader.load(Class) mechanism.
Since:
1.0
  • Method Summary

    Modifier and Type Method Description
    void deregister​(S service)
    Removes the specified service from the ServiceManager's list of registered services.
    static <S> ServiceManager<S> from​(java.lang.Class<S> cls)
    Creates a new ServiceManager for the given service type.
    S get​(java.util.function.Predicate<? super S> predicate)
    Attempts to locate a service that is bound to this manager with the given Predicate to filter.
    S getOrDefault​(java.util.function.Predicate<? super S> predicate, S defaultVal)
    Attempts to locate a service that is bound to this manager with the given Predicate to filter.
    java.util.Enumeration<S> getServices()
    Retrieves an Enumeration with all the currently loaded services to which the current caller has access.
    void register​(S service)
    Registers the given service with the ServiceManager.
    java.util.stream.Stream<S> services()
    Retrieves a Stream with all the currently loaded services to which the current caller has access.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • from

      public static <S> ServiceManager<S> from​(java.lang.Class<S> cls)
      Creates a new ServiceManager for the given service type.
      Type Parameters:
      S - the type of service this manager will provide
      Parameters:
      cls - the service clas
      Returns:
      a new ServiceManager for the given service type.
    • register

      public void register​(S service)
      Registers the given service with the ServiceManager.

      A newly-loaded driver class should call the method register to make itself known to the ServiceManager. If the driver is currently registered, no action is taken.

      Parameters:
      service - the new service that is to be registered with the ServiceManager
      Throws:
      java.lang.NullPointerException - if service is null
    • deregister

      public void deregister​(S service)
      Removes the specified service from the ServiceManager's list of registered services.

      If a null value is specified for the service to be removed, then no action is taken.

      If the specified service is not found in the list of registered services, then no action is taken. If the service was found, it will be removed from the list of registered services.

      Parameters:
      service - the service to remove
    • get

      public S get​(java.util.function.Predicate<? super S> predicate)
      Attempts to locate a service that is bound to this manager with the given Predicate to filter.
      Parameters:
      predicate - a filter to locate the service
      Returns:
      a service object of type <S>
    • getOrDefault

      public S getOrDefault​(java.util.function.Predicate<? super S> predicate, S defaultVal)
      Attempts to locate a service that is bound to this manager with the given Predicate to filter.
      Parameters:
      predicate - a filter to locate the service
      Returns:
      a service object of type <S> or the given default value
    • getServices

      public java.util.Enumeration<S> getServices()
      Retrieves an Enumeration with all the currently loaded services to which the current caller has access.

      Note: The classname of a service can be found using d.getClass().getName()

      Returns:
      the list of services loaded by the caller's class loader
      See Also:
      services()
    • services

      public java.util.stream.Stream<S> services()
      Retrieves a Stream with all the currently loaded services to which the current caller has access.
      Returns:
      the stream of services loaded by the caller's class loader
      Since:
      Java 9