org.hypergraphdb.peer.workflow
Class TaskActivity<StateType>
java.lang.Object
org.hypergraphdb.peer.workflow.AbstractActivity<StateType>
org.hypergraphdb.peer.workflow.TaskActivity<StateType>
- Type Parameters:
StateType -
- All Implemented Interfaces:
- java.lang.Runnable, ActivityStateListener
- Direct Known Subclasses:
- CatchUpTaskClient, CatchUpTaskServer, RememberTaskClient, RememberTaskServer
public abstract class TaskActivity<StateType>
- extends AbstractActivity<StateType>
- implements ActivityStateListener
Base class for tasks. A task is an AbstractActivity that
manages certain conversations and uses the state changes in the conversations
as triggers for transactions in own state. Unlike Conversation activities,
messages are accepted even if the task is not in a state where a transition
is possible with that message. This class ensures implementors that those
messages are saved and will trigger transformations when (if ever) the task
enters an appropriate state.
The task is also registered against the PeerInterface and
routes all messages received through that interface to the appropriate
conversations.
- Author:
- Cipri Costa
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TaskActivity
public TaskActivity(HyperGraphPeer thisPeer,
StateType start,
StateType end)
TaskActivity
public TaskActivity(HyperGraphPeer thisPeer,
java.util.UUID taskId,
StateType start,
StateType end)
stateChanged
public void stateChanged(java.lang.Object newState,
AbstractActivity<?> activity)
- Specified by:
stateChanged in interface ActivityStateListener
handleMessage
public void handleMessage(Message msg)
Called by the peer interface when a message arrives for this task. Can be
overridden by derived TaskActivity implementations. The
default implementation delegates to the conversation identified by the
CONVERSATION_ID attribute of the message (if any). If there's
no conversation associated with this message, an attempt to create a new one
is made by calling createNewConversation which can be overridden
also. If createNewConversation returns a non-null
Conversation instance, the conversation is assigned an ID and
registered with this task.
So a task implementation can chose to implement handleMessage and
respond to messages directly on it own or it can just implement createNewConversation
to delegate the work to conversation implementations. Or it can have a combination
of both like the following pattern:
public void handleMessage(Object msg)
{
if msg should trigger a new conversation between this peer and
the sending peer then
super.handleMessage(msg);
else
respond to msg directly here...
}
public void createNewConversation(Object msg)
{
// handleMessage determined that a new conversation must be started
// so based on the content of the message, create and return
// an appropriate conversation here.
}
- Parameters:
msg - The message just received.
getTaskId
public java.util.UUID getTaskId()
setTaskId
public void setTaskId(java.util.UUID taskId)
getThisPeer
public HyperGraphPeer getThisPeer()
getPeerInterface
public PeerInterface getPeerInterface()