GigaSpaces XAP 9.7.2 API

org.openspaces.remoting.scripting
Class DefaultScriptingExecutor

java.lang.Object
  extended by org.openspaces.remoting.scripting.DefaultScriptingExecutor
All Implemented Interfaces:
EventListener, ClusterInfoAware, ScriptingExecutor, Aware, InitializingBean, ApplicationContextAware, ApplicationListener

public class DefaultScriptingExecutor
extends Object
implements ScriptingExecutor, ApplicationContextAware, InitializingBean, ApplicationListener, ClusterInfoAware

A Default "server" side script executor. Can execute Scripts based on a set of registered LocalScriptExecutors.

Will automatically register groovy (GroovyLocalScriptExecutor) if it exists within the classpath. Will also automatically register ruby (JRubyLocalScriptExecutor) if the jruby jars exists within the classpath.

If working under Java 6, or adding JSR 223 jars into the classpath, will use its scripting support as a fall-back if no local script executors are found for a given type. The JSR allows for a unified API on top of different scripting libraries with pluggable types.

The executor will automatically add the Spring application context as a parameter to the script under the name applicationContext allowing to get any beans defined on the "server side". Since GigaSpace instances are often used within the script, it will automatically add all the different GigaSpace instances defined within the application context under their respective bean names.

Another parameter that will be passed to the script is the ClusterInfo allowing the script to be "aware" of which cluster instance it is executed on, and the cluster size.

This executor also supports caching of compiled scripts using the CompiledScriptCache abstraction. There are two special caches, one for compiled scripts that are thread safe (the same compiled script can be executed by several threads) and one for compiled scripts that are not thread safe (the same compiled scripts can only be executed by a single thread). Note, caching is done based on the script name (Script.getName(), this means that changed scripts should change their name in order to recompile them and insert them into the cache.

Author:
kimchy

Field Summary
static String APPLICATION_CONTEXT_KEY
           
static String CLUSTER_INFO_KEY
           
static String GROOVY_LOCAL_EXECUTOR_TYPE
           
static String JRUBY_LOCAL_EXECUTOR_TYPE
           
 
Constructor Summary
DefaultScriptingExecutor()
           
 
Method Summary
 void afterPropertiesSet()
           
 Future asyncExecute(Script script)
          Executes the given script and return a future that can be used to read the response at a later stage.
 Object execute(Script script)
          Executes the given script and returns a response.
 void onApplicationEvent(ApplicationEvent applicationEvent)
          On applicaiton context refresh event get all the GigaSpace beans and put them in a map that will later be appeneded to any script parameters.
 void setApplicationContext(ApplicationContext applicationContext)
           
 void setClusterInfo(ClusterInfo clusterInfo)
          Sets the cluster information.
 void setExecutors(Map<String,LocalScriptExecutor> executors)
           
 void setNonThreadSafeCopmiledScriptCache(CompiledScriptCache nonThreadSafeCopmiledScriptCache)
          Sets a compiled script cache for compiled scripts taht are not thread safe (the same script can not be executed by different threads).
 void setParameters(Map<String,Object> parameters)
          Sets parameters that will be added to each script.
 void setParameterTypes(Map<String,Class<?>> parameterTypes)
          Sets parameter types for parameters that will be added to each script.
 void setThreadSafeCompiledScriptCache(CompiledScriptCache threadSafeCompiledScriptCache)
          Sets a compiled script cache for compiled scripts taht are thread safe (the same script can be executed by different threads).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

APPLICATION_CONTEXT_KEY

public static final String APPLICATION_CONTEXT_KEY
See Also:
Constant Field Values

CLUSTER_INFO_KEY

public static final String CLUSTER_INFO_KEY
See Also:
Constant Field Values

GROOVY_LOCAL_EXECUTOR_TYPE

public static final String GROOVY_LOCAL_EXECUTOR_TYPE
See Also:
Constant Field Values

JRUBY_LOCAL_EXECUTOR_TYPE

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

DefaultScriptingExecutor

public DefaultScriptingExecutor()
Method Detail

setApplicationContext

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

setClusterInfo

public void setClusterInfo(ClusterInfo clusterInfo)
Description copied from interface: ClusterInfoAware
Sets the cluster information.

Note, the cluster information is obtained externally from the application context which means that this feature need to be supported by specific containers (and is not supported by plain Spring application context). This means that beans that implement ClusterInfoAware should take into account the fact that the cluster info provided might be null.

Specified by:
setClusterInfo in interface ClusterInfoAware
Parameters:
clusterInfo - The cluster information to be injected

setParameters

public void setParameters(Map<String,Object> parameters)
Sets parameters that will be added to each script. The key of the map is the parameter name (a String) and the value if a free Object as the parameter value.


setParameterTypes

public void setParameterTypes(Map<String,Class<?>> parameterTypes)
Sets parameter types for parameters that will be added to each script. The key of the map is the parameter name (a String) and the value is a class representing that static type for the key name.


setExecutors

public void setExecutors(Map<String,LocalScriptExecutor> executors)

setThreadSafeCompiledScriptCache

public void setThreadSafeCompiledScriptCache(CompiledScriptCache threadSafeCompiledScriptCache)
Sets a compiled script cache for compiled scripts taht are thread safe (the same script can be executed by different threads). Defaults to LRUThreadSafeCompiledScriptCache.

See Also:
LocalScriptExecutor.isThreadSafe()

setNonThreadSafeCopmiledScriptCache

public void setNonThreadSafeCopmiledScriptCache(CompiledScriptCache nonThreadSafeCopmiledScriptCache)
Sets a compiled script cache for compiled scripts taht are not thread safe (the same script can not be executed by different threads). Defaults to LRUNonThreadSafeCompiledScriptCache.

See Also:
LocalScriptExecutor.isThreadSafe()

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

onApplicationEvent

public void onApplicationEvent(ApplicationEvent applicationEvent)
On applicaiton context refresh event get all the GigaSpace beans and put them in a map that will later be appeneded to any script parameters.

Specified by:
onApplicationEvent in interface ApplicationListener

execute

public Object execute(Script script)
               throws ScriptingException
Description copied from interface: ScriptingExecutor
Executes the given script and returns a response.

Specified by:
execute in interface ScriptingExecutor
Throws:
ScriptingException

asyncExecute

public Future asyncExecute(Script script)
                    throws ScriptingException
Description copied from interface: ScriptingExecutor
Executes the given script and return a future that can be used to read the response at a later stage.

Note, this only works with "async" remoting.

Specified by:
asyncExecute in interface ScriptingExecutor
Throws:
ScriptingException

GigaSpaces XAP 9.7.2 API

Copyright © GigaSpaces.