com.retrogui.messageserver.common
Class Session

java.lang.Object
  extended bycom.retrogui.messageserver.common.Session

public class Session
extends java.lang.Object

Create message handlers that process inbound and outbound messages. After instantiating a new Session, call startMessageHandlers() to start the processing threads.

 closeSession() will stop inbound and outbound queue and close socket
 If sessionControl isSendAndReceiveMessages() is false then sendMessage() and
 getMessage() do not function and do not throw exception - typically done
 prior to a shutdown.
 


Constructor Summary
Session(ISessionControl sessionControl, java.net.Socket socket)
          Constructor
 
Method Summary
 void closeSession()
          close the session, stop the inbound & outbound queues and close the socket
protected  InboundMessageHandler getInboundHandler()
          getter
protected  java.io.BufferedReader getInstream()
          getter
 javax.security.auth.login.LoginContext getLoginContext()
           
 Message getMessage(boolean blockUntilMessage)
          get next inbound message from queue if blockUntilMessage=false then return null if no messages in queue if blockUntilMessage=true then block until message comes in.
protected  OutboundMessageHandler getOutboundHandler()
          getter
protected  java.io.PrintStream getOutstream()
          getter
 java.security.cert.Certificate[] getRemoteCertificates()
          get remote client certificates (if available) for ie.
 java.lang.String getRemoteHost()
          get remote host ip
 int getRemotePort()
          get remote port
 ISessionControl getSessionControl()
          DOCUMENT ME!
 long getSessionId()
          getter
protected  java.net.Socket getSocket()
          getter
 void sendMessage(Message msg)
          send a message, throws exceptions if session is invalid or send-receive flag is false.
protected  void setInboundHandler(InboundMessageHandler inboundHandler)
          setter
protected  void setInstream(java.io.BufferedReader instream)
          setter
 void setLoginContext(javax.security.auth.login.LoginContext loginContext)
           
protected  void setOutboundHandler(OutboundMessageHandler outboundHandler)
          setter
protected  void setOutstream(java.io.PrintStream outstream)
          setter
 void setSessionControl(ISessionControl sessionControl)
          DOCUMENT ME!
 void setSessionId(long sessionId)
          setter
protected  void setSocket(java.net.Socket socket)
          setter
 void startMessageHandlers()
          Start the handler threads so that the inbound and outbound messages will be processed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Session

public Session(ISessionControl sessionControl,
               java.net.Socket socket)
        throws java.io.IOException
Constructor

Parameters:
sessionControl - - usually a MessageClient or MessageServer object
socket - - the client socket
Throws:
java.io.IOException
See Also:
Method Detail

startMessageHandlers

public void startMessageHandlers()
Start the handler threads so that the inbound and outbound messages will be processed. Note: findbugs indicated that I shouldn't start threads in a constructor because if Session was subclassed then the threads would be started before the subclass was complete instantiated. Therefore I moved the starting of the handler threads to a this separate method. Call startMessageHandlers() after the constructor (new Session()).


getRemoteHost

public java.lang.String getRemoteHost()
get remote host ip

Returns:
See Also:

getRemotePort

public int getRemotePort()
get remote port

Returns:
See Also:

getRemoteCertificates

public java.security.cert.Certificate[] getRemoteCertificates()
get remote client certificates (if available) for ie. further authentication

Returns:
See Also:

sendMessage

public void sendMessage(Message msg)
                 throws SessionException
send a message, throws exceptions if session is invalid or send-receive flag is false. Note: I synchronized this method based upon threadsafety concerns found by running JLint

Parameters:
msg -
Throws:
SessionException
See Also:

getMessage

public Message getMessage(boolean blockUntilMessage)
                   throws SessionException
get next inbound message from queue if blockUntilMessage=false then return null if no messages in queue if blockUntilMessage=true then block until message comes in. Throws exceptions if session is invalid or send-receive flag is false

Parameters:
blockUntilMessage -
Returns:
Throws:
SessionException
See Also:

closeSession

public void closeSession()
close the session, stop the inbound & outbound queues and close the socket

See Also:

setSocket

protected void setSocket(java.net.Socket socket)
setter

Parameters:
socket -

getSocket

protected java.net.Socket getSocket()
getter

Returns:

setInstream

protected void setInstream(java.io.BufferedReader instream)
setter

Parameters:
instream -

getInstream

protected java.io.BufferedReader getInstream()
getter

Returns:

setOutstream

protected void setOutstream(java.io.PrintStream outstream)
setter

Parameters:
outstream -

getOutstream

protected java.io.PrintStream getOutstream()
getter

Returns:

setSessionId

public void setSessionId(long sessionId)
setter

Parameters:
sessionId -

getSessionId

public long getSessionId()
getter

Returns:

setInboundHandler

protected void setInboundHandler(InboundMessageHandler inboundHandler)
setter

Parameters:
inboundHandler -

getInboundHandler

protected InboundMessageHandler getInboundHandler()
getter

Returns:

setOutboundHandler

protected void setOutboundHandler(OutboundMessageHandler outboundHandler)
setter

Parameters:
outboundHandler -

getOutboundHandler

protected OutboundMessageHandler getOutboundHandler()
getter

Returns:

setSessionControl

public void setSessionControl(ISessionControl sessionControl)
DOCUMENT ME!

Parameters:
sessionControl -

getSessionControl

public ISessionControl getSessionControl()
DOCUMENT ME!

Returns:

setLoginContext

public void setLoginContext(javax.security.auth.login.LoginContext loginContext)
Parameters:
loginContext - The loginContext to set.

getLoginContext

public javax.security.auth.login.LoginContext getLoginContext()
Returns:
Returns the loginContext.