public final Set<String> getWorkspaceNames() {
return Collections.unmodifiableSet(this.workspaceNames);
}
WorkspaceCache workspace( final String name ) {
WorkspaceCache workspaceCache = workspaceCachesByName.get(name);
if (workspaceCache != null) {
return workspaceCache;
}
final boolean isSystemWorkspace = this.systemWorkspaceName.equals(name);
if (!this.workspaceNames.contains(name) && !isSystemWorkspace) {
throw new WorkspaceNotFoundException(name);
}
// We know that this workspace is not the system workspace, so find it ...
final WorkspaceCache systemWorkspaceCache = isSystemWorkspace ? null : workspaceCachesByName.get(systemWorkspaceName);
// when multiple threads (e.g. re-indexing threads) are performing ws cache initialization, we want this to be atomic
synchronized (this) {
// after we have the lock, check if maybe another thread has already finished
if (!workspaceCachesByName.containsKey(name)) {
WorkspaceCache initializedWsCache = runInTransaction(new Callable<WorkspaceCache>() {
@SuppressWarnings( "synthetic-access" )
@Override
public WorkspaceCache call() throws Exception {
// Create/get the Infinispan workspaceCache that we'll use within the WorkspaceCache, using the
// workspaceCache manager's
// default configuration ...
Cache<NodeKey, CachedNode> nodeCache = cacheForWorkspace(name);
ExecutionContext context = context();
// Compute the root key for this workspace ...
String workspaceKey = NodeKey.keyForWorkspaceName(name);
NodeKey rootKey = new NodeKey(sourceKey, workspaceKey, rootNodeId);
// Create the root document for this workspace ...
EditableDocument rootDoc = Schematic.newDocument();
DocumentTranslator trans = new DocumentTranslator(context, documentStore, Long.MAX_VALUE);
trans.setProperty(rootDoc,
context.getPropertyFactory().create(JcrLexicon.PRIMARY_TYPE, ModeShapeLexicon.ROOT),
null, null);
trans.setProperty(rootDoc, context.getPropertyFactory().create(JcrLexicon.UUID, rootKey.toString()),
null, null);
WorkspaceCache workspaceCache = new WorkspaceCache(context, getKey(), name, systemWorkspaceCache,
documentStore, translator, rootKey, nodeCache,
changeBus);
if (documentStore.localStore().putIfAbsent(rootKey.toString(), rootDoc) == null) {
// we are the first node to perform the initialization, so we need to link the system node