fipaos.agent.task
Class Task

Direct Known Subclasses:
FIPAOSAgent.TopLevelHandlerTask, DFSearchTask, SynchronousTask, WaitTask, PingAgent.IdleTask, AgentManagementSystem.IdleTask, AMSDeregistrationTask, AMSRegistrationTask, AMSTask, DFDeregistrationTask, DFListenerTask, DFModifyTask, DFRegistrationTask, DFTask, StandardDFSubscriptionFactory.IdleTask, SubscriptionHandlerTask, SubscriptionManagerTask, DirectoryFacilitator.IdleTask, FIPAWrapperTask, MessageTimingAgent.IdleTask, MessageTimingAgent.MessageTestTask, MessageTimingAgent.TestingTask, TestAgent.IdleTask, TestAgent.IdleTask

public abstract class Task

This class is an abstract representation of an agent task. It contains message dispatchers and dummy
handling methods. To implement tasks in your agent, subclass this class and override the methods for
the message types that you need to handle. For example, if your agent handles two conversations -
one of type request and the other of contract net, then you would create two task classes that
subclass this class. One that handles fipa-request protocol messages only, and on the handles
fipa-contract-net messages only.

The Task-lifecycle is as follows:


Field Summary
 (package private) boolean_done
          Indicates if this task is done, or has timedout
 (package private) String_id
          ID of this task (?)
 (package private) Task_parent
          Reference to the "parent" Task of this.
 (package private) TaskState_state
          State of this Task
 (package private) long_timeout
          Timeout value for this task
 (package private) Set_tm_ids
          TaskManager ID's that this is associated with

Constructor Summary
Task()
          Constructs a Task object - to fully initialise a Task object, use the
Task or TaskManager newTask() method

Method Summary
 voiddoneDFSearchTask(Object result)
          Callback method to indicate that a DFSearchTask has completed.
 voidendTask()
          Can be invoked to end a task
 voiderrorDFSearchTask(Task t, Throwable exception)
          Callback method to indicate that a DFSearchTask has failed.
 ObjectgetContext()
          Gets a context object for this Task - allows a parent-Task to associate some
arbritary "context" with a child-Task which it can pickup when the child
completes/fails
 TaskStategetState()
          Returns the TaskState associated with this Task
 voidhandleAcceptProposal(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleAgree(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleCfp(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleConfirm(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleDisconfirm(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleFailure(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleInform(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleInformIf(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleInformRef(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleLateMessage(Message msg)
          Please override implementation - by default sends a not-understood
 voidhandleNotUnderstood(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandlePropagate(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandlePropose(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleProxy(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleQueryIf(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleQueryRef(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleRefuse(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleRejectProposal(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleRequest(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleRequestWhen(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleRequestWhenever(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleSubscribe(Conversation c)
          Dummy method - please override implementation and DO NOT invoke
 voidhandleUndeliverableMessage(Message msg)
          Please override implementation to deal with undeliverable messages
NOTE: Not yet implemented
 voidnotify(Conversation conv)
          Dispatches incoming messages to the correct message handling method.
 (package private) voidnotifyDone(Task child)
          Invokes the appropriate doneX() method on this, given the child task
 (package private) voidnotifyDone(Task child, Object result)
          Invokes the appropriate doneX(Object) method on this, given the child task
 (package private) voidnotifyError(Task child, Throwable error)
          Invoked by child-tasks to indicate that it has had an error
 voidnotifyMessageFailure(Message msg)
          Dispatches incoming messages that have bounced for some reason.
 voidnotifyMessageForEndedConversation(Message msg)
          Dispatches incoming message for ended conversation to the correct method.
 (package private) voidnotifyStart()
          Starts the given Task executing
 (package private) voidnotifyTimeout(Task child)
          Invokes the appropriate timeoutX() method on this, given the child task
 (package private) voidremoveReferences()
          Cleans up the reference that this task has to enable quicker garbage collection
 voidsetContext(Object o)
          Sets a context object for this Task - allows a parent-Task to associate some
arbritary "context" with a child-Task which it can pickup when the child
completes/fails
 (package private) booleanthisThreadFirstToIndicateDone()
          Ensure that we indicate that the Task is completed, without requiring
a lock on the TM first (can lead to dealock since we need to check that
_done is false BEFORE sync'ing on _tm - if _done is true it is possible
that _tm is null, therefore we cannot safely sync.
 voidtimeoutDFSearchTask(Task t)
          Callback method to indicate that a DFSearchTask has failed.
 (package private) voidtimeoutReached()
          Invoked when the timeout for this Task has been reached

Field Detail

_done

boolean _done
Indicates if this task is done, or has timedout

_id

String _id
ID of this task (?)

_parent

Task _parent
Reference to the "parent" Task of this. If null, then this task
has no parent.

_state

TaskState _state
State of this Task

_timeout

long _timeout
Timeout value for this task

_tm_ids

Set _tm_ids
TaskManager ID's that this is associated with
Constructor Detail

Task

public Task()
Constructs a Task object - to fully initialise a Task object, use the
Task or TaskManager newTask() method
Method Detail

doneDFSearchTask

public void doneDFSearchTask(Object result)
throws java.lang.Exception
Callback method to indicate that a DFSearchTask has completed. This
simply invokes DFSearchResults unless it is overridden.
Parameters:
result - The result of the DF-search

endTask

public void endTask()
Can be invoked to end a task

errorDFSearchTask

public void errorDFSearchTask(Task t, Throwable exception)
Callback method to indicate that a DFSearchTask has failed. This
simply invokes DFSearchResults unless it is overridden.

getContext

public Object getContext()
Gets a context object for this Task - allows a parent-Task to associate some
arbritary "context" with a child-Task which it can pickup when the child
completes/fails

getState

public TaskState getState()
Returns the TaskState associated with this Task
Returns: The TaskState associated with this

handleAcceptProposal

public void handleAcceptProposal(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleAgree

public void handleAgree(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleCfp

public void handleCfp(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleConfirm

public void handleConfirm(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleDisconfirm

public void handleDisconfirm(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleFailure

public void handleFailure(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleInform

public void handleInform(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleInformIf

public void handleInformIf(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleInformRef

public void handleInformRef(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleLateMessage

public void handleLateMessage(Message msg)
throws java.lang.Exception
Please override implementation - by default sends a not-understood

handleNotUnderstood

public void handleNotUnderstood(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handlePropagate

public void handlePropagate(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handlePropose

public void handlePropose(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleProxy

public void handleProxy(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleQueryIf

public void handleQueryIf(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleQueryRef

public void handleQueryRef(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleRefuse

public void handleRefuse(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleRejectProposal

public void handleRejectProposal(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleRequest

public void handleRequest(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleRequestWhen

public void handleRequestWhen(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleRequestWhenever

public void handleRequestWhenever(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleSubscribe

public void handleSubscribe(Conversation c)
throws java.lang.Exception
Dummy method - please override implementation and DO NOT invoke

handleUndeliverableMessage

public void handleUndeliverableMessage(Message msg)
throws java.lang.Exception
Please override implementation to deal with undeliverable messages

NOTE: Not yet implemented


notify

public void notify(Conversation conv)
Dispatches incoming messages to the correct message handling method.
Parameters:
conv - Conversation containing incoming message

notifyDone

void notifyDone(Task child)
Invokes the appropriate doneX() method on this, given the child task
Parameters:
child - The child task that has completed

notifyDone

void notifyDone(Task child, Object result)
Invokes the appropriate doneX(Object) method on this, given the child task
Parameters:
child - The child task that has completed
result - The result associated with the complete child Task

notifyError

void notifyError(Task child, Throwable error)
Invoked by child-tasks to indicate that it has had an error
Parameters:
child - Child Task which had the error
error - The associated error exception

notifyMessageFailure

public void notifyMessageFailure(Message msg)
Dispatches incoming messages that have bounced for some reason.
Parameters:
conv - Conversation containing incoming message

notifyMessageForEndedConversation

public void notifyMessageForEndedConversation(Message msg)
Dispatches incoming message for ended conversation to the correct method.
Parameters:
msg - Message that has arrived after end of conversation

notifyStart

void notifyStart()
Starts the given Task executing

notifyTimeout

void notifyTimeout(Task child)
Invokes the appropriate timeoutX() method on this, given the child task
Parameters:
child - The child task that has timed-out

removeReferences

void removeReferences()
Cleans up the reference that this task has to enable quicker garbage collection

setContext

public void setContext(Object o)
Sets a context object for this Task - allows a parent-Task to associate some
arbritary "context" with a child-Task which it can pickup when the child
completes/fails

thisThreadFirstToIndicateDone

boolean thisThreadFirstToIndicateDone()
Ensure that we indicate that the Task is completed, without requiring
a lock on the TM first (can lead to dealock since we need to check that
_done is false BEFORE sync'ing on _tm - if _done is true it is possible
that _tm is null, therefore we cannot safely sync. on it).

timeoutDFSearchTask

public void timeoutDFSearchTask(Task t)
Callback method to indicate that a DFSearchTask has failed. This
simply invokes DFSearchResults unless it is overridden.
Parameters:
t - The DFSearchTask that has timed-out
exception

timeoutReached

void timeoutReached()
Invoked when the timeout for this Task has been reached

Association Links

to Class java.lang.String

to Class java.lang.String

to Class java.lang.String

to Class java.lang.String

to Class fipaos.agent.FIPAOSAgent

The agent that owns this task - should only be used for the purpose of
updating/retreiving parent-Agent state information

to Class fipaos.agent.task.TaskManager

The task manager that manages this task object - useful for registering new tasks based on
incoming conversations

to Class fipaos.agent.task.TaskState

State of this Task

to Class java.lang.String

ID of this task (?)

to Class java.util.Set

List of children of this task.

to Class fipaos.agent.task.Task

Reference to the "parent" Task of this. If null, then this task
has no parent.

to Class java.util.Set

TaskManager ID's that this is associated with

to Class java.lang.Object

Lock - ensures mutual exclusion between threads modifying this Task

to Class java.lang.Object

Context info - allows an object to provide context info to parent-Task
which launched this task