QJCC homepage

biz.chitec.quarterback.gjsa
Class SessionConnector

java.lang.Object
  extended bybiz.chitec.quarterback.gjsa.ServerConnector
      extended bybiz.chitec.quarterback.gjsa.SessionConnector

public class SessionConnector
extends ServerConnector

Session-wise connection class for GJSA clients.

SessionConnector is used by Java programs communicating with GJSA servers. This class offers the query() methods to issue requests and receive replies. The overall design of SessionConnector performs synchronous queries, even though the GJSA protocol would allow asynchronous communication as well.

A SessionConnector is always bound to exactly one session in the connection. If a command results in opening a new session, three strategies are possible:

  1. Call the normal query() method. It returns the result of the query which is already in the context of the new session. After that, use getNewSessionServerConnector() to obtain the SessionConnector for the new session. Further queries through this SessionConnector will stay in the current session.
  2. Call the queryOrBranch() method. It returns either a SessionConnector object which is the new session's SessionConnector or the ServerEnvelope containing the reply for the query in the current session. If a SessionConnector is returned, the actual content of the reply is saved there and can be retrieved by getInitialEnvelope() or getInitialReply().
  3. Call openSession(). This one will send the OPENSESSION command in advance automatically (with the two other alternatives, you have to send that command manually or through the parameterless openSession() method). It will always return the SessionConnector for the new session. If opening the session fails, a GJSASessionFailedException is thrown. The reply for the command can then be retrieved through the exceptions getReply() method.

All strategies are equally in their result. Choose whichever fits best into the existing program scheme. If in doubt, take strategy 3, as it is the semantically clearest.

All querying methods exist in two shapes: One named qxxx() and one named qxxxNE(). The first alternative may throw an IOException in case of a communication failure. The second, however will not throw an exception but return a reply of the type SERIOUSERROR. Additionally to the ConnectionDesasterListener concept, this offers up to three ways to cope with connection problems.

Version:
$Id: 6f9144de7f661653d0ca4103139ad5bbc0e29e93 $
Author:
Dirk Hillbrecht 1997-2000, chitec/Dirk Hillbrecht 2000,2001,2002,2003, cantamen/Dirk Hillbrecht 2003. Distributed under the terms of the GNU LGPL.

Field Summary
private  java.util.List children
           
private  SessionConnector father
           
private  ServerEnvelope initialenvelope
           
private  SessionedServerConnector llsc
           
private  SessionConnector newsessionsc
           
private  int sessionid
           
protected  SyncBurstReceiver syncburstreceiver
           
protected  java.lang.Thread syncburstreceiverthread
           
private  boolean throttling
           
 
Constructor Summary
SessionConnector(SessionedServerConnector llscx, int sidx)
           
SessionConnector(SessionedServerConnector llscx, ServerEnvelope iex)
           
 
Method Summary
 void addConnectionDesasterListener(ConnectionDesasterListener cdl)
          Add listener for connection desasterts
 void addConnectionEncryptionPresentor(ConnectionEncryptionPresentor ccep)
          Adds a presentor for the encryption state
 void addConnectionStatePresentor(ConnectionStatePresentor ccsp)
          Adds a connection state presentor.
 void attachSyncBurstReceiver(SyncBurstReceiver sbr)
          Attaches and starts a SyncBurstReceiver to this SessionConnector.
 void close()
          Close myself, leads to children being closed anyway
private  void close(boolean proactive)
          Close myself, unregister myself from father and server if parameter is set to true
 void connDesaster()
          Raises a connection desaster
 void connectionOnHold(ServerEnvelope reest)
          Closes the connection to the server transparently for higher layers.
 void disableErrorMsgs()
          Deprecated. Feature is not supported any more
 int getEncodingMode()
          Return encoding of the connection
 ServerEnvelope getInitialEnvelope()
           
 SessionConnector getNewSessionConnector()
          Returns branched SessionConnector if last query has branched, null if not.
 SessionedServerConnector getSessionedServerConnector()
          Returns the SessionedServerConnector for this SessionConnector
 int getSessionID()
           
 boolean isBackgroundSession()
          Return whether the connector is throttling.
 boolean isEncrypting()
          Gets the encrypting attribute of the ServerConnector object
 ServerEnvelope query(ServerEnvelope se)
          Query for standard requests.
 java.lang.Object queryOrBranch(ServerEnvelope se)
          Basic method for querying.
 java.lang.Object queryOrBranchNE(ServerEnvelope se)
          Query for standard requests or new sessions without any exceptions.
 void quit()
          Quit connection.
 void removeConnectionDesasterListener(ConnectionDesasterListener cdl)
          Remove listener for connection desasters
 void removeConnectionStatePresentor()
          Removes the presentor for the connection state
 void setBackgroundSession(boolean t)
          Set the connector to "throttling" mode => if someone else is sending, wait for that one to finish.
private  void setFather(SessionConnector fatherx)
           
 void setFreeFloatingInterface(ThreadInterface ti)
          Set the interface where free floating messages are sent to.
 void setMessageLogger(Logger mx)
          Sets the messageLogger attribute of the ServerConnector object
 void setReaderPriority(int newprio)
          Set priority of the reader thread.
 void startLineWakeupToggler()
          Deprecated. Use SessionedServerConnector.setSendKeepAlive() instead
 void stopSyncBurstReceiver()
          Stops a currently running SyncBurstReceiver.
private  void unregisterChild(SessionConnector child)
          Unregister a child.
 
Methods inherited from class biz.chitec.quarterback.gjsa.ServerConnector
openLegacyServerConnector, openLegacyServerConnector, openLegacyServerConnector, openLegacyServerConnector, openLegacyServerConnector, openLegacyServerConnector, openLegacyServerConnector, query, query, query, query, query, query, query, query, query, query, queryNE, queryNE, queryNE, queryNE, queryNE, queryNE, queryNE, queryNE, queryNE, queryNE, queryNE
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sessionid

private int sessionid

llsc

private SessionedServerConnector llsc

initialenvelope

private ServerEnvelope initialenvelope

newsessionsc

private SessionConnector newsessionsc

father

private SessionConnector father

children

private java.util.List children

throttling

private boolean throttling

syncburstreceiverthread

protected java.lang.Thread syncburstreceiverthread

syncburstreceiver

protected SyncBurstReceiver syncburstreceiver
Constructor Detail

SessionConnector

public SessionConnector(SessionedServerConnector llscx,
                        int sidx)

SessionConnector

public SessionConnector(SessionedServerConnector llscx,
                        ServerEnvelope iex)
Method Detail

getSessionID

public int getSessionID()

setFather

private void setFather(SessionConnector fatherx)

getInitialEnvelope

public ServerEnvelope getInitialEnvelope()

setBackgroundSession

public void setBackgroundSession(boolean t)
Description copied from class: ServerConnector
Set the connector to "throttling" mode => if someone else is sending, wait for that one to finish.

Specified by:
setBackgroundSession in class ServerConnector

isBackgroundSession

public boolean isBackgroundSession()
Description copied from class: ServerConnector
Return whether the connector is throttling.

Specified by:
isBackgroundSession in class ServerConnector

queryOrBranch

public java.lang.Object queryOrBranch(ServerEnvelope se)
                               throws java.io.IOException
Basic method for querying. Returns either the reply ServerEnvelope or a SessionConnector which acts in the new session context. Its up to the caller to make the distinction correctly.

Throws:
java.io.IOException

queryOrBranchNE

public java.lang.Object queryOrBranchNE(ServerEnvelope se)
Query for standard requests or new sessions without any exceptions.


query

public ServerEnvelope query(ServerEnvelope se)
                     throws java.io.IOException
Query for standard requests. This method tracks internally whether a new session is spread by the query. If so, it puts the new SessionConnector object into an internal storage and makes it queriable through getNewSessionSC(). It always returns the real reply.

Specified by:
query in class ServerConnector
Parameters:
se - ServerEnvelope with one or more queries set
Returns:
ServerEnvelope with one or more reples set
Throws:
java.io.IOException - If something goes wrong in the communication between client and server
See Also:
ServerEnvelope

getNewSessionConnector

public SessionConnector getNewSessionConnector()
Returns branched SessionConnector if last query has branched, null if not. Note that no further query() or queryOrBranch() calls must have happened in between, otherwise the branched SessionConnector is lost.


getSessionedServerConnector

public SessionedServerConnector getSessionedServerConnector()
Returns the SessionedServerConnector for this SessionConnector


unregisterChild

private void unregisterChild(SessionConnector child)
Unregister a child.


close

public void close()
Close myself, leads to children being closed anyway

Specified by:
close in class ServerConnector

close

private void close(boolean proactive)
Close myself, unregister myself from father and server if parameter is set to true


quit

public void quit()
Quit connection. Leads to everything being closed. If called for another session than session 0, go up the tree until 0 is reached.


attachSyncBurstReceiver

public void attachSyncBurstReceiver(SyncBurstReceiver sbr)
Attaches and starts a SyncBurstReceiver to this SessionConnector. The SyncBurstReceiver is started in a new Thread object instantiated directly by this SessionConnector.

Specified by:
attachSyncBurstReceiver in class ServerConnector
Parameters:
sbr - Description of the Parameter

stopSyncBurstReceiver

public void stopSyncBurstReceiver()
Stops a currently running SyncBurstReceiver. Called internally everytime a sync burst must be stopped. It doesn't hurt to call this method with no sync burst running.

Specified by:
stopSyncBurstReceiver in class ServerConnector

isEncrypting

public boolean isEncrypting()
Deprecated. Use SessionedServerConnector methods instead

Description copied from class: ServerConnector
Gets the encrypting attribute of the ServerConnector object

Specified by:
isEncrypting in class ServerConnector
Returns:
The encrypting value

connectionOnHold

public void connectionOnHold(ServerEnvelope reest)
                      throws java.io.IOException
Deprecated. Feature is not supported any more

Description copied from class: ServerConnector
Closes the connection to the server transparently for higher layers. The socket holding the connection to the server is closed. From now on, no connection to the server exists any more.

The next query sent to the ServerConnector will reestablish the connection. After opening the ports, the complete reest ServerEnvelope will be sent to the server to reach the state it had on closing.

Specified by:
connectionOnHold in class ServerConnector
Parameters:
reest - Description of the Parameter
Throws:
java.io.IOException - Description of the Exception

setMessageLogger

public void setMessageLogger(Logger mx)
Deprecated. Use SessionedServerConnector methods instead

Description copied from class: ServerConnector
Sets the messageLogger attribute of the ServerConnector object

Specified by:
setMessageLogger in class ServerConnector
Parameters:
mx - The new messageLogger value

disableErrorMsgs

public void disableErrorMsgs()
Deprecated. Feature is not supported any more

Specified by:
disableErrorMsgs in class ServerConnector

startLineWakeupToggler

public void startLineWakeupToggler()
Deprecated. Use SessionedServerConnector.setSendKeepAlive() instead

Specified by:
startLineWakeupToggler in class ServerConnector

connDesaster

public void connDesaster()
Deprecated. Feature is not supported any more

Description copied from class: ServerConnector
Raises a connection desaster

Specified by:
connDesaster in class ServerConnector

addConnectionStatePresentor

public void addConnectionStatePresentor(ConnectionStatePresentor ccsp)
Deprecated. Feature is not supported any more

Description copied from class: ServerConnector
Adds a connection state presentor.

Specified by:
addConnectionStatePresentor in class ServerConnector

addConnectionEncryptionPresentor

public void addConnectionEncryptionPresentor(ConnectionEncryptionPresentor ccep)
Deprecated. Feature is not supported any more

Description copied from class: ServerConnector
Adds a presentor for the encryption state

Specified by:
addConnectionEncryptionPresentor in class ServerConnector

removeConnectionStatePresentor

public void removeConnectionStatePresentor()
Deprecated. Feature is not supported any more

Description copied from class: ServerConnector
Removes the presentor for the connection state

Specified by:
removeConnectionStatePresentor in class ServerConnector

getEncodingMode

public int getEncodingMode()
Deprecated. Use SessionedServerConnector methods instead

Description copied from class: ServerConnector
Return encoding of the connection

Specified by:
getEncodingMode in class ServerConnector

addConnectionDesasterListener

public void addConnectionDesasterListener(ConnectionDesasterListener cdl)
Deprecated. Feature is not supported any more

Description copied from class: ServerConnector
Add listener for connection desasterts

Specified by:
addConnectionDesasterListener in class ServerConnector

removeConnectionDesasterListener

public void removeConnectionDesasterListener(ConnectionDesasterListener cdl)
Deprecated. Feature is not supported any more

Description copied from class: ServerConnector
Remove listener for connection desasters

Specified by:
removeConnectionDesasterListener in class ServerConnector

setFreeFloatingInterface

public void setFreeFloatingInterface(ThreadInterface ti)
Deprecated. Use SessionedServerConnector.addFreeFloatingReceiver instead

Description copied from class: ServerConnector
Set the interface where free floating messages are sent to.

Specified by:
setFreeFloatingInterface in class ServerConnector

setReaderPriority

public void setReaderPriority(int newprio)
Deprecated. Feature is not supported any more

Description copied from class: ServerConnector
Set priority of the reader thread.

Specified by:
setReaderPriority in class ServerConnector

QJCC homepage