ModeShape Distribution 3.5.0.Final

org.modeshape.jcr.cache
Class RepositoryCache

java.lang.Object
  extended by org.modeshape.jcr.cache.RepositoryCache
All Implemented Interfaces:
Observable

public class RepositoryCache
extends Object
implements Observable


Nested Class Summary
static interface RepositoryCache.ContentInitializer
           
protected  class RepositoryCache.LocalChangeListener
           
 
Field Summary
protected  Logger logger
           
static RepositoryCache.ContentInitializer NO_OP_INITIALIZER
           
protected  NodeKey systemMetadataKey
           
protected  Set<String> workspaceNames
           
 
Constructor Summary
RepositoryCache(ExecutionContext context, DocumentStore documentStore, RepositoryConfiguration configuration, RepositoryCache.ContentInitializer initializer, SessionEnvironment sessionContext, ChangeBus changeBus, org.infinispan.manager.CacheContainer workspaceCacheContainer)
           
 
Method Summary
protected  org.infinispan.Cache<NodeKey,CachedNode> cacheForWorkspace(String name)
           
protected  String cacheNameForWorkspace(String workspaceName)
           
 void completeInitialization()
           
 void completeShutdown()
           
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)
           
 boolean register(ChangeSetListener observer)
          Register the supplied observer.
 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()
           
 boolean unregister(ChangeSetListener observer)
          Unregister the supplied observer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

systemMetadataKey

protected final NodeKey systemMetadataKey

workspaceNames

protected final Set<String> workspaceNames

logger

protected final Logger logger

NO_OP_INITIALIZER

public static final RepositoryCache.ContentInitializer NO_OP_INITIALIZER
Constructor Detail

RepositoryCache

public RepositoryCache(ExecutionContext context,
                       DocumentStore documentStore,
                       RepositoryConfiguration configuration,
                       RepositoryCache.ContentInitializer initializer,
                       SessionEnvironment sessionContext,
                       ChangeBus changeBus,
                       org.infinispan.manager.CacheContainer workspaceCacheContainer)
Method Detail

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.


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 void completeInitialization()

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

register

public boolean register(ChangeSetListener observer)
Description copied from interface: Observable
Register the supplied observer. This method does nothing if the observer reference is null.

Specified by:
register in interface Observable
Parameters:
observer - the observer to be added; may be null
Returns:
true if the observer was added, or false if the observer was null, if the observer was already registered, or if the observer could not be added

unregister

public boolean unregister(ChangeSetListener observer)
Description copied from interface: Observable
Unregister the supplied observer. This method does nothing if the observer reference is null.

Specified by:
unregister in interface Observable
Parameters:
observer - the observer to be removed; may not be null
Returns:
true if the observer was removed, or false if the observer was null or if the observer was not registered on this source

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 org.infinispan.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

ModeShape Distribution 3.5.0.Final

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