QJCC homepage

biz.chitec.quarterback.gjsa
Class SessionedServerConnector

java.lang.Object
  extended bybiz.chitec.quarterback.gjsa.SessionedServerConnector
Direct Known Subclasses:
CBServerConnector, DirectSessionedServerConnector

public abstract class SessionedServerConnector
extends java.lang.Object

Low level communication with GJSA server Keeps connection to server one way or the other. Gets all data from server and passes it to the appropriate SessionConnector object. All ServerConnectors are connected to this one and send and receive data from here. SessionedServerConnector tells interested party through PropertyChangeEvents what is happening with the connection. The following property names and values can be sent during normal operation:

A connection to a GJSA server can be opened by either calling openConnection() or openConnectionAsynchonously(). The first call blocks until either the connection could have been established or the socket did timeout. The second one detaches into a seperate thread which tries to open the connection in the background. That thread can be stopped by calling stopOpenConnectionAsynchonously(). Asynchronous connection establishing indicates mode changes also via property events. The following ones can occur:

Version:
$Id: cdc0efc936f95584cc573f0f185e7523c1a4dc63 $
Author:
cantamen/Dirk Hillbrecht 2003-2004. Distributed under the terms of the GNU LGPL.

Nested Class Summary
private  class SessionedServerConnector.BackgroundConnectionOpener
          Seperate thread for connection opening in the background.
 
Field Summary
private  SessionedServerConnector.BackgroundConnectionOpener bco
           
protected  boolean connected
           
protected  int connectionport
           
protected  int encodingmode
           
protected  boolean encrypted
           
private  java.util.List freefloatingreceivers
           
protected  Logger mess
           
protected  int myscno
           
protected  java.beans.PropertyChangeSupport pcs
           
private static int sccount
           
private  java.util.Map serverconnectors
          For passing free floating information.
protected  java.lang.String serverseenclientip
           
protected  java.lang.String serverseenclientname
           
private  SessionConnector session0
           
static int SOCKET_SO_TIME
          Timeout for the socket in initialisation phase.
private static boolean sslavailable
           
protected  java.lang.String[] sslciphers
           
protected  javax.net.ssl.SSLSocketFactory sslfactory
           
protected  boolean transmitting
           
 
Constructor Summary
SessionedServerConnector()
           
 
Method Summary
 void addFreeFloatingReceiver(ThreadInterface ti)
          Add a new receiver for free floating messages.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
           
 void addPropertyChangeListener(java.lang.String propertyname, java.beans.PropertyChangeListener listener)
           
 void closeConnection()
          Close the connection.
protected abstract  void doCloseConnection()
          Perform necessary operations to actually close the connection.
protected abstract  void doOpenConnection()
          Perform necessary operations to actually open the connection.
protected  void fireDesaster()
           
protected  void fireFreeFloatingMessage(ServerEnvelope se)
          Fires a free floating message.
 int getEncodingMode()
           
protected  boolean getEncryptionAdvice(int clientstrategy, int serverwish)
          Determines whether the connection should be encrypted or not.
private  java.util.List getFirstAndSecondVersionPart(java.lang.String vers)
          Puts first and second part of a multipart version number into a list.
 java.lang.String getServerSeenClientIP()
           
 java.lang.String getServerSeenClientName()
           
 SessionConnector getSession0()
           
static SessionedServerConnector getSessionedServerConnector(java.lang.String host, int port)
           
static SessionedServerConnector getSessionedServerConnector(java.lang.String host, int port, java.util.List params)
           
static SessionedServerConnector getSessionedServerConnector(java.lang.String host, int port, java.util.Map params)
           
 boolean isConnected()
           
 boolean isEncrypted()
           
 boolean isTransmitting()
           
 SessionConnector openConnection()
          Opens the connection to the server.
 void openConnectionAsynchronously()
          Opens a connection asynchronously without waiting at the beginning.
 void openConnectionAsynchronously(long initialwaittime)
          Starts a seperate thread which tries to open the connection asynchronously.
 java.lang.Object queryOrBranch(ServerEnvelope se)
           
protected abstract  ServerEnvelope readEnvelope()
          Read a reply from the server.
 void removeFreeFloatingReceiver(ThreadInterface ti)
          Removes a receiver for free floating messages from the internal list.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
           
 void removePropertyChangeListener(java.lang.String propertyname, java.beans.PropertyChangeListener listener)
           
protected  void setConnected(boolean newconnected)
           
protected  void setEncodingMode(int newencodingmode)
           
protected  void setEncrypted(boolean newencrypted)
           
 void setMessageLogger(Logger mx)
           
abstract  void setSendKeepAlive(boolean b)
          Enables and disables the session connector to/from sending keep alive packets to the server.
protected  void setTransmission(boolean newtransmitting)
           
protected  void setupConnectionParameters(boolean forcestring, java.util.List clientprotocolversion, int clientencstrategy, java.util.Map serverparams)
           
 void stopOpenConnectionAsynchronously(boolean waitforstop)
          Stops an asynchronous connection opening.
 void unregisterServerConnector(SessionConnector sc)
           
protected abstract  void writeEnvelope(ServerEnvelope se)
          Write an envelope to the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sslavailable

private static boolean sslavailable

SOCKET_SO_TIME

public static final int SOCKET_SO_TIME
Timeout for the socket in initialisation phase.

See Also:
Constant Field Values

sccount

private static int sccount

myscno

protected int myscno

serverconnectors

private java.util.Map serverconnectors
For passing free floating information. Registered automatically, unregistering must be done by ServerConnectors on their own.


encodingmode

protected int encodingmode

encrypted

protected boolean encrypted

connected

protected boolean connected

transmitting

protected boolean transmitting

sslfactory

protected javax.net.ssl.SSLSocketFactory sslfactory

sslciphers

protected java.lang.String[] sslciphers

connectionport

protected int connectionport

mess

protected Logger mess

serverseenclientip

protected java.lang.String serverseenclientip

serverseenclientname

protected java.lang.String serverseenclientname

pcs

protected java.beans.PropertyChangeSupport pcs

freefloatingreceivers

private java.util.List freefloatingreceivers

bco

private SessionedServerConnector.BackgroundConnectionOpener bco

session0

private SessionConnector session0
Constructor Detail

SessionedServerConnector

public SessionedServerConnector()
Method Detail

queryOrBranch

public java.lang.Object queryOrBranch(ServerEnvelope se)
                               throws java.io.IOException
Throws:
java.io.IOException

unregisterServerConnector

public void unregisterServerConnector(SessionConnector sc)

getServerSeenClientIP

public java.lang.String getServerSeenClientIP()

getServerSeenClientName

public java.lang.String getServerSeenClientName()

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyname,
                                      java.beans.PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyname,
                                         java.beans.PropertyChangeListener listener)

getEncodingMode

public int getEncodingMode()

isEncrypted

public boolean isEncrypted()

isConnected

public boolean isConnected()

isTransmitting

public boolean isTransmitting()

setEncodingMode

protected void setEncodingMode(int newencodingmode)

setEncrypted

protected void setEncrypted(boolean newencrypted)

setConnected

protected void setConnected(boolean newconnected)

setTransmission

protected void setTransmission(boolean newtransmitting)

setMessageLogger

public void setMessageLogger(Logger mx)

fireDesaster

protected void fireDesaster()

openConnection

public SessionConnector openConnection()
                                throws java.io.IOException
Opens the connection to the server. Tries to open the connection to the server which has been given to the factory method. Throws an IOException if the connection cannot be opened, an error occurs during opening attempt of if the connection is already open and has not been closed in advance.

Returns:
SessionConnector to the initial session of the server connection.
Throws:
java.io.IOException - If something goes wrong with opening the connection.

getSession0

public SessionConnector getSession0()

closeConnection

public void closeConnection()
Close the connection. Closing the connection does not render the Connector invalid, the connection can be reopened.


doOpenConnection

protected abstract void doOpenConnection()
                                  throws java.io.IOException
Perform necessary operations to actually open the connection.

Throws:
java.io.IOException

doCloseConnection

protected abstract void doCloseConnection()
Perform necessary operations to actually close the connection.


writeEnvelope

protected abstract void writeEnvelope(ServerEnvelope se)
                               throws java.io.IOException
Write an envelope to the server.

Throws:
java.io.IOException

readEnvelope

protected abstract ServerEnvelope readEnvelope()
                                        throws java.io.IOException
Read a reply from the server.

Throws:
java.io.IOException

setSendKeepAlive

public abstract void setSendKeepAlive(boolean b)
Enables and disables the session connector to/from sending keep alive packets to the server. These packets prevent the server from closing the connection in case of inactivity.


addFreeFloatingReceiver

public void addFreeFloatingReceiver(ThreadInterface ti)
Add a new receiver for free floating messages. The receiver is given as ThreadInterface. It is put into the receiver list (if it is not already in there). This method synchronized with the receiver list, so no delivery of free floating messages takes place while there are receivers to be added.

Parameters:
ti - The ThreadInterface to be removed

removeFreeFloatingReceiver

public void removeFreeFloatingReceiver(ThreadInterface ti)
Removes a receiver for free floating messages from the internal list. The receiver is given as the same ThreadInterface as which it was added. If the receiver is not in the list, noting happens. This method synchronized with the receiver list, so no delivery of free floating messages takes place while there are receivers to be added. Note that a receiver's ThreadInterface is removed automatically if writing to it fails. Therefore, it could be better not to remove the ThreadInterface explicitly but simply to close it on the receiver side. This circumvents the need of an additional synchronization on the receiver list just for the removing task.

Parameters:
ti - The ThreadInterface to be removed

fireFreeFloatingMessage

protected void fireFreeFloatingMessage(ServerEnvelope se)
Fires a free floating message. The message is sent into all ThreadInterfaces registered through addFreeFloatingReceiver. If produce()ing the message into a ThreadInterface fails, that ThreadInterface is removed from the internal list immediately. The complete action is synchronized on the receiver's list. As sending data into a ThreadInterface does never delay, this should be ok.

Parameters:
se - The message to be sent

openConnectionAsynchronously

public void openConnectionAsynchronously(long initialwaittime)
Starts a seperate thread which tries to open the connection asynchronously. Throws exception if an asynchronous attempt to open the connection is already running. Otherwise, instanciates a seperate thread which tries to connect regulary to the server. If the initialwaittime is greater than zero, the background opener will wait for the given amount of milliseconds before the first connection attempt is made.

Parameters:
initialwaittime - Milliseconds to wait before the first connection attempt is done.

openConnectionAsynchronously

public void openConnectionAsynchronously()
Opens a connection asynchronously without waiting at the beginning.


stopOpenConnectionAsynchronously

public void stopOpenConnectionAsynchronously(boolean waitforstop)
Stops an asynchronous connection opening. If an asynchronous connection opening thread is currently running, it is asked to stop. It is not guaranteed that the connection is not established quite between calling this method and stop call to the async thread. The real connection state can only be derived from the events sent by the connector.

Parameters:
waitforstop - If true, method does not return before asynchronous thread has finished.

getFirstAndSecondVersionPart

private java.util.List getFirstAndSecondVersionPart(java.lang.String vers)
Puts first and second part of a multipart version number into a list.


getEncryptionAdvice

protected boolean getEncryptionAdvice(int clientstrategy,
                                      int serverwish)
Determines whether the connection should be encrypted or not. The Server has one of four wishes about encryption while the client follows one of five strategies. The actual result of the connection being encrypted or not or the whole connect process being aborted can be looked up in the following table (client in rows, server in columns):

Client\Serverno encryptionFORBIDDENNOTNEEDEDWANTED REQUIRED
neverclearclearclearclearfail
onrequireclearclearclearclearencrypted
onwantedclearclearclearencryptedencrypted
alwaysclearclearencryptedencryptedencrypted
alwaysforcedfailfailencryptedencrypted encrypted

Parameters:
clientstrategy - encryption strategy of the client
serverwish - encryption wish of the server
Returns:
indication whether the connection should be encrypted (true) or not (false)

setupConnectionParameters

protected void setupConnectionParameters(boolean forcestring,
                                         java.util.List clientprotocolversion,
                                         int clientencstrategy,
                                         java.util.Map serverparams)

getSessionedServerConnector

public static SessionedServerConnector getSessionedServerConnector(java.lang.String host,
                                                                   int port,
                                                                   java.util.Map params)

getSessionedServerConnector

public static SessionedServerConnector getSessionedServerConnector(java.lang.String host,
                                                                   int port,
                                                                   java.util.List params)

getSessionedServerConnector

public static SessionedServerConnector getSessionedServerConnector(java.lang.String host,
                                                                   int port)

QJCC homepage