Class WhiteboardServiceRegistry<T>
- Type Parameters:
T
- service object implementation type
- Direct Known Subclasses:
HippoEventListenerRegistry
,HippoWebappContextRegistry
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addTracker
(ServiceTracker<T> tracker) Add aServiceTracker<T>
for tracking service objects of type <T>registered
andunregistered
in this registry.protected List<ServiceHolder<T>>
void
Register a service object of type <T>boolean
removeTracker
(ServiceTracker<T> tracker) Remove a previously addedServiceObjectTracker<T>
.int
size()
boolean
unregister
(T serviceObject) Unregister a previously registered service object
-
Constructor Details
-
WhiteboardServiceRegistry
public WhiteboardServiceRegistry()
-
-
Method Details
-
getEntriesList
-
register
Register a service object of type <T>- Parameters:
serviceObject
- the service object- 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 aServiceTracker<T>
for tracking service objects of type <T>registered
andunregistered
in this registry.- Parameters:
tracker
- the service tracker- Throws:
HippoServiceException
- when the provided service tracker instance already was added before
-
removeTracker
Remove a previously addedServiceObjectTracker<T>
.- Parameters:
tracker
- the tracker- Returns:
- true if the tracker was added before and now removed, false otherwise
-
getEntries
- Returns:
- the registered service entries
-
size
public int size()- Returns:
- the number of services registered
-