GigaSpaces XAP 9.7.2 API

org.openspaces.remoting
Class ExecutorSpaceRemotingProxyFactoryBean

java.lang.Object
  extended by org.springframework.remoting.support.RemotingSupport
      extended by org.springframework.remoting.support.RemoteAccessor
          extended by org.openspaces.remoting.ExecutorSpaceRemotingProxyFactoryBean
All Implemented Interfaces:
Advice, Interceptor, MethodInterceptor, RemotingInvoker, Aware, BeanClassLoaderAware, FactoryBean, InitializingBean, ApplicationContextAware

public class ExecutorSpaceRemotingProxyFactoryBean
extends RemoteAccessor
implements FactoryBean, InitializingBean, MethodInterceptor, RemotingInvoker, ApplicationContextAware

A space executor remoting proxy that forward the service execution to a remote service with the space as the transport layer. Services are remotely exported in the "server side" using the SpaceRemotingServiceExporter. The actual invocations uses the space executors mechanism to perform the actual method invocation, allowing to perform async invocations (invocations that return Future (which is better than the sync remoting option). In general, the executor based remoting should be used over the sync remoting option.

The proxy requires a setGigaSpace(org.openspaces.core.GigaSpace) interface to be set in order to write execute.

A timeout which controls how long the proxy will wait for the response can be set using setTimeout(long). The timeout value if in milliseconds.

The space remote proxy supports a future based invocation. This means that if, on the client side, one of the service interface methods returns Future, it can be used for async execution. Note, this means that in terms of interfaces there will have to be two different service interfaces (under the same package and with the same name). One for the server side service that returns the actual value, and one on the client side that for the same method simply returns the future. Another option is not having two different interfaces, but having the same interface with async methods (returning Future). The async methods should start with a specified prefix (defaults to async) and should have no implementation on the server side (simply return null).

In case of remote invocation over a partitioned space the default partitioned routing index will be random (the hashCode of the newly created ExecutorRemotingTask class). The proxy allows for a pluggable routing handler implementation by setting setRemoteRoutingHandler(org.openspaces.remoting.RemoteRoutingHandler).

The proxy allows to perform broadcast the remote invocation to all different cluster members (partitions for example) by setting the broadcast flag to true. In such cases, a custom setRemoteResultReducer(org.openspaces.remoting.RemoteResultReducer) can be plugged to reduce the results of all different services into a single response (assuming that the service has a return value).

The actual remote invocation can be replaced with an aspect implementing RemoteInvocationAspect which can be set using setRemoteInvocationAspect(org.openspaces.remoting.RemoteInvocationAspect). It is up the aspect to then call the actual remote invocation.

Note that it is also possible to configure method level broadcasting, RemoteResultReducer, RemoteRoutingHandler, RemoteInvocationAspect and MetaArgumentsHandler using the ExecutorRemotingMethod annotation.

Author:
kimchy
See Also:
SpaceRemotingServiceExporter

Field Summary
static String DEFAULT_ASYNC_METHOD_PREFIX
           
 
Fields inherited from class org.springframework.remoting.support.RemotingSupport
logger
 
Constructor Summary
ExecutorSpaceRemotingProxyFactoryBean()
           
 
Method Summary
 void afterPropertiesSet()
           
 Object getObject()
           
 Class<?> getObjectType()
           
 Object invoke(MethodInvocation methodInvocation)
           
 Object invokeRemote(MethodInvocation methodInvocation)
          This invocation will cause the actual remote invocation.
 boolean isSingleton()
           
 void setApplicationContext(ApplicationContext applicationContext)
           
 void setBroadcast(boolean broadcast)
          If set the true (defaults to false) causes the remote invocation to be called on all active (primary) cluster members.
 void setGigaSpace(GigaSpace gigaSpace)
          Sets the GigaSpace interface that will be used to work with the space as the transport layer.
 void setMetaArgumentsHandler(MetaArgumentsHandler metaArgumentsHandler)
          Allows to set a meta argument handler that will control SpaceRemotingInvocation.getMetaArguments().
 void setRemoteInvocationAspect(RemoteInvocationAspect remoteInvocationAspect)
          The actual remote invocation can be replaced with an aspect implementing RemoteInvocationAspect which can be set using setRemoteInvocationAspect(org.openspaces.remoting.RemoteInvocationAspect).
 void setRemoteResultReducer(RemoteResultReducer remoteResultReducer)
          When using broadcast set to true, allows to plug a custom reducer that can reduce the array of result objects into another response object.
 void setRemoteRoutingHandler(RemoteRoutingHandler remoteRoutingHandler)
          In case of remote invocation over a partitioned space the default partitioned routing index will be random.
 void setReturnFirstResult(boolean returnFirstResult)
          When set to true (defaults to true) will return the first result when using broadcast.
 void setTimeout(long timeout)
          Sets the timeout that will be used to wait for the remote invocation response.
 
Methods inherited from class org.springframework.remoting.support.RemoteAccessor
getServiceInterface, setServiceInterface
 
Methods inherited from class org.springframework.remoting.support.RemotingSupport
getBeanClassLoader, overrideThreadContextClassLoader, resetThreadContextClassLoader, setBeanClassLoader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ASYNC_METHOD_PREFIX

public static final String DEFAULT_ASYNC_METHOD_PREFIX
See Also:
Constant Field Values
Constructor Detail

ExecutorSpaceRemotingProxyFactoryBean

public ExecutorSpaceRemotingProxyFactoryBean()
Method Detail

setGigaSpace

public void setGigaSpace(GigaSpace gigaSpace)
Sets the GigaSpace interface that will be used to work with the space as the transport layer.


setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)
                           throws BeansException
Specified by:
setApplicationContext in interface ApplicationContextAware
Throws:
BeansException

setTimeout

public void setTimeout(long timeout)
Sets the timeout that will be used to wait for the remote invocation response. The timeout value is in milliseconds and defaults to 60000 (60 seconds).


setRemoteRoutingHandler

public void setRemoteRoutingHandler(RemoteRoutingHandler remoteRoutingHandler)
In case of remote invocation over a partitioned space the default partitioned routing index will be random. This RemoteRoutingHandler allows for custom routing computation (for example, based on one of the service method parameters).


setBroadcast

public void setBroadcast(boolean broadcast)
If set the true (defaults to false) causes the remote invocation to be called on all active (primary) cluster members.


setRemoteResultReducer

public void setRemoteResultReducer(RemoteResultReducer remoteResultReducer)
When using broadcast set to true, allows to plug a custom reducer that can reduce the array of result objects into another response object.


setMetaArgumentsHandler

public void setMetaArgumentsHandler(MetaArgumentsHandler metaArgumentsHandler)
Allows to set a meta argument handler that will control SpaceRemotingInvocation.getMetaArguments().


setReturnFirstResult

public void setReturnFirstResult(boolean returnFirstResult)
When set to true (defaults to true) will return the first result when using broadcast. If set to false, an array of results will be retuned.

Note, this only applies if no reducer is provided.


setRemoteInvocationAspect

public void setRemoteInvocationAspect(RemoteInvocationAspect remoteInvocationAspect)
The actual remote invocation can be replaced with an aspect implementing RemoteInvocationAspect which can be set using setRemoteInvocationAspect(org.openspaces.remoting.RemoteInvocationAspect). It is up the aspect to then call the actual remote invocation.


afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface InitializingBean

getObject

public Object getObject()
Specified by:
getObject in interface FactoryBean

getObjectType

public Class<?> getObjectType()
Specified by:
getObjectType in interface FactoryBean

isSingleton

public boolean isSingleton()
Specified by:
isSingleton in interface FactoryBean

invoke

public Object invoke(MethodInvocation methodInvocation)
              throws Throwable
Specified by:
invoke in interface MethodInterceptor
Throws:
Throwable

invokeRemote

public Object invokeRemote(MethodInvocation methodInvocation)
                    throws Throwable
Description copied from interface: RemotingInvoker
This invocation will cause the actual remote invocation.

Specified by:
invokeRemote in interface RemotingInvoker
Throws:
Throwable

GigaSpaces XAP 9.7.2 API

Copyright © GigaSpaces.