fipaos.agent.task
Class Task

Direct Known Subclasses:
FIPAOSAgent.TopLevelHandlerTask, DFSearchTask, SynchronousTask, TaskManager.TestTask1, TaskManager.TestTask2, TaskManager.TestTask3, TaskManager.TestTask4, WaitTask, TestAgent.IdleTask, AgentManagementSystem.IdleTask, AMSDeregistrationTask, AMSRegistrationTask, AMSTask, DFDeregistrationTask, DFListenerTask, DFRegistrationTask, DFTask, SubscriptionHandlerTask, SubscriptionManagerTask, DirectoryFacilitator.IdleTask, FIPAWrapperTask

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.
 voiderrorDFSearchTask(Task t, Throwable exception)
          Callback method to indicate that a DFSearchTask has failed.
 TaskStategetState()
          Returns the TaskState associated with this Task
 voidhandleFailure(Conversation c)
          Dummy method - please override implementation
 voidhandleInform(Conversation c)
          Dummy method - please override implementation
 voidhandleRequest(Conversation c)
          Dummy method - please override implementation
 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
 (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
 (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.

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)
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

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.

getState

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

handleFailure

public void handleFailure(Conversation c)
Dummy method - please override implementation

handleInform

public void handleInform(Conversation c)
Dummy method - please override implementation

handleRequest

public void handleRequest(Conversation c)
Dummy method - please override implementation

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

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

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

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