fipaos.agent.task
Class TaskManager


public class TaskManager
implements ConversationListener

The TaskManager class stores task objects with their associated conversation IDs for
an agent. The agent must add it's tasks during initialisation.

Each task can be used to handle the messages for a particular conversation that an
agent participates in. For example. if an agent registers with a DF on startup, one task
object can be used to handle this conversation without having to store any state for
other conversations - even if they have the same protocol.


Inner Class Summary
 public static classTaskManager.DefaultTaskManagerListener
          Default implementation of the TM Listener - just adds events back to TM
in the order they arrive

Field Summary
 (package private) boolean_shutdown
          Indicates if the TM has been shutdown

Constructor Summary
TaskManager(FIPAOSAgent owner, MessageSender ms, Task top_level_parent, TaskManagerProfile tmp)
          Constructs an empty task manager.

Method Summary
 (package private) voidaddEvent(Task task, TaskEvent event)
          Adds the given TaskEvent to the given Task, and informs the registered
listener
 synchronized voidappendToExecutionOrder(Task t)
          Append a Task to the execution order (Tasks are executed in the
order they are added to the execution order).
 (package private) voidforward(ACL acl, Task task)
          Sends an ACL message on behalf of the given Task.
 (package private) voidforward(Message msg, Task task)
          Sends a Message on behalf of the given Task.
 synchronized SetgetActiveTasks()
          List the active Tasks
 (package private) ACLgetNewConversation(String protocol)
          Sets up a new Conversation using the given protocol
 synchronized intgetPendingTaskEvents()
          Get info.
 synchronized intgetTaskCount()
          Get info.
 intgetTimeoutCount()
          Get info.
 static SetgetVMTaskManagers()
          Get set of all TM's in VM
 voidnewTask(Task task)
          Initializes a new "top-level" task and adds it to the TaskManager.
 (package private) voidnewTask(Task task, Task parent)
          Creates a new Task with the given parent
 (package private) voidnewTask(String name, Task task, Task parent)
          Creates a new Task with the given parent and the given alternate Task name
 voidnewTask(String name, Task task)
          Creates a new Task with the top level handler task as parent and the given alternate Task name
 voidnewTask(Task t, String id)
          Initializes a new "top-level" task and adds it to the TaskManager.
 voidnewTask(Task t, Conversation conv)
          Initializes a new "top-level" task and adds it to the TaskManager.
 voidnewTask(Task task, Conversation conv, Task parent)
          Initializes a new child-task and adds it to the TaskManager.
 voidnewTask(String name, Task task, Conversation conv)
          Initializes a new child-task and adds it to the TaskManager.
 voidnewTask(String name, Task task, Conversation conv, Task parent)
          Initializes a new child-task and adds it to the TaskManager.
 voidnewTask(Task task, long timeout)
          Initialises the given task, and invokes its start() method.
 (package private) voidnewTask(Task task, long timeout, Task parent)
          Initialises the given task, and invokes its start() method.
 voidnewTask(Task task, Conversation conv, long timeout)
          Initialises the given task, and invokes its start() method.
 voidnewTask(Task task, Conversation conv, long timeout, Task parent)
          Initializes a new "top-level" task and adds it to the TaskManager.
 voidnotify(Conversation conv)
          Conversation listener method to deal with conversations being sent by the
planner scheduler.
 voidnotify(Enumeration enum)
          Deals with multiple conversations at once - just calls notify( Conversation )
for each one.
 voidnotifyMessageInEndedConversation(Message msg)
          Indicates that the given Message arrived for a completed Conversation - pass it to IDLE task
 voidnotifyMessageUndeliverable(Message msg)
          Indicates that the given Message was not deliverable
NOTE: This is a new feature which hasn't been fully tested
 booleanremoveTask(String key)
          Removes a task object associated with the specified conversation id from the manager.
 booleanremoveTask(Task task)
          Removes a task object from the manager.
 voidsetMessageSender(MessageSender ms)
          Sets the MessageSender that this should use
 synchronized voidsetTaskManagerListener(TaskManagerListener tml)
          Setup the TaskManageristener
 synchronized voidshutdown()
          Shuts-down this TaskManager - prevents any new Tasks from starting
 StringtoString()
          Get the name of the owning Agent

Field Detail

_shutdown

boolean _shutdown
Indicates if the TM has been shutdown
Constructor Detail

TaskManager

public TaskManager(FIPAOSAgent owner, MessageSender ms, Task top_level_parent, TaskManagerProfile tmp)
Constructs an empty task manager. Tasks can be added via the newTask() methods.
Parameters:
owner - Reference to parent Agent
ms - MessageSender to send messages - this may be null (can be set
later via the setMessageSender() method).
Method Detail

addEvent

void addEvent(Task task, TaskEvent event)
Adds the given TaskEvent to the given Task, and informs the registered
listener

appendToExecutionOrder

public synchronized void appendToExecutionOrder(Task t)
Append a Task to the execution order (Tasks are executed in the
order they are added to the execution order).

forward

void forward(ACL acl, Task task)

Sends an ACL message on behalf of the given Task.

If the message is part of a new conversation, a Conversation object will
be created within the ConversationManager and the Task will be bound to that
Conversation's ID - hence the task will subsequently receive any messages in response
automatically.
Note: a call to this method will update the table of all conversation ids and related tasks so
that the conversation id is always associated with the last task that calls this method.

Parameters:
acl - The ACL message to send
task

forward

void forward(Message msg, Task task)

Sends a Message on behalf of the given Task.

If the message is part of a new conversation, a Conversation object will
be created within the ConversationManager and the Task will be bound to that
Conversation's ID - hence the task will subsequently receive any messages in response
automatically.
Note: a call to this method will update the table of all conversation ids and related tasks so
that the conversation id is always associated with the last task that calls this method.

Parameters:
msg - The Message to send
task

getActiveTasks

public synchronized Set getActiveTasks()
List the active Tasks

getNewConversation

ACL getNewConversation(String protocol)
Sets up a new Conversation using the given protocol

getPendingTaskEvents

public synchronized int getPendingTaskEvents()
Get info. about the number of pending TaskEvents

getTaskCount

public synchronized int getTaskCount()
Get info. about number of active tasks managed by TM

getTimeoutCount

public int getTimeoutCount()
Get info. about number of timeouts currently being monitored

getVMTaskManagers

public static Set getVMTaskManagers()
Get set of all TM's in VM

newTask

public void newTask(Task task)
Initializes a new "top-level" task and adds it to the TaskManager.

newTask

void newTask(Task task, Task parent)
Creates a new Task with the given parent

newTask

void newTask(String name, Task task, Task parent)
Creates a new Task with the given parent and the given alternate Task name

newTask

public void newTask(String name, Task task)
Creates a new Task with the top level handler task as parent and the given alternate Task name

newTask

public void newTask(Task t, String id)
Initializes a new "top-level" task and adds it to the TaskManager. The task is associated with
the given String.

newTask

public void newTask(Task t, Conversation conv)
Initializes a new "top-level" task and adds it to the TaskManager. The task is associated with
the given conversation.

newTask

public void newTask(Task task, Conversation conv, Task parent)
Initializes a new child-task and adds it to the TaskManager. The task is associated with
the given conversation.

newTask

public void newTask(String name, Task task, Conversation conv)
Initializes a new child-task and adds it to the TaskManager. The
task is associated with
the given conversation.

The name parameter sets the alternate callback method

newTask

public void newTask(String name, Task task, Conversation conv, Task parent)
Initializes a new child-task and adds it to the TaskManager. The task is associated with
the given conversation.

The name parameter sets the alternate callback method

newTask

public void newTask(Task task, long timeout)
Initialises the given task, and invokes its start() method. If the task doesn't invoke
done() in the given amount of time, a timeoutX() method will be invoked on
the parent-Task, where X is the id of the task
Parameters:
timeout - The time in milliseconds to wait before timing out
task - The new Task to be initialised and added to the system
conv - Conversation to be associated with this Task

newTask

void newTask(Task task, long timeout, Task parent)
Initialises the given task, and invokes its start() method. If the task doesn't invoke
done() in the given amount of time, a timeoutX() method will be invoked on
the parent-Task, where X is the id of the task
Parameters:
timeout - The time in milliseconds to wait before timing out
task - The new Task to be initialised and added to the system
conv - Conversation to be associated with this Task

newTask

public void newTask(Task task, Conversation conv, long timeout)
Initialises the given task, and invokes its start() method. If the task doesn't invoke
done() in the given amount of time, a timeoutX() method will be invoked on
the parent-Task, where X is the id of the task
Parameters:
timeout - The time in milliseconds to wait before timing out
task - The new Task to be initialised and added to the system
conv - Conversation to be associated with this Task

newTask

public void newTask(Task task, Conversation conv, long timeout, Task parent)
Initializes a new "top-level" task and adds it to the TaskManager. The task is associated with
the passed in conversation.

notify

public void notify(Conversation conv)
Conversation listener method to deal with conversations being sent by the
planner scheduler. These should be overriden as default by the sub-class
if necessary
Parameters:
conv - The updated conversation to deal with

notify

public void notify(Enumeration enum)
Deals with multiple conversations at once - just calls notify( Conversation )
for each one. Override in sub class to replace this behavior. ( NOTE: When
overriding this method, it should be noted that care should be taken because
this method could be invoked at any time after the FIPAOSAgent() constructor
had been used. Normally this method doesn't do anything until after startPushing()
is invoked).
Parameters:
enum - An enumeration of updated conversations to deal with

notifyMessageInEndedConversation

public void notifyMessageInEndedConversation(Message msg)
Indicates that the given Message arrived for a completed Conversation - pass it to IDLE task

notifyMessageUndeliverable

public void notifyMessageUndeliverable(Message msg)
Indicates that the given Message was not deliverable

NOTE: This is a new feature which hasn't been fully tested


removeTask

public boolean removeTask(String key)
Removes a task object associated with the specified conversation id from the manager.
Parameters:
key - The conversation id of the task to be removed.
Returns: True if the conversation id and task were removed, false otherwise

removeTask

public boolean removeTask(Task task)
Removes a task object from the manager.
Any conversation bound to the task will be removed as well.
Parameters:
task - Task to be removed
Returns: True if the task was removed, false otherwise

setMessageSender

public void setMessageSender(MessageSender ms)
Sets the MessageSender that this should use

setTaskManagerListener

public synchronized void setTaskManagerListener(TaskManagerListener tml)
Setup the TaskManageristener

shutdown

public synchronized void shutdown()
Shuts-down this TaskManager - prevents any new Tasks from starting

toString

public String toString()
Get the name of the owning Agent

Association Links

to Class java.lang.String

to Class java.lang.String

to Class java.util.Set

Set of all TaskManagers

to Class java.util.Map

Task index table. The table contains a map of conversation-id, index to TaskState objects

to Class java.util.Set

The set of all TaskState objects

to Class java.util.Set

Set of timeouts being monitored

to Class java.util.Set

A List of all conversation ids' for which a Task has been assigned, but the
Conversation hasn't ended - allows Tasks to terminate before the end of a Conversation
without worrying about carrying out the rest of the Conversation (i.e. in a
failure case).

to Class fipaos.agent.FIPAOSAgent

Owner of this

to Class fipaos.mts.MessageSender

Message sender of this

to Class fipaos.util.Queue

Order in which we should execute the next set of ready Task's

to Class fipaos.agent.task.TaskManagerListener

TaskManagerListener associated with this

to Class fipaos.agent.task.Task

Task to substitue for parent-Task for top-level Tasks

to Class fipaos.util.ThreadPool

ThreadPool used by this TM to dispatch events

to Class fipaos.util.ThreadPool

ThreadPool used by this TM to monitor Tasks

to Class fipaos.agent.profile.TaskManagerProfile

Profile used by this TaskManager