@ProviderType
public abstract class AbstractSlingRepositoryManager
extends java.lang.Object
AbstractSlingRepositoryManager
is the basis for controlling
the JCR repository instances used by Sling. As a manager it starts and stops
the actual repository instance, manages service registration and hands out
SlingRepository
instances to be used by the consumers.
This base class controls the livecycle of repository instance whereas implementations of this class provide actual integration into the runtime context. The livecycle of the repository instance is defined as follows:
To start the repository instance, the implementation calls the
start(BundleContext, String, boolean)
method which goes through the
steps of instantiating the repository, setting things up, and registering the
repository as an OSGi service:
setup
method,
whatever code was there can be moved to the create
method.
If starting the repository fails, the method stoppingOnError(String, Throwable)
will be called. By default the exception is logged as an error, but this can
be customized by overwriting the method.
To stop the repository instance, the implementation calls the stop()
method which goes through the steps of unregistering the OSGi service,
tearing all special settings down and finally shutting down the repository:
unregisterService(ServiceRegistration)
destroy(AbstractSlingRepository2)
disposeRepository(Repository)
Instances of this class manage a single repository instance backing the OSGi service instances. Each consuming bundle, though, gets its own service instance backed by the single actual repository instance managed by this class.
AbstractSlingRepository2
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractSlingRepositoryManager.Config
Configuration pojo to be passed to the
start(BundleContext, Config) method. |
Constructor and Description |
---|
AbstractSlingRepositoryManager() |
Modifier and Type | Method and Description |
---|---|
protected abstract javax.jcr.Repository |
acquireRepository()
Creates the backing JCR repository instances.
|
protected boolean |
allowLoginAdministrativeForBundle(org.osgi.framework.Bundle bundle)
Returns whether or not the provided bundle is allowed to use
SlingRepository.loginAdministrative(String) . |
protected abstract AbstractSlingRepository2 |
create(org.osgi.framework.Bundle usingBundle)
Creates an instance of the
AbstractSlingRepository2
implementation for use by the given usingBundle . |
protected abstract void |
destroy(AbstractSlingRepository2 repositoryServiceInstance)
Cleans up the given
AbstractSlingRepository2 instance previously
created by the create(Bundle) method. |
protected abstract void |
disposeRepository(javax.jcr.Repository repository)
Disposes off the given
repository . |
java.lang.String |
getDefaultWorkspace()
Returns the default workspace, which may be
null meaning to
use the repository provided default workspace. |
protected javax.jcr.Repository |
getRepository()
Returns the repository underlying this instance or
null if
no repository is currently being available. |
protected java.lang.String[] |
getServiceRegistrationInterfaces()
Returns the service types to be used to register the repository service
in
registerService() . |
protected abstract java.util.Dictionary<java.lang.String,java.lang.Object> |
getServiceRegistrationProperties()
Return the service registration properties to be used to register the
repository service in
registerService() . |
protected abstract ServiceUserMapper |
getServiceUserMapper()
Returns the
ServiceUserMapper service to map the service name to
a service user name. |
boolean |
isDisableLoginAdministrative()
Returns whether to disable the
SlingRepository.loginAdministrative method or not. |
protected org.osgi.framework.ServiceRegistration |
registerService()
Registers this component as an OSGi service with the types provided by
the
getServiceRegistrationInterfaces() method and properties
provided by the getServiceRegistrationProperties() method. |
protected void |
start(org.osgi.framework.BundleContext bundleContext,
AbstractSlingRepositoryManager.Config config)
This method actually starts the backing repository instannce and
registeres the repository service.
|
protected boolean |
start(org.osgi.framework.BundleContext bundleContext,
java.lang.String defaultWorkspace,
boolean disableLoginAdministrative)
Deprecated.
|
protected void |
stop() |
protected void |
stoppingOnError(java.lang.String message,
java.lang.Throwable t)
Called when the repository service cannot be initialized or registered
because an exception occurred.
|
protected void |
unregisterService(org.osgi.framework.ServiceRegistration serviceRegistration)
Unregisters the service represented by the
serviceRegistration . |
public final java.lang.String getDefaultWorkspace()
null
meaning to
use the repository provided default workspace.null
indicating the repository's
default workspace is actually used.public final boolean isDisableLoginAdministrative()
SlingRepository.loginAdministrative
method or not.true
if SlingRepository.loginAdministrative
is
disabled.protected abstract ServiceUserMapper getServiceUserMapper()
ServiceUserMapper
service to map the service name to
a service user name.
The ServiceUserMapper
is used to implement the
AbstractSlingRepository2.loginService(String, String)
method used
to replace the
AbstractSlingRepository2.loginAdministrative(String)
method. If
this method returns null
and hence the
ServiceUserMapperService
is not available, the
loginService
method is not able to login.
ServiceUserMapper
service or null
if not
available.AbstractSlingRepository2.loginService(String, String)
protected boolean allowLoginAdministrativeForBundle(org.osgi.framework.Bundle bundle)
SlingRepository.loginAdministrative(String)
.bundle
- The bundle requiring access to loginAdministrative
loginAdministrative
.protected abstract javax.jcr.Repository acquireRepository()
This method does not throw any Throwable
but instead just
returns null
if not repository is available. Any problems
trying to acquire the repository must be caught and logged as
appropriate.
Repository
or null
if
not repository can be acquired.start(BundleContext, String, boolean)
protected final org.osgi.framework.ServiceRegistration registerService()
getServiceRegistrationInterfaces()
method and properties
provided by the getServiceRegistrationProperties()
method.
The repository is actually registered as an OSGi ServiceFactory
where the create(Bundle)
method is called to create an actual
AbstractSlingRepository2
repository instance for a calling
(using) bundle. When the bundle is done using the repository instance,
the destroy(AbstractSlingRepository2)
method is called to clean
up.
ServiceRegistration
object representing the
registered service.start(BundleContext, String, boolean)
,
getServiceRegistrationInterfaces()
,
getServiceRegistrationProperties()
,
create(Bundle)
,
destroy(AbstractSlingRepository2)
protected abstract java.util.Dictionary<java.lang.String,java.lang.Object> getServiceRegistrationProperties()
registerService()
.registerService()
registerService()
protected java.lang.String[] getServiceRegistrationInterfaces()
registerService()
. All interfaces returned must be accessible
to the class loader of the class of this instance.
This method may be overwritten to return additional types but the types
returned from this base implementation, SlingRepository
and
Repository
, must always be included.
registerService()
registerService()
protected abstract AbstractSlingRepository2 create(org.osgi.framework.Bundle usingBundle)
AbstractSlingRepository2
implementation for use by the given usingBundle
.
This method is called when the repository service is requested from within the using bundle for the first time.
This method is expected to return a new instance on every call.
usingBundle
- The bundle providing from which the repository is
requested.AbstractSlingRepository2
implementation instance to
be used by the usingBundle
.registerService()
protected abstract void destroy(AbstractSlingRepository2 repositoryServiceInstance)
AbstractSlingRepository2
instance previously
created by the create(Bundle)
method.repositoryServiceInstance
- The AbstractSlingRepository2
istance to cleanup.registerService()
protected final javax.jcr.Repository getRepository()
null
if
no repository is currently being available.protected final void unregisterService(org.osgi.framework.ServiceRegistration serviceRegistration)
serviceRegistration
.serviceRegistration
- The service to unregisterprotected abstract void disposeRepository(javax.jcr.Repository repository)
repository
.repository
- The repository to be disposed off which is the same as
the one returned from acquireRepository()
.protected void stoppingOnError(java.lang.String message, java.lang.Throwable t)
This default implementation logs the exception as an error.
message
- failure details.t
- the exception.@Deprecated protected final boolean start(org.osgi.framework.BundleContext bundleContext, java.lang.String defaultWorkspace, boolean disableLoginAdministrative)
start(BundleContext, AbstractSlingRepositoryManager.Config)
instead.
Instead a ServiceListener
for SlingRepository
may be
registered to get informed about its successful registration.
bundleContext
- The BundleContext
to register the repository
service (and optionally more services required to operate the
repository)defaultWorkspace
- The name of the default workspace to use to
login. This may be null
to have the actual repository
instance define its own defaultdisableLoginAdministrative
- Whether to disable the
SlingRepository.loginAdministrative
method or not.true
if the repository has been started and the service
is registered; false
if the service has not been registered,
which may indicate that startup was unsuccessful OR that it is happening
asynchronously. A more reliable way to determin availability of the
SlingRepository
as a service is using a
ServiceListener
.protected final void start(org.osgi.framework.BundleContext bundleContext, AbstractSlingRepositoryManager.Config config)
Multiple subsequent calls to this method without calling stop()
first have no effect.
bundleContext
- The BundleContext
to register the repository
service (and optionally more services required to operate the
repository)config
- The configuration to apply to this instance.protected final void stop()
Copyright © 2022 The Apache Software Foundation. All rights reserved.