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
-
_addresses
-
Address table
-
_connections
- Connection table, which contains active ReceiverThread.
-
_durationTime
- Set maximum idle time for the message receiving threads.
-
_endWith
- EndWith character to create ServerThread and ReceiverThead.
-
_queue
- Message Buffer data member
-
_security
- Regisger, unregister protocol will be taken by this security object.
-
AgentAction()
- Default constructor
-
AgentAction(String)
- Set the thread name identical to the agent name
-
AgentAction(String, MessageBuffer, AddressTable, ConnectionTable, Security)
- Constructor
-
AgentAction(String, MessageBuffer, AddressTable, ConnectionTable, Security, ThreadGroup)
- Constructor
-
AgentAction(ThreadGroup, String)
- Set the thread name identical to the agent name.
-
Act(Object)
- Actual Action method.
-
broadCast(String)
- Broad cast to all the running connecitons.
-
createReceiverThread(String, int)
- Abstract class to create ReceiverThread.
-
createServerThread(String, int)
- Abstract class to create ServerThread.
-
endAction()
- You can stop gracefully to clean up
-
getAddressTable()
- Get AddressTable
-
getConnectionTable()
- Get ConnectionTable
-
getDurationTime()
- Get current duration time set
-
getEndWith()
- Get endWith character
-
getMessageQueue()
- Get MessageBuffer
-
getSecurity()
- Accessor to get Security object
-
processMessage(String, Object)
- Abstract method to process message given any other objects.
-
run()
- Override run() method as you need.
-
sendMessage(String, String)
- Send Message by specifying a receiver and a message.
-
setAddressTable(AddressTable)
- Set AddressTable
-
setConnectionTable(ConnectionTable)
- Set ConnectionTable
-
setDurationTime(int)
- Set ReceiverThread maximum idle time.
-
setEndWith(char)
- Set endWith character for all the ServerThread and ReceiverThread
-
setMessageQueue(MessageBuffer)
- Set MessageBuffer
-
setSecurity(Security)
- Set Security object
_queue
protected MessageBuffer _queue
- Message Buffer data member
- See Also:
- MessageBuffer
_addresses
protected AddressTable _addresses
- Address table
- See Also:
- AddressTable
_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
_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
_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
_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
AgentAction
public AgentAction()
- Default constructor
AgentAction
public AgentAction(String id)
- Set the thread name identical to the agent name
- Parameters:
- id - Agent Name
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
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
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
setMessageQueue
public void setMessageQueue(MessageBuffer queue)
- Set MessageBuffer
- Parameters:
- queue - MessageBuffer to restore the message from the socket buffer
setAddressTable
public void setAddressTable(AddressTable addresses)
- Set AddressTable
- Parameters:
- addresses - AddressTable
setConnectionTable
public void setConnectionTable(ConnectionTable connections)
- Set ConnectionTable
- Parameters:
- connections - ConnectionTable
getMessageQueue
public MessageBuffer getMessageQueue()
- Get MessageBuffer
- Returns:
- MessageBuffer, the AgentAction has
getAddressTable
public AddressTable getAddressTable()
- Get AddressTable
- Returns:
- Agent action's AddressTable
getConnectionTable
public ConnectionTable getConnectionTable()
- Get ConnectionTable
- Returns:
- Agent action's ConnectionTable
setSecurity
public void setSecurity(Security security)
- Set Security object
- Parameters:
- security - Security object
getSecurity
public Security getSecurity()
- Accessor to get Security object
- Returns:
- _security data member
setEndWith
public void setEndWith(char c)
- Set endWith character for all the ServerThread and ReceiverThread
- Parameters:
- c - End with character to be set
getEndWith
public char getEndWith()
- Get endWith character
- Returns:
- End with character
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
getDurationTime
public int getDurationTime()
- Get current duration time set
- Returns:
- Maximum idle time for the ReceiverThread
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
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
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
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
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
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.
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) {
if(!_queue.isEmpty()) {
Act(_queue.getMessage());
}
else {
}
}
}
endAction
public abstract void endAction()
- You can stop gracefully to clean up
All Packages Class Hierarchy This Package Previous Next Index