T
- service interface typepublic abstract class WhiteboardProxiedServiceRegistry<T> extends Object
This WhiteboardProxiedServiceRegistry base class supports (un)registering service objects, and
ProxiedServiceTracker
s to retrieve those currently registered as well as be notified on future
(un)registrations. Also currently registered service entries can be retrieved through getEntries()
.
All service objects registered through a WhiteboardProxiedServiceRegistry implementation must implement a common interface of generic type T.
For example with the following (complete) PersistedHippoEventListenerRegistry
implementation from the hippo-repository-api module using interface type
PersistedHippoEventListener
, service objects
implementing that interface can be registered:
public final class PersistedHippoEventListenerRegistry extends WhiteboardProxiedServiceRegistry<PersistedHippoEventListener> {
private static final PersistedHippoEventListenerRegistry INSTANCE = new PersistedHippoEventListenerRegistry();
private HippoEventListenerRegistry() {
super(PersistedHippoEventListener.class);
}
public static PersistedHippoEventListenerRegistry get() { return INSTANCE; }
}
For a typical usage of a WhiteboardProxiedServiceRegistry see the javadoc for the
PersistedHippoEventListenerRegistry
and
PersistedHippoEventListener
service interface
in the hippo-repository-api module.
For each registered service object a ProxiedServiceHolder
is created and passed on to
the ProxiedServiceTracker
(s), storing the service object itself together with the context classloader used to
register the service object. Furthermore it provides access to a dynamically created
service proxy
for the service exposing only the service interface
and optionally extra interfaces. When using the service proxy all method invocation will be executed with the
context classloader set to its registration classloader. Also, the
serviceRegistered
and
serviceUnregistered
callback methods
provided by the service tracker will be invoked using the context classloader of the service tracker.
When a service object should be used as a singleton then use HippoServiceRegistry
instead.
When only the registration and tracking of one or more service objects of a certain (base) type (class or interface)
is needed nor a service proxy with automatic enforcing of its context classloader during method invocation, use the
WhiteboardServiceRegistry<T>
base class instead, Note that
it then requires manual enforcement of the current context classloader in case of cross-context usage of
the service objects.
Constructor and Description |
---|
WhiteboardProxiedServiceRegistry(Class<T> serviceInterface)
Constructor needed for storing the required common interface of generic type T which must be implemented by all
service objects registered.
|
Modifier and Type | Method and Description |
---|---|
void |
addTracker(ProxiedServiceTracker<T> tracker)
Add a
ProxiedServiceTracker<T> for tracking service objects of common
interface <T> registered and unregistered
in this registry. |
Stream<ProxiedServiceHolder<T>> |
getEntries() |
protected List<ProxiedServiceHolder<T>> |
getEntriesList() |
Stream<T> |
getServices() |
void |
register(T serviceObject,
Class<?>... extraInterfaces)
Register a service object implementing interface type <T> and optionally some additional interfaces which
all will be exposed by the
service proxy created for this service object. |
boolean |
removeTracker(ProxiedServiceTracker<T> tracker)
Remove a previously added
ProxiedServiceTracker<T> . |
int |
size() |
boolean |
unregister(T serviceObject)
Unregister a previously registered service object
|
protected List<ProxiedServiceHolder<T>> getEntriesList()
public void register(T serviceObject, Class<?>... extraInterfaces)
service proxy
created for this service object.serviceObject
- the service objectextraInterfaces
- additional interfaces implemented by the service object to be exposed by the service proxyHippoServiceException
- when the service object was already registeredpublic boolean unregister(T serviceObject)
serviceObject
- the service objectpublic void addTracker(ProxiedServiceTracker<T> tracker)
ProxiedServiceTracker<T>
for tracking service objects of common
interface <T> registered
and unregistered
in this registry.tracker
- the service trackerHippoServiceException
- when the provided tracker instance already was added beforepublic boolean removeTracker(ProxiedServiceTracker<T> tracker)
ProxiedServiceTracker<T>
.tracker
- the service trackerpublic Stream<ProxiedServiceHolder<T>> getEntries()
public int size()
Copyright © 2012–2019 Hippo B.V. (http://www.onehippo.com). All rights reserved.