Class WhiteboardProxiedServiceRegistry<T>
- Type Parameters:
T
- service interface type
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) org.onehippo.repository.events.PersistedHippoEventListenerRegistry implementation from the hippo-repository-api module using interface type org.onehippo.repository.events.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 org.onehippo.repository.events.PersistedHippoEventListenerRegistry and org.onehippo.repository.events.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 Summary
ConstructorDescriptionWhiteboardProxiedServiceRegistry
(Class<T> serviceInterface) Constructor needed for storing the required common interface of generic type T which must be implemented by all service objects registered. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addTracker
(ProxiedServiceTracker<T> tracker) Add aProxiedServiceTracker<T>
for tracking service objects of common interface <T>registered
andunregistered
in this registry.protected List<ProxiedServiceHolder<T>>
void
Register a service object implementing interface type <T> and optionally some additional interfaces which all will be exposed by theservice proxy
created for this service object.boolean
removeTracker
(ProxiedServiceTracker<T> tracker) Remove a previously addedProxiedServiceTracker<T>
.int
size()
boolean
unregister
(T serviceObject) Unregister a previously registered service object
-
Constructor Details
-
WhiteboardProxiedServiceRegistry
Constructor needed for storing the required common interface of generic type T which must be implemented by all service objects registered.- Parameters:
serviceInterface
- common interface
-
-
Method Details
-
getEntriesList
- Returns:
- a new copied List of current service entries to guard against potential concurrent service (un)registrations
-
register
Register a service object implementing interface type <T> and optionally some additional interfaces which all will be exposed by theservice proxy
created for this service object.- Parameters:
serviceObject
- the service objectextraInterfaces
- additional interfaces implemented by the service object to be exposed by the service proxy- Throws:
HippoServiceException
- when the service object was already registered
-
unregister
Unregister a previously registered service object- Parameters:
serviceObject
- the service object- Returns:
- true if the service object was registered before and now removed, false otherwise
-
addTracker
Add aProxiedServiceTracker<T>
for tracking service objects of common interface <T>registered
andunregistered
in this registry.- Parameters:
tracker
- the service tracker- Throws:
HippoServiceException
- when the provided tracker instance already was added before
-
removeTracker
Remove a previously addedProxiedServiceTracker<T>
.- Parameters:
tracker
- the service tracker- Returns:
- true if the service tracker was added before and now removed, false otherwise
-
getEntries
- Returns:
- the registered service entries
-
getServices
- Returns:
- the registered services (proxied)
-
size
public int size()- Returns:
- the number of registered services
-