T
- service object implementation typepublic abstract class WhiteboardServiceRegistry<T> extends Object
This WhiteboardServiceRegistry base class supports (un)registering service objects,
and ServiceTracker
s to retrieve those currently registered as well as be notified on future
(un)registrations. Currently registered service object holders also can be retrieved through
getEntries()
.
All service objects registered through a WhiteboardServiceRegistry implementation need to be an instanceof of a common class or interface type T.
For example with the following (complete) HippoEventListenerRegistry
implementation, using implementation type Object, effectively all possible service
objects can be registered:
public final class HippoEventListenerRegistry extends WhiteboardServiceRegistry<Object> {
private static final HippoEventListenerRegistry INSTANCE = new HippoEventListenerRegistry();
private HippoEventListenerRegistry() {}
public static HippoEventListenerRegistry get() { return INSTANCE; }
}
For a typical usage of a WhiteboardServiceRegistry see the javadoc for the
HippoEventListenerRegistry
and
HippoEventBus
service interface.
A more restricted variation is the PersistedHippoEventListenerRegistry in the hippo-repository-api module which is restricted to registering service objects implementing the PersistedHippoEventListener interface.
For each registered service object a ServiceHolder
is created and passed on to
the ServiceTracker
(s) (if any), which is just holding the service object itself together with the context
classloader used to register the object. The serviceRegistered
* and serviceUnregistered
callback methods
* provided by the service tracker will be invoked using the context classloader of the service tracker.
When one or more service objects (only) should be exposed through a common service interface (and optionally
additional interfaces), use the WhiteboardProxiedServiceRegistry<T>
base class instead, or the HippoServiceRegistry
for singleton service registration and lookup, like
for the HippoEventBus
service.
Constructor and Description |
---|
WhiteboardServiceRegistry() |
Modifier and Type | Method and Description |
---|---|
void |
addTracker(ServiceTracker<T> tracker)
Add a
ServiceTracker<T> for tracking service objects of type <T>
registered and unregistered in this
registry. |
Stream<ServiceHolder<T>> |
getEntries() |
protected List<ServiceHolder<T>> |
getEntriesList() |
void |
register(T serviceObject)
Register a service object of type <T>
|
boolean |
removeTracker(ServiceTracker<T> tracker)
Remove a previously added
ServiceObjectTracker<T> . |
int |
size() |
boolean |
unregister(T serviceObject)
Unregister a previously registered service object
|
protected List<ServiceHolder<T>> getEntriesList()
public void register(T serviceObject) throws HippoServiceException
serviceObject
- the service objectHippoServiceException
- when the service object was already registeredpublic boolean unregister(T serviceObject)
serviceObject
- the service objectpublic void addTracker(ServiceTracker<T> tracker) throws HippoServiceException
ServiceTracker<T>
for tracking service objects of type <T>
registered
and unregistered
in this
registry.tracker
- the service trackerHippoServiceException
- when the provided service tracker instance already was added beforepublic boolean removeTracker(ServiceTracker<T> tracker)
ServiceObjectTracker<T>
.tracker
- the trackerpublic Stream<ServiceHolder<T>> getEntries()
public int size()
Copyright © 2012–2019 Hippo B.V. (http://www.onehippo.com). All rights reserved.