maslab.telemetry
Class JugClient

java.lang.Object
  extended by maslab.telemetry.JugClient

public class JugClient
extends java.lang.Object

Manages sending and receiving packets via a hub for inter-process/inter-robot communication.


Constructor Summary
JugClient()
          Create a new client and connect to the hub on localhost using the default TCP port
JugClient(java.net.InetAddress addr, int port)
          Create a new client and connect to the hub on the specified host and port.
 
Method Summary
 void addStatusListener(StatusListener listener)
          Add a StatusListener who will be notified of connection/disconnection events and new channel events.
 void advertise(java.lang.String channel)
          Advertise the existence of a new channel.
 void displayQueueSizes()
          As a debugging aid, dump the sizes of each queue to stdout.
 java.util.ArrayList<java.lang.String> getChannels()
          Get a list of all channels which are currently advertised.
 void publish(java.lang.String channel, byte[] data)
          Publish data on a previously advertised channel.
 boolean publishing(java.lang.String channel)
          Determine if a message would actually be sent on a channel.
 void reconnect(java.net.InetAddress addr, int port)
           
 void removeStatusListener(StatusListener listener)
          Remove a StatusListener
 void setMaximumQueueSize(java.lang.String channel, int size)
          Limit the number of messages that can be queued up on a particular channel.
 void subscribe(java.lang.String cname, JugMessageListener listener)
          Subscribe to a channel.
 void unadvertise(java.lang.String channel)
          Unadvertise a channel.
 void unsubscribe(java.lang.String cname, JugMessageListener listener)
          Unsubscribe to a channel.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JugClient

public JugClient()
Create a new client and connect to the hub on localhost using the default TCP port


JugClient

public JugClient(java.net.InetAddress addr,
                 int port)
          throws java.io.IOException
Create a new client and connect to the hub on the specified host and port.

Throws:
java.io.IOException
Method Detail

reconnect

public void reconnect(java.net.InetAddress addr,
                      int port)
               throws java.io.IOException
Throws:
java.io.IOException

addStatusListener

public void addStatusListener(StatusListener listener)
Add a StatusListener who will be notified of connection/disconnection events and new channel events.


removeStatusListener

public void removeStatusListener(StatusListener listener)
Remove a StatusListener


getChannels

public java.util.ArrayList<java.lang.String> getChannels()
Get a list of all channels which are currently advertised.

Returns:
ArrayList of String

subscribe

public void subscribe(java.lang.String cname,
                      JugMessageListener listener)
Subscribe to a channel.

Parameters:
cname - The name of the channel.
listener - The listener to be notified of received data.

unsubscribe

public void unsubscribe(java.lang.String cname,
                        JugMessageListener listener)
Unsubscribe to a channel.

Parameters:
cname - The name of the channel.
listener - The listener that was subscribed

advertise

public void advertise(java.lang.String channel)
Advertise the existence of a new channel.

Parameters:
channel - The channel name that you will be publishing on.

unadvertise

public void unadvertise(java.lang.String channel)
Unadvertise a channel.

Parameters:
channel - The channel name that you will no longer be publishing on

publish

public void publish(java.lang.String channel,
                    byte[] data)
Publish data on a previously advertised channel.

Parameters:
channel - The channel name.
data - The data (opaque) to be sent. The data is NOT copied and thus should not be modified.

setMaximumQueueSize

public void setMaximumQueueSize(java.lang.String channel,
                                int size)
Limit the number of messages that can be queued up on a particular channel.

Parameters:
channel - The channel name
size - The maximum number of bytes before new published messages are dropped. If the size is less than zero, no limit is enforced.

displayQueueSizes

public void displayQueueSizes()
As a debugging aid, dump the sizes of each queue to stdout.


publishing

public boolean publishing(java.lang.String channel)
Determine if a message would actually be sent on a channel. This function can be used as an optimization by calling it before actually constructing an expensive packet and calling publish.

Parameters:
channel - The channel name.
Returns:
true if the message would be sent.