OpenSpaces Scripting over remoting allows to simply execute dynamic languages scripts as remote "jobs". The following diagram shows the work flow: Scripting CodeHere is how we write it on the client side (Scripting Counter Processing Unit): The pu.xml configuration file The pu.xml contains the configuration for the client (the Scripting Counter Processing Unit in this case). <!-- A bean representing a space (an IJSpace implementation). --> <os-core:space id="space" url="jini://*/*/spaceQueries"/> <!-- OpenSpaces simplified space API built on top of IJSpace/JavaSpace. --> <os-core:giga-space id="gigaSpace" space="space"/> <os-remoting:annotation-support/> <bean id="scriptRunner" class="com.gigaspaces.examples.tutorials.queries.scriptingcounter.ScriptRunner"/> The ScriptRunner bean The ScriptRunner bean uses the syncScriptingExecutor proxy to load the QuerySpace Groovy script transparently to the remote syncScriptingExecutor service(the script - "QuerySpace" is located in the client classpath). public class ScriptRunner implements InitializingBean { // The proxy to the remote SyncScriptingExecutor @SyncScriptingExecutor private ScriptingExecutor syncScriptingExecutor; public void setSyncScriptingExecutor(ScriptingExecutor syncScriptingExecutor) { this.syncScriptingExecutor = syncScriptingExecutor; } public void afterPropertiesSet() throws Exception { init(); } public void init() throws Exception { // Sends a script placed in the client classpath, to the remote sync scripting executor // Results from the script execution will be returned and displayed. int OrdersCount = (Integer)syncScriptingExecutor.execute(new ResourceLazyLoadingScript() .cache(false) // Maintain the executed script in the server for future executions .name("scriptbasedcounter") .type("groovy") .parameter("lastName" /* name */, "LN7" /* value */) // Parameter , referenced inside the // script, will be used during execution time .script("classpath:/QuerySpace.groovy")); // Script location on the client side System.out.println("Orders count [" + OrdersCount + "]"); } } The SpaceQuery Groovy script A simple script, returns the number of accounts found with a certain lastName attribute, import com.j_spaces.core.client.SQLQuery import com.gigaspaces.examples.tutorials.queries.common.Account // Create a query for all accounts lastName attribute equal to the lastName sent // in the ScriptRunner bean query = new SQLQuery<Account>(Account.class,"lastName = '"+lastName+"'") // Read all accounts satisfying the query accounts = (Object[])gigaSpace.readMultiple((Object)query,Integer.MAX_VALUE) // This will be printed out on the server side println 'Found ' + accounts.length + ' accounts' //return number of accounts found return accounts.length |
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |