com.echomine.net
Class SocketConnector

java.lang.Object
  extended by com.echomine.net.Connection
      extended by com.echomine.net.TimeableConnection
          extended by com.echomine.net.SocketConnector

public class SocketConnector
extends TimeableConnection

Makes a connection to a remote client using TCP protocol. The connector is synchronous and asynchronous; Asynchronous connections have methods that begin with an "a" (ie. aconnect). This class is simply a helper class so you don't have to deal with the connection details. Most of the details should still be implemented by the writer in the SocketHandler instances.

There are four ways to call connect. Aside from the synchronous and asynchronous, the choice is yours to use an internal socket handler or pass in your own external socket handler. The connector is basically amphibious, acting both as an instance-based single-threaded object (ie. one connector per connection) and a non-instance-based multi-threaded object (ie. one connector for multiple handlers/connections). The recommended usage is: if you require listening to connection events for each connection made, then instantiate a connector for each handler (a 1-to-1 connector-handler pairing); if you don't care about connection events (or if your handler fires its own events that you need), then you can instantiate one connector for multiple handlers (ie. a 1-to-many connector-handler pairing).

This class also fully support SSL connections. Certain properties can be set to change the location on where to look for the keystore, passphrase, etc.

The SSL-related key property names are: com.echomine.net.keyStorePath, com.echomine.netkeyStorePassphrase, com.echomine.net.trustManager. By default, the keystore is ~/.keystore, the passphrase is empty, and trust manager uses com.echomine.util.SimpleTrustManager.


Field Summary
 
Fields inherited from class com.echomine.net.Connection
listenerList
 
Constructor Summary
SocketConnector()
          Do-nothing constructor.
SocketConnector(SocketHandler socketHandler)
           
 
Method Summary
 void aconnect(ConnectionModel connectionModel)
          makes a connection asynchronously using internal socket handler.
 void aconnect(SocketHandler socketHandler, ConnectionModel connectionModel)
          makes a connection asynchronously.
 void connect(ConnectionModel connectionModel)
          Synchronous connect method using internal socket handler.
 void connect(SocketHandler socketHandler, ConnectionModel connectionModel)
          Synchronous connect method.
 SocketHandler getSocketHandler()
           
 void setSocketHandler(SocketHandler socketHandler)
           
 
Methods inherited from class com.echomine.net.TimeableConnection
fireConnectionClosed, fireConnectionEstablished
 
Methods inherited from class com.echomine.net.Connection
addConnectionListener, fireConnectionStarting, fireConnectionStartingWithoutVeto, removeConnectionListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketConnector

public SocketConnector(SocketHandler socketHandler)

SocketConnector

public SocketConnector()
Do-nothing constructor. Usually used for multi-threading reuse of this instance since the Handler can be passed in as a parameter for connect().

Method Detail

connect

public void connect(ConnectionModel connectionModel)
             throws ConnectionFailedException
Synchronous connect method using internal socket handler. The method will return when handling of the connection is finished.

Throws:
ConnectionFailedException

connect

public void connect(SocketHandler socketHandler,
                    ConnectionModel connectionModel)
             throws ConnectionFailedException
Synchronous connect method. The method will return when handling of the connection is finished.

Throws:
ConnectionFailedException

aconnect

public void aconnect(ConnectionModel connectionModel)
makes a connection asynchronously using internal socket handler. This means that the method will be run in a separate thread and return control to the caller of the method immediately.


aconnect

public void aconnect(SocketHandler socketHandler,
                     ConnectionModel connectionModel)
makes a connection asynchronously. This means that the method will be run in a separate thread and return control to the caller of the method immediately.


getSocketHandler

public SocketHandler getSocketHandler()

setSocketHandler

public void setSocketHandler(SocketHandler socketHandler)


Copyright © 2001-2005 Echomine. All Rights Reserved.