Class AbstractRegistrationSupport

java.lang.Object
org.apache.sling.jcr.registration.AbstractRegistrationSupport

public abstract class AbstractRegistrationSupport extends Object
The AbstractRegistrationSupport class is the base class for registration purposes of embedded repositories.

This base class cares for synchronization issues of the activate(ComponentContext), deactivate(ComponentContext), bindRepository(ServiceReference) and unbindRepository(ServiceReference) methods. Implementations of the abstract API may safely assume to run thread-safe.

To ensure this thread-safeness, said methods should not be overwritten.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Object
    A lock to serialize access to the registry management in this class.
    static final String
    The JCR Repository service registration property used to create the registration name.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    activate(org.osgi.service.component.ComponentContext componentContext)
    Activates this component thread-safely as follows: Set the OSGi ComponentContext field Call doActivate() Register repositores bound before activation calling bindRepository(String, Repository) for each such repository.
    protected void
    bindLog(org.osgi.service.log.LogService log)
    Binds the LogService
    protected abstract Object
    bindRepository(String name, javax.jcr.Repository repository)
    Called to actually register a repository with the registry.
    protected void
    bindRepository(org.osgi.framework.ServiceReference reference)
    Registers the repository identified by the OSGi service reference under the name set as service property.
    protected void
    deactivate(org.osgi.service.component.ComponentContext context)
    Deactivates this component thread-safely as follows: Unregister repositores still bound calling unbindRepository(String, Object) for each such repository.
    protected abstract boolean
    Performs additional activation tasks.
    protected abstract void
    Performs additional deactivation tasks.
    protected org.osgi.service.component.ComponentContext
    Returns the OSGi ComponentContext of this component.
    protected String
    getName(org.osgi.framework.ServiceReference reference)
    Returns the name property from the service properties or null if no such property exists or the property is an empty string.
    protected void
    log(int level, String message, Throwable t)
    Logs a message with optional Throwable stack trace to the log service or stderr if no log service is available.
    protected void
    unbindLog(org.osgi.service.log.LogService log)
    Unbinds the LogService
    protected abstract void
    Called to actually unregister a repository with the registry.
    protected void
    unbindRepository(org.osgi.framework.ServiceReference reference)
    Unregisters the repository identified by the OSGi service reference under the name set as service property.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • REPOSITORY_REGISTRATION_NAME

      public static final String REPOSITORY_REGISTRATION_NAME
      The JCR Repository service registration property used to create the registration name. If this service registration property (assumed to be a single string) does not exist, the repository is not registered.
      See Also:
    • registryLock

      protected final Object registryLock
      A lock to serialize access to the registry management in this class.
  • Constructor Details

    • AbstractRegistrationSupport

      public AbstractRegistrationSupport()
  • Method Details

    • doActivate

      protected abstract boolean doActivate()
      Performs additional activation tasks. This method is called by the activate(ComponentContext) method and is intended for internal setup, such as acquiring the registry.
      Returns:
      Whether the activation succeeded or not. If true is returned, activation succeeded and any repositories which have been bound before the component was activated are now actually registered. If false is returned, activation failed and this component is disabled and receives no further repository bind and unbound events (apart for unbind events for repositories which have already been bound).
    • doDeactivate

      protected abstract void doDeactivate()
      Performs additional deactivation tasks. This method is called by the deactivate(ComponentContext) method and is intended for internal cleanup of setup done by the doActivate() method.

      This method is always called, regardless of whether doActivate() succeeded or not.

    • bindRepository

      protected abstract Object bindRepository(String name, javax.jcr.Repository repository)
      Called to actually register a repository with the registry. This method is called by activate(ComponentContext) for any repositories bound before the component was activated and by bindRepository(ServiceReference) for any repositories bound after the component was activated.

      If actual registration fails, this method is expected to return null to indicate this fact. In this case, the unbindRepository(String, Object) will NOT be called for the named repository.

      This method may safely assume that it is only called on or after activation of this component on or before the component deactivation.

      Parameters:
      name - The name under which the repository is to be registered.
      repository - The javax.jcr.Repository to register.
      Returns:
      Returns an object which is later given as the data parameter to the unbindRepository(String, Object) method to unregister the repository of the given name. This may be null if actual registration failed.
    • unbindRepository

      protected abstract void unbindRepository(String name, Object data)
      Called to actually unregister a repository with the registry. This method is called by unbindRepository(ServiceReference) for any repositories unbound before the component is deactivated and by deactivate(ComponentContext) for any repositories not unbound before the component is deactivated.

      If the bindRepository(String, Repository) returned null for when the named repository was registered, this method is not called.

      This method may safely assume that it is only called on or after activation of this component on or before the component deactivation.

      Parameters:
      name - The name under which the repository is to be registered.
      data - The data object returned by the bindRepositoryInternal(String, ServiceReference) method.
    • getComponentContext

      protected org.osgi.service.component.ComponentContext getComponentContext()
      Returns the OSGi ComponentContext of this component. This method returns null before the doActivate() method is called and after the doDeactivate() method has been called. That is, this method does not return null if it is fully operational.
    • log

      protected void log(int level, String message, Throwable t)
      Logs a message with optional Throwable stack trace to the log service or stderr if no log service is available.
      Parameters:
      level - The LogService level at which to log the message.
      message - The message to log, this should of course not be null.
      t - The Throwable to log along with the message. This may be null.
    • getName

      protected String getName(org.osgi.framework.ServiceReference reference)
      Returns the name property from the service properties or null if no such property exists or the property is an empty string.
      Parameters:
      reference - The ServiceReference whose name property is to be returned.
      Returns:
      The non-empty name property or null.
    • activate

      protected void activate(org.osgi.service.component.ComponentContext componentContext)
      Activates this component thread-safely as follows:
      1. Set the OSGi ComponentContext field
      2. Call doActivate()
      3. Register repositores bound before activation calling bindRepository(String, Repository) for each such repository.

      If doActivate() returns false, the repositories already bound are not actually registered, but this component is disabled.

      Parameters:
      componentContext - The OSGi ComponentContext of this component.
    • deactivate

      protected void deactivate(org.osgi.service.component.ComponentContext context)
      Deactivates this component thread-safely as follows:
      1. Unregister repositores still bound calling unbindRepository(String, Object) for each such repository.
      2. Call doDeactivate()
      3. Clear the OSGi ComponentContext field
      Parameters:
      context - The OSGi ComponentContext of this component.
    • bindRepository

      protected void bindRepository(org.osgi.framework.ServiceReference reference)
      Registers the repository identified by the OSGi service reference under the name set as service property. If the repository service has not name property, the repository is not registered.
      Parameters:
      reference - The ServiceReference representing the repository to register.
    • unbindRepository

      protected void unbindRepository(org.osgi.framework.ServiceReference reference)
      Unregisters the repository identified by the OSGi service reference under the name set as service property. If the repository service has no name property, the repository is assumed not be registered and nothing needs to be done.
      Parameters:
      reference - The ServiceReference representing the repository to unregister.
    • bindLog

      protected void bindLog(org.osgi.service.log.LogService log)
      Binds the LogService
    • unbindLog

      protected void unbindLog(org.osgi.service.log.LogService log)
      Unbinds the LogService