marquee.xmlrpc.processors
Class SessionInvocationProcessor

java.lang.Object
  extended by marquee.xmlrpc.processors.SessionInvocationProcessor
All Implemented Interfaces:
XmlRpcInvocationProcessor

public class SessionInvocationProcessor
extends java.lang.Object
implements XmlRpcInvocationProcessor

The SessionProcessor allows invocation handlers to store client state in session objects between invocations. A session objects is associated with the caller IP address, hence if a client makes several simultaneous calls, each handler thread will acquire the same session objects when calling the getSession() method.

Note that the getSession() method is static, so in this form sessions span the whole JVM regardless of how many XmlRpcServers are instantiated. Should not be a problem though.

Since:
JDK 1.1
Version:
$Revision: 1.4 $
Author:
Greger Ohlson (greger.ohlson@marquee.se)

Constructor Summary
SessionInvocationProcessor()
           
 
Method Summary
static java.util.Map getSession()
          Returns the session associated with the calling thread.
 void onException(int callId, java.lang.String callerIp, java.lang.String handler, java.lang.String method, java.util.List arguments, java.lang.Throwable exception)
          Does nothing.
 java.lang.Object postProcess(int callId, java.lang.String callerIp, java.lang.String handler, java.lang.String method, java.util.List arguments, java.lang.Object returnValue)
          Does nothing.
 boolean preProcess(int callId, java.lang.String callerIp, java.lang.String handler, java.lang.String method, java.util.List arguments)
          Associates the calling thread (the thread handling the invocation) with the IP address of the client.
static void setSessionTimeout(int timeout_)
          Sets the timout value for sessions, expressed in minutes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionInvocationProcessor

public SessionInvocationProcessor()
Method Detail

getSession

public static java.util.Map getSession()
Returns the session associated with the calling thread. In preProcess, the calling thread was also associated with the IP address of the caller. In other words, calling getSession() returns the Session object associated with the client, assuming the calling thread is the thread used to handle the client invocation.

Returns:
the session object associated with the client. The calling thread must be the thread used to handle the client invocation for this to work. Note that the session is returned as a Hashtable which the user may put stuff into.

setSessionTimeout

public static void setSessionTimeout(int timeout_)
Sets the timout value for sessions, expressed in minutes.

Parameters:
timeout - The number of minutes that sessions should remain in memory before thay expire, supplied in minutes. A value of 0 indicates that sessions never expire.

preProcess

public boolean preProcess(int callId,
                          java.lang.String callerIp,
                          java.lang.String handler,
                          java.lang.String method,
                          java.util.List arguments)
Associates the calling thread (the thread handling the invocation) with the IP address of the client. If the client currently has a session, the timestamp of the session will be updated. The invocation handler may at any time call getSession() to get the session associated with the client. getSession() will, using the information setup in this method, be able to determine which session belongs to the calling thread.

Specified by:
preProcess in interface XmlRpcInvocationProcessor
Parameters:
callId - A sequence number for tracing calls between preProcess() and postProcess() calls. This is unique within each session. That is, the sequence is restarted when the application restarts.
handler - The name of the handler being called.
method - The name of the method being called.
arguments - The arguments that will be sent to the method.
Returns:
true if the invocation should proceed, or false if not.
See Also:
XmlRpcInvocationProcessor

postProcess

public java.lang.Object postProcess(int callId,
                                    java.lang.String callerIp,
                                    java.lang.String handler,
                                    java.lang.String method,
                                    java.util.List arguments,
                                    java.lang.Object returnValue)
Does nothing.

Specified by:
postProcess in interface XmlRpcInvocationProcessor
Parameters:
callId - A sequence number for tracing calls between preProcess() and postProcess() calls. This is unique within each session. That is, the sequence is restarted when the application restarts.
handler - The name of the handler being called.
method - The name of the method that just has returned.
returnValue - The objects returned by the method. If the method returned a primitive, it is wrapped in its object counterpart.
Returns:
The (possibly modified) returnValue argument.

onException

public void onException(int callId,
                        java.lang.String callerIp,
                        java.lang.String handler,
                        java.lang.String method,
                        java.util.List arguments,
                        java.lang.Throwable exception)
Does nothing.

Specified by:
onException in interface XmlRpcInvocationProcessor
Parameters:
callId - A sequence number for tracing calls between preProcess() and postProcess() calls. This is unique within each session. That is, the sequence is restarted when the application restarts.
handler - The name of the handler being called.
method - The name of the method that just has returned by throwing an exception.
exception - The exception thrown by the method.