fipaos.agent.task
Class TaskManager


public class TaskManager
implements ConversationListener, Runnable

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
           
 public static classTaskManager.TestSender
           
 public static classTaskManager.TestTask1
           
 public static classTaskManager.TestTask2
           
 public static classTaskManager.TestTask3
           
 public static classTaskManager.TestTask4
           

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

Constructor Summary
TaskManager(FIPAOSAgent owner, MessageSender ms, Task top_level_parent)
          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.
 synchronized SetgetActiveTasks()
          List the active Tasks
 (package private) ACLgetNewConversation(String protocol)
          Sets up a new Conversation using the given protocol
 static voidmain(String[] args)
           
 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
 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.
 (package private) 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.
 (package private) 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.
 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.
 voidrun()
          Method invoked when the TM starts
 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

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

getActiveTasks

public synchronized Set getActiveTasks()
List the active Tasks

getNewConversation

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

main

public static void main(String[] args)

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

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

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

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

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

run

public void run()
Method invoked when the TM starts

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

Association Links

to Class java.lang.String

to Class java.lang.String

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

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 java.lang.Thread

Thread associated with this TM

to Class fipaos.agent.task.Task

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