public abstract class AbstractRegistrationSupport extends Object
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.
Modifier and Type | Field and Description |
---|---|
protected Object |
registryLock
A lock to serialize access to the registry management in this class.
|
static String |
REPOSITORY_REGISTRATION_NAME
The JCR Repository service registration property used to create
the registration name.
|
Constructor and Description |
---|
AbstractRegistrationSupport() |
Modifier and Type | Method and 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 void |
bindRepository(org.osgi.framework.ServiceReference reference)
Registers the repository identified by the OSGi service reference under
the name set as service property.
|
protected abstract Object |
bindRepository(String name,
javax.jcr.Repository repository)
Called to actually register a repository with the registry.
|
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 |
doActivate()
Performs additional activation tasks.
|
protected abstract void |
doDeactivate()
Performs additional deactivation tasks.
|
protected org.osgi.service.component.ComponentContext |
getComponentContext()
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 void |
unbindRepository(org.osgi.framework.ServiceReference reference)
Unregisters the repository identified by the OSGi service reference under
the name set as service property.
|
protected abstract void |
unbindRepository(String name,
Object data)
Called to actually unregister a repository with the registry.
|
public static final String REPOSITORY_REGISTRATION_NAME
protected final Object registryLock
protected abstract boolean doActivate()
activate(ComponentContext)
method and is intended for internal
setup, such as acquiring the registry.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).protected abstract void doDeactivate()
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.
protected abstract Object bindRepository(String name, javax.jcr.Repository repository)
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.
name
- The name under which the repository is to be registered.repository
- The javax.jcr.Repository
to register.data
parameter to the unbindRepository(String, Object)
method
to unregister the repository of the given name. This may be
null
if actual registration failed.protected abstract void unbindRepository(String name, Object data)
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.
name
- The name under which the repository is to be registered.data
- The data object returned by the
bindRepositoryInternal(String, ServiceReference)
method.protected org.osgi.service.component.ComponentContext getComponentContext()
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.protected void log(int level, String message, Throwable t)
Throwable
stack trace to the
log service or stderr
if no log service is available.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
.protected String getName(org.osgi.framework.ServiceReference reference)
name
property from the service properties or
null
if no such property exists or the property is an
empty string.reference
- The ServiceReference
whose
name
property is to be returned.null
.protected void activate(org.osgi.service.component.ComponentContext componentContext)
doActivate()
bindRepository(String, Repository)
for each such repository.
If doActivate()
returns false
, the repositories
already bound are not actually registered, but this component is
disabled.
componentContext
- The OSGi ComponentContext
of this
component.protected void deactivate(org.osgi.service.component.ComponentContext context)
unbindRepository(String, Object)
for each such repository.
doDeactivate()
componentContext
- The OSGi ComponentContext
of this
component.protected void bindRepository(org.osgi.framework.ServiceReference reference)
reference
- The ServiceReference
representing the
repository to register.protected void unbindRepository(org.osgi.framework.ServiceReference reference)
reference
- The ServiceReference
representing the
repository to unregister.protected void bindLog(org.osgi.service.log.LogService log)
protected void unbindLog(org.osgi.service.log.LogService log)
Copyright © 2014 The Apache Software Foundation. All rights reserved.