org.jscience.net
Class SocketConnection

java.lang.Object
  extended by org.jscience.net.SocketConnection
All Implemented Interfaces:
NetConnection

public class SocketConnection
extends java.lang.Object
implements NetConnection

A SocketConnection provides simplified access to a remote process through a Socket connection. To create a SocketConnection, use createNetConnection()

See Also:
NetConnectionServer, NetConnectionHandler, ConnectionDispatcher, NetConnection

Constructor Summary
protected SocketConnection(java.net.Socket socket, java.io.ObjectInputStream in, java.io.ObjectOutputStream out, java.lang.Object signature)
          called by objects that create the connection themselves - including the handshake
protected SocketConnection(java.lang.String hostname, int port, java.lang.Object signature)
          called by createConnection(), createServerConnection(), or a subclass
 
Method Summary
 void close()
          closes the SocketConnection
static SocketConnection createConnection(java.lang.String hostname, int port)
          DOCUMENT ME!
static SocketConnection createConnection(java.lang.String hostname, int port, java.lang.Object signature)
          returns a SocketConnection provided there is a Server listening at the specified location with the secified signature; note that this method is blocking.
static SocketConnection createServerConnection(java.net.ServerSocket serverSocket)
          DOCUMENT ME!
static SocketConnection createServerConnection(java.net.ServerSocket serverSocket, java.lang.Object signature)
          waits and listens for a single connection to be made and returns a SocketConnection if the connection made matches the signature
 int getLocalPort()
          DOCUMENT ME!
 Logger getLogger()
          loggs standard events - no exceptions are logged here
 java.net.InetAddress getRemoteHost()
          DOCUMENT ME!
 int getRemotePort()
          DOCUMENT ME!
 java.lang.Object getSignature()
          DOCUMENT ME!
 java.net.Socket getSocket()
          DOCUMENT ME!
 boolean isActive()
          DOCUMENT ME!
 java.lang.Object readMessage()
          DOCUMENT ME!
 void reconnect()
          DOCUMENT ME!
 void sendMessage(java.lang.Object message)
          DOCUMENT ME!
 void setLogger(Logger logger)
          DOCUMENT ME!
 void setSoTimeout(int timeout)
          propagates to the embedded socket
 java.lang.String toString()
          DOCUMENT ME!
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SocketConnection

protected SocketConnection(java.lang.String hostname,
                           int port,
                           java.lang.Object signature)
                    throws java.io.IOException
called by createConnection(), createServerConnection(), or a subclass

Parameters:
hostname - DOCUMENT ME!
port - DOCUMENT ME!
signature - DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!

SocketConnection

protected SocketConnection(java.net.Socket socket,
                           java.io.ObjectInputStream in,
                           java.io.ObjectOutputStream out,
                           java.lang.Object signature)
                    throws java.io.IOException
called by objects that create the connection themselves - including the handshake

Parameters:
socket - DOCUMENT ME!
in - DOCUMENT ME!
out - DOCUMENT ME!
signature - DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!
Method Detail

createServerConnection

public static SocketConnection createServerConnection(java.net.ServerSocket serverSocket)
                                               throws java.io.IOException,
                                                      HandshakeException
DOCUMENT ME!

Parameters:
serverSocket - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!
HandshakeException - DOCUMENT ME!

createServerConnection

public static SocketConnection createServerConnection(java.net.ServerSocket serverSocket,
                                                      java.lang.Object signature)
                                               throws java.io.IOException,
                                                      HandshakeException
waits and listens for a single connection to be made and returns a SocketConnection if the connection made matches the signature

Parameters:
serverSocket - DOCUMENT ME!
signature - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!
HandshakeException - if the signatures did not match

createConnection

public static SocketConnection createConnection(java.lang.String hostname,
                                                int port)
                                         throws java.io.IOException,
                                                HandshakeException
DOCUMENT ME!

Parameters:
hostname - DOCUMENT ME!
port - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!
HandshakeException - DOCUMENT ME!

createConnection

public static SocketConnection createConnection(java.lang.String hostname,
                                                int port,
                                                java.lang.Object signature)
                                         throws java.io.IOException,
                                                HandshakeException
returns a SocketConnection provided there is a Server listening at the specified location with the secified signature; note that this method is blocking.

Parameters:
hostname - DOCUMENT ME!
port - DOCUMENT ME!
signature - - an object that identifies the desired type of connection
Returns:
DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!
HandshakeException - if the signatures did not match
See Also:
NetConnectionServer

isActive

public boolean isActive()
DOCUMENT ME!

Specified by:
isActive in interface NetConnection
Returns:
DOCUMENT ME!

reconnect

public void reconnect()
               throws java.io.IOException,
                      HandshakeException
DOCUMENT ME!

Throws:
java.io.IOException - DOCUMENT ME!
HandshakeException - DOCUMENT ME!

sendMessage

public void sendMessage(java.lang.Object message)
                 throws java.io.IOException
DOCUMENT ME!

Specified by:
sendMessage in interface NetConnection
Parameters:
message - DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!

readMessage

public java.lang.Object readMessage()
                             throws java.io.IOException,
                                    java.lang.ClassNotFoundException
DOCUMENT ME!

Specified by:
readMessage in interface NetConnection
Returns:
DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!
java.lang.ClassNotFoundException - DOCUMENT ME!

setSoTimeout

public void setSoTimeout(int timeout)
                  throws java.io.IOException
propagates to the embedded socket

Parameters:
timeout - DOCUMENT ME!
Throws:
java.io.IOException - DOCUMENT ME!

getSignature

public java.lang.Object getSignature()
DOCUMENT ME!

Specified by:
getSignature in interface NetConnection
Returns:
DOCUMENT ME!

close

public void close()
closes the SocketConnection

Specified by:
close in interface NetConnection

getLogger

public Logger getLogger()
loggs standard events - no exceptions are logged here

Returns:
DOCUMENT ME!

setLogger

public void setLogger(Logger logger)
DOCUMENT ME!

Parameters:
logger - DOCUMENT ME!
Throws:
java.lang.NullPointerException - DOCUMENT ME!

getSocket

public java.net.Socket getSocket()
DOCUMENT ME!

Specified by:
getSocket in interface NetConnection
Returns:
DOCUMENT ME!

getRemoteHost

public java.net.InetAddress getRemoteHost()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getRemotePort

public int getRemotePort()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getLocalPort

public int getLocalPort()
DOCUMENT ME!

Returns:
DOCUMENT ME!

toString

public java.lang.String toString()
DOCUMENT ME!

Overrides:
toString in class java.lang.Object
Returns:
DOCUMENT ME!