org.apache.sling.jcr.base
Class AbstractSlingRepository

java.lang.Object
  extended by org.apache.sling.jcr.base.AbstractSlingRepository
All Implemented Interfaces:
java.lang.Runnable, java.util.EventListener, javax.jcr.Repository, org.apache.sling.jcr.api.SlingRepository, org.osgi.framework.BundleListener, org.osgi.framework.SynchronousBundleListener

public abstract class AbstractSlingRepository
extends java.lang.Object
implements org.apache.sling.jcr.api.SlingRepository, org.osgi.framework.SynchronousBundleListener, java.lang.Runnable

The AbstractSlingRepository is an abstract implementation of the SlingRepository interface which provides core support for session pooling. Implementations of the SlingRepository interface may wish to extend this class to benefit from a default implementation.

Extensions of this class will have to declare the following scr.property tags to have them declared automatically in the respective component and metatype definitions by the maven-sling-plugin:


Field Summary
static java.lang.String DEFAULT_ADMIN_PASS
           
static java.lang.String DEFAULT_ADMIN_USER
           
static java.lang.String DEFAULT_ANONYMOUS_PASS
           
static java.lang.String DEFAULT_ANONYMOUS_USER
           
static int DEFAULT_POLL_ACTIVE
          The default value for the number of seconds to wait between two consecutive checks while the repository is active (value is 10).
static int DEFAULT_POLL_INACTIVE
          The default value for the number of seconds to wait between two consecutive checks while the repository is not active (value is 10).
static int MIN_POLL
          The minimum number of seconds allowed for any of the two poll times
static java.lang.String PROPERTY_ADMIN_PASS
           
static java.lang.String PROPERTY_ADMIN_USER
           
static java.lang.String PROPERTY_ANONYMOUS_PASS
           
static java.lang.String PROPERTY_ANONYMOUS_USER
           
static java.lang.String PROPERTY_DEFAULT_WORKSPACE
           
static java.lang.String PROPERTY_MAX_ACTIVE_SESSIONS
          The name of the configuration parameter containing the upper limit of the simultaneously active sessions (value is "pool.maxActive").
static java.lang.String PROPERTY_MAX_ACTIVE_SESSIONS_WAIT
          The name of the configuration parameter containing the maximum number of seconds to wait for the number of currently active sessions to drop be low the upper limit before giving up (value is "pool.maxActiveWait").
static java.lang.String PROPERTY_MAX_IDLE_SESSIONS
          The name of the configuration parameter containing the upper limit of the currently idle sessions to keep in the pool (value is "pool.maxIdle").
static java.lang.String PROPERTY_POLL_ACTIVE
           
static java.lang.String PROPERTY_POLL_INACTIVE
           
 
Fields inherited from interface javax.jcr.Repository
LEVEL_1_SUPPORTED, LEVEL_2_SUPPORTED, OPTION_LOCKING_SUPPORTED, OPTION_OBSERVATION_SUPPORTED, OPTION_QUERY_SQL_SUPPORTED, OPTION_TRANSACTIONS_SUPPORTED, OPTION_VERSIONING_SUPPORTED, QUERY_XPATH_DOC_ORDER, QUERY_XPATH_POS_INDEX, REP_NAME_DESC, REP_VENDOR_DESC, REP_VENDOR_URL_DESC, REP_VERSION_DESC, SPEC_NAME_DESC, SPEC_VERSION_DESC
 
Constructor Summary
protected AbstractSlingRepository()
           
 
Method Summary
protected  javax.jcr.Repository acquireRepository()
          Acquires the repository by calling the RepositoryAccessor.getRepositoryFromURL(String) with the value of the RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY framework or configuration property.
protected  void activate(org.osgi.service.component.ComponentContext componentContext)
          This method must be called if overwritten by implementations !!
protected  void bindLog(org.osgi.service.log.LogService log)
           
 void bundleChanged(org.osgi.framework.BundleEvent event)
          Loads and unloads any components provided by the bundle whose state changed.
protected  org.apache.sling.jcr.base.internal.SessionPool createSessionPool(org.apache.sling.jcr.base.internal.SessionPoolManager mgr, javax.jcr.SimpleCredentials credentials)
           
protected  void deactivate(org.osgi.service.component.ComponentContext componentContext)
          This method must be called if overwritten by implementations !!
protected  void disposeRepository(javax.jcr.Repository repository)
          Disposes off the given repository.
protected  org.osgi.service.component.ComponentContext getComponentContext()
           
 java.lang.String getDefaultWorkspace()
          Returns the default workspace, which may be null meaning to use the repository provided default workspace.
 java.lang.String getDescriptor(java.lang.String name)
           
 java.lang.String[] getDescriptorKeys()
           
protected  org.apache.sling.jcr.base.internal.SessionPoolManager getPoolManager()
           
protected  javax.jcr.Repository getRepository()
          Returns the repository underlying this instance or null if no repository is currently being available.
protected  RepositoryAccessor getRepositoryAccessor()
          Returns a new instance of the RepositoryAccessor class to access a repository over RMI or through JNDI.
protected  org.apache.sling.jcr.base.internal.SessionPoolFactory getSessionPoolFactory()
           
protected  void log(int level, java.lang.String message)
           
protected  void log(int level, java.lang.String message, java.lang.Throwable t)
           
 javax.jcr.Session login()
          Logs in as an anonymous user.
 javax.jcr.Session login(javax.jcr.Credentials credentials)
           
 javax.jcr.Session login(javax.jcr.Credentials credentials, java.lang.String workspace)
           
 javax.jcr.Session login(java.lang.String workspace)
           
 javax.jcr.Session loginAdministrative(java.lang.String workspace)
           
protected  boolean pingAndCheck()
          Ping our current repository and check that admin login (required by Sling) works.
protected  boolean pingRepository(javax.jcr.Repository repository)
          Checks that the given repository is still available.
protected  org.osgi.framework.ServiceRegistration registerService()
          Registers this component as an OSGi service with type javax.jcr.Repository and org.apache.sling.jcr.api.SlingRepository using the component properties as service registration properties.
 void run()
           
protected  void setupRepository(javax.jcr.Repository repository)
          This method is called after a repository has been acquired by acquireRepository() but before the repository is registered as a service.
protected  void tearDown(javax.jcr.Repository repository)
          Performs any cleanups before the repository is actually disposed off by the disposeRepository(Repository) method.
protected  void unbindLog(org.osgi.service.log.LogService log)
           
protected  void unregisterService(org.osgi.framework.ServiceRegistration serviceRegistration)
          Unregisters the service represented by the serviceRegistration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_DEFAULT_WORKSPACE

public static final java.lang.String PROPERTY_DEFAULT_WORKSPACE
See Also:
Constant Field Values

PROPERTY_ANONYMOUS_USER

public static final java.lang.String PROPERTY_ANONYMOUS_USER
See Also:
Constant Field Values

PROPERTY_ANONYMOUS_PASS

public static final java.lang.String PROPERTY_ANONYMOUS_PASS
See Also:
Constant Field Values

PROPERTY_ADMIN_USER

public static final java.lang.String PROPERTY_ADMIN_USER
See Also:
Constant Field Values

PROPERTY_ADMIN_PASS

public static final java.lang.String PROPERTY_ADMIN_PASS
See Also:
Constant Field Values

PROPERTY_POLL_ACTIVE

public static final java.lang.String PROPERTY_POLL_ACTIVE
See Also:
Constant Field Values

PROPERTY_POLL_INACTIVE

public static final java.lang.String PROPERTY_POLL_INACTIVE
See Also:
Constant Field Values

PROPERTY_MAX_ACTIVE_SESSIONS_WAIT

public static final java.lang.String PROPERTY_MAX_ACTIVE_SESSIONS_WAIT
The name of the configuration parameter containing the maximum number of seconds to wait for the number of currently active sessions to drop be low the upper limit before giving up (value is "pool.maxActiveWait").

See Also:
Constant Field Values

PROPERTY_MAX_ACTIVE_SESSIONS

public static final java.lang.String PROPERTY_MAX_ACTIVE_SESSIONS
The name of the configuration parameter containing the upper limit of the simultaneously active sessions (value is "pool.maxActive").

See Also:
Constant Field Values

PROPERTY_MAX_IDLE_SESSIONS

public static final java.lang.String PROPERTY_MAX_IDLE_SESSIONS
The name of the configuration parameter containing the upper limit of the currently idle sessions to keep in the pool (value is "pool.maxIdle").

See Also:
Constant Field Values

DEFAULT_ANONYMOUS_USER

public static final java.lang.String DEFAULT_ANONYMOUS_USER
See Also:
Constant Field Values

DEFAULT_ANONYMOUS_PASS

public static final java.lang.String DEFAULT_ANONYMOUS_PASS
See Also:
Constant Field Values

DEFAULT_ADMIN_USER

public static final java.lang.String DEFAULT_ADMIN_USER
See Also:
Constant Field Values

DEFAULT_ADMIN_PASS

public static final java.lang.String DEFAULT_ADMIN_PASS
See Also:
Constant Field Values

DEFAULT_POLL_ACTIVE

public static final int DEFAULT_POLL_ACTIVE
The default value for the number of seconds to wait between two consecutive checks while the repository is active (value is 10).

See Also:
Constant Field Values

DEFAULT_POLL_INACTIVE

public static final int DEFAULT_POLL_INACTIVE
The default value for the number of seconds to wait between two consecutive checks while the repository is not active (value is 10).

See Also:
Constant Field Values

MIN_POLL

public static final int MIN_POLL
The minimum number of seconds allowed for any of the two poll times

See Also:
Constant Field Values
Constructor Detail

AbstractSlingRepository

protected AbstractSlingRepository()
Method Detail

getDefaultWorkspace

public final java.lang.String getDefaultWorkspace()
Returns the default workspace, which may be null meaning to use the repository provided default workspace. Declared final to make sure the SLING-256 rule is enforced.

Specified by:
getDefaultWorkspace in interface org.apache.sling.jcr.api.SlingRepository

login

public javax.jcr.Session login()
                        throws javax.jcr.LoginException,
                               javax.jcr.RepositoryException
Logs in as an anonymous user. This implementation simply returns the result of calling login(Credentials, String)

Specified by:
login in interface javax.jcr.Repository
Throws:
javax.jcr.LoginException
javax.jcr.RepositoryException

loginAdministrative

public javax.jcr.Session loginAdministrative(java.lang.String workspace)
                                      throws javax.jcr.RepositoryException
Specified by:
loginAdministrative in interface org.apache.sling.jcr.api.SlingRepository
Throws:
javax.jcr.RepositoryException

login

public javax.jcr.Session login(javax.jcr.Credentials credentials)
                        throws javax.jcr.LoginException,
                               javax.jcr.RepositoryException
Specified by:
login in interface javax.jcr.Repository
Throws:
javax.jcr.LoginException
javax.jcr.RepositoryException

login

public javax.jcr.Session login(java.lang.String workspace)
                        throws javax.jcr.LoginException,
                               javax.jcr.NoSuchWorkspaceException,
                               javax.jcr.RepositoryException
Specified by:
login in interface javax.jcr.Repository
Throws:
javax.jcr.LoginException
javax.jcr.NoSuchWorkspaceException
javax.jcr.RepositoryException

login

public javax.jcr.Session login(javax.jcr.Credentials credentials,
                               java.lang.String workspace)
                        throws javax.jcr.LoginException,
                               javax.jcr.NoSuchWorkspaceException,
                               javax.jcr.RepositoryException
Specified by:
login in interface javax.jcr.Repository
Throws:
javax.jcr.LoginException
javax.jcr.NoSuchWorkspaceException
javax.jcr.RepositoryException

getDescriptor

public java.lang.String getDescriptor(java.lang.String name)
Specified by:
getDescriptor in interface javax.jcr.Repository

getDescriptorKeys

public java.lang.String[] getDescriptorKeys()
Specified by:
getDescriptorKeys in interface javax.jcr.Repository

getPoolManager

protected final org.apache.sling.jcr.base.internal.SessionPoolManager getPoolManager()

getSessionPoolFactory

protected org.apache.sling.jcr.base.internal.SessionPoolFactory getSessionPoolFactory()
Returns:

createSessionPool

protected org.apache.sling.jcr.base.internal.SessionPool createSessionPool(org.apache.sling.jcr.base.internal.SessionPoolManager mgr,
                                                                           javax.jcr.SimpleCredentials credentials)

log

protected void log(int level,
                   java.lang.String message)

log

protected void log(int level,
                   java.lang.String message,
                   java.lang.Throwable t)

getRepositoryAccessor

protected RepositoryAccessor getRepositoryAccessor()
Returns a new instance of the RepositoryAccessor class to access a repository over RMI or through JNDI.

Extensions of this method may return an extension of the RepositoryAccessor class if the provide extended functionality.


acquireRepository

protected javax.jcr.Repository acquireRepository()
Acquires the repository by calling the RepositoryAccessor.getRepositoryFromURL(String) with the value of the RepositoryAccessor.REPOSITORY_URL_OVERRIDE_PROPERTY framework or configuration property. If the property exists and a repository can be accessed using this property, that repository is returned. Otherwise null is returned.

Extensions of this class may overwrite this method with implementation specific acquisition semantics and may call this base class method or not as the implementation sees fit.

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.

Returns:
The acquired JCR Repository or null if not repository can be acquired.

setupRepository

protected void setupRepository(javax.jcr.Repository repository)
This method is called after a repository has been acquired by acquireRepository() but before the repository is registered as a service.

Implementations may overwrite this method but MUST call this base class implementation first.

Parameters:
repository - The JCR Repository to setup.

registerService

protected org.osgi.framework.ServiceRegistration registerService()
Registers this component as an OSGi service with type javax.jcr.Repository and org.apache.sling.jcr.api.SlingRepository using the component properties as service registration properties.

This method may be overwritten to register the component with different types.

Returns:
The OSGi ServiceRegistration object representing the registered service.

getRepository

protected javax.jcr.Repository getRepository()
Returns the repository underlying this instance or null if no repository is currently being available.


pingRepository

protected boolean pingRepository(javax.jcr.Repository repository)
Checks that the given repository is still available. This implementation tries to get the Repository.SPEC_NAME_DESC descriptor from the repository and returns true if the returned value is not null.

Extensions of this class may overwrite this method to implement different access checks. The contract of this method must be obeyed, though in a sense, the true must only be returned if repository is actually usable.

Parameters:
repository - The JCR Repository to check for availability.
Returns:
true if repository is not null and accessible.

pingAndCheck

protected boolean pingAndCheck()
Ping our current repository and check that admin login (required by Sling) works.


unregisterService

protected void unregisterService(org.osgi.framework.ServiceRegistration serviceRegistration)
Unregisters the service represented by the serviceRegistration.

This method may be overwritten by extensions of this class as long as it is made sure, the given service registration is unregistered.


tearDown

protected void tearDown(javax.jcr.Repository repository)
Performs any cleanups before the repository is actually disposed off by the disposeRepository(Repository) method.

This method is meant for cleanup tasks before the repository is actually disposed off. Extensions of this class may overwrite but must call this base class implementation.

Parameters:
repository -

disposeRepository

protected void disposeRepository(javax.jcr.Repository repository)
Disposes off the given repository. This base class implementation does nothing. Extensions should overwrite if any special disposal operation is required.

Parameters:
repository -

bundleChanged

public void bundleChanged(org.osgi.framework.BundleEvent event)
Loads and unloads any components provided by the bundle whose state changed. If the bundle has been started, the components are loaded. If the bundle is about to stop, the components are unloaded.

Specified by:
bundleChanged in interface org.osgi.framework.BundleListener
Parameters:
event - The BundleEvent representing the bundle state change.

getComponentContext

protected org.osgi.service.component.ComponentContext getComponentContext()

activate

protected void activate(org.osgi.service.component.ComponentContext componentContext)
                 throws java.lang.Exception
This method must be called if overwritten by implementations !!

Throws:
nothing, - but allow derived classes to throw any Exception
java.lang.Exception

deactivate

protected void deactivate(org.osgi.service.component.ComponentContext componentContext)
This method must be called if overwritten by implementations !!

Parameters:
componentContext -

bindLog

protected void bindLog(org.osgi.service.log.LogService log)

unbindLog

protected void unbindLog(org.osgi.service.log.LogService log)

run

public void run()
Specified by:
run in interface java.lang.Runnable


Copyright © 2007-2009. All Rights Reserved.