org.resoa.stack.protocol
Class Session

java.lang.Object
  extended by org.resoa.stack.protocol.Session
All Implemented Interfaces:
org.resoa.grid.GridSession

public class Session
extends java.lang.Object
implements org.resoa.grid.GridSession

Session wraps a connection handle and is created during connection to or from remote. Use this object for message sending and disconnect requests to a remote end point. Sessions are generated by the stack, do not try to instance them by yourself!

If you intend to develop a server based solution, using Resoa stack, you should cache Session instances, when they have been initialized in order to use them for message sending. New Sessions and state changes to a session are broadcasted by the stack, using the Callback Callbacks.SessionState.

Incoming message from remote are broadcasted to the StackChannelProcessor.onMessage(Object, Message). You should implement a little message dispatcher within your StackChannel implementation to process all incoming messages. The dispatcher might create Java objects out of the binary message content (i.E. using jaxb for XML or JSON) and pass the newly instanced Java objects to the underlying session/application.


Constructor Summary
  Session(Stack stack, java.security.KeyPair privateRSA)
          FOR INTERNAL USE ONLY.
  Session(Stack stack, java.security.KeyPair privateRSA, org.resoa.stack.config.StackProfile connectTo)
          Session constructor FOR INTERNAL USE ONLY.
protected Session(java.lang.String sessionID)
          Used for debugging only
 
Method Summary
 boolean checkProfile(org.resoa.stack.config.StackProfile remoteProfile)
          FOR INTERNAL USE ONLY.
 void closeSocket()
          Closes the socket
 void disconnect()
          performs a regular disconnect
 void executeProtocolService(java.lang.String serviceID)
          FOR INTERNAL USE ONLY.
 org.resoa.stack.config.StackConfig getConfig()
          The underlying stack configuration
 int getFragmentationSize()
          Returns the size in bytes, used for internal message fragmentation
 java.util.concurrent.locks.ReentrantLock getKillLock()
           
 org.resoa.stack.config.StackProfile getLocalProfile()
          Returns the local profile of the connection
 java.io.OutputStream getOutputStream()
          FOR INTERNAL USE ONLY.
 org.resoa.stack.config.StackProfile getRemoteProfile()
          Returns the remoteProfile of the connection
 java.lang.String getRsaAESKeyString()
          FOR INTERNAL USE ONLY.
 SecurityParameter getSecurity()
          FOR INTERNAL USE ONLY.
 java.lang.String getSessionID()
          Returns the sessionID.
 java.nio.channels.SocketChannel getSocketChannel()
          FOR INTERNAL USE ONLY.
 java.util.concurrent.locks.ReentrantLock getSocketLock()
           
 TCPReader getTcpReader()
          FOR INTERNAL USE ONLY.
 long getUpTime()
          The uptime of the session
 boolean isBigEndian()
          indicates the endian mode, default is true (BigEndian)
 boolean isDisconnecting()
          True, if the session is disconnecting
 boolean isHandshakeTimeout()
          true, if the session has a TCP socket connection, but handshake has run into timeout
 boolean isInitialized()
          true, if session handshake has been completed and the message is ready for sending data.
 boolean isKilled()
          true, if the session has been disconnected and will not reconnect again.
 boolean isNewInstanced()
          true, if the session is in state instanced (0)
 boolean isReconnectable()
          Returns true, if the session is reconnectable In case of a remote disconnect (not caused by exception), it is set to false.
 boolean isReconnecting()
          true, if the session has been disconnected by remote or exception.
 boolean isServer()
          indicates, if the stack runs in server mode
 boolean isTCPConnected()
          true, if the session has a tcp socket (1)
 org.resoa.grid.Transaction newTransaction(org.resoa.grid.Transaction t)
          send a message within a transactional context, use this if you need synchronized communication with the remote end point.
 void notifyTransaction(org.resoa.grid.Message msg)
          FOR INTERNAL USE ONLY.
 void reconnect()
          FOR INTERNAL USE ONLY.
 void registerFragmentID(java.lang.String fid)
          FOR INTERNAL USE ONLY.
 void removeFragmentID(java.lang.String fid)
          FOR INTERNAL USE ONLY.
 void sendMessage(org.resoa.grid.Message msg)
          Send a new message
 void setBigEndian(boolean isBigEndian)
          FOR INTERNAL USE ONLY.
 void setDisconnecting()
          mark the session as disconnect request pending
 void setFragmentationSize(int fragmentationSize)
          FOR INTERNAL USE ONLY.
 void setInitialized()
          FOR INTERNAL USE ONLY.
 void setKilled(boolean notify)
          FOR INTERNAL USE ONLY.
 void setReconnectable(boolean reconnectable)
          Set the session reconnect state
 void setRemoteProfile(org.resoa.stack.config.StackProfile remoteProfile)
          FOR INTERNAL USE ONLY.
 void setRsaAESKeyString(java.lang.String rsaAESKeyString)
          FOR INTERNAL USE ONLY.
 void setSocket(java.net.Socket sessionSocket)
          FOR INTERNAL USE ONLY.
 void startHandShake()
          FOR INTERNAL USE ONLY.
 boolean waitForInitialized()
          FOR INTERNAL USE ONLY.
 void writeSignature(org.resoa.grid.Message message)
          FOR INTERNAL USE ONLY.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Session

protected Session(java.lang.String sessionID)
Used for debugging only


Session

public Session(Stack stack,
               java.security.KeyPair privateRSA)
        throws org.resoa.exception.ProtocolException

FOR INTERNAL USE ONLY.

Constructor for incoming connections

Parameters:
stack - the underlying stack
privateRSA - the private RSA
Throws:
org.resoa.exception.ProtocolException

Session

public Session(Stack stack,
               java.security.KeyPair privateRSA,
               org.resoa.stack.config.StackProfile connectTo)
        throws org.resoa.exception.ProtocolException
Session constructor

FOR INTERNAL USE ONLY.

Parameters:
stack - the stack
privateRSA - the RSY keypair
connectTo - the remote profile
Throws:
org.resoa.exception.ProtocolException
Method Detail

getSessionID

public java.lang.String getSessionID()
Returns the sessionID.

Specified by:
getSessionID in interface org.resoa.grid.GridSession
Returns:
Returns the sessionID.

isNewInstanced

public boolean isNewInstanced()
true, if the session is in state instanced (0)

Returns:
true, if the session is in state instanced (0)

isTCPConnected

public boolean isTCPConnected()
true, if the session has a tcp socket (1)

Returns:
true, if the session session has a tcp socket

isHandshakeTimeout

public boolean isHandshakeTimeout()
true, if the session has a TCP socket connection, but handshake has run into timeout

Returns:
true, if the session has a TCP socket connection, but handshake has run into timeout

isInitialized

public boolean isInitialized()
true, if session handshake has been completed and the message is ready for sending data.

Specified by:
isInitialized in interface org.resoa.grid.GridSession
Returns:
initialized true, if session handshake has been completed and the message is ready for sending

isDisconnecting

public boolean isDisconnecting()
True, if the session is disconnecting

Specified by:
isDisconnecting in interface org.resoa.grid.GridSession
Returns:
True, if the session is disconnecting

setDisconnecting

public void setDisconnecting()
mark the session as disconnect request pending


isReconnecting

public boolean isReconnecting()
true, if the session has been disconnected by remote or exception. If configured in the stack parameters, the session will try an auto-reconnect and return true during these attempts.

Specified by:
isReconnecting in interface org.resoa.grid.GridSession
Returns:
initialized true, if the session is within auto-reconnection mode

isReconnectable

public boolean isReconnectable()
Returns true, if the session is reconnectable In case of a remote disconnect (not caused by exception), it is set to false.

Specified by:
isReconnectable in interface org.resoa.grid.GridSession
Returns:
true, if the session is reconnectable.

setReconnectable

public void setReconnectable(boolean reconnectable)
Set the session reconnect state

Parameters:
reconnectable -

isKilled

public boolean isKilled()
true, if the session has been disconnected and will not reconnect again.

Specified by:
isKilled in interface org.resoa.grid.GridSession
Returns:
true if session is finally killed

setInitialized

public void setInitialized()

FOR INTERNAL USE ONLY.

Sets the session status to initialized. Used by ProtocolSerivces only!


setKilled

public void setKilled(boolean notify)

FOR INTERNAL USE ONLY.

Sets the session status to initialized. Used by ProtocolSerivces only!


getUpTime

public long getUpTime()
The uptime of the session

Specified by:
getUpTime in interface org.resoa.grid.GridSession
Returns:
The uptime of the session

waitForInitialized

public boolean waitForInitialized()

FOR INTERNAL USE ONLY.

Waits timeout and returns true, is session is initialized

Returns:
true if initialized waiting is active

newTransaction

public org.resoa.grid.Transaction newTransaction(org.resoa.grid.Transaction t)
                                          throws org.resoa.exception.ProtocolException,
                                                 org.resoa.exception.SystemOverloadException

send a message within a transactional context, use this if you need synchronized communication with the remote end point.

Transactions might be generated by org.resoa.grid.Transaction#newTransaction, which will wrap an stack message for transactional processing.

This procedure will try to send the message to the backend and wait for a reply or run into a timeout. Timeouts have a default value, changed by org.resoa.grid.Transaction#TRANSACTION_TIMEOUT_SEC_DEFAULT. Individual timeouts in milliseconds might be set by Transaction#setTimeOut(long).

If the request was answered within the wait time, you can find the content in the returned transaction object. In case of timeout the returned transaction object will still hold the request message, and the state is set to TransactionState#Timeout. You should be prepared, that the transactional reply might arrive after the wait time! The stack will notify you about this through the channel listeners and by setting the state to TransactionState#Delayed.

Specified by:
newTransaction in interface org.resoa.grid.GridSession
Returns:
a Transaction handle
Throws:
org.resoa.exception.ProtocolException
org.resoa.exception.SystemOverloadException

notifyTransaction

public void notifyTransaction(org.resoa.grid.Message msg)

FOR INTERNAL USE ONLY.

notifies transaction on a new incoming transaction reply

Parameters:
msg - the Message

isServer

public boolean isServer()
indicates, if the stack runs in server mode

Specified by:
isServer in interface org.resoa.grid.GridSession
Returns:
true, if the stack runs in server mode

isBigEndian

public boolean isBigEndian()
indicates the endian mode, default is true (BigEndian)

Specified by:
isBigEndian in interface org.resoa.grid.GridSession
Returns:
Returns the isBigEndian.

setBigEndian

public void setBigEndian(boolean isBigEndian)

FOR INTERNAL USE ONLY.

Parameters:
isBigEndian - The isBigEndian to set.

getFragmentationSize

public int getFragmentationSize()
Returns the size in bytes, used for internal message fragmentation

Returns:
Returns the fragmentationSize.

setFragmentationSize

public void setFragmentationSize(int fragmentationSize)

FOR INTERNAL USE ONLY.

Changes the fragmentation size. This should only be done by protocol services. You can parameterize this value in the stack configuration.

Parameters:
fragmentationSize - The fragmentationSize to set.

registerFragmentID

public void registerFragmentID(java.lang.String fid)

FOR INTERNAL USE ONLY.

Register a new pending fragmentID

Parameters:
fid -

removeFragmentID

public void removeFragmentID(java.lang.String fid)

FOR INTERNAL USE ONLY.

Remove a fragmentID from pending cache

Parameters:
fid -

getLocalProfile

public org.resoa.stack.config.StackProfile getLocalProfile()
Returns the local profile of the connection

Returns:
Returns the remoteProfile.

getRemoteProfile

public org.resoa.stack.config.StackProfile getRemoteProfile()
Returns the remoteProfile of the connection

Specified by:
getRemoteProfile in interface org.resoa.grid.GridSession
Returns:
Returns the remoteProfile.

setRemoteProfile

public void setRemoteProfile(org.resoa.stack.config.StackProfile remoteProfile)

FOR INTERNAL USE ONLY.

Parameters:
remoteProfile - The remoteProfile to set.

getSecurity

public SecurityParameter getSecurity()

FOR INTERNAL USE ONLY.

Returns:
Returns a helper object for security processing.

getRsaAESKeyString

public java.lang.String getRsaAESKeyString()

FOR INTERNAL USE ONLY.

Returns:
rsaAESKeyString

setRsaAESKeyString

public void setRsaAESKeyString(java.lang.String rsaAESKeyString)

FOR INTERNAL USE ONLY.

Parameters:
rsaAESKeyString - Festzulegender rsaAESKeyString

getConfig

public org.resoa.stack.config.StackConfig getConfig()
The underlying stack configuration

Returns:
Returns the config.

getSocketLock

public java.util.concurrent.locks.ReentrantLock getSocketLock()
Returns:
a object you should use for synchronized access to session socket

getKillLock

public java.util.concurrent.locks.ReentrantLock getKillLock()
Returns:
the a synchronization object used during session kill

closeSocket

public void closeSocket()
Closes the socket


getOutputStream

public java.io.OutputStream getOutputStream()

FOR INTERNAL USE ONLY. Ensure, that the session is synchronized, when invoking

Returns a BufferedOutputStream, wrapping the Socket out stream

Returns:
the writeStream

getSocketChannel

public java.nio.channels.SocketChannel getSocketChannel()

FOR INTERNAL USE ONLY. Ensure, that the session is synchronized, when invoking

Returns a the SocketChannel instance

Returns:
the socketchannel or null

setSocket

public void setSocket(java.net.Socket sessionSocket)
               throws java.io.IOException

FOR INTERNAL USE ONLY.

Parameters:
sessionSocket - set the session socket
Throws:
java.io.IOException

getTcpReader

public TCPReader getTcpReader()

FOR INTERNAL USE ONLY.

Returns:
tcpHandler

checkProfile

public boolean checkProfile(org.resoa.stack.config.StackProfile remoteProfile)

FOR INTERNAL USE ONLY.

checks for acceptance of a remote profile

Parameters:
remoteProfile -

disconnect

public void disconnect()
performs a regular disconnect

Specified by:
disconnect in interface org.resoa.grid.GridSession

reconnect

public void reconnect()

FOR INTERNAL USE ONLY.

Reconnects session to a Resoa accesspoint


sendMessage

public void sendMessage(org.resoa.grid.Message msg)
                 throws org.resoa.exception.ProtocolException,
                        org.resoa.exception.SystemOverloadException,
                        java.io.IOException
Send a new message

Specified by:
sendMessage in interface org.resoa.grid.GridSession
Parameters:
msg - the message to send. You can create a message i.e. by Message#newDownMessage(Session, byte[], Object, Priority, int).
Throws:
org.resoa.exception.ProtocolException
org.resoa.exception.SystemOverloadException
java.io.IOException

executeProtocolService

public void executeProtocolService(java.lang.String serviceID)
                            throws org.resoa.exception.ProtocolException

FOR INTERNAL USE ONLY.

Execute a protocol Service

Parameters:
serviceID - the serviceID
Throws:
org.resoa.exception.ProtocolException

startHandShake

public void startHandShake()
                    throws org.resoa.exception.ProtocolException

FOR INTERNAL USE ONLY.

Starts the session handshaking after a new tcp connection

Throws:
org.resoa.exception.ProtocolException

writeSignature

public void writeSignature(org.resoa.grid.Message message)
                    throws org.resoa.exception.ProtocolException

FOR INTERNAL USE ONLY.

Creates a Resoa StackSignature

Parameters:
message - the message
Throws:
org.resoa.exception.ProtocolException


Copyright © 2007 www.resoa.org. All Rights Reserved.