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.LAFProviderclass, that are loaded via theServiceLoader.load(Class)mechanism.
- Since:
- 1.0
-
Method Summary
Modifier and Type Method Description voidderegister(S service)Removes the specified service from theServiceManager's list of registered services.static <S> ServiceManager<S>from(java.lang.Class<S> cls)Creates a newServiceManagerfor the given service type.Sget(java.util.function.Predicate<? super S> predicate)Attempts to locate a service that is bound to this manager with the givenPredicateto filter.SgetOrDefault(java.util.function.Predicate<? super S> predicate, S defaultVal)Attempts to locate a service that is bound to this manager with the givenPredicateto filter.java.util.Enumeration<S>getServices()Retrieves an Enumeration with all the currently loaded services to which the current caller has access.voidregister(S service)Registers the given service with theServiceManager.java.util.stream.Stream<S>services()Retrieves a Stream with all the currently loaded services to which the current caller has access.
-
Method Details
-
from
Creates a newServiceManagerfor the given service type.- Type Parameters:
S- the type of service this manager will provide- Parameters:
cls- the service clas- Returns:
- a new
ServiceManagerfor the given service type.
-
register
Registers the given service with theServiceManager.A newly-loaded driver class should call the method
registerto make itself known to theServiceManager. If the driver is currently registered, no action is taken.- Parameters:
service- the newservicethat is to be registered with theServiceManager- Throws:
java.lang.NullPointerException- ifserviceis null
-
deregister
Removes the specified service from theServiceManager's list of registered services.If a
nullvalue 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- theserviceto remove
-
get
Attempts to locate a service that is bound to this manager with the givenPredicateto filter.- Parameters:
predicate- a filter to locate the service- Returns:
- a service object of type
<S>
-
getOrDefault
Attempts to locate a service that is bound to this manager with the givenPredicateto filter.- Parameters:
predicate- a filter to locate the service- Returns:
- a service object of type
<S>or the given default value
-
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
Retrieves a Stream with all the currently loaded services to which the current caller has access.- Returns:
- the stream of
servicesloaded by the caller's class loader - Since:
- Java 9
-