org.jboss.system.server.profileservice.repository.clustered.local
Class AbstractLocalContentManager<T extends SynchronizationActionContext>

java.lang.Object
  extended by org.jboss.system.server.profileservice.repository.clustered.local.AbstractLocalContentManager<T>
All Implemented Interfaces:
LocalContentManager<T>
Direct Known Subclasses:
FilesystemLocalContentManager

public abstract class AbstractLocalContentManager<T extends SynchronizationActionContext>
extends Object
implements LocalContentManager<T>

Abstract base class for a LocalContentManager implementation.

Version:
$Revision: $
Author:
Brian Stansberry

Constructor Summary
protected AbstractLocalContentManager(Map<String,URI> namedURIMap, org.jboss.profileservice.spi.ProfileKey profileKey, String localNodeName, ContentMetadataPersister contentMetadataPersister)
          Create a new AbstractLocalContentManager.
 
Method Summary
 void commitSynchronization(SynchronizationId<?> id)
          Complete the two-phase commit process for the cluster synchronization that has been prepared.
protected abstract  TwoPhaseCommitAction<T> createDirectoryTimestampMismatchAction(ContentModification mod, boolean localLed)
          Create an action to handle the local end of a node updating a directory timestamp to match the cluster.
 RepositoryContentMetadata createEmptyContentMetadata()
          Creates a new RepositoryContentMetadata with a child RepositoryRootMetadata for each of this persister's URIs, but no RepositoryItemMetadatas under those roots.
protected abstract  TwoPhaseCommitAction<T> createMkdirFromClusterAction(ContentModification mod, boolean localLed)
          Create an action to handle the local end of a node adding a directory due to its presence on the cluster.
protected abstract  TwoPhaseCommitAction<T> createMkdirToClusterAction(ContentModification mod, boolean localLed)
          Create an action to handle the local end of a node adding a directory to the cluster.
protected abstract  TwoPhaseCommitAction<T> createPrepareRmdirFromClusterAction(ContentModification mod, boolean localLed)
           
protected abstract  TwoPhaseCommitAction<T> createPrepareRmdirToClusterAction(ContentModification mod, boolean localLed)
          Create an action to handle the local end of a node removing a directory from the cluster.
protected abstract  TwoPhaseCommitAction<T> createPullFromClusterAction(ContentModification mod, boolean localLed)
          Create an action to handle the local end of a node pulling content from the cluster.
protected abstract  TwoPhaseCommitAction<T> createPushStreamToClusterAction(ContentModification mod, InputStream stream)
          Create an action to handle the local end of a node pushing content that is read from an external-to-the-repository stream to the cluster.
protected abstract  TwoPhaseCommitAction<T> createPushToClusterAction(ContentModification mod, boolean localLed)
          Create an action to handle the local end of a node pushing content to the cluster.
protected abstract  TwoPhaseCommitAction<T> createRemoveFromClusterAction(ContentModification mod, boolean localLed)
          Create an action to handle the local end of a node removing content that the rest of the cluster regards as invalid.
protected abstract  TwoPhaseCommitAction<T> createRemoveToClusterAction(ContentModification mod, boolean localLed)
          Create an action to handle the local end of a node removing content from the cluster.
protected static String createStoreName(org.jboss.profileservice.spi.ProfileKey key)
           
protected abstract  T createSynchronizationActionContext(SynchronizationId<?> id, RepositoryContentMetadata toUpdate)
          Create a SynchronizationActionContext for the given cluster-wide content synchronization.
protected  org.jboss.virtual.VirtualFile getCachedVirtualFile(URI uri)
          Gets a VirtualFile corresponding to the given URI.
 RepositoryContentMetadata getContentMetadataForAdd(RepositoryItemMetadata toAdd, InputStream contentIS)
          Generate content metadata that would reflect what the metadata would look like if an item with path vfsPath were added.
 RepositoryContentMetadata getContentMetadataForRemove(org.jboss.virtual.VirtualFile vf)
          Generate content metadata that would reflect what the metadata would look like if an item with path vfsPath were removed.
 RepositoryContentMetadata getCurrentContentMetadata()
          Scan the persistent store for the current content metadata.
 RepositoryItemMetadata getItemForAddition(String vfsPath)
          Gets a RepositoryItemMetadata that will describe an item that may be added.
 String getLocalNodeName()
           
 RepositoryContentMetadata getOfficialContentMetadata()
          Gets the "official" record of the contents of the persistent store.
protected  URI getRootURIForModification(ContentModification mod)
          Gets the URI of the repository root with which the given modification is associated.
 String getStoreName()
           
protected  T getSynchronizationActionContext()
          Gets the current SynchronizationActionContext.
 org.jboss.virtual.VirtualFile getVirtualFileForItem(RepositoryItemMetadata item)
          Get a VirtualFile for the content indicated by item.
 List<? extends SynchronizationAction<T>> initiateSynchronization(SynchronizationId<?> id, List<ContentModification> modifications, RepositoryContentMetadata toInstall, boolean localLed)
          Initiate a process of synchronizing this node's persistent store with the rest of the cluster
 void installCurrentContentMetadata()
          Install the result from the latest call to LocalContentManager.getCurrentContentMetadata() as the "official" content metadata.
 boolean prepareSynchronization(SynchronizationId<?> id)
          Execute the prepare phase of the two phase commit process for the cluster synchronization that has been initialized.
 void rollbackSynchronization(SynchronizationId<?> id)
          Roll back the cluster synchronization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractLocalContentManager

protected AbstractLocalContentManager(Map<String,URI> namedURIMap,
                                      org.jboss.profileservice.spi.ProfileKey profileKey,
                                      String localNodeName,
                                      ContentMetadataPersister contentMetadataPersister)
Create a new AbstractLocalContentManager.

Parameters:
namedURIMap - Map of URIs managed by this object, keyed by a String identifier
profileKey - key of the profile the content of which this object is managing
localNodeName - name of the local node in the cluster
contentMetadataPersister - object to use for storing/retrieving content metadata
Method Detail

createStoreName

protected static String createStoreName(org.jboss.profileservice.spi.ProfileKey key)

getLocalNodeName

public String getLocalNodeName()

getStoreName

public String getStoreName()

getOfficialContentMetadata

public RepositoryContentMetadata getOfficialContentMetadata()
Description copied from interface: LocalContentManager
Gets the "official" record of the contents of the persistent store. This is the version persisted to disk following synchronization of changes with the cluster.

Specified by:
getOfficialContentMetadata in interface LocalContentManager<T extends SynchronizationActionContext>
Returns:
the content metadata

createEmptyContentMetadata

public RepositoryContentMetadata createEmptyContentMetadata()
Description copied from interface: LocalContentManager
Creates a new RepositoryContentMetadata with a child RepositoryRootMetadata for each of this persister's URIs, but no RepositoryItemMetadatas under those roots. When a node that is starting for the first time does not have a persisted set of content metadata, this method should be used to create an object that can be used as a base to generate a set of modifications needed to synchronize the node with the cluster.

Specified by:
createEmptyContentMetadata in interface LocalContentManager<T extends SynchronizationActionContext>
Returns:
a RepositoryContentMetadata with no grandchildren.

getCurrentContentMetadata

public RepositoryContentMetadata getCurrentContentMetadata()
                                                    throws IOException
Description copied from interface: LocalContentManager
Scan the persistent store for the current content metadata. This is not the "official" metadata that has been persisted, as any changes between it and the official version have not been synchronized with the cluster.

Specified by:
getCurrentContentMetadata in interface LocalContentManager<T extends SynchronizationActionContext>
Returns:
the content metadata
Throws:
IOException

initiateSynchronization

public List<? extends SynchronizationAction<T>> initiateSynchronization(SynchronizationId<?> id,
                                                                        List<ContentModification> modifications,
                                                                        RepositoryContentMetadata toInstall,
                                                                        boolean localLed)
Description copied from interface: LocalContentManager
Initiate a process of synchronizing this node's persistent store with the rest of the cluster

Specified by:
initiateSynchronization in interface LocalContentManager<T extends SynchronizationActionContext>
Parameters:
id - a unique id for this cluster synchronization process
modifications - the overall list of modifications that will occur during this process
toInstall - TODO
localLed - true if this node is driving the synchronization, false if another node is
Returns:
list of SynchronizationActions each of which can be executed by the caller to fulfill a portion of this node's role in the overall cluster synchronization

prepareSynchronization

public boolean prepareSynchronization(SynchronizationId<?> id)
Description copied from interface: LocalContentManager
Execute the prepare phase of the two phase commit process for the cluster synchronization that has been initialized.

Specified by:
prepareSynchronization in interface LocalContentManager<T extends SynchronizationActionContext>
Parameters:
id - id of the synchronization. Cannot be null
Returns:
true if the prepare phase was successful; false if not and the synchronization needs to be rolled back

commitSynchronization

public void commitSynchronization(SynchronizationId<?> id)
Description copied from interface: LocalContentManager
Complete the two-phase commit process for the cluster synchronization that has been prepared.

Specified by:
commitSynchronization in interface LocalContentManager<T extends SynchronizationActionContext>
Parameters:
id - id of the synchronization. Cannot be null

rollbackSynchronization

public void rollbackSynchronization(SynchronizationId<?> id)
Description copied from interface: LocalContentManager
Roll back the cluster synchronization.

Specified by:
rollbackSynchronization in interface LocalContentManager<T extends SynchronizationActionContext>
Parameters:
id - id of the synchronization. Cannot be null

installCurrentContentMetadata

public void installCurrentContentMetadata()
Description copied from interface: LocalContentManager
Install the result from the latest call to LocalContentManager.getCurrentContentMetadata() as the "official" content metadata. Intended for use during node startup when the node discovers it is the only member of the cluster, and thus that it's "current" content metadata is "official".

Specified by:
installCurrentContentMetadata in interface LocalContentManager<T extends SynchronizationActionContext>

getItemForAddition

public RepositoryItemMetadata getItemForAddition(String vfsPath)
                                          throws IOException
Description copied from interface: LocalContentManager
Gets a RepositoryItemMetadata that will describe an item that may be added.

Specified by:
getItemForAddition in interface LocalContentManager<T extends SynchronizationActionContext>
Parameters:
vfsPath - path relative to one of this repository's root URIs
Returns:
the item metadata
Throws:
IOException

getContentMetadataForAdd

public RepositoryContentMetadata getContentMetadataForAdd(RepositoryItemMetadata toAdd,
                                                          InputStream contentIS)
                                                   throws IOException
Description copied from interface: LocalContentManager
Generate content metadata that would reflect what the metadata would look like if an item with path vfsPath were added.

Specified by:
getContentMetadataForAdd in interface LocalContentManager<T extends SynchronizationActionContext>
Returns:
Throws:
IOException

getVirtualFileForItem

public org.jboss.virtual.VirtualFile getVirtualFileForItem(RepositoryItemMetadata item)
                                                    throws IOException
Description copied from interface: LocalContentManager
Get a VirtualFile for the content indicated by item.

Specified by:
getVirtualFileForItem in interface LocalContentManager<T extends SynchronizationActionContext>
Parameters:
item - metadata describing the content
Returns:
the virtual file
Throws:
IOException

getContentMetadataForRemove

public RepositoryContentMetadata getContentMetadataForRemove(org.jboss.virtual.VirtualFile vf)
                                                      throws IOException
Description copied from interface: LocalContentManager
Generate content metadata that would reflect what the metadata would look like if an item with path vfsPath were removed.

Specified by:
getContentMetadataForRemove in interface LocalContentManager<T extends SynchronizationActionContext>
Returns:
the content metadata
Throws:
IOException

createSynchronizationActionContext

protected abstract T createSynchronizationActionContext(SynchronizationId<?> id,
                                                        RepositoryContentMetadata toUpdate)
Create a SynchronizationActionContext for the given cluster-wide content synchronization.

Parameters:
id - the id of the synchronization
toUpdate - metadata object that should be updated as synchronization actions are performed.

createPullFromClusterAction

protected abstract TwoPhaseCommitAction<T> createPullFromClusterAction(ContentModification mod,
                                                                       boolean localLed)
Create an action to handle the local end of a node pulling content from the cluster.

Parameters:
mod - object describing the content modification this action is part of
localLed - true if this node is driving the synchronization process the action is part of; false if another node is
Returns:
the action. Will not return null.

createPushToClusterAction

protected abstract TwoPhaseCommitAction<T> createPushToClusterAction(ContentModification mod,
                                                                     boolean localLed)
Create an action to handle the local end of a node pushing content to the cluster.

Parameters:
mod - object describing the content modification this action is part of
localLed - true if this node is driving the synchronization process the action is part of; false if another node is
Returns:
the action. Will not return null.

createPushStreamToClusterAction

protected abstract TwoPhaseCommitAction<T> createPushStreamToClusterAction(ContentModification mod,
                                                                           InputStream stream)
Create an action to handle the local end of a node pushing content that is read from an external-to-the-repository stream to the cluster. Used to handle installation of content to the repository via DeploymentRepository.addDeployment(String, org.jboss.profileservice.spi.ProfileDeployment).

This is only invoked on the node that is driving the synchronization process.

Parameters:
mod - object describing the content modification this action is part of
stream - the stream from which content will be read.
Returns:
an action that will handle both the local end of pushing the stream content to other nodes in the cluster and storing the stream content in this node's repository. Will not return null.

createRemoveFromClusterAction

protected abstract TwoPhaseCommitAction<T> createRemoveFromClusterAction(ContentModification mod,
                                                                         boolean localLed)
Create an action to handle the local end of a node removing content that the rest of the cluster regards as invalid.

Parameters:
mod - object describing the content modification this action is part of
localLed - true if this node is driving the synchronization process the action is part of; false if another node is
Returns:
the action. Will not return null.

createRemoveToClusterAction

protected abstract TwoPhaseCommitAction<T> createRemoveToClusterAction(ContentModification mod,
                                                                       boolean localLed)
Create an action to handle the local end of a node removing content from the cluster.

Parameters:
mod - object describing the content modification this action is part of
localLed - true if this node is driving the synchronization process the action is part of; false if another node is
Returns:
the action. Will not return null.

createPrepareRmdirToClusterAction

protected abstract TwoPhaseCommitAction<T> createPrepareRmdirToClusterAction(ContentModification mod,
                                                                             boolean localLed)
Create an action to handle the local end of a node removing a directory from the cluster.

Parameters:
mod - object describing the content modification this action is part of
localLed - true if this node is driving the synchronization process the action is part of; false if another node is
Returns:
the action. Will not return null.

createPrepareRmdirFromClusterAction

protected abstract TwoPhaseCommitAction<T> createPrepareRmdirFromClusterAction(ContentModification mod,
                                                                               boolean localLed)

createMkdirToClusterAction

protected abstract TwoPhaseCommitAction<T> createMkdirToClusterAction(ContentModification mod,
                                                                      boolean localLed)
Create an action to handle the local end of a node adding a directory to the cluster.

Parameters:
mod - object describing the content modification this action is part of
localLed - true if this node is driving the synchronization process the action is part of; false if another node is
Returns:
the action. Will not return null.

createMkdirFromClusterAction

protected abstract TwoPhaseCommitAction<T> createMkdirFromClusterAction(ContentModification mod,
                                                                        boolean localLed)
Create an action to handle the local end of a node adding a directory due to its presence on the cluster.

Parameters:
mod - object describing the content modification this action is part of
localLed - true if this node is driving the synchronization process the action is part of; false if another node is
Returns:
the action. Will not return null.

createDirectoryTimestampMismatchAction

protected abstract TwoPhaseCommitAction<T> createDirectoryTimestampMismatchAction(ContentModification mod,
                                                                                  boolean localLed)
Create an action to handle the local end of a node updating a directory timestamp to match the cluster.

Parameters:
mod - object describing the content modification this action is part of
localLed - true if this node is driving the synchronization process the action is part of; false if another node is
Returns:
the action. Will not return null.

getSynchronizationActionContext

protected T getSynchronizationActionContext()
Gets the current SynchronizationActionContext.

Returns:
the current context, or null if there isn't one

getCachedVirtualFile

protected org.jboss.virtual.VirtualFile getCachedVirtualFile(URI uri)
                                                      throws IOException
Gets a VirtualFile corresponding to the given URI.

Parameters:
uri - the uri. Cannot be null.
Returns:
the virtual file
Throws:
IOException
NullPointerException - if uri is null.

getRootURIForModification

protected URI getRootURIForModification(ContentModification mod)
Gets the URI of the repository root with which the given modification is associated.

Parameters:
mod - the modification. Cannot be null
Returns:
the URI. May be null if the modification is for an unknown root
Throws:
NullPointerException - if uri is null.
See Also:
ContentModification.getRootName()


Copyright © 2009 JBoss, a division of Red Hat, Inc.. All Rights Reserved.