Package org.nuxeo.ecm.core.repository
Class RepositoryService
- java.lang.Object
-
- org.nuxeo.runtime.model.DefaultComponent
-
- org.nuxeo.ecm.core.repository.RepositoryService
-
- All Implemented Interfaces:
Adaptable
,Component
,Extensible
,TimestampedService
public class RepositoryService extends DefaultComponent
Component and service managing low-level repository instances.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
RepositoryService.SessionFactory
protected class
RepositoryService.SessionSynchronization
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.pool2.impl.GenericKeyedObjectPool<String,Session>
basePool
static Duration
CLUSTER_START_DURATION_DEFAULT
static String
CLUSTER_START_DURATION_PROP
static ComponentName
NAME
protected org.apache.commons.pool2.KeyedObjectPool<String,Session>
pool
protected PoolConfiguration
poolConfig
protected static Map<String,ThreadLocal<Session>>
SESSIONS
Thread-local sessions allocated, per repository.static String
XP_REPOSITORY
-
Fields inherited from class org.nuxeo.runtime.model.DefaultComponent
lastModified, name
-
-
Constructor Summary
Constructors Constructor Description RepositoryService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
createRepository(String repositoryName, RepositoryFactory factory)
protected void
doCreateRepositories()
Creates all the repositories.protected void
doInitRepositories()
Initializes all the repositories.int
getActiveSessionsCount()
int
getActiveSessionsCount(String repositoryName)
<T> T
getAdapter(Class<T> adapter)
Returns an object which is an instance of the given class associated with this object.int
getApplicationStartedOrder()
The component notification order forComponent.applicationStarted(org.nuxeo.runtime.model.ComponentContext)
.protected RepositoryFactory
getFactory(String repositoryName)
org.apache.commons.pool2.impl.GenericKeyedObjectPool<String,?>
getPool()
Repository
getRepository(String repositoryName)
Gets a repository given its name.List<String>
getRepositoryNames()
Session
getSession(String repositoryName)
Gets a session.protected Session
getSessionFromPool(String repositoryName, Runnable cleanup)
protected void
initializeRepository(RepositoryInitializationHandler handler, String name)
protected void
initPool()
protected void
initPoolConfig()
void
initRepositories()
Start a tx and initialize repositories content.void
resetPool()
void
shutdown()
protected void
shutdownPool()
void
start(ComponentContext context)
Start the component.void
stop(ComponentContext context)
Stop the component.-
Methods inherited from class org.nuxeo.runtime.model.DefaultComponent
activate, addRuntimeMessage, addRuntimeMessage, deactivate, getDescriptor, getDescriptors, getLastModified, getRegistry, register, registerContribution, registerExtension, setLastModified, setModifiedNow, setName, unregister, unregisterContribution, unregisterExtension
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nuxeo.runtime.model.Component
applicationStarted
-
-
-
-
Field Detail
-
NAME
public static final ComponentName NAME
-
CLUSTER_START_DURATION_PROP
public static final String CLUSTER_START_DURATION_PROP
- Since:
- 11.1
- See Also:
- Constant Field Values
-
CLUSTER_START_DURATION_DEFAULT
public static final Duration CLUSTER_START_DURATION_DEFAULT
- Since:
- 11.1
-
XP_REPOSITORY
public static final String XP_REPOSITORY
- See Also:
- Constant Field Values
-
poolConfig
protected PoolConfiguration poolConfig
-
SESSIONS
protected static final Map<String,ThreadLocal<Session>> SESSIONS
Thread-local sessions allocated, per repository.
-
-
Method Detail
-
shutdown
public void shutdown()
-
getApplicationStartedOrder
public int getApplicationStartedOrder()
Description copied from interface:Component
The component notification order forComponent.applicationStarted(org.nuxeo.runtime.model.ComponentContext)
.Components are notified in increasing order. Order 1000 is the default order for components that don't care. Order 100 is the repository initialization.
- Returns:
- the order, 1000 by default
-
start
public void start(ComponentContext context)
Description copied from interface:Component
Start the component. This method is called after all the components were resolved and activated- Specified by:
start
in interfaceComponent
- Overrides:
start
in classDefaultComponent
-
stop
public void stop(ComponentContext context)
Description copied from interface:Component
Stop the component.- Specified by:
stop
in interfaceComponent
- Overrides:
stop
in classDefaultComponent
-
initPoolConfig
protected void initPoolConfig()
-
initPool
protected void initPool()
-
shutdownPool
protected void shutdownPool()
-
resetPool
public void resetPool()
-
getPool
public org.apache.commons.pool2.impl.GenericKeyedObjectPool<String,?> getPool()
-
initRepositories
public void initRepositories()
Start a tx and initialize repositories content. This method is publicly exposed since it is needed by tests to initialize repositories after cleanups (see CoreFeature).- Since:
- 8.4
-
doCreateRepositories
protected void doCreateRepositories()
Creates all the repositories. Requires an active transaction.- Since:
- 9.3
-
createRepository
protected void createRepository(String repositoryName, RepositoryFactory factory)
-
doInitRepositories
protected void doInitRepositories()
Initializes all the repositories. Requires an active transaction.- Since:
- 9.3
-
getAdapter
public <T> T getAdapter(Class<T> adapter)
Description copied from interface:Adaptable
Returns an object which is an instance of the given class associated with this object. Returnsnull
if no such object can be found.- Specified by:
getAdapter
in interfaceAdaptable
- Overrides:
getAdapter
in classDefaultComponent
- Parameters:
adapter
- the adapter class to look up- Returns:
- a object castable to the given class, or
null
if this object does not have an adapter for the given class
-
initializeRepository
protected void initializeRepository(RepositoryInitializationHandler handler, String name)
-
getRepository
public Repository getRepository(String repositoryName)
Gets a repository given its name.Null is returned if no repository with that name was registered.
- Parameters:
repositoryName
- the repository name- Returns:
- the repository instance or null if no repository with that name was registered
-
getFactory
protected RepositoryFactory getFactory(String repositoryName)
-
getActiveSessionsCount
public int getActiveSessionsCount()
-
getActiveSessionsCount
public int getActiveSessionsCount(String repositoryName)
-
getSession
public Session getSession(String repositoryName)
Gets a session.The session is first looked up in the current transaction, otherwise fetched from a pool.
- Parameters:
repositoryName
- the repository name- Returns:
- the session
- Since:
- 11.1
-
-