roomba.roombanetwork.client
Class RoombaNetworkClient

java.lang.Object
  extended by roomba.roombanetwork.client.RoombaNetworkClient
All Implemented Interfaces:
SocketListener

public class RoombaNetworkClient
extends java.lang.Object
implements SocketListener

This class performs the role of RNC (Roomba Network Client). It provides the base for a service to build upon.

Author:
Drew Housten

Field Summary
static java.lang.String PROTOCOL_VERSION
          The Protocol version that the client is using
 
Constructor Summary
RoombaNetworkClient(ClientListener clientListener, java.lang.String serviceName, java.lang.String serviceType, java.lang.String rnsHost, int rnsPort, boolean verbose)
          Constructor for creating the RNC.
RoombaNetworkClient(ClientListener clientListener, java.lang.String serviceName, java.lang.String serviceType, java.lang.String rnsHost, int rnsPort, boolean verbose, boolean blockStart)
          Constructor for creating the RNC.
 
Method Summary
 void connect()
          Connects to the RNS.
 void disconnect()
          Disconnects from the RNS.
 int getOutgoingQueueSize()
          Returns the queue size of messages waiting to be sent
 int getServiceID()
          Gets the service ID that has been assigned to the RNC
 boolean isConnected()
          Returns the flag indicating if the client is connected to the RNS.
static void main(java.lang.String[] args)
          Test main method
 void messageReceived(java.lang.String message)
          Processes a message received.
 void messageReceived(java.lang.String messageType, java.lang.String[] messageComponents)
          Processes a message received.
protected  boolean sendMessage(java.lang.String message)
          Sends a message to the RNS.
 boolean sendMessage(java.lang.String[] messageComponents)
          Sends a message to the RNS.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROTOCOL_VERSION

public static final java.lang.String PROTOCOL_VERSION
The Protocol version that the client is using

See Also:
Constant Field Values
Constructor Detail

RoombaNetworkClient

public RoombaNetworkClient(ClientListener clientListener,
                           java.lang.String serviceName,
                           java.lang.String serviceType,
                           java.lang.String rnsHost,
                           int rnsPort,
                           boolean verbose)
Constructor for creating the RNC. This will block until the client is connected to the server.

Parameters:
clientListener - The client listener for any incoming messages. This can be null
serviceName - The name of the client service
serviceType - The type of the client service
rnsHost - The host name that the RNS is running on
rnsPort - The port number that the RNS is running on
verbose - True iff the client should be verbose

RoombaNetworkClient

public RoombaNetworkClient(ClientListener clientListener,
                           java.lang.String serviceName,
                           java.lang.String serviceType,
                           java.lang.String rnsHost,
                           int rnsPort,
                           boolean verbose,
                           boolean blockStart)
Constructor for creating the RNC.

Parameters:
clientListener - The client listener for any incoming messages. This can be null
serviceName - The name of the client service
serviceType - The type of the client service
rnsHost - The host name that the RNS is running on
rnsPort - The port number that the RNS is running on
verbose - True iff the client should be verbose
blockStart - If true, the constructor will block until the client is connected to the server.
Method Detail

connect

public void connect()
Connects to the RNS. This method will block until the connection is complete


getOutgoingQueueSize

public int getOutgoingQueueSize()
Returns the queue size of messages waiting to be sent

Returns:
The size of the outgoing message queue

disconnect

public void disconnect()
Disconnects from the RNS.


isConnected

public boolean isConnected()
Returns the flag indicating if the client is connected to the RNS.

Returns:
true iff the client is properly connected to the RNS

messageReceived

public void messageReceived(java.lang.String message)
Processes a message received. This method should NOT be overridden. See the overloaded messageReceived method if that is desired.

Specified by:
messageReceived in interface SocketListener
Parameters:
message - The message that is received

messageReceived

public void messageReceived(java.lang.String messageType,
                            java.lang.String[] messageComponents)
Processes a message received. This method can be safely overridden by an extending class

Parameters:
messageType - The message type
messageComponents - The components of the received message

sendMessage

protected boolean sendMessage(java.lang.String message)
Sends a message to the RNS.

Parameters:
message - The message to send
Returns:
true iff the message was sent successfully. If the client is disconnected, this will return false

sendMessage

public boolean sendMessage(java.lang.String[] messageComponents)
Sends a message to the RNS.

Parameters:
messageComponents - The message components to send
Returns:
true iff the message was sent successfully. If the client is disconnected, this will return false

getServiceID

public int getServiceID()
Gets the service ID that has been assigned to the RNC

Returns:
the service ID

main

public static void main(java.lang.String[] args)
Test main method