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 ServiceTrackers 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 Details

    • WhiteboardServiceRegistry

      public WhiteboardServiceRegistry()
  • Method Details

    • 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 a ServiceTracker<T> for tracking service objects of type <T> registered and unregistered 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 added ServiceObjectTracker<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