All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class ProtocolLayer.ConnectorThread

ProtocolLayer.ConnectorThread

public class ConnectorThread
Socket connector between an applet and server(SMTP,POP3,FTP,HTTP,etc.). Since an applet can not create socket other than it spawned from, router will take a role as proxy to connect the applet and servers. Router will create connector which connects the applet and servers. Connector will have two sockets, one for a server and one for an applet. Data input from any of two socket will be redirected to other side. Initially, a server address(host,port) will be passed to the constructor. After Connector connect to the server, it will create a server socket for the applet. The server socket port number will be passed to the applet and the applet will connect to the server socket. The socket port number will be passed as high level KQML message with performative 'port-info'.


Variable Index

 o _client
 o _clientQueue
Message buffer for a client applet
 o _clientServerSocket
Server socket, created for an applet connection for data transfer
 o _endWith
Message endWith character.
 o _maxWaitTime
Maximum time set in minutes
 o _server
Receiver thread for an internet server such as SMTP, FTP
 o _serverQueue
Message buffer for a server thread
 o _timer
Timer to check time out.

Constructor Index

 o ConnectorThread()
Default constructor
 o ConnectorThread(Address, int, int)
Constructor with internet service server address, priority and maximum idle time.
 o ConnectorThread(Socket, int, int)
Constructor with internet service server address, priority and maximum idle time.

Method Index

 o disconnectCon()
Disconnect connection but does not kill timer.
 o endConn()
Kill timer and disconnect.
 o getClientServerSocketNumber()
Accessor to get machine generated client ServerSocket number.
 o init(Socket, int, int)
Initialize data members, Server thread will be created and ServerSocket for an applet will be created.
 o isConnected()
Accessor to see whether client applet is connected or not
 o resetTimer()
Reset timer.
 o run()
Default behavior is to read from any of message queues - server side and client side.
 o setEndWith(char)
Set endWith character if different from '\n'
 o stopTimer()
Stop timer thread

Variables

 o _client
 protected BRecvThread _client
 o _clientQueue
 protected BMessageBuffer _clientQueue
Message buffer for a client applet

 o _server
 protected BRecvThread _server
Receiver thread for an internet server such as SMTP, FTP

 o _serverQueue
 protected BMessageBuffer _serverQueue
Message buffer for a server thread

 o _clientServerSocket
 protected ServerSocket _clientServerSocket
Server socket, created for an applet connection for data transfer

 o _maxWaitTime
 protected int _maxWaitTime
Maximum time set in minutes

 o _endWith
 protected char _endWith
Message endWith character. Default is '\n'. You need to use setEndWith(char) method if messages are not ended with '\n'.

 o _timer
 protected ConnectorTimerThread _timer
Timer to check time out. If time out, the thread will stop this thread and timer itself will stop. If data transfer is successful, timer will be stop by this thread.

Constructors

 o ConnectorThread
 public ConnectorThread()
Default constructor

 o ConnectorThread
 public ConnectorThread(Address serverAddress,
                        int priority,
                        int connectionWaitTime) throws ConnectionException
Constructor with internet service server address, priority and maximum idle time. Router will try to connect to given service address.

Parameters:
serverAddress - Internet service server address.
priority - Thread priority
connectionWaitTime - Maximum idle time.
Throws: ConnectionException
If server connection is failed, or fails to create ServerSocket for an applet.
 o ConnectorThread
 public ConnectorThread(Socket toSocket,
                        int priority,
                        int connectionWaitTime) throws ConnectionException
Constructor with internet service server address, priority and maximum idle time. Router will try to connect to given service address.

Parameters:
toSocket - Internet service server socket.
priority - Thread priority
connectionWaitTime - Maximum idle time.
Throws: ConnectionException
If server connection is failed, or fails to create ServerSocket for an applet.

Methods

 o init
 protected void init(Socket socket,
                     int priority,
                     int connectionTime) throws ConnectionException
Initialize data members, Server thread will be created and ServerSocket for an applet will be created. Client thread for an applet will not be initialized here. Initialization of client thread will be performed at run time, after accept a connection from the applet.

Parameters:
socket - Socket for internet service server
priority - Priority for this thread
connectionTime - Max. idle time
 o isConnected
 public boolean isConnected()
Accessor to see whether client applet is connected or not

Returns:
true if connected
 o setEndWith
 public void setEndWith(char endwith)
Set endWith character if different from '\n'

Parameters:
endWith - End with character
 o getClientServerSocketNumber
 public int getClientServerSocketNumber()
Accessor to get machine generated client ServerSocket number.

Returns:
ServerSocket number for the applet to connect
 o run
 public void run()
Default behavior is to read from any of message queues - server side and client side. If there's a message, send it to counter part(e.g. a message from server side will send to applet , vice versa.) Default behavior may not be appropriate for FTP, HTTP, POP3, etc. For each protocol, Connector will need to be extended. Timer will be set for waiting connection from an applet. If time limit is over, thread will close all the connection and stop.

 o disconnectCon
 public void disconnectCon()
Disconnect connection but does not kill timer. This method should be invoked only from ConnectorTimer.

 o endConn
 protected void endConn()
Kill timer and disconnect.

 o stopTimer
 protected void stopTimer()
Stop timer thread

 o resetTimer
 protected void resetTimer()
Reset timer. If timer is not created yet, created one.


All Packages  Class Hierarchy  This Package  Previous  Next  Index