Class AbstractRegistrationSupport
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidactivate(org.osgi.service.component.ComponentContext componentContext) Activates this component thread-safely as follows: Set the OSGi ComponentContext field CalldoActivate()Register repositores bound before activation callingbindRepository(String, Repository)for each such repository.protected voidbindLog(org.osgi.service.log.LogService log) Binds the LogServiceprotected abstract ObjectbindRepository(String name, javax.jcr.Repository repository) Called to actually register a repository with the registry.protected voidbindRepository(org.osgi.framework.ServiceReference reference) Registers the repository identified by the OSGi service reference under the name set as service property.protected voiddeactivate(org.osgi.service.component.ComponentContext context) Deactivates this component thread-safely as follows: Unregister repositores still bound callingunbindRepository(String, Object)for each such repository.protected abstract booleanPerforms additional activation tasks.protected abstract voidPerforms additional deactivation tasks.protected org.osgi.service.component.ComponentContextReturns the OSGiComponentContextof this component.protected StringgetName(org.osgi.framework.ServiceReference reference) Returns thenameproperty from the service properties ornullif no such property exists or the property is an empty string.protected voidLogs a message with optionalThrowablestack trace to the log service orstderrif no log service is available.protected voidunbindLog(org.osgi.service.log.LogService log) Unbinds the LogServiceprotected abstract voidunbindRepository(String name, Object data) Called to actually unregister a repository with the registry.protected voidunbindRepository(org.osgi.framework.ServiceReference reference) Unregisters the repository identified by the OSGi service reference under the name set as service property.
-
Field Details
-
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
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 theactivate(ComponentContext)method and is intended for internal setup, such as acquiring the registry.- Returns:
- Whether the activation succeeded or not. If
trueis returned, activation succeeded and any repositories which have been bound before the component was activated are now actually registered. Iffalseis 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 thedeactivate(ComponentContext)method and is intended for internal cleanup of setup done by thedoActivate()method.This method is always called, regardless of whether
doActivate()succeeded or not. -
bindRepository
Called to actually register a repository with the registry. This method is called byactivate(ComponentContext)for any repositories bound before the component was activated and bybindRepository(ServiceReference)for any repositories bound after the component was activated.If actual registration fails, this method is expected to return
nullto indicate this fact. In this case, theunbindRepository(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- Thejavax.jcr.Repositoryto register.- Returns:
- Returns an object which is later given as the
dataparameter to theunbindRepository(String, Object)method to unregister the repository of the given name. This may benullif actual registration failed.
-
unbindRepository
Called to actually unregister a repository with the registry. This method is called byunbindRepository(ServiceReference)for any repositories unbound before the component is deactivated and bydeactivate(ComponentContext)for any repositories not unbound before the component is deactivated.If the
bindRepository(String, Repository)returnednullfor 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 thebindRepositoryInternal(String, ServiceReference)method.
-
getComponentContext
protected org.osgi.service.component.ComponentContext getComponentContext()Returns the OSGiComponentContextof this component. This method returnsnullbefore thedoActivate()method is called and after thedoDeactivate()method has been called. That is, this method does not returnnullif it is fully operational. -
log
Logs a message with optionalThrowablestack trace to the log service orstderrif no log service is available.- Parameters:
level- TheLogServicelevel at which to log the message.message- The message to log, this should of course not benull.t- TheThrowableto log along with the message. This may benull.
-
getName
Returns thenameproperty from the service properties ornullif no such property exists or the property is an empty string.- Parameters:
reference- TheServiceReferencewhosenameproperty 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:- Set the OSGi ComponentContext field
- Call
doActivate() - Register repositores bound before activation calling
bindRepository(String, Repository)for each such repository.
If
doActivate()returnsfalse, the repositories already bound are not actually registered, but this component is disabled.- Parameters:
componentContext- The OSGiComponentContextof this component.
-
deactivate
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. - Call
doDeactivate() - Clear the OSGi ComponentContext field
- Parameters:
context- The OSGiComponentContextof this component.
- Unregister repositores still bound calling
-
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- TheServiceReferencerepresenting 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- TheServiceReferencerepresenting 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
-