org.modeshape.jcr.cache

## Class RepositoryCache

- java.lang.Object
- - org.modeshape.jcr.cache.RepositoryCache

-     public class RepositoryCache
      extends Object

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `RepositoryCache.ChangesToWorkspacesListener`
    `static interface` | `RepositoryCache.ContentInitializer`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Logger` | `logger`
    `static RepositoryCache.ContentInitializer` | `NO_OP_INITIALIZER`
    `protected NodeKey` | `systemMetadataKey`
    `protected Upgrades` | `upgrades`
    `protected Set<String>` | `workspaceNames`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RepositoryCache(ExecutionContext context, DocumentStore documentStore, ClusteringService clusteringService, RepositoryConfiguration configuration, RepositoryCache.ContentInitializer initializer, SessionEnvironment sessionContext, ChangeBus changeBus, CacheContainer workspaceCacheContainer, Upgrades upgradeFunctions)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Cache<NodeKey,CachedNode>` | `cacheForWorkspace(String name)`
    `protected String` | `cacheNameForWorkspace(String workspaceName)`
    `ChangeBus` | `changeBus()`
    `RepositoryCache` | `completeInitialization()`
    `void` | `completeShutdown()`
    `RepositoryCache` | `completeUpgrade(Upgrades.Context resources)`
    `protected ExecutionContext` | `context()`
    `SessionCache` | `createSession(ExecutionContext context, String workspaceName, boolean readOnly)` Create a session for the workspace with the given name, using the supplied ExecutionContext for the session.
    `WorkspaceCache` | `createWorkspace(String name)` Create a new workspace in this repository, if the repository is appropriately configured.
    `boolean` | `destroyWorkspace(String name, WritableSessionCache removeSession)` Permanently destroys the workspace with the supplied name, if the repository is appropriately configured, also unlinking the jcr:system node from the root node .
    `protected DocumentStore` | `documentStore()`
    `DocumentTranslator` | `getDocumentTranslator()`
    `String` | `getKey()` Get the key for this repository.
    `String` | `getName()` Get the name for this repository.
    `NodeKey` | `getRepositoryMetadataDocumentKey()` Get the identifier of the repository's metadata document.
    `NodeKey` | `getSystemKey()`
    `String` | `getSystemWorkspaceKey()`
    `String` | `getSystemWorkspaceName()`
    `WorkspaceCache` | `getWorkspaceCache(String workspaceName)` Get the NodeCache for the workspace with the given name.
    `Set<String>` | `getWorkspaceNames()` Get the names of all available workspaces in this repository.
    `boolean` | `isAccessControlEnabled()`
    `boolean` | `isInitializingRepository()`
    `long` | `largeValueSizeInBytes()`
    `protected Name` | `name(String name)`
    `LocalDocumentStore.DocumentOperationResults` | `optimizeChildren(int targetCountPerBlock, int tolerance)` Optimize the children in the supplied node document Note that this method changes the underlying db as well as the given document, so *it must* be called either from a transactional context or it must be followed by a session.save call, otherwise there might be inconsistencies between what a session sees as "persisted" state and the reality.
    `protected String` | `processKey()`
    `protected void` | `refreshRepositoryMetadata(boolean update)`
    `void` | `rollbackRepositoryInfo()` Removes the repository info document, in case the repository has not yet been initialized (as indicated by the presence of the #REPOSITORY_INITIALIZED_AT_FIELD_NAME field).
    `void` | `runOneTimeSystemInitializationOperation(Callable<Void> initOperation)` Executes the given operation only once, when the repository is created for the first time, using child node under jcr:system as a global "lock".
    `protected SessionEnvironment` | `sessionContext()`
    `void` | `setAccessControlEnabled(boolean enabled)`
    `void` | `setLargeStringLength(long sizeInBytes)`
    `void` | `startShutdown()`
    `String` | `toString()`
    `protected boolean` | `waitUntil(Callable<Boolean> condition, long time, TimeUnit unit, I18n failureMsg)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### systemMetadataKey

          protected final NodeKey systemMetadataKey

    - #### workspaceNames

          protected final Set<String> workspaceNames

    - #### logger

          protected final Logger logger

    - #### upgrades

          protected final Upgrades upgrades

    - #### NO_OP_INITIALIZER

          public static final RepositoryCache.ContentInitializer NO_OP_INITIALIZER

  - ### Constructor Detail

    - #### RepositoryCache

          public RepositoryCache(ExecutionContext context,
                         DocumentStore documentStore,
                         ClusteringService clusteringService,
                         RepositoryConfiguration configuration,
                         RepositoryCache.ContentInitializer initializer,
                         SessionEnvironment sessionContext,
                         ChangeBus changeBus,
                         CacheContainer workspaceCacheContainer,
                         Upgrades upgradeFunctions)

  - ### Method Detail

    - #### waitUntil

          protected boolean waitUntil(Callable<Boolean> condition,
                          long time,
                          TimeUnit unit,
                          I18n failureMsg)

    - #### rollbackRepositoryInfo

          public final void rollbackRepositoryInfo()

      Removes the repository info document, in case the repository has not yet been initialized (as indicated by the presence of the #REPOSITORY_INITIALIZED_AT_FIELD_NAME field). This should only be used during repository startup, in case an unexpected error occurs.

    - #### changeBus

          public final ChangeBus changeBus()

    - #### sessionContext

          protected final SessionEnvironment sessionContext()

    - #### processKey

          protected final String processKey()

    - #### name

          protected Name name(String name)

    - #### isInitializingRepository

          public final boolean isInitializingRepository()

    - #### isAccessControlEnabled

          public final boolean isAccessControlEnabled()

    - #### setAccessControlEnabled

          public final void setAccessControlEnabled(boolean enabled)

    - #### documentStore

          protected final DocumentStore documentStore()

    - #### context

          protected final ExecutionContext context()

    - #### completeInitialization

          public RepositoryCache completeInitialization()

    - #### completeUpgrade

          public RepositoryCache completeUpgrade(Upgrades.Context resources)

    - #### startShutdown

          public void startShutdown()

    - #### completeShutdown

          public void completeShutdown()

    - #### getRepositoryMetadataDocumentKey

          public NodeKey getRepositoryMetadataDocumentKey()

      Get the identifier of the repository's metadata document.
      Returns:
        the cache key for the repository's metadata document; never null

    - #### setLargeStringLength

          public void setLargeStringLength(long sizeInBytes)

    - #### largeValueSizeInBytes

          public long largeValueSizeInBytes()

    - #### refreshRepositoryMetadata

          protected void refreshRepositoryMetadata(boolean update)

    - #### runOneTimeSystemInitializationOperation

          public void runOneTimeSystemInitializationOperation(Callable<Void> initOperation)
                                                       throws Exception

      Executes the given operation only once, when the repository is created for the first time, using child node under jcr:system as a global "lock". In a cluster, this should only be run by the node which performs the initialization.
      Parameters:
        `initOperation` - a `non-null` `Callable` instance
      Throws:
        `Exception` - if anything unexpected occurs, clients are expected to handle this

    - #### getKey

          public final String getKey()

      Get the key for this repository.
      Returns:
        the repository's key; never null

    - #### getSystemKey

          public final NodeKey getSystemKey()

    - #### getSystemWorkspaceKey

          public final String getSystemWorkspaceKey()

    - #### getSystemWorkspaceName

          public final String getSystemWorkspaceName()

    - #### getName

          public final String getName()

      Get the name for this repository.
      Returns:
        the repository's name; never null

    - #### getWorkspaceNames

          public final Set<String> getWorkspaceNames()

      Get the names of all available workspaces in this repository. Not all workspaces may be loaded. This set does not contain the system workspace name, as that workspace is not accessible/visible to JCR clients.
      Returns:
        the names of all available workspaces; never null and immutable

    - #### cacheForWorkspace

          protected Cache<NodeKey,CachedNode> cacheForWorkspace(String name)

    - #### cacheNameForWorkspace

          protected final String cacheNameForWorkspace(String workspaceName)

    - #### getDocumentTranslator

          public final DocumentTranslator getDocumentTranslator()

    - #### createWorkspace

          public WorkspaceCache createWorkspace(String name)

      Create a new workspace in this repository, if the repository is appropriately configured. If the repository already contains a workspace with the supplied name, then this method simply returns that workspace. Otherwise, this method attempts to create the named workspace and will return a cache for this newly-created workspace.
      Parameters:
        `name` - the workspace name
      Returns:
        the workspace cache for the new (or existing) workspace; never null
      Throws:
        `UnsupportedOperationException` - if this repository was not configured to allow `creation of workspaces`.

    - #### destroyWorkspace

          public boolean destroyWorkspace(String name,
                                 WritableSessionCache removeSession)

      Permanently destroys the workspace with the supplied name, if the repository is appropriately configured, also unlinking the jcr:system node from the root node . If no such workspace exists in this repository, this method simply returns. Otherwise, this method attempts to destroy the named workspace.
      Parameters:
        `name` - the workspace name
        `removeSession` - an outside session which will be used to unlink the jcr:system node and which is needed to guarantee atomicity.
      Returns:
        true if the workspace with the supplied name existed and was destroyed, or false otherwise
      Throws:
        `UnsupportedOperationException` - if this repository was not configured to allow `creation (and destruction) of workspaces`.

    - #### getWorkspaceCache

          public WorkspaceCache getWorkspaceCache(String workspaceName)

      Get the NodeCache for the workspace with the given name. This session can be used (by multiple concurrent threads) to read, create, change, or delete content.

      The session maintains a transient set of changes to the workspace content, and these changes are always visible. But additionally any changes to the workspace content saved by other sessions will immediately be visible to this session. Notice that at times the changes persisted by other sessions may cause some of this session's transient state to become invalid. (For example, this session's newly-created child of some node, A, may become invalid or inaccessible if some other session saved a deletion of node A.)

      Parameters:
        `workspaceName` - the name of the workspace; may not be null
      Returns:
        the node cache; never null
      Throws:
        `WorkspaceNotFoundException` - if no such workspace exists

    - #### createSession

          public SessionCache createSession(ExecutionContext context,
                                   String workspaceName,
                                   boolean readOnly)

      Create a session for the workspace with the given name, using the supplied ExecutionContext for the session.
      Parameters:
        `context` - the context for the new session; may not be null
        `workspaceName` - the name of the workspace; may not be null
        `readOnly` - true if the session is to be read-only
      Returns:
        the new session that supports writes; never null
      Throws:
        `WorkspaceNotFoundException` - if no such workspace exists

    - #### optimizeChildren

          public LocalDocumentStore.DocumentOperationResults optimizeChildren(int targetCountPerBlock,
                                                                     int tolerance)

      Optimize the children in the supplied node document

      Note that this method changes the underlying db as well as the given document, so *it must* be called either from a transactional context or it must be followed by a session.save call, otherwise there might be inconsistencies between what a session sees as "persisted" state and the reality.

      Parameters:
        `targetCountPerBlock` - the target number of children per block
        `tolerance` - the allowed tolerance between the target and actual number of children per block
      Returns:
        the results of the optimization; never null

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.