unsw.cse.mica.agent.transport
Class TCPAgentConnection

java.lang.Object
  extended by unsw.cse.mica.agent.transport.TCPAgentConnection
All Implemented Interfaces:
AgentConnection

public class TCPAgentConnection
extends java.lang.Object
implements AgentConnection

An implementation of the AgentConnection interface using TCP sockets.

Author:
jhw
See Also:
TCPBlackboardConnection

Constructor Summary
TCPAgentConnection(java.lang.String host, int port)
          Create a new TCP connection with ther given host and port.
 
Method Summary
 void connect()
          Make a connection.
 void disconnect()
          terminate the connection.
 java.lang.String getHost()
          Get the host specified for this connection
 java.io.InputStream getInputStream()
          Get an input stream for this connection
 java.io.OutputStream getOutputStream()
          Get an output stream for this connection
 int getPort()
          Get the port specified for this connection
 boolean isConnected()
          Check if a connection is open.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TCPAgentConnection

public TCPAgentConnection(java.lang.String host,
                          int port)
Create a new TCP connection with ther given host and port.

Parameters:
host - the host on which the blackbnoard resides
port - the port on which the blackboard communicates.
Method Detail

getHost

public java.lang.String getHost()
Get the host specified for this connection

Returns:
the host for this connection

getPort

public int getPort()
Get the port specified for this connection

Returns:
the port specified for this connection

connect

public void connect()
             throws TransportException
Description copied from interface: AgentConnection
Make a connection. The details of how this occurs this will be implementation-specific.

Specified by:
connect in interface AgentConnection
Throws:
TransportException - if the connection could not be made

disconnect

public void disconnect()
                throws TransportException
Description copied from interface: AgentConnection
terminate the connection.

Specified by:
disconnect in interface AgentConnection
Throws:
TransportException - if something went wrong...

isConnected

public boolean isConnected()
Description copied from interface: AgentConnection
Check if a connection is open.

Specified by:
isConnected in interface AgentConnection
Returns:
true if the connection is active, false otherwise

getInputStream

public java.io.InputStream getInputStream()
                                   throws TransportException
Description copied from interface: AgentConnection
Get an input stream for this connection

Specified by:
getInputStream in interface AgentConnection
Returns:
an input stream for this connection
Throws:
TransportException - if an inputstream could not be obtained for some reason.

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws TransportException
Description copied from interface: AgentConnection
Get an output stream for this connection

Specified by:
getOutputStream in interface AgentConnection
Returns:
an output stream for this connection
Throws:
TransportException - if an output stream could not be obtained for some reason.