org.granite.messaging.service
Class ServiceInvoker<T extends ServiceFactory>

java.lang.Object
  extended by org.granite.messaging.service.ServiceInvoker<T>
Direct Known Subclasses:
EjbServiceInvoker, SimpleServiceInvoker, TideServiceInvoker

@TransientReference
public abstract class ServiceInvoker<T extends ServiceFactory>
extends Object

Abstract base class for all service's methods calls. This class mainly implements a final invocation method which deals with parameter conversions, security and listeners.

Author:
Franck WOLFF
See Also:
ServiceFactory, ServiceInvocationListener, ServiceExceptionHandler

Field Summary
protected  Destination destination
           
protected  T factory
           
protected  List<ServiceInvocationListener> invocationListeners
           
protected  Object invokee
           
 
Constructor Summary
protected ServiceInvoker(Destination destination, T factory)
          Constructs a new ServiceInvoker.
 
Method Summary
protected  Object adjustInvokee(RemotingMessage request, String methodName, Object[] args)
          Called at the beginning of the invoke(RemotingMessage) method.
protected  Object afterInvocation(ServiceInvocationContext context, Object result)
          Called after a successful invocation of the service's method.
protected  void afterInvocationError(ServiceInvocationContext context, Throwable error)
          Called after a failed invocation of the service's method, possibly after a new attempt (see retryInvocation(ServiceInvocationContext, Throwable).
protected  void beforeInvocation(ServiceInvocationContext context)
          Called before the invocation of the services method.
protected  Object[] beforeMethodSearch(Object invokee, String methodName, Object[] args)
          Called before the invoke(RemotingMessage) method starts to search for a method named methodName with the arguments args on the invokee object.
 Object invoke(RemotingMessage request)
          Call a service's method according to the informations contained in the given remoting message.
protected  boolean retryInvocation(ServiceInvocationContext context, Throwable t)
          Called after a failed invocation of the service's method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

invocationListeners

protected final List<ServiceInvocationListener> invocationListeners

destination

protected final Destination destination

factory

protected final T extends ServiceFactory factory

invokee

protected Object invokee
Constructor Detail

ServiceInvoker

protected ServiceInvoker(Destination destination,
                         T factory)
                  throws ServiceException
Constructs a new ServiceInvoker. This constructor is used by a dedicated ServiceFactory.

Parameters:
destination - the remote destination of this service (services-config.xml).
factory - the factory that have called this constructor.
Throws:
ServiceException - if anything goes wrong.
Method Detail

adjustInvokee

protected Object adjustInvokee(RemotingMessage request,
                               String methodName,
                               Object[] args)
                        throws ServiceException
Called at the beginning of the invoke(RemotingMessage) method. Give a chance to modify the the services (invokee) about to be called. Does nothing by default. The default invokee object is created by actual implementations of this abstract class.

Parameters:
request - the current remoting message (sent from Flex).
methodName - the name of the method to be called.
args - the method parameter values.
Returns:
the (possibly adjusted) invokee object.
Throws:
ServiceException - if anything goes wrong.

beforeMethodSearch

protected Object[] beforeMethodSearch(Object invokee,
                                      String methodName,
                                      Object[] args)
Called before the invoke(RemotingMessage) method starts to search for a method named methodName with the arguments args on the invokee object. Give a chance to modify the method name or the paramaters. Does nothing by default.

Parameters:
invokee - the service instance used for searching the method with the specified arguments.
methodName - the method name.
args - the arguments of the method.
Returns:
an array of containing the (possibly adjusted) method name and its arguments.

beforeInvocation

protected void beforeInvocation(ServiceInvocationContext context)
Called before the invocation of the services method. Does nothing by default.

Parameters:
context - the current invocation context.

retryInvocation

protected boolean retryInvocation(ServiceInvocationContext context,
                                  Throwable t)
Called after a failed invocation of the service's method. Returns false by default.

Parameters:
context - the current invocation context.
t - the exception that caused the invocation failure.
Returns:
true if invocation should be retried, false otherwise.

afterInvocationError

protected void afterInvocationError(ServiceInvocationContext context,
                                    Throwable error)
Called after a failed invocation of the service's method, possibly after a new attempt (see retryInvocation(ServiceInvocationContext, Throwable). Does nothing by default.

Parameters:
context - the current invocation context.
error - the exception that caused the invocation failure.

afterInvocation

protected Object afterInvocation(ServiceInvocationContext context,
                                 Object result)
Called after a successful invocation of the service's method. Does nothing by default.

Parameters:
context - the current invocation context.
result - the result of the invocation (returned by the called method).

invoke

public final Object invoke(RemotingMessage request)
                    throws ServiceException
Call a service's method according to the informations contained in the given remoting message. This method is final and implements a standard way of calling a service's method, independent of the underlying framework (EJB3, Spring, Seam, etc.) It deals with security, parameter conversions, exception handling and offers several ways of listening (and possibly adjusting) the invocation process.

Parameters:
request - the remoting message containing informations about the call.
Returns:
the result of the service's method invocation.
Throws:
ServiceException - if anything goes wrong (security, invocation target exception, etc.)