org.clazzes.remoting.beans
Class ReturnCallbackInvocationHandler

java.lang.Object
  extended by org.clazzes.remoting.beans.ReturnCallbackInvocationHandler
All Implemented Interfaces:
ReturnCallbackHandler, Destroyable, Initializable, InvocationHandler, ClientTerminationListener

public class ReturnCallbackInvocationHandler
extends java.lang.Object
implements ReturnCallbackHandler, Initializable, Destroyable, ClientTerminationListener

This ServerInvocationHandler delegates jboss remote calls to a spring bean by intelligently discovering the service interface.

Author:
wglas

Field Summary
 
Fields inherited from interface org.clazzes.remoting.beans.ReturnCallbackHandler
RETURN_PROXY_GUID_PROPERTY
 
Constructor Summary
ReturnCallbackInvocationHandler()
           
 
Method Summary
 void clientTerminated(java.rmi.server.UID clientUID)
           
 int countCallbacks(java.rmi.server.UID sessionId)
          Count all callbacks of a given client.
 void deregisterAllCallbacks(java.rmi.server.UID sessionId)
          Deregister all callbacks of a given client.
 void deregisterCallback(java.rmi.server.UID sessionId, java.rmi.server.UID guid)
          Deregister a single callback of a given client.
 void destroy()
          Cleanup internal resources.
 java.util.List<java.lang.Class<?>> getCallbackInterfaces()
           
 java.lang.String getCloseMethodRegex()
           
 void initialize()
          Initialize the internal state of this bean.
 java.lang.Object invoke(InvocationContext ctx, java.lang.Object arg, java.util.Map<java.lang.String,java.lang.Object> metadata)
           
 boolean isCallbackInterface(java.lang.Class<?> iface)
           
 boolean isInitialized()
           
 java.rmi.server.UID registerCallback(java.rmi.server.UID sessionId, java.lang.Class<?> iface, java.lang.Object target)
           
 void setCallbackInterfaces(java.util.List<java.lang.Class<?>> callbackInterfaces)
           
 void setCloseMethodRegex(java.lang.String closeMethodRegex)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReturnCallbackInvocationHandler

public ReturnCallbackInvocationHandler()
Method Detail

isInitialized

public boolean isInitialized()
Specified by:
isInitialized in interface Initializable
Returns:
Whether this bean needs to be initialized using Initializable.initialize().

initialize

public void initialize()
                throws java.lang.Exception
Description copied from interface: Initializable
Initialize the internal state of this bean.

Specified by:
initialize in interface Initializable
Throws:
java.lang.Exception - Upon errors.

destroy

public void destroy()
Description copied from interface: Destroyable
Cleanup internal resources. An implementation must be safe to be called twice. Any error should be logged rather than thrown as exceptions. If this bean implements Initializable too, the general contract is, that after calling this method, Initializable.isInitialized() returns false.

Specified by:
destroy in interface Destroyable

invoke

public java.lang.Object invoke(InvocationContext ctx,
                               java.lang.Object arg,
                               java.util.Map<java.lang.String,java.lang.Object> metadata)
                        throws java.lang.Throwable
Specified by:
invoke in interface InvocationHandler
Parameters:
ctx - The context under which the call has been issued.
arg - The argument of the call.
metadata - The metadata accompanying the remote call, which is passed to the invocation handler. Metadata may be used to communicate authorization information such as user/password or a session Id.
Returns:
The result of the operation.
Throws:
java.lang.Throwable - Any exception raised by the call. This exception will be reported back to the invoker as the root cause of an InvocationTargetException.

countCallbacks

public int countCallbacks(java.rmi.server.UID sessionId)
Description copied from interface: ReturnCallbackHandler
Count all callbacks of a given client.

Specified by:
countCallbacks in interface ReturnCallbackHandler
Parameters:
sessionId - A client session Id.
Returns:
The number of callbacks currently registered for the given client ID.

deregisterAllCallbacks

public void deregisterAllCallbacks(java.rmi.server.UID sessionId)
Description copied from interface: ReturnCallbackHandler
Deregister all callbacks of a given client.

Specified by:
deregisterAllCallbacks in interface ReturnCallbackHandler
Parameters:
sessionId - A client session Id.

clientTerminated

public void clientTerminated(java.rmi.server.UID clientUID)
Specified by:
clientTerminated in interface ClientTerminationListener
Parameters:
clientUID - The UID of the client which has terminated.

deregisterCallback

public void deregisterCallback(java.rmi.server.UID sessionId,
                               java.rmi.server.UID guid)
Description copied from interface: ReturnCallbackHandler
Deregister a single callback of a given client.

Specified by:
deregisterCallback in interface ReturnCallbackHandler
Parameters:
sessionId - A client session Id.
guid - The GUID of the callback to be deregistered a returned by #registerCallback(String, Class, Object).

isCallbackInterface

public boolean isCallbackInterface(java.lang.Class<?> iface)
Specified by:
isCallbackInterface in interface ReturnCallbackHandler
Parameters:
iface - The interface of a return value.
Returns:
Whether this interface is registered as a callback interface.

registerCallback

public java.rmi.server.UID registerCallback(java.rmi.server.UID sessionId,
                                            java.lang.Class<?> iface,
                                            java.lang.Object target)
Specified by:
registerCallback in interface ReturnCallbackHandler
Parameters:
sessionId - A client session Id.
iface - The interface of a service return value.
target - The proxy object to be served.
Returns:
A UID for the registered proxy return value.

getCallbackInterfaces

public java.util.List<java.lang.Class<?>> getCallbackInterfaces()
Returns:
the callbackInterfaces

setCallbackInterfaces

public void setCallbackInterfaces(java.util.List<java.lang.Class<?>> callbackInterfaces)
Parameters:
callbackInterfaces - the callbackInterfaces to set

getCloseMethodRegex

public java.lang.String getCloseMethodRegex()
Returns:
The regular expression, which is used to identify context lose methods. A context close method deregisters the callback object and hence marks the end of the lifecycle of a return proxy.

setCloseMethodRegex

public void setCloseMethodRegex(java.lang.String closeMethodRegex)
Parameters:
closeMethodRegex - the closeMethodRegex to set


Copyright © 2010. All Rights Reserved.