All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class Abstract.AgentAction

Abstract.AgentAction

public abstract class AgentAction
Abstract AgentAction class. You will need to subclass this class to act according to the message received. Since JATLite assumes to use MessageBuffer, the ReceiverThread will receive message and add it to MessageBuffer. AgentAction will check the received message and retrieve it when available.

See Also:
BAgentAction, KQMLAgentAction, RouterAction, RouterClientAction

Variable Index

 o _addresses
Address table
 o _connections
Connection table, which contains active ReceiverThread.
 o _durationTime
Set maximum idle time for the message receiving threads.
 o _endWith
EndWith character to create ServerThread and ReceiverThead.
 o _queue
Message Buffer data member
 o _security
Regisger, unregister protocol will be taken by this security object.

Constructor Index

 o AgentAction()
Default constructor
 o AgentAction(String)
Set the thread name identical to the agent name
 o AgentAction(String, MessageBuffer, AddressTable, ConnectionTable, Security)
Constructor
 o AgentAction(String, MessageBuffer, AddressTable, ConnectionTable, Security, ThreadGroup)
Constructor
 o AgentAction(ThreadGroup, String)
Set the thread name identical to the agent name.

Method Index

 o Act(Object)
Actual Action method.
 o broadCast(String)
Broad cast to all the running connecitons.
 o createReceiverThread(String, int)
Abstract class to create ReceiverThread.
 o createServerThread(String, int)
Abstract class to create ServerThread.
 o endAction()
You can stop gracefully to clean up
 o getAddressTable()
Get AddressTable
 o getConnectionTable()
Get ConnectionTable
 o getDurationTime()
Get current duration time set
 o getEndWith()
Get endWith character
 o getMessageQueue()
Get MessageBuffer
 o getSecurity()
Accessor to get Security object
 o processMessage(String, Object)
Abstract method to process message given any other objects.
 o run()
Override run() method as you need.
 o sendMessage(String, String)
Send Message by specifying a receiver and a message.
 o setAddressTable(AddressTable)
Set AddressTable
 o setConnectionTable(ConnectionTable)
Set ConnectionTable
 o setDurationTime(int)
Set ReceiverThread maximum idle time.
 o setEndWith(char)
Set endWith character for all the ServerThread and ReceiverThread
 o setMessageQueue(MessageBuffer)
Set MessageBuffer
 o setSecurity(Security)
Set Security object

Variables

 o _queue
 protected MessageBuffer _queue
Message Buffer data member

See Also:
MessageBuffer
 o _addresses
 protected AddressTable _addresses
Address table

See Also:
AddressTable
 o _connections
 protected ConnectionTable _connections
Connection table, which contains active ReceiverThread. The key is receiver name and the field is the ReceiverThread object.

See Also:
ConnectionTable, ReceiverThread
 o _security
 protected Security _security
Regisger, unregister protocol will be taken by this security object. For any communication, this protocol should be specified.

See Also:
Security
 o _endWith
 protected char _endWith
EndWith character to create ServerThread and ReceiverThead. If your messages are finished with other than '\004', you must set endWith by setEndWith(char) method. For example, if you want to set endWith character for ServerThread,
AgentAction action = new AgentAction();
action.setEndWith('\004');
ServerThread server = action.createServerThread("Server",Thread.NORM_PRIORITY);
....
If you set the endWith character on the ServerThread, the generated ReceiverThread will have the same endWith character.

See Also:
ServerThread, ReceiverThread
 o _durationTime
 protected int _durationTime
Set maximum idle time for the message receiving threads. Unit is minute. Maximum idle time is not absolute value. If a message is received or sent, timer will reset timer. If this is set to -1, no time out check. Default is -1.

See Also:
ServerThread, ReceiverThread

Constructors

 o AgentAction
 public AgentAction()
Default constructor

 o AgentAction
 public AgentAction(String id)
Set the thread name identical to the agent name

Parameters:
id - Agent Name
 o AgentAction
 public AgentAction(ThreadGroup tg,
                    String id)
Set the thread name identical to the agent name. Default endWithChar and duration time will be assigned.

Parameters:
tg - Thread group to which this thread will be owned
id - Agent Name
 o AgentAction
 public AgentAction(String id,
                    MessageBuffer queue,
                    AddressTable addresses,
                    ConnectionTable connections,
                    Security security)
Constructor

Parameters:
id - Agent Name which is identical to the thread name
queue - MessageBuffer
addresses - AddressTable
connections - ConnectionTable
security - Security object
 o AgentAction
 public AgentAction(String id,
                    MessageBuffer queue,
                    AddressTable addresses,
                    ConnectionTable connections,
                    Security security,
                    ThreadGroup tg)
Constructor

Parameters:
id - Agent Name which is identical to the thread name
queue - MessageBuffer
addresses - AddressTable
connections - ConnectionTable
security - Security object
tg - Thread group for the initiated receiver thread

Methods

 o setMessageQueue
 public void setMessageQueue(MessageBuffer queue)
Set MessageBuffer

Parameters:
queue - MessageBuffer to restore the message from the socket buffer
 o setAddressTable
 public void setAddressTable(AddressTable addresses)
Set AddressTable

Parameters:
addresses - AddressTable
 o setConnectionTable
 public void setConnectionTable(ConnectionTable connections)
Set ConnectionTable

Parameters:
connections - ConnectionTable
 o getMessageQueue
 public MessageBuffer getMessageQueue()
Get MessageBuffer

Returns:
MessageBuffer, the AgentAction has
 o getAddressTable
 public AddressTable getAddressTable()
Get AddressTable

Returns:
Agent action's AddressTable
 o getConnectionTable
 public ConnectionTable getConnectionTable()
Get ConnectionTable

Returns:
Agent action's ConnectionTable
 o setSecurity
 public void setSecurity(Security security)
Set Security object

Parameters:
security - Security object
 o getSecurity
 public Security getSecurity()
Accessor to get Security object

Returns:
_security data member
 o setEndWith
 public void setEndWith(char c)
Set endWith character for all the ServerThread and ReceiverThread

Parameters:
c - End with character to be set
 o getEndWith
 public char getEndWith()
Get endWith character

Returns:
End with character
 o setDurationTime
 public void setDurationTime(int time)
Set ReceiverThread maximum idle time. All the ReceiverThread's idle time will be set if you pass time other than -1.

Parameters:
time - Maximum idle time in minutes
 o getDurationTime
 public int getDurationTime()
Get current duration time set

Returns:
Maximum idle time for the ReceiverThread
 o createServerThread
 public abstract ServerThread createServerThread(String id,
                                                 int priority)
Abstract class to create ServerThread. Create server thread using name of the agent. Override this method if your connection type is different.

Parameters:
id - ServerThread name
priority - Server thread priority
Returns:
ServerThread, generated
 o createReceiverThread
 public abstract ReceiverThread createReceiverThread(String serverid,
                                                     int priority) throws ConnectionException
Abstract class to create ReceiverThread. Create client receiver thread using name of the agent. Override this method if your connection type is different.

Parameters:
id - agent name. This name is not my name. The name of the other agent you want to connect
priority - Receiver thread priority
Returns:
ReceiverThread, generated
Throws: ConnectionException
if error occurs while creating and checking security
 o sendMessage
 public abstract void sendMessage(String receiver,
                                  String msg) throws ConnectionException
Send Message by specifying a receiver and a message.

Parameters:
receiver - Receiver Agent
msg - Message to be sent
Throws: ConnectionException
if a message can not be sent
 o broadCast
 public abstract void broadCast(String msg) throws ConnectionException
Broad cast to all the running connecitons. If connection is not alive, sending to the agent will be ignored.

Parameters:
msg - Message to be sent all the living connections
 o processMessage
 public abstract void processMessage(String command,
                                     Object obj)
Abstract method to process message given any other objects. This method can be used for data exchange between threads or between application and GUI. Alpha version processMessage(String,String[]) should be replaced by this method. If you already used processMessage(String,String[]) method, modify the processMessage(String,String[]) to processMessage(String,Object) and cast Object as String[].
For example :
processMessage(String c,String[] s) should be replaced as
processMessage(String c,Object obj) {
String[] s = (String[])obj;
.....
}

Parameters:
command - Command to be executed
obj - Reference object
 o Act
 protected abstract boolean Act(Object o)
Actual Action method. Note that the parameter is object, which should be instantiated by casting according to the parameter type. This method will be called whenever there's a received message from Receiver Thread object.

 o run
 public void run()
Override run() method as you need. You can check the MessageBuffer and act according to the message received. Example implementation for run() method is
public void run() {
while(true) {
}

 o endAction
 public abstract void endAction()
You can stop gracefully to clean up


All Packages  Class Hierarchy  This Package  Previous  Next  Index