org.springframework.webflow.execution.repository.support
Class AbstractConversationFlowExecutionRepository

java.lang.Object
  extended by org.springframework.webflow.execution.repository.support.AbstractFlowExecutionRepository
      extended by org.springframework.webflow.execution.repository.support.AbstractConversationFlowExecutionRepository
All Implemented Interfaces:
FlowExecutionRepository
Direct Known Subclasses:
ClientContinuationFlowExecutionRepository, ContinuationFlowExecutionRepository, SimpleFlowExecutionRepository

public abstract class AbstractConversationFlowExecutionRepository
extends AbstractFlowExecutionRepository

A convenient base class for flow execution repository implementations that delegate to a conversation service for managing conversations that govern the persistent state of paused flow executions.

Author:
Keith Donald
See Also:
ConversationManager

Field Summary
protected  org.apache.commons.logging.Log logger
          Logger, usable in subclasses
 
Constructor Summary
protected AbstractConversationFlowExecutionRepository(FlowExecutionStateRestorer executionStateRestorer, ConversationManager conversationManager)
          Constructor for use in subclasses.
 
Method Summary
protected  ConversationParameters createConversationParameters(FlowExecution flowExecution)
          Factory method that maps a new flow execution to a descriptive conversation parameters object.
protected abstract  java.io.Serializable generateContinuationId(FlowExecution flowExecution)
          Template method used to generate a new continuation id for given flow execution.
 FlowExecutionKey generateKey(FlowExecution flowExecution)
          Generate a unique flow execution key to be used as the persistent identifier of the flow execution.
protected  java.io.Serializable getContinuationId(FlowExecutionKey key)
          Returns the continuation id part of given composite flow execution key.
protected  Conversation getConversation(FlowExecutionKey key)
          Returns the conversation governing the execution of the FlowExecution with the provided key.
protected  ConversationId getConversationId(FlowExecutionKey key)
          Returns the conversation id part of given composite flow execution key.
 ConversationManager getConversationManager()
          Returns the configured conversation manager.
protected  MutableAttributeMap getConversationScope(FlowExecutionKey key)
          Returns the "conversation scope" for the flow execution with the key provided.
abstract  FlowExecution getFlowExecution(FlowExecutionKey key)
          Return the FlowExecution indexed by the provided key.
 FlowExecutionLock getLock(FlowExecutionKey key)
          Return the lock for the flow execution, allowing for the lock to be acquired or released.
 FlowExecutionKey getNextKey(FlowExecution flowExecution, FlowExecutionKey previousKey)
          Obtain the "next" flow execution key to be used as the flow execution's persistent identity.
protected  void onBegin(Conversation conversation)
          An "on begin conversation" callback, allowing for insertion of custom logic after a new conversation has begun.
protected  void onEnd(Conversation conversation)
          An "on conversation end" callback, allowing for insertion of custom logic after a conversation has ended (it's Conversation.end() method has been called).
protected abstract  java.io.Serializable parseContinuationId(java.lang.String encodedId)
          Template method to parse the continuation id from the encoded string.
 FlowExecutionKey parseFlowExecutionKey(java.lang.String encodedKey)
          Parse the string-encoded flow execution key into its object form.
protected  void putConversationScope(FlowExecutionKey key, MutableAttributeMap scope)
          Sets the conversation scope attribute for the flow execution with the key provided.
abstract  void putFlowExecution(FlowExecutionKey key, FlowExecution flowExecution)
          Place the FlowExecution in this repository under the provided key.
 void removeFlowExecution(FlowExecutionKey key)
          Remove the flow execution from the repository.
 
Methods inherited from class org.springframework.webflow.execution.repository.support.AbstractFlowExecutionRepository
getExecutionStateRestorer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Logger, usable in subclasses

Constructor Detail

AbstractConversationFlowExecutionRepository

protected AbstractConversationFlowExecutionRepository(FlowExecutionStateRestorer executionStateRestorer,
                                                      ConversationManager conversationManager)
Constructor for use in subclasses.

Parameters:
executionStateRestorer - the transient flow execution state restorer
conversationManager - the conversation manager to use
Method Detail

getConversationManager

public ConversationManager getConversationManager()
Returns the configured conversation manager.


generateKey

public FlowExecutionKey generateKey(FlowExecution flowExecution)
Description copied from interface: FlowExecutionRepository
Generate a unique flow execution key to be used as the persistent identifier of the flow execution. This method should be called after a new flow execution is started and remains active; thus needing to be saved. The FlowExecutionKey is the execution's persistent identity.

Parameters:
flowExecution - the flow execution
Returns:
the flow execution key

getNextKey

public FlowExecutionKey getNextKey(FlowExecution flowExecution,
                                   FlowExecutionKey previousKey)
Description copied from interface: FlowExecutionRepository
Obtain the "next" flow execution key to be used as the flow execution's persistent identity. This method should be called after a existing flow execution has resumed and remains active; thus needing to be updated. This repository may choose to return the previous key or generate a new key.

Parameters:
flowExecution - the flow execution
previousKey - the current key associated with the flow exection

getLock

public FlowExecutionLock getLock(FlowExecutionKey key)
                          throws FlowExecutionRepositoryException
Description copied from interface: FlowExecutionRepository
Return the lock for the flow execution, allowing for the lock to be acquired or released.

Caution: care should be made not to allow for a deadlock situation. If you acquire a lock make sure you release it when you are done.

The general pattern for safely doing work against a locked conversation follows:

 FlowExecutionLock lock = repository.getLock(key);
 lock.lock();
 try {
        FlowExecution execution = repository.getFlowExecution(key);
        // do work
 } finally {
        lock.unlock();
 }
 

Parameters:
key - the identifier of the flow execution to lock
Returns:
the lock
Throws:
FlowExecutionRepositoryException - a problem occured accessing the lock object

getFlowExecution

public abstract FlowExecution getFlowExecution(FlowExecutionKey key)
                                        throws FlowExecutionRepositoryException
Description copied from interface: FlowExecutionRepository
Return the FlowExecution indexed by the provided key. The returned flow execution represents the restored state of an executing flow from a point in time. This should be called to resume a persistent flow execution.

Before calling this method, you should aquire the lock for the keyed flow execution.

Parameters:
key - the flow execution key
Returns:
the flow execution, fully hydrated and ready to signal an event against
Throws:
FlowExecutionRepositoryException - if no flow execution was indexed with the key provided

putFlowExecution

public abstract void putFlowExecution(FlowExecutionKey key,
                                      FlowExecution flowExecution)
                               throws FlowExecutionRepositoryException
Description copied from interface: FlowExecutionRepository
Place the FlowExecution in this repository under the provided key. This should be called to save or update the persistent state of an active (but paused) flow execution.

Before calling this method, you should aquire the lock for the keyed flow execution.

Parameters:
key - the flow execution key
flowExecution - the flow execution
Throws:
FlowExecutionRepositoryException - the flow execution could not be stored

removeFlowExecution

public void removeFlowExecution(FlowExecutionKey key)
                         throws FlowExecutionRepositoryException
Description copied from interface: FlowExecutionRepository
Remove the flow execution from the repository. This should be called when the flow execution ends (is no longer active).

Before calling this method, you should aquire the lock for the keyed flow execution.

Parameters:
key - the flow execution key
Throws:
FlowExecutionRepositoryException - the flow execution could not be removed.

parseFlowExecutionKey

public FlowExecutionKey parseFlowExecutionKey(java.lang.String encodedKey)
                                       throws FlowExecutionRepositoryException
Description copied from interface: FlowExecutionRepository
Parse the string-encoded flow execution key into its object form. Essentially, the reverse of FlowExecutionKey.toString().

Parameters:
encodedKey - the string encoded key
Returns:
the parsed flow execution key, the persistent identifier for exactly one flow execution
Throws:
FlowExecutionRepositoryException

createConversationParameters

protected ConversationParameters createConversationParameters(FlowExecution flowExecution)
Factory method that maps a new flow execution to a descriptive conversation parameters object.

Parameters:
flowExecution - the new flow execution
Returns:
the conversation parameters object to pass to the conversation manager when the conversation is started

onBegin

protected void onBegin(Conversation conversation)
An "on begin conversation" callback, allowing for insertion of custom logic after a new conversation has begun. This implementation is emtpy.

Parameters:
conversation - the conversation that has begun

onEnd

protected void onEnd(Conversation conversation)
An "on conversation end" callback, allowing for insertion of custom logic after a conversation has ended (it's Conversation.end() method has been called). This implementation is empty.

Parameters:
conversation - the conversation that has ended

getConversationId

protected ConversationId getConversationId(FlowExecutionKey key)
Returns the conversation id part of given composite flow execution key.

Parameters:
key - the composite key
Returns:
the conversationId key part

getContinuationId

protected java.io.Serializable getContinuationId(FlowExecutionKey key)
Returns the continuation id part of given composite flow execution key.

Parameters:
key - the composite key
Returns:
the continuation id key part

getConversation

protected Conversation getConversation(FlowExecutionKey key)
                                throws NoSuchFlowExecutionException
Returns the conversation governing the execution of the FlowExecution with the provided key.

Parameters:
key - the flow execution key
Returns:
the governing conversation
Throws:
NoSuchFlowExecutionException - when the conversation for identified flow execution cannot be found

getConversationScope

protected MutableAttributeMap getConversationScope(FlowExecutionKey key)
Returns the "conversation scope" for the flow execution with the key provided. This is mainly useful for reinitialisation of a flow execution after restoration from the repository.

Parameters:
key - the flow execution key
Returns:
the execution's conversation scope

putConversationScope

protected void putConversationScope(FlowExecutionKey key,
                                    MutableAttributeMap scope)
Sets the conversation scope attribute for the flow execution with the key provided.

Parameters:
key - the flow execution key
scope - the execution's conversation scope

generateContinuationId

protected abstract java.io.Serializable generateContinuationId(FlowExecution flowExecution)
Template method used to generate a new continuation id for given flow execution. Subclasses must override.

Parameters:
flowExecution - the flow execution
Returns:
the continuation id

parseContinuationId

protected abstract java.io.Serializable parseContinuationId(java.lang.String encodedId)
                                                     throws FlowExecutionRepositoryException
Template method to parse the continuation id from the encoded string.

Parameters:
encodedId - the string identifier
Returns:
the parsed continuation id
Throws:
FlowExecutionRepositoryException


Copyright © 2009 Spring Framework. All Rights Reserved.