org.jscience.net
Class SSLSocketConnection

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

public class SSLSocketConnection
extends java.lang.Object
implements NetConnection

An SSLSocketConnection provides simplified access to a remote process through an SSLSocket connection.

not done yet

See Also:
NetConnectionServer, NetConnectionHandler, ConnectionDispatcher, NetConnection

Constructor Summary
protected SSLSocketConnection(javax.net.ssl.SSLSocket 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 SSLSocketConnection(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 SSLSocketConnection 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 SSLSocketConnection createServerConnection(int port, java.lang.Object signature)
           
static SSLSocketConnection createServerConnection(javax.net.ssl.SSLServerSocket serverSocket, java.lang.Object signature)
          waits and listens for a single connection to be made and returns an SSLSocketConnection if the connection made matches the signature
 int getLocalPort()
           
 java.net.InetAddress getRemoteHost()
           
 int getRemotePort()
           
 java.lang.Object getSignature()
          returns the identification type object for this connection; this signature is the same on both sides of the connection.
 java.net.Socket getSocket()
          returns an SSLSocket
static void init(java.security.KeyStore keyStore, char[] password)
           
 boolean isActive()
          returns whether this NetConnection is currently active
 java.lang.Object readMessage()
          reads an object from the connection (operation blocks until object is read)
 void sendMessage(java.lang.Object message)
          sends an object over the connection
 void setSoTimeout(int timeout)
          propagates to the embedded socket
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SSLSocketConnection

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

Throws:
java.io.IOException

SSLSocketConnection

protected SSLSocketConnection(javax.net.ssl.SSLSocket 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

Throws:
java.io.IOException
Method Detail

init

public static void init(java.security.KeyStore keyStore,
                        char[] password)

createServerConnection

public static SSLSocketConnection createServerConnection(int port,
                                                         java.lang.Object signature)
                                                  throws java.io.IOException,
                                                         HandshakeException,
                                                         java.lang.IllegalStateException,
                                                         java.security.GeneralSecurityException
Throws:
java.io.IOException
HandshakeException
java.lang.IllegalStateException
java.security.GeneralSecurityException

createServerConnection

public static SSLSocketConnection createServerConnection(javax.net.ssl.SSLServerSocket serverSocket,
                                                         java.lang.Object signature)
                                                  throws java.io.IOException,
                                                         HandshakeException,
                                                         java.lang.IllegalStateException
waits and listens for a single connection to be made and returns an SSLSocketConnection if the connection made matches the signature

Throws:
HandshakeException - if the signatures did not match
java.io.IOException
java.lang.IllegalStateException

createConnection

public static SSLSocketConnection 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:
signature - - an object that identifies the desired type of connection
Throws:
HandshakeException - if the signatures did not match
java.io.IOException
See Also:
NetConnectionServer

isActive

public boolean isActive()
Description copied from interface: NetConnection
returns whether this NetConnection is currently active

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

sendMessage

public void sendMessage(java.lang.Object message)
                 throws java.io.IOException
Description copied from interface: NetConnection
sends an object over the connection

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
Description copied from interface: NetConnection
reads an object from the connection (operation blocks until object is read)

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

Throws:
java.io.IOException

getSignature

public java.lang.Object getSignature()
Description copied from interface: NetConnection
returns the identification type object for this connection; this signature is the same on both sides of the connection. Note that this object requires the equals(Object obj) method to work after serialization/de-serialization; Strings work just fine.

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

close

public void close()
closes the SocketConnection

Specified by:
close in interface NetConnection

getSocket

public java.net.Socket getSocket()
returns an SSLSocket

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

getRemoteHost

public java.net.InetAddress getRemoteHost()

getRemotePort

public int getRemotePort()

getLocalPort

public int getLocalPort()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object