fipaos.agent.task
Class TaskManager

java.lang.Object
  |
  +--fipaos.agent.task.TaskManager
All Implemented Interfaces:
ConversationListener

public class TaskManager
extends java.lang.Object
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
static class TaskManager.DefaultTaskManagerListener
          Default implementation of the TM Listener - just adds events back to TM in the order they arrive
 
Field Summary
protected  java.util.Set _conversation_ids
          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.
 
Constructor Summary
TaskManager(FIPAOSAgent owner, MessageSender ms, Task top_level_parent, TaskManagerProfile tmp)
          Constructs an empty task manager.
 
Method Summary
 void appendToExecutionOrder(Task t)
          Append a Task to the execution order (Tasks are executed in the order they are added to the execution order).
protected  void checkConversationEnded(Conversation conv)
          Check if Conversation is finished - if so we should remove it from _conversation_ids
 java.util.Set getActiveTasks()
          List the active Tasks
 int getPendingTaskEvents()
          Get info.
 int getTaskCount()
          Get info.
 int getTimeoutCount()
          Get info.
static java.util.Set getVMTaskManagers()
          Get set of all TM's in VM
 void newTask(java.lang.String name, Task task)
          Creates a new Task with the top level handler task as parent and the given alternate Task name
 void newTask(java.lang.String name, Task task, Conversation conv, Task parent)
          Initializes a new child-task and adds it to the TaskManager.
 void newTask(Task task)
          Initializes a new "top-level" task and adds it to the TaskManager.
 void newTask(Task t, Conversation conv)
          Initializes a new "top-level" task and adds it to the TaskManager.
 void newTask(Task task, Conversation conv, long timeout)
          Initialises the given task, and invokes its start() method.
 void newTask(Task task, Conversation conv, long timeout, Task parent)
          Initializes a new "top-level" task and adds it to the TaskManager.
 void newTask(Task task, Conversation conv, Task parent)
          Initializes a new child-task and adds it to the TaskManager.
 void newTask(Task task, long timeout)
          Initialises the given task, and invokes its start() method.
 void newTask(Task t, java.lang.String id)
          Initializes a new "top-level" task and adds it to the TaskManager.
 void notify(Conversation conv)
          Conversation listener method to deal with conversations being sent by the planner scheduler.
 void notify(java.util.Enumeration enum)
          Deals with multiple conversations at once - just calls notify( Conversation ) for each one.
 void notifyMessageInEndedConversation(Message msg)
          Indicates that the given Message arrived for a completed Conversation - pass it to IDLE task
 void notifyMessageUndeliverable(Message msg)
          Indicates that the given Message was not deliverable
 boolean removeTask(java.lang.String key)
          Removes a task object associated with the specified conversation id from the manager.
 boolean removeTask(Task task)
          Removes a task object from the manager.
 void setMessageSender(MessageSender ms)
          Sets the MessageSender that this should use
 void setTaskManagerListener(TaskManagerListener tml)
          Setup the TaskManageristener
 void shutdown()
          Shuts-down this TaskManager - prevents any new Tasks from starting
 java.lang.String toString()
          Get the name of the owning Agent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_conversation_ids

protected java.util.Set _conversation_ids
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).
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

shutdown

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

newTask

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

newTask

public void newTask(java.lang.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,
                    java.lang.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(java.lang.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

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.

removeTask

public boolean removeTask(java.lang.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

getTaskCount

public 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

getPendingTaskEvents

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

toString

public java.lang.String toString()
Get the name of the owning Agent
Overrides:
toString in class java.lang.Object

getVMTaskManagers

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

appendToExecutionOrder

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

getActiveTasks

public java.util.Set getActiveTasks()
List the active Tasks

setTaskManagerListener

public void setTaskManagerListener(TaskManagerListener tml)
Setup the TaskManageristener

checkConversationEnded

protected void checkConversationEnded(Conversation conv)
Check if Conversation is finished - if so we should remove it from _conversation_ids

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
Specified by:
notify in interface ConversationListener
Parameters:
conv - The updated conversation to deal with

notify

public void notify(java.util.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).
Specified by:
notify in interface ConversationListener
Parameters:
enum - An enumeration of updated conversations to deal with

setMessageSender

public void setMessageSender(MessageSender ms)
Sets the MessageSender that this should use
Specified by:
setMessageSender in interface ConversationListener

notifyMessageInEndedConversation

public void notifyMessageInEndedConversation(Message msg)
Indicates that the given Message arrived for a completed Conversation - pass it to IDLE task
Specified by:
notifyMessageInEndedConversation in interface ConversationListener

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

Specified by:
notifyMessageUndeliverable in interface ConversationListener