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 theServiceLoader.load(Class)
mechanism.
- Since:
- 1.0
-
Method Summary
Modifier and Type Method Description void
deregister(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 newServiceManager
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 givenPredicate
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 givenPredicate
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 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 newServiceManager
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
Registers the given service with theServiceManager
.A newly-loaded driver class should call the method
register
to make itself known to theServiceManager
. If the driver is currently registered, no action is taken.- Parameters:
service
- the newservice
that is to be registered with theServiceManager
- Throws:
java.lang.NullPointerException
- ifservice
is null
-
deregister
Removes the specified service from theServiceManager
'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
- theservice
to remove
-
get
Attempts to locate a service that is bound to this manager with the givenPredicate
to 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 givenPredicate
to 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
services
loaded by the caller's class loader - Since:
- Java 9
-