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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
activate
(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 void
bindLog
(org.osgi.service.log.LogService log) Binds the LogServiceprotected 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 callingunbindRepository(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 OSGiComponentContext
of this component.protected String
getName
(org.osgi.framework.ServiceReference reference) Returns thename
property from the service properties ornull
if no such property exists or the property is an empty string.protected void
Logs a message with optionalThrowable
stack trace to the log service orstderr
if no log service is available.protected void
unbindLog
(org.osgi.service.log.LogService log) Unbinds the LogServiceprotected abstract void
unbindRepository
(String name, Object data) 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.
-
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
true
is returned, activation succeeded and any repositories which have been bound before the component was activated are now actually registered. Iffalse
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 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
null
to 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.Repository
to register.- Returns:
- Returns an object which is later given as the
data
parameter to theunbindRepository(String, Object)
method to unregister the repository of the given name. This may benull
if 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)
returnednull
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 thebindRepositoryInternal(String, ServiceReference)
method.
-
getComponentContext
protected org.osgi.service.component.ComponentContext getComponentContext()Returns the OSGiComponentContext
of this component. This method returnsnull
before thedoActivate()
method is called and after thedoDeactivate()
method has been called. That is, this method does not returnnull
if it is fully operational. -
log
Logs a message with optionalThrowable
stack trace to the log service orstderr
if no log service is available.- Parameters:
level
- TheLogService
level at which to log the message.message
- The message to log, this should of course not benull
.t
- TheThrowable
to log along with the message. This may benull
.
-
getName
Returns thename
property from the service properties ornull
if no such property exists or the property is an empty string.- Parameters:
reference
- TheServiceReference
whosename
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:- 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 OSGiComponentContext
of 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 OSGiComponentContext
of 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
- TheServiceReference
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
- TheServiceReference
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
-