Class AbstractSlingRepositoryManager
- java.lang.Object
-
- org.apache.sling.jcr.base.AbstractSlingRepositoryManager
-
@ProviderType public abstract class AbstractSlingRepositoryManager extends Object
TheAbstractSlingRepositoryManager
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 outSlingRepository
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
Earlier versions of this class had an additionalstart(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 thecreate
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.
- Since:
- API version 2.3 (bundle version 2.2.2)
- See Also:
AbstractSlingRepository2
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractSlingRepositoryManager.Config
Configuration pojo to be passed to thestart(BundleContext, Config)
method.
-
Constructor Summary
Constructors Constructor Description AbstractSlingRepositoryManager()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method 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 useSlingRepository.loginAdministrative(String)
.protected abstract AbstractSlingRepository2
create(org.osgi.framework.Bundle usingBundle)
Creates an instance of theAbstractSlingRepository2
implementation for use by the givenusingBundle
.protected abstract void
destroy(AbstractSlingRepository2 repositoryServiceInstance)
Cleans up the givenAbstractSlingRepository2
instance previously created by thecreate(Bundle)
method.protected abstract void
disposeRepository(javax.jcr.Repository repository)
Disposes off the givenrepository
.String
getDefaultWorkspace()
Returns the default workspace, which may benull
meaning to use the repository provided default workspace.protected javax.jcr.Repository
getRepository()
Returns the repository underlying this instance ornull
if no repository is currently being available.protected String[]
getServiceRegistrationInterfaces()
Returns the service types to be used to register the repository service inregisterService()
.protected abstract Dictionary<String,Object>
getServiceRegistrationProperties()
Return the service registration properties to be used to register the repository service inregisterService()
.protected abstract org.apache.sling.serviceusermapping.ServiceUserMapper
getServiceUserMapper()
Returns theServiceUserMapper
service to map the service name to a service user name.boolean
isDisableLoginAdministrative()
Returns whether to disable theSlingRepository.loginAdministrative
method or not.protected org.osgi.framework.ServiceRegistration
registerService()
Registers this component as an OSGi service with the types provided by thegetServiceRegistrationInterfaces()
method and properties provided by thegetServiceRegistrationProperties()
method.protected boolean
start(org.osgi.framework.BundleContext bundleContext, String defaultWorkspace, boolean disableLoginAdministrative)
Deprecated.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 void
stop()
protected void
stoppingOnError(String message, 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 theserviceRegistration
.
-
-
-
Method Detail
-
getDefaultWorkspace
public final String getDefaultWorkspace()
Returns the default workspace, which may benull
meaning to use the repository provided default workspace.- Returns:
- the default workspace or
null
indicating the repository's default workspace is actually used.
-
isDisableLoginAdministrative
public final boolean isDisableLoginAdministrative()
Returns whether to disable theSlingRepository.loginAdministrative
method or not.- Returns:
true
ifSlingRepository.loginAdministrative
is disabled.
-
getServiceUserMapper
protected abstract org.apache.sling.serviceusermapping.ServiceUserMapper getServiceUserMapper()
Returns theServiceUserMapper
service to map the service name to a service user name.The
ServiceUserMapper
is used to implement theAbstractSlingRepository2.loginService(String, String)
method used to replace theAbstractSlingRepository2.loginAdministrative(String)
method. If this method returnsnull
and hence theServiceUserMapperService
is not available, theloginService
method is not able to login.- Returns:
- The
ServiceUserMapper
service ornull
if not available. - See Also:
AbstractSlingRepository2.loginService(String, String)
-
allowLoginAdministrativeForBundle
protected boolean allowLoginAdministrativeForBundle(org.osgi.framework.Bundle bundle)
Returns whether or not the provided bundle is allowed to useSlingRepository.loginAdministrative(String)
.- Parameters:
bundle
- The bundle requiring access tologinAdministrative
- Returns:
- A boolean value indicating whether or not the bundle is allowed
to use
loginAdministrative
.
-
acquireRepository
protected abstract javax.jcr.Repository acquireRepository()
Creates the backing JCR repository instances. It is expected for this method to just start the repository.This method does not throw any
Throwable
but instead just returnsnull
if not repository is available. Any problems trying to acquire the repository must be caught and logged as appropriate.- Returns:
- The acquired JCR
Repository
ornull
if not repository can be acquired. - See Also:
start(BundleContext, String, boolean)
-
registerService
protected final org.osgi.framework.ServiceRegistration registerService()
Registers this component as an OSGi service with the types provided by thegetServiceRegistrationInterfaces()
method and properties provided by thegetServiceRegistrationProperties()
method.The repository is actually registered as an OSGi
ServiceFactory
where thecreate(Bundle)
method is called to create an actualAbstractSlingRepository2
repository instance for a calling (using) bundle. When the bundle is done using the repository instance, thedestroy(AbstractSlingRepository2)
method is called to clean up.- Returns:
- The OSGi
ServiceRegistration
object representing the registered service. - See Also:
start(BundleContext, String, boolean)
,getServiceRegistrationInterfaces()
,getServiceRegistrationProperties()
,create(Bundle)
,destroy(AbstractSlingRepository2)
-
getServiceRegistrationProperties
protected abstract Dictionary<String,Object> getServiceRegistrationProperties()
Return the service registration properties to be used to register the repository service inregisterService()
.- Returns:
- The service registration properties to be used to register the
repository service in
registerService()
- See Also:
registerService()
-
getServiceRegistrationInterfaces
protected String[] getServiceRegistrationInterfaces()
Returns the service types to be used to register the repository service inregisterService()
. 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
andRepository
, must always be included.- Returns:
- The service types to be used to register the repository service
in
registerService()
- See Also:
registerService()
-
create
protected abstract AbstractSlingRepository2 create(org.osgi.framework.Bundle usingBundle)
Creates an instance of theAbstractSlingRepository2
implementation for use by the givenusingBundle
.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.
- Parameters:
usingBundle
- The bundle providing from which the repository is requested.- Returns:
- The
AbstractSlingRepository2
implementation instance to be used by theusingBundle
. - See Also:
registerService()
-
destroy
protected abstract void destroy(AbstractSlingRepository2 repositoryServiceInstance)
Cleans up the givenAbstractSlingRepository2
instance previously created by thecreate(Bundle)
method.- Parameters:
repositoryServiceInstance
- TheAbstractSlingRepository2
istance to cleanup.- See Also:
registerService()
-
getRepository
protected final javax.jcr.Repository getRepository()
Returns the repository underlying this instance ornull
if no repository is currently being available.- Returns:
- The repository
-
unregisterService
protected final void unregisterService(org.osgi.framework.ServiceRegistration serviceRegistration)
Unregisters the service represented by theserviceRegistration
.- Parameters:
serviceRegistration
- The service to unregister
-
disposeRepository
protected abstract void disposeRepository(javax.jcr.Repository repository)
Disposes off the givenrepository
.- Parameters:
repository
- The repository to be disposed off which is the same as the one returned fromacquireRepository()
.
-
stoppingOnError
protected void stoppingOnError(String message, Throwable t)
Called when the repository service cannot be initialized or registered because an exception occurred.This default implementation logs the exception as an error.
- Parameters:
message
- failure details.t
- the exception.
-
start
@Deprecated protected final boolean start(org.osgi.framework.BundleContext bundleContext, String defaultWorkspace, boolean disableLoginAdministrative)
Deprecated.This method was deprecated with the introduction of asynchronous repository registration. With asynchronous registration a boolean return value can no longer be guaranteed, as registration may happen after the method returns.Instead a
ServiceListener
forSlingRepository
may be registered to get informed about its successful registration.- Parameters:
bundleContext
- TheBundleContext
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 benull
to have the actual repository instance define its own defaultdisableLoginAdministrative
- Whether to disable theSlingRepository.loginAdministrative
method or not.- Returns:
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 theSlingRepository
as a service is using aServiceListener
.
-
start
protected final void start(org.osgi.framework.BundleContext bundleContext, AbstractSlingRepositoryManager.Config config)
This method actually starts the backing repository instannce and registeres the repository service.Multiple subsequent calls to this method without calling
stop()
first have no effect.- Parameters:
bundleContext
- TheBundleContext
to register the repository service (and optionally more services required to operate the repository)config
- The configuration to apply to this instance.
-
stop
protected final void stop()
-
-