Class Client

java.lang.Object
   |
   +----Client

public class Client
extends Object
A class that implements the necesary connecting and messaging functions for connecting and communicating with the RoundRobinServerThread

In order not to overload the server a simple CTS mechanism is implemented. The client should NOT SEND again, before it receives a CTS Message from the server. He is allowed to send, but the Message just gets queued up and the feedback becomes slower, The method sendOK() returns a value that tests if some CTS Message was received and no other Message was sent. You have the option to change if the control Messages reach the child class or not.

Written: Radu Sion
Version: 0.61
Source: Client.java

See Also:
Player, ClientMessageCreator, Message, RoundRobinServerThread, ConnectServerThread, SimpleQueue, ClientConnectAAA

Constructor Index

 o Client(ClientConnectAAA)
Creates a new client that will use the specified AAA object to negociate at connect with the connection server.

Method Index

 o available()
Gets the number of available Messages for reading.
 o connect(String, int, int, int, int, int, int)
Connects to the remote RoundRobinServerThread and creates all needed structures for connecting.
 o disconnect()
Disconnects from the RoundRobinServerThread and stops everything.
 o getAAA()
Returns the internal AAA object.
 o getGroup()
Gets the clients group number from the server structures.
 o getNumber()
Gets the clients number in the server structures.
 o getPlayer()
Gets the internal Player object used.
 o readRaw(long)
Waits for some message to appear and then returns it rightaway.
 o recv()
Reads a incomming Message.
 o send(Message)
Sends a Message.
 o sendOK()
Gives a recommandation if it's ok to send, in order to maintain good feedback.
 o setAAA(ClientConnectAAA)
Changes the internal AAA object, that is the way the connection is to be done from now on.
 o setGroup(int)
Tries to set the client's group in the server structures.
 o setMessageFilter(boolean)
Sets the filter control Messages on/off.
 o test()
Tests the status of the connection & others.
 o waitForMessage(Message, long)
Waits for a specified message a given timeinterval.

Constructors

 o Client
 public Client(ClientConnectAAA a)
Creates a new client that will use the specified AAA object to negociate at connect with the connection server. (AAA = Auth & Auth & Accounting)

Parameters:
a - AAA object to use in talking with connect server

Methods

 o getAAA
 public synchronized ClientConnectAAA getAAA()
Returns the internal AAA object.

 o setAAA
 public synchronized void setAAA(ClientConnectAAA a)
Changes the internal AAA object, that is the way the connection is to be done from now on. (Authentication, Authorisation, Accounting) No parameter checkings performed.

Parameters:
a - New internal AAA object to use
 o connect
 public boolean connect(String serverhost,
                        int serverport,
                        int in_queue_len,
                        int out_queue_len,
                        int rsleep,
                        int wsleep,
                        int timeout)
Connects to the remote RoundRobinServerThread and creates all needed structures for connecting. Should be used at the beginning.

Parameters:
serverhost - The server name/address to which to connect to
in_queue_len - The maximum length of the incomming Message queue
out_queue_len - The maximum length of the outgoing Message queue
rsleep - Read thread sleep delay (arround 100)
wsleep - Write thread sleep delay (arround 100)
timeout - Timeout after which the connection is closed if no valid RESET message received
Returns:
Returns true if ok, false otherwise (timeout or others)
 o test
 public boolean test()
Tests the status of the connection & others. The child class should shutdown if the return is false.

Returns:
Returns true if ok, false otherwise.
 o waitForMessage
 public synchronized boolean waitForMessage(Message msg,
                                            long timeout)
Waits for a specified message a given timeinterval. The message is bypassing the messagefilter !!! Comparision is done by comparing the whole dataarea of the messages. DURING THIS CALL NO OTHER MESSAGES REACH recv() !!!!!!!!!!!!
THIS METHOD SHOULD BE USED WITH CARE ONLY IN UNUSUAL CASES !
IT IS VERY TRICKY INTERNALLY !!!
NOT TO BE USED INSIDE A STOP !!!

NOT IMPLEMENTED YET !!!
This method works only for small messages that don't exceed the systems socket buffer !!!

Parameters:
msg - Message to wait for
timeout - Timeout to wait for that message
Returns:
True if message received in that interval, false otherwise
 o readRaw
 public synchronized Message readRaw(long timeout)
Waits for some message to appear and then returns it rightaway. The message is returned as it is, bypassing the messagefilter. If no message appears in the specified timeout then returns null.

THIS METHOD SHOULD BE USED WITH CARE ONLY IN UNUSUAL CASES !
FOR REGULAR MESSAGE READING USE recv() INSTEAD !

NOT IMPLEMENTED YET !!!
This method works only for small messages that don't exceed the systems socket buffer !!!

Parameters:
timeout - Timeout to wait for message. (timeout*10ms !!!)
Returns:
A new received message or null in case of error
 o send
 public void send(Message m) throws FullException
Sends a Message. It's internally synchronized !!!

Parameters:
m - The Message to send
Throws: FullException
When the outgoing queue is full
 o sendOK
 public synchronized boolean sendOK()
Gives a recommandation if it's ok to send, in order to maintain good feedback. The issue is not to fill the queues by the server. If they are full then the feedback will be very bad because the incoming Messages (from the clients) will be handled only after the ones in the queue. If the queue is not too long then it's ok. But who knows. Use it before you send any other Message.

Returns:
If true then it's ok to send, else wait
 o setMessageFilter
 public synchronized void setMessageFilter(boolean how)
Sets the filter control Messages on/off. By default the control Messages (CTS,NOP,etc) will reach also the child class via recv. If you change this, recv() will more often throw EmptyException.

Parameters:
filter - If true sets the filtering on, else off
 o getGroup
 public synchronized int getGroup()
Gets the clients group number from the server structures.

Returns:
Group number or MessageConstants.INVALID if error
 o getPlayer
 public Player getPlayer()
Gets the internal Player object used.

Returns:
Player object
 o setGroup
 public void setGroup(int newgroup)
Tries to set the client's group in the server structures. The change will not be imediately and may not happen if the requested group is invalid. No return is made and no guaranties are given (in this version) that the request will be fulfilled. Generaly speaking everything should be ok. Some old queued messages may get lost during this process.

 o getNumber
 public synchronized int getNumber()
Gets the clients number in the server structures.

Returns:
The clients number
 o recv
 public Message recv() throws EmptyException
Reads a incomming Message. It's internally synchronized !!! (is it really ?)

Returns:
The read Message
Throws: EmptyException
When there is nothing to read
 o available
 public int available()
Gets the number of available Messages for reading.

Returns:
The number of Messages available for reading
 o disconnect
 public void disconnect()
Disconnects from the RoundRobinServerThread and stops everything. Should be used when stopping. // * @param delay Delay to use in order to allow the writethread to write remained messages