datum API Documentation

datum.protocol
Class Connection

java.lang.Object
  |
  +--datum.protocol.Connection
All Implemented Interfaces:
Runnable

public final class Connection
extends Object
implements Runnable

Provides connection services to remote hosts or log files using datum.protocol messages. The host information is passed to the constructor and not the connect method because it is undesirable to reuse Connection objects to more that one host. This is due to the potential damage to the Library services which depend on host specific message definitions.

See Also:
Library, Receiver

Constructor Summary
Connection(FileReader fileReader, Receiver receiver)
          Creates a connection that holds state information for a specific log file.
Connection(String host, String[][] definitions, Receiver receiver)
          Creates a connection that holds information for a specific host.
Connection(URL location, Receiver receiver)
          Creates a connection that holds information for a specific log file from a URL.
 
Method Summary
 void connect()
          Attepts to connect to the host passed to the constructor.
 void connect(String routerHost)
          Attepts to connect to the host passed to the constructor via a Router.
 void disconnect()
          Forces the connection to be dropped immediately.
 int getDelay()
          Returns the miniumum delay between receivedData events.
 boolean getImmediateSend()
           
 Library getLibrary()
          Returns a reference to the Library for this Connection.
 String getName()
           
 boolean isConnected()
           
 boolean isSuspended()
           
 void run()
          Do not use.
 boolean send(File file)
           
 boolean send(Object[] message)
          Sends a message over this connection.
 boolean sendConfigs(File directory)
           
 void setDelay(int delay)
          Sets the miniumum delay between receivedData events.
 void setImmediateSend(boolean immediateSend)
           
 void setName(String name)
           
 void setSuspended(boolean suspended)
          Pauses the receiveData events, but does not loose any data, or disconnect from the server.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Connection

public Connection(String host,
                  String[][] definitions,
                  Receiver receiver)
Creates a connection that holds information for a specific host. Does not initiate the actual connection to the host. That is done by calling the connect method.

Parameters:
host - The IP address or registered (domain) name of the host. E.g. "127.0.0.1" or "server.rutgers.edu"
definitions - An array of message field name definitions. Each String in the array should be a delimited list of field names, the first field should be the message type. See the Server class documentation for an example.
receiver - The class that will receive events from this connection.
See Also:
connect(), connect(java.lang.String), Server

Connection

public Connection(URL location,
                  Receiver receiver)
Creates a connection that holds information for a specific log file from a URL. Does not initiate the actual connection to the log file, though. That is done by calling the connect method.

Parameters:
location - The URL of the log file to be read. E.g. "http://server.rutgers.edu/sim-out.dpf"
receiver - The class that will receive events from this connection.
See Also:
connect()

Connection

public Connection(FileReader fileReader,
                  Receiver receiver)
Creates a connection that holds state information for a specific log file. Does not initiate the actual connection to the log file, though. That is done by calling the connect method.

Parameters:
location - A FileReader for the log file to be read.
receiver - The class that will receive events from this connection.
See Also:
connect()
Method Detail

setName

public void setName(String name)

getName

public String getName()

toString

public String toString()
Overrides:
toString in class Object

connect

public void connect()
Attepts to connect to the host passed to the constructor. If successful the connected method of this connection's receiver will be called. Otherwise the error method will be called with a description of what went wrong.
See Also:
Receiver.connected(Connection), Receiver.error(Connection, java.lang.String)

connect

public void connect(String routerHost)
Attepts to connect to the host passed to the constructor via a Router. The address of the Router is usually determined by calling Applet.getCodeBase.getHost(). If successful the connected method of this connection's receiver will be called. Otherwise the error method will be called with a description of what went wrong.

Parameters:
routerHost - The address of the Router to be used.
See Also:
Receiver.connected(Connection), Receiver.error(Connection, java.lang.String)

getLibrary

public Library getLibrary()
Returns a reference to the Library for this Connection. Each Connection has it's own Library to handle simultaneous connections to different types of servers and different message definitions.

Returns:
A reference to this Connection's Library.

isConnected

public boolean isConnected()

getDelay

public int getDelay()
Returns the miniumum delay between receivedData events. The delay value is useful for controlling the speed of log file playback.

Returns:
The minimum delay between receivedData events in miliseconds.

setDelay

public void setDelay(int delay)
Sets the miniumum delay between receivedData events. The delay value is useful for controlling the speed of log file playback. The delay can only control the minimum delay as delays on the server end are uncontrolable.

Parameters:
int - The minimum delay between receivedData events in miliseconds.

setSuspended

public void setSuspended(boolean suspended)
Pauses the receiveData events, but does not loose any data, or disconnect from the server.

isSuspended

public boolean isSuspended()

sendConfigs

public boolean sendConfigs(File directory)

send

public boolean send(File file)

send

public boolean send(Object[] message)
Sends a message over this connection. The message argument should be an array of fields, the first field being the message name. The toString() method is used on each field before they are sent.

Parameters:
message - The array of fields to send.
Returns:
true if the message was sent, false if the message could not be sent.

getImmediateSend

public boolean getImmediateSend()

setImmediateSend

public void setImmediateSend(boolean immediateSend)

disconnect

public void disconnect()
Forces the connection to be dropped immediately. A call to the disconnected method of this Connection's receiver follows immedietly.
See Also:
Receiver.disconnected(Connection)

run

public void run()
Do not use.
Specified by:
run in interface Runnable

Up to datum