com.sibvisions.rad.server
Class DirectServerSession

java.lang.Object
  extended by com.sibvisions.rad.server.DirectServerSession
All Implemented Interfaces:
ICloseable, ICloseableSession, ISession

public class DirectServerSession
extends java.lang.Object
implements ICloseableSession

The DirectServerSession is a wrapper for server-side sessions. It is fully attached and forwards every method call to the server-side session. To create a new instance of DirectServerSession use DirectServerSession session = DirectServerSession.createMasterSession(...); or session.createSubSession(...);


Method Summary
 java.lang.Object call(java.lang.String pObjectName, java.lang.String pMethod, java.lang.Object... pParams)
          Executes a method from an object in the life-cycle object.
 java.lang.Object callAction(java.lang.String pAction, java.lang.Object... pParams)
          Executes an action from the life-cycle object.
 void close()
          Closes the object (stream, connection, ...) and releases any system resources associated with it.
static DirectServerSession createMasterSession(java.lang.String pApplicationName, java.util.Map<java.lang.String,java.lang.Object> pProperties)
          Creates a new instance of DirectServerSession for the given application and properties.
static DirectServerSession createMasterSession(java.lang.String pApplicationName, java.lang.String pUserName, java.lang.String pPassword)
          Creates a new instance of DirectServerSession for the given application and credentials.
static DirectServerSession createMasterSession(java.lang.String pApplicationName, java.lang.String pUserName, java.lang.String pPassword, java.util.Map<java.lang.String,java.lang.Object> pProperties)
          Creates a new instance of DirectServerSession for the given application, credentials and properties.
protected static ChangedHashtable<java.lang.String,java.lang.Object> createProperties(java.util.Map<java.lang.String,java.lang.Object> pProperties)
          Creates a new ChangedHashtable instance with given properties as base.
 DirectServerSession createSubSession(java.lang.String pLifeCycleName)
          Creates a new instance of DirectServerSession as sub session for the given life-cycle object name.
 DirectServerSession createSubSession(java.lang.String pLifeCycleName, java.util.Map<java.lang.String,java.lang.Object> pProperties)
          Creates a new instance of DirectServerSession as sub session for the given life-cycle object name and properties.
 void destroy()
          Destroys the session.
 java.lang.Object get(java.lang.String pObjectName)
          Gets an object from the life-cycle object.
 long getAliveInterval()
          Gets the desired client-side communication interval for this session.
 java.lang.String getApplicationName()
          Gets the associated application name of the session.
 IConfiguration getConfig()
          Gets the IConfiguration of the session.
 java.lang.Object getId()
          Gets the session identifier.
 long getLastAccessTime()
          Gets the time of the last session access.
 long getLastAliveTime()
          Gets the time of the last communication of the session.
 java.lang.String getLifeCycleName()
          Gets the name of the life-cycle object.
 int getMaxInactiveInterval()
          Returns the maximum time interval, in seconds, that this session will be active.
 java.lang.String getPassword()
          Gets the sessions password.
 java.util.Hashtable<java.lang.String,java.lang.Object> getProperties()
          Gets all properties.
 java.lang.Object getProperty(java.lang.String pName)
          Gets the value of a property.
 long getStartTime()
          Gets the session start/create time.
 java.lang.String getUserName()
          Gets the sessions user name.
 boolean isAlive(long pAccessTime)
          Checks if the session is alive.
 boolean isInactive(long pAccessTime)
          Checks if the session is inactive.
 java.lang.Object put(java.lang.String pObjectName, java.lang.Object pObject)
          Puts an object to the life-cycle object.
 void setAliveInterval(long pAliveInterval)
          Sets the desired client-side communication interval for this session.
 void setMaxInactiveInterval(int pMaxInactiveInterval)
          Specifies the time, in seconds, before the session will be inactive.
 void setProperty(java.lang.String pName, java.lang.Object pValue)
          Sets the value of a property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getId

public java.lang.Object getId()
Gets the session identifier.

Specified by:
getId in interface ISession
Returns:
session id

getApplicationName

public java.lang.String getApplicationName()
Gets the associated application name of the session.

Specified by:
getApplicationName in interface ISession
Returns:
service name

getLifeCycleName

public java.lang.String getLifeCycleName()
Gets the name of the life-cycle object.

Specified by:
getLifeCycleName in interface ISession
Returns:
the name of the life-cycle object

getUserName

public java.lang.String getUserName()
Gets the sessions user name.

Specified by:
getUserName in interface ISession
Returns:
the user name

getPassword

public java.lang.String getPassword()
Gets the sessions password.

Specified by:
getPassword in interface ISession
Returns:
the password

get

public java.lang.Object get(java.lang.String pObjectName)
                     throws java.lang.Throwable
Gets an object from the life-cycle object.

Specified by:
get in interface ISession
Parameters:
pObjectName - the object name
Returns:
the object
Throws:
java.lang.Throwable - if the object was not found or an error occured during object creation

put

public java.lang.Object put(java.lang.String pObjectName,
                            java.lang.Object pObject)
                     throws java.lang.Throwable
Puts an object to the life-cycle object.

Specified by:
put in interface ISession
Parameters:
pObjectName - the object name
pObject - the object
Returns:
the object if an object was already specified
Throws:
java.lang.Throwable - if an unknown error occurs while putting the object

call

public java.lang.Object call(java.lang.String pObjectName,
                             java.lang.String pMethod,
                             java.lang.Object... pParams)
                      throws java.lang.Throwable
Executes a method from an object in the life-cycle object.

Specified by:
call in interface ISession
Parameters:
pObjectName - list of already mapped server object name/alias
pMethod - method name which should be called
pParams - parameters for the method call
Returns:
result of method call or null if it's an asynchronous method call
Throws:
java.lang.Throwable - if the object identified by pObjectName was found but can not be created
java.lang.SecurityException - if the method call is not allowed

callAction

public java.lang.Object callAction(java.lang.String pAction,
                                   java.lang.Object... pParams)
                            throws java.lang.Throwable
Executes an action from the life-cycle object.

Specified by:
callAction in interface ISession
Parameters:
pAction - action which should be called
pParams - the parameters for the action call
Returns:
result from the action call
Throws:
java.lang.Throwable - communication error, security checks, invalid action, ...

getConfig

public IConfiguration getConfig()
Gets the IConfiguration of the session.

Specified by:
getConfig in interface ISession
Returns:
the sessions configuration

getLastAccessTime

public long getLastAccessTime()
Gets the time of the last session access.

Specified by:
getLastAccessTime in interface ISession
Returns:
access time in millis

getLastAliveTime

public long getLastAliveTime()
Gets the time of the last communication of the session.

Specified by:
getLastAliveTime in interface ISession
Returns:
the last communication/alive time

setProperty

public void setProperty(java.lang.String pName,
                        java.lang.Object pValue)
Sets the value of a property.

Specified by:
setProperty in interface ISession
Parameters:
pName - the property name
pValue - the value for the property or null to delete the property

getProperty

public java.lang.Object getProperty(java.lang.String pName)
Gets the value of a property.

Specified by:
getProperty in interface ISession
Parameters:
pName - the property name
Returns:
the value of the property or null if the property is not available

getProperties

public java.util.Hashtable<java.lang.String,java.lang.Object> getProperties()
Gets all properties.

Specified by:
getProperties in interface ISession
Returns:
a Hashtable with property names and values

getStartTime

public long getStartTime()
Gets the session start/create time.

Specified by:
getStartTime in interface ISession
Returns:
start time in millis

isAlive

public boolean isAlive(long pAccessTime)
Checks if the session is alive. That means the client sends alive messages. The session is not alive if the client doesn't send alive messages.

Specified by:
isAlive in interface ISession
Parameters:
pAccessTime - current access time
Returns:
true if the session is alive
See Also:
ISession.getLastAliveTime(), ISession.getAliveInterval()

isInactive

public boolean isInactive(long pAccessTime)
Checks if the session is inactive.

Specified by:
isInactive in interface ISession
Parameters:
pAccessTime - current access time
Returns:
true if the session is inactive
See Also:
ISession.getMaxInactiveInterval(), ISession.getLastAccessTime()

getAliveInterval

public long getAliveInterval()
Gets the desired client-side communication interval for this session.

Specified by:
getAliveInterval in interface ISession
Returns:
the alive interval (client-side)

setAliveInterval

public void setAliveInterval(long pAliveInterval)
Sets the desired client-side communication interval for this session.

Specified by:
setAliveInterval in interface ISession
Parameters:
pAliveInterval - the alive interval (client-side)

getMaxInactiveInterval

public int getMaxInactiveInterval()
Returns the maximum time interval, in seconds, that this session will be active. After this interval, the session is inactive. The maximum time interval can be set with the setMaxInactiveInterval method. A zero or negative time indicates the session should never be inactive.

Specified by:
getMaxInactiveInterval in interface ISession
Returns:
time in seconds
See Also:
ISession.setMaxInactiveInterval(int)

setMaxInactiveInterval

public void setMaxInactiveInterval(int pMaxInactiveInterval)
Specifies the time, in seconds, before the session will be inactive. A zero or negative time indicates the session should never be inactive.

Specified by:
setMaxInactiveInterval in interface ISession
Parameters:
pMaxInactiveInterval - time in seconds

close

public void close()
           throws java.lang.Throwable
Closes the object (stream, connection, ...) and releases any system resources associated with it. If the object is already closed, then invoking this method has no effect.

Specified by:
close in interface ICloseable
Throws:
java.lang.Throwable - if an error occurs

destroy

public void destroy()
Destroys the session.


createMasterSession

public static DirectServerSession createMasterSession(java.lang.String pApplicationName,
                                                      java.util.Map<java.lang.String,java.lang.Object> pProperties)
                                               throws java.lang.Throwable
Creates a new instance of DirectServerSession for the given application and properties.

Parameters:
pApplicationName - the name of the application
pProperties - the additional session properties
Returns:
the newly created session
Throws:
java.lang.Throwable - if session creation fails

createMasterSession

public static DirectServerSession createMasterSession(java.lang.String pApplicationName,
                                                      java.lang.String pUserName,
                                                      java.lang.String pPassword)
                                               throws java.lang.Throwable
Creates a new instance of DirectServerSession for the given application and credentials.

Parameters:
pApplicationName - the name of the application
pUserName - the user name
pPassword - the password
Returns:
the newly created session
Throws:
java.lang.Throwable - if session creation fails

createMasterSession

public static DirectServerSession createMasterSession(java.lang.String pApplicationName,
                                                      java.lang.String pUserName,
                                                      java.lang.String pPassword,
                                                      java.util.Map<java.lang.String,java.lang.Object> pProperties)
                                               throws java.lang.Throwable
Creates a new instance of DirectServerSession for the given application, credentials and properties.

Parameters:
pApplicationName - the name of the application
pUserName - the user name
pPassword - the password
pProperties - the additional session properties
Returns:
the newly created session
Throws:
java.lang.Throwable - if session creation fails

createSubSession

public DirectServerSession createSubSession(java.lang.String pLifeCycleName)
                                     throws java.lang.Throwable
Creates a new instance of DirectServerSession as sub session for the given life-cycle object name.

Parameters:
pLifeCycleName - the full qualified class name of the life-cycle object
Returns:
the newly created session
Throws:
java.lang.Throwable - if session creation fails

createSubSession

public DirectServerSession createSubSession(java.lang.String pLifeCycleName,
                                            java.util.Map<java.lang.String,java.lang.Object> pProperties)
                                     throws java.lang.Throwable
Creates a new instance of DirectServerSession as sub session for the given life-cycle object name and properties.

Parameters:
pLifeCycleName - the full qualified class name of the life-cycle object
pProperties - the additional session properties
Returns:
the newly created session
Throws:
java.lang.Throwable - if session creation fails

createProperties

protected static ChangedHashtable<java.lang.String,java.lang.Object> createProperties(java.util.Map<java.lang.String,java.lang.Object> pProperties)
Creates a new ChangedHashtable instance with given properties as base.

Parameters:
pProperties - the base properties
Returns:
the newly created ChangedHashtable


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.