Class DefaultScriptingExecutor
- All Implemented Interfaces:
EventListener,ClusterInfoAware,ScriptingExecutor,org.springframework.beans.factory.Aware,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationContextAware,org.springframework.context.ApplicationListener
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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidasyncExecute(Script script) Executes the given script and return a future that can be used to read the response at a later stage.Executes the given script and returns a response.voidonApplicationEvent(org.springframework.context.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.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetClusterInfo(ClusterInfo clusterInfo) Sets the cluster information.voidsetExecutors(Map<String, LocalScriptExecutor> executors) voidsetNonThreadSafeCopmiledScriptCache(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).voidsetParameters(Map<String, Object> parameters) Sets parameters that will be added to each script.voidsetParameterTypes(Map<String, Class<?>> parameterTypes) Sets parameter types for parameters that will be added to each script.voidsetThreadSafeCompiledScriptCache(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, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
-
Field Details
-
APPLICATION_CONTEXT_KEY
- See Also:
-
CLUSTER_INFO_KEY
- See Also:
-
GROOVY_LOCAL_EXECUTOR_TYPE
- See Also:
-
JRUBY_LOCAL_EXECUTOR_TYPE
- See Also:
-
-
Constructor Details
-
DefaultScriptingExecutor
public DefaultScriptingExecutor()
-
-
Method Details
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
setClusterInfo
Description copied from interface:ClusterInfoAwareSets 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
ClusterInfoAwareshould take into account the fact that the cluster info provided might be null.- Specified by:
setClusterInfoin interfaceClusterInfoAware- Parameters:
clusterInfo- The cluster information to be injected
-
setParameters
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
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
-
setThreadSafeCompiledScriptCache
Sets a compiled script cache for compiled scripts taht are thread safe (the same script can be executed by different threads). Defaults toLRUThreadSafeCompiledScriptCache.- See Also:
-
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 toLRUNonThreadSafeCompiledScriptCache.- See Also:
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.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:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener
-
execute
Description copied from interface:ScriptingExecutorExecutes the given script and returns a response.- Specified by:
executein interfaceScriptingExecutor- Throws:
ScriptingException
-
asyncExecute
Description copied from interface:ScriptingExecutorExecutes 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:
asyncExecutein interfaceScriptingExecutor- Throws:
ScriptingException
-