roomba.roombanetwork.services.userservice
Class UserService

java.lang.Object
  extended by roomba.roombanetwork.services.userservice.UserService
All Implemented Interfaces:
ClientListener

public class UserService
extends java.lang.Object
implements ClientListener

Connects to the RNS as a user service and handles message passing to and from the RNS. The setServerAddress and setName methods MUST be called before any other methods.

Author:
Drew Housten

Field Summary
protected  java.util.Vector listeners
           
protected static java.lang.String name
           
protected  RoombaNetworkClient rnc
           
protected static java.lang.String serverAddress
           
protected static UserService userService
           
 
Method Summary
static void addListener(ClientListener listener)
          Adds a listener for incoming messages.
static void disconnect()
          Disconnect from the server
static int getServiceID()
          Gets the assigned service ID of the user service
 void messageReceived(java.lang.String messageType, java.lang.String[] messageComponents)
          Processes a message received.
static void sendMessage(java.lang.String[] messageComponents)
          Sends a message to the RNS
static void setName(java.lang.String name)
          Sets the name of the user service.
static void setServerAddress(java.lang.String serverAddress)
          Sets the RNS hostname (or ip address) that the RNC should connect to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

userService

protected static UserService userService

serverAddress

protected static java.lang.String serverAddress

name

protected static java.lang.String name

rnc

protected RoombaNetworkClient rnc

listeners

protected java.util.Vector listeners
Method Detail

setServerAddress

public static void setServerAddress(java.lang.String serverAddress)
Sets the RNS hostname (or ip address) that the RNC should connect to. If this is called after any of the other methods (besides setName), this will have no effect.

Parameters:
serverAddress - The RNS address to set

setName

public static void setName(java.lang.String name)
Sets the name of the user service. If this is called after any of the other methods (besides setServerAddress), this will have no effect.

Parameters:
name - The name of the user service to set.

sendMessage

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

Parameters:
messageComponents - The components of the message to send

getServiceID

public static int getServiceID()
Gets the assigned service ID of the user service

Returns:
The assigned service ID

addListener

public static void addListener(ClientListener listener)
Adds a listener for incoming messages.

Parameters:
listener - The listener to add

disconnect

public static void disconnect()
Disconnect from the server


messageReceived

public void messageReceived(java.lang.String messageType,
                            java.lang.String[] messageComponents)
Processes a message received. The message is passed to any listeners subscribed to the user service

Specified by:
messageReceived in interface ClientListener
Parameters:
messageType - The message type
messageComponents - The components of the received message