Class WhiteboardServiceRegistry<T>
- java.lang.Object
-
- org.onehippo.cms7.services.WhiteboardServiceRegistry<T>
-
- Type Parameters:
T
- service object implementation type
- Direct Known Subclasses:
HippoEventListenerRegistry
,HippoWebappContextRegistry
public abstract class WhiteboardServiceRegistry<T> extends Object
WhiteboardServiceRegistry<T> is an abstract base class for implementing and using the Whiteboard Patternfor decoupled lookup/wiring of multiple service objects by a common (base) type, which can be a class or interface.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 throughgetEntries()
.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
andHippoEventBus
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 theServiceTracker
(s) (if any), which is just holding the service object itself together with the context classloader used to register the object. TheserviceRegistered
* andserviceUnregistered
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 theHippoServiceRegistry
for singleton service registration and lookup, like for theHippoEventBus
service.
-
-
Constructor Summary
Constructors Constructor Description WhiteboardServiceRegistry()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTracker(ServiceTracker<T> tracker)
Add aServiceTracker<T>
for tracking service objects of type <T>registered
andunregistered
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 addedServiceObjectTracker<T>
.int
size()
boolean
unregister(T serviceObject)
Unregister a previously registered service object
-
-
-
Method Detail
-
getEntriesList
protected List<ServiceHolder<T>> getEntriesList()
-
register
public void register(T serviceObject) throws HippoServiceException
Register a service object of type <T>- Parameters:
serviceObject
- the service object- Throws:
HippoServiceException
- when the service object was already registered
-
unregister
public boolean unregister(T serviceObject)
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
public void addTracker(ServiceTracker<T> tracker) throws HippoServiceException
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
public boolean removeTracker(ServiceTracker<T> tracker)
Remove a previously addedServiceObjectTracker<T>
.- Parameters:
tracker
- the tracker- Returns:
- true if the tracker was added before and now removed, false otherwise
-
getEntries
public Stream<ServiceHolder<T>> getEntries()
- Returns:
- the registered service entries
-
size
public int size()
- Returns:
- the number of services registered
-
-