All Packages Class Hierarchy This Package Previous Next Index
Class RouterLayer.Router.RouterRecvThread
Abstract.Connection
|
+----Abstract.ReceiverThread
|
+----BaseLayer.BRecvThread
|
+----KQMLLayer.KQMLRecvThread
|
+----RouterLayer.Router.RouterRecvThread
- public class RouterRecvThread
- extends KQMLRecvThread
RouterRecvThread is a subclass of the BReceiverThread class.
RouterRecvThread action is:
Run(while true)
Check message queue
If message queue is not empty
retrieve messages(not just one message. All the messages in the queue at once)
send messages through the connection, save messages to the file, update idle time
Check socket buffer
if socket buffer is not empty
retrieve messages
for all the messages
parse the message to find out the receiver
if the receiver is the Router itself, perform the message
if the receiver is another agent
Check the ConnectionTable
if the receiver is connected
store the message to the receiver queue
if the receiver is disconnected
Check the connection can be initiated
if the connection can be initiated
Try to connect to the receiver
if connection success
store the message to the receiver queue
if connection failure
save the message to the receiver file
if the connection can not be initiated
save the message to the receiver file
The RouterRecvThread will retain its own MessageBuffer, which does not related to the
RouterAction. The Router utilities will be delegated to the RouterRecvThread.
For message reservation, the RouterRecvThread will create Reservation object and
add it to the ReservationTable, cretated and maintained by the RouterAction.
For delete-message operation, the delete-messages can be buffered.
You can set the _maxDeleteSize to change the buffer size. Default is 1, this
means that the message numbers will be updated every time for delete operation
is performed. The message numbering should be identical to the RotuerClientAction.
Therefore, if you set the delete-message buffer size, the RouterClientAction
delete-message buffer size should be changed, too.
- See Also:
- RouterServerThread, RouterClientAgentAction, RouterAction
-
_currentFileSize
- Current incoming file size
-
_currentFPTSize
- Current message size in the MessageBuffer
-
_deleteFPT
- Vector to contains deleted message number.
-
_deleteFPTSize
- Current delete-message size
-
_disconnectTable
- Table, which contains the disconnected agent list.
-
_incomingFile
- Incoming file
-
_maxDeleteSize
- Maximun buffer size for deleted messages
-
_messageBoxPath
- Message box file path
By giving messageBoxPath, I am assuming that the file extension as
incoming file - agentname.incoming
message file pointer file - agentname.fpt
reserved message file - agentname.reserved.timestamp.
-
_msgFPTStream
- Cache file pointer of the messages.
-
_offLineList
- Agent name array which contains the agent names those are off-line intentionally.
-
_reservedBook
- Hashtable to record reserved messages.
-
CREATEFILEFAILED
- File creation for the incoming file box failed
-
EMAILNOTSPECIFIED
- Can not find email address for receiver
-
INTERNALERROR
- Internal error
-
MESSAGESIZETOOBIG
- Message size is over MAX_MSG_LEN.
-
NAMENOTSPECIFIED
- The receiver name is not specified in the KMQL message.
-
NOTREGISTEREDUSER
- The agent is not an registered user.
-
NOTVALIDMESSAGEMETHOD
- Message method is not understandable
-
PARSEERROR
- Parse error will be immediately returned
-
PASSWORDMISSING
- Agent password is not passed during the Security process
-
RECEIVERMISSING
- Receiver is not specified
-
UNREGISTERFAILED
- Unregister is not authorized
-
WRONGKQMLFORMAT
- Wrong format KQML message will be immediately returned
-
RouterRecvThread()
- Default Constructor.
-
RouterRecvThread(Address, Address, ConnectionTable, String, Security, OffLineAgentTable)
- Router receiver thread to send off-line agent's messages back to the senders with error.
-
RouterRecvThread(Address, int, Address, ConnectionTable, MessageBuffer, Security, String, Hashtable, OffLineAgentTable, Vector, ThreadGroup)
- This constructor is called when an agent want to initialize a connection
to the other agents, using Address
-
RouterRecvThread(Socket, int, Address, ConnectionTable, MessageBuffer, Security, String, Hashtable, OffLineAgentTable, Vector)
- Constructor, to be called from the serverthread after accepting
a connection.
-
RouterRecvThread(String)
- Constructor with the Agent name.
-
checkTime()
- Override BRecvThread's checkTime method to add the agent name to the off line agent list
-
cleanUp()
- Clean up the files and remove connection from the connection table
-
closeSocket()
- Close socket and stop this thread
-
deleteMessages()
- Does not necessarily be synchronized.
-
endConn()
- If there are messages to be deleted, deleteMessages() will be invoked
Send 'disconnect' message to the agent and Close all the connections.
-
forwardMessage(String)
- New messages are received from the socket.
-
getMsgHeader()
- Return message header, 'N 86472389 ' where 86472389 represent current time
-
initialize()
- Send queued messages to the agent.
-
openFiles()
- Send messages to the receiver by retriving file and open necessary files.
-
processDefaultProtocol(KQMLmessage)
- Processing default protocols : disconnect-agent, reserve-message, list-agent, request-address,
and unregister-agent.
-
receiveMessage()
- Message received to the queue.
-
reserveMessages(KQMLmessage)
- Message reservation on a specific time
Generate reserved message file.
-
run()
- The run() method will performed the Security check at first.
-
saveMessageToFile(String, String)
- This method is invoked under the assumption that the receiver is off-line and
the Router can not connect to the receiver
-
saveMessageToIncomingFile(String)
-
-
sendErrorMessage(int, String)
- Send error message to the agent is error occurs.
-
sendMessage(String, String)
- Send message to the intended receiver.
-
sendOffLineAgentErrorMessages()
-
-
sendReservedMessages(String)
- send reserved messages, invoked from the RouterAction
The reasoning is that when the RouterAction want to send reserved
message and the receiver thread is running, it does not need to
open a new connection to send.
-
setDisconnectTable(Vector)
- Set the disconnect table
-
setOffLineList(OffLineAgentTable)
- Set the off line agent name list.
-
setReservedBook(Hashtable)
- Set the ReservationTable
-
writeMsg(String)
- The thread just writes on the connection for the remote side.
NOTREGISTEREDUSER
protected static final int NOTREGISTEREDUSER
- The agent is not an registered user. The error message will be sent
when an agent want to ANS service, but the agent is not on the
registered user list
NAMENOTSPECIFIED
protected static final int NAMENOTSPECIFIED
- The receiver name is not specified in the KMQL message. Error message
will be sent
CREATEFILEFAILED
protected static final int CREATEFILEFAILED
- File creation for the incoming file box failed
PASSWORDMISSING
protected static final int PASSWORDMISSING
- Agent password is not passed during the Security process
NOTVALIDMESSAGEMETHOD
protected static final int NOTVALIDMESSAGEMETHOD
- Message method is not understandable
RECEIVERMISSING
protected static final int RECEIVERMISSING
- Receiver is not specified
INTERNALERROR
protected static final int INTERNALERROR
- Internal error
UNREGISTERFAILED
protected static final int UNREGISTERFAILED
- Unregister is not authorized
PARSEERROR
protected static final int PARSEERROR
- Parse error will be immediately returned
WRONGKQMLFORMAT
protected static final int WRONGKQMLFORMAT
- Wrong format KQML message will be immediately returned
EMAILNOTSPECIFIED
protected static final int EMAILNOTSPECIFIED
- Can not find email address for receiver
MESSAGESIZETOOBIG
protected static final int MESSAGESIZETOOBIG
- Message size is over MAX_MSG_LEN. Will be disconnected from the router
_reservedBook
protected Hashtable _reservedBook
- Hashtable to record reserved messages. The key is time stamp and the field
value is reservation object
_offLineList
protected OffLineAgentTable _offLineList
- Agent name array which contains the agent names those are off-line intentionally.
If a message receiver is in the off-line list, the RouterRecvThread will not send
the message to the receiver. The message will be saved to the file. If the receiver
is reconnect, the received messages will be sent.
_disconnectTable
protected Vector _disconnectTable
- Table, which contains the disconnected agent list. If the agent send 'disconnect-agent'
message to the router, the router will add the agent to this table. Until the agent
will reconnect, the router will not send message to the agent.
_messageBoxPath
protected String _messageBoxPath
- Message box file path
By giving messageBoxPath, I am assuming that the file extension as
incoming file - agentname.incoming
message file pointer file - agentname.fpt
reserved message file - agentname.reserved.timestamp. Time stamp is 12 digit numbers
_deleteFPT
protected int _deleteFPT[]
- Vector to contains deleted message number. Delete operation will
be performed either when the receiver thread is disconnected
or number of delete-message is greater than _maxDeleteSize
_currentFPTSize
protected int _currentFPTSize
- Current message size in the MessageBuffer
_currentFileSize
protected long _currentFileSize
- Current incoming file size
_deleteFPTSize
protected int _deleteFPTSize
- Current delete-message size
_maxDeleteSize
protected int _maxDeleteSize
- Maximun buffer size for deleted messages
_msgFPTStream
protected RandomAccessFile _msgFPTStream
- Cache file pointer of the messages.
_incomingFile
protected RandomAccessFile _incomingFile
- Incoming file
RouterRecvThread
public RouterRecvThread()
- Default Constructor.
RouterRecvThread
public RouterRecvThread(String name)
- Constructor with the Agent name. If you use this constructor, you should
use set methods to set data members
- Parameters:
- name - Agent name
RouterRecvThread
public RouterRecvThread(Socket client_socket,
int priority,
Address myaddress,
ConnectionTable connections,
MessageBuffer queue,
Security security,
String messageboxpath,
Hashtable reservedBook,
OffLineAgentTable offlinelist,
Vector disconnectlist) throws ConnectionException
- Constructor, to be called from the serverthread after accepting
a connection.
- Parameters:
- client_scoket - The socket for the remote client;
- priority - The priority of the thread.
- myaddress - My address to be sent to the Router to check security
- connections - The connection table is passed as an argument.
- queue - The Message Queue. Normally null. It will be created by this if null
- security - The RouterSecurity
- messageboxpath - The Message incoming box directory
- reservedBook - The reservation table, passed from the RouterAction
- offlinelist - The off line agent name list.
- disconnectlist - The disconnected agent name list.
RouterRecvThread
public RouterRecvThread(Address serveraddress,
int priority,
Address myaddress,
ConnectionTable connections,
MessageBuffer queue,
Security security,
String messageboxpath,
Hashtable reservedBook,
OffLineAgentTable offlinelist,
Vector disconnectlist,
ThreadGroup tg) throws ConnectionException
- This constructor is called when an agent want to initialize a connection
to the other agents, using Address
- Parameters:
- serveraddress - The Router address
- priority - The priority of the thread.
- myaddress - My address to be sent to the Router to check security
- connections - The connection table is passed as an argument.
- queue - The Message Queue. Normally null. It will be created by this if null
- security - The RouterSecurity
- messageboxpath - The Message incoming box directory
- reservedBook - The reservation table, passed from the RouterAction
- offlinelist - The off line agent name list.
- disconnectlist - The disconnected agent name list.
- tg - The thread group to which this receiver thread will be owned to
RouterRecvThread
public RouterRecvThread(Address serveraddress,
Address myaddress,
ConnectionTable connections,
String messageboxpath,
Security security,
OffLineAgentTable offlinelist)
- Router receiver thread to send off-line agent's messages back to the senders with error.
- Parameters:
- serveraddress - Router address
- myaddress - Router address to be sent to the Router to check security
- connections - The connection table is passed as an argument.
- security - The RouterSecurity
- messageboxpath - The Message incoming box directory
- offlinelist - The off line agent name list.
setReservedBook
public void setReservedBook(Hashtable reservedBook)
- Set the ReservationTable
- Parameters:
- reservedBook - ReservationTable from the RouterAction
setOffLineList
public void setOffLineList(OffLineAgentTable offlinelist)
- Set the off line agent name list. The off-line means that an agent
intentionally wants not to receive message before it reconnect to the Router.
- Parameters:
- offlinelist - Off line agent name list.
setDisconnectTable
public void setDisconnectTable(Vector disconnectlist)
- Set the disconnect table
- Parameters:
- disconnectlist - Disconnected agent list
initialize
protected void initialize()
- Send queued messages to the agent. Update off-line/disconnect table
openFiles
public synchronized void openFiles()
- Send messages to the receiver by retriving file and open necessary files.
This method is invoked after security check has been passed.
run
public void run()
- The run() method will performed the Security check at first. If the security
check has been passed, the Security will update the ConnectionTable. Then
the run() method will send the incoming messages and start to receive messages
- Overrides:
- run in class BRecvThread
checkTime
protected void checkTime()
- Override BRecvThread's checkTime method to add the agent name to the off line agent list
- Overrides:
- checkTime in class BRecvThread
forwardMessage
protected void forwardMessage(String msg)
- New messages are received from the socket. The RouterRecvThread parse the message
to find out the receiver. If the receiver is the Router itself, it will provide
necessary services. If the receiver is another agent, it will pass the message
to other agent after adding time stamp. For Router service, refer to
RouterAction class.
- Parameters:
- msg - String, received from the buffer
processDefaultProtocol
protected synchronized void processDefaultProtocol(KQMLmessage kqml)
- Processing default protocols : disconnect-agent, reserve-message, list-agent, request-address,
and unregister-agent. You need to extend this method if your router has extended capability
other than message routing(e.g. to support another internet protocol such as SMTP, FTP,etc.)
- Parameters:
- kqml - Received KQML message
sendMessage
protected synchronized void sendMessage(String receiver,
String msg)
- Send message to the intended receiver. If the receiver is on-line, add message to the
receiver message buffer. If the receiver is off-line, try to connect to the receiver
If connected, add message to the receiver buffer. If fails, save message to the receiver
incoming file.
- Parameters:
- receiver - The receiver agent
- stampmsg - The stamped message
reserveMessages
protected synchronized void reserveMessages(KQMLmessage kqml)
- Message reservation on a specific time
Generate reserved message file. Extension is reserved time.
To evade confusion, delete messages first if exist.
The received KQML will look like
(reserve-message :sender A :receiver A :time 123456789012
:content (2 5 7) :address (receiver-address :name B
:host cdr.stanford.edu :port 1234 :message-method RouterRecvThread
:description (agent-info :password xyz))
The delete slot is optional but it would be better to set as 'y'
to delete message after you reserve
The address slot is optional. If you want to receive at a specific
location other than where you are working now, you will need to
set the location. The description slot is optional. However, if
the Server side need password check, you should provide password
to the Router to connect safely.
- Parameters:
- kqml - KQMLmessage, which contains the message reservation info.
sendReservedMessages
public synchronized void sendReservedMessages(String time)
- send reserved messages, invoked from the RouterAction
The reasoning is that when the RouterAction want to send reserved
message and the receiver thread is running, it does not need to
open a new connection to send. The messages will be saved to
my message queue rather than sending directly, since if you
send the message directly, you will be in trouble to update the
incoming file, FPT file - the agent will received the messages
which is not registered to the Router and it will cause confusion.
No clean up after sending the reserved file.
- Parameters:
- time - String, reserved time
saveMessageToFile
protected synchronized void saveMessageToFile(String receiver,
String msg)
- This method is invoked under the assumption that the receiver is off-line and
the Router can not connect to the receiver
- Parameters:
- receiver - The receiver agent
- msg - Time stamped message
receiveMessage
protected synchronized void receiveMessage()
- Message received to the queue. send message and save it to the file
Time stamp is already attatched by other receiver threads
Should be synchronized, not to add messages to the queue
while writing.
saveMessageToIncomingFile
protected void saveMessageToIncomingFile(String msg)
deleteMessages
protected void deleteMessages()
- Does not necessarily be synchronized. All the other threads
knows that this thread is running, therefore they will try to
add received messages to this thread to the message queue.
This method will be invoked when the agent wants to disconnect or
the _maxDeleteSize is reached.
sendOffLineAgentErrorMessages
public void sendOffLineAgentErrorMessages()
writeMsg
public synchronized void writeMsg(String writebuffer) throws ConnectionException
- The thread just writes on the connection for the remote side.
- Parameters:
- writebuffer: - the message as a normal ASCII string.
- Throws: ConnectionException
- If IOError occurs, IOException will be thrown
- Overrides:
- writeMsg in class BRecvThread
endConn
public synchronized void endConn()
- If there are messages to be deleted, deleteMessages() will be invoked
Send 'disconnect' message to the agent and Close all the connections.
- Overrides:
- endConn in class BRecvThread
cleanUp
protected void cleanUp()
- Clean up the files and remove connection from the connection table
- Overrides:
- cleanUp in class BRecvThread
closeSocket
protected void closeSocket()
- Close socket and stop this thread
- Overrides:
- closeSocket in class BRecvThread
sendErrorMessage
public void sendErrorMessage(int code,
String content)
- Send error message to the agent is error occurs.
- Parameters:
- code - Error code
- content - Error content
getMsgHeader
protected String getMsgHeader()
- Return message header, 'N 86472389 ' where 86472389 represent current time
All Packages Class Hierarchy This Package Previous Next Index