GS == "XAP9NET" || GS == "XAP9" || GS == "XAP9NET")

Spring Parallel Processing Integration

  GigaSpaces 5.X

Documentation Home
Quick Start Guide
Release Notes

Previous release

  Search Here
Searching GigaSpaces Platform 5.X Documentation


Summary: Sample implementation showing how to perform remote invocation for business logic of parallel processing units.


If you wish to allow users to utilize the GigaSpaces Grid, you can invoke your business logic on remote processes. Proxies to the remote objects are generated automatically. Remoting is implemented using JavaSpaces as the transport layer, similar to existing Spring remoting technologies such as RMI or web services.

The remoting support is composed of three logical units: Taker, Worker and Delegate. The Taker is responsible for accessing the Delegate, which, in turn, executes code located on the Worker. These three units may be co-located within the same virtual machine, or separately deployed on three different nodes / virtual machines. The different parties communicate via Task and Result objects.

This section explains how Spring remoting works in GigaSpaces, by means of an example. A sample implementation is shown for Master, Worker, Task and Result classes and related classes.

The Master

The Master executes remote business logic running on the Worker. The ITask implementation is the actual business logic executed on the Worker. The remote worker returns a Result object:

ITask proxy =  (ITask)applicationContext.getBean("proxy");
Result res = proxy.execute("data");

The Worker

The Worker implementation uses the generic DelegatingWorker:

public class Worker 
	//member for gigaspaces template
	private GigaSpacesTemplate template;
	//The delegator worker
	private DelegatingWorker iTestBeanWorker;
	private ApplicationContext	applicationContext;

	private Thread itbThread;
	protected void init() throws Exception {
		applicationContext = new ClassPathXmlApplicationContext("gigaspaces_master_remoting.xml");
		template = (GigaSpacesTemplate)applicationContext.getBean("gigaspacesTemplate");
		iTestBeanWorker = (DelegatingWorker)applicationContext.getBean("testBeanWorker");

	protected void start() {
		itbThread = new Thread(iTestBeanWorker);

	public static void main(String[] args) {
		try {
			System.out.println("nWelcome to Spring GigaSpaces Worker remote Example!n");
			Worker worker = new Worker();
		} catch (Exception ux) {
			System.err.println("transError problem..." + ux.getMessage());

The Task and its execution by the Worker

This is the task interface:

public interface ITask extends Serializable{
	public Result execute(String data);

This is the ITask interface implementation used at the worker:

public class Task implements ITask{
	private long counter = 0;
    public Task() {

     * Execute the task
	public Result execute(String data)
		System.out.println("I am doing the task id = "+counter+" with data : "+data);
		Result result = new Result();
		// do the calc
		return result ;

The Result

The Result object used to transport the Answer back to the client caller:

public class Result implements Serializable
	private long taskID; // task id
	private String answer = null; // result
	public Result() {}
	public String getAnswer()	{return answer;	}
	public void setAnswer(String answer){this.answer = answer;}
	public long getTaskID(){	return taskID;}
	public void setTaskID(long taskID){this.taskID = taskID;}


This file includes properties injected into the following classes:

Class Description Bean Name
Generates unique UIDs for tasks. When using a partitioned space, the UID hashcode determines the target space of the Entry. gigaSpacesUid
The Generic worker invoking the Task business logic. testBeanWorker
The Interceptor that passes the Task from the client to the worker, via the space. javaSpace
FactoryBean implementation for use in sourcing AOP proxies from a Spring BeanFactory. proxy
The remote Task implementation taskBean


To ensure each client gets the relevant result object back from the Worker, the Task and Result are injected with a unique UID generated on the client side.


The org.springmodules.javaspaces.gigaspaces.DelegatingWorker class configures the Worker. This is not a singleton class. The DelegatingWorker class includes the following properties:

Property Description
javaSpaceTemplate The GigaSpaces Spring template
delegate The Task bean to be injected into the worker
businessInterface The Task class interface


The com.gigaspaces.spring.GigaSpacesInterceptor controls the client side Interceptor that submits the task into the space and gets the result back. The latter can be done either synchronously or asynchronously, allowing the client to either wait or continue with its activities before the result is returned from the worker. The GigaSpacesInterceptor extends the JavaSpaceInterceptor, which supports UID injection to the task and result objects, allowing clients to retrieve the related result for a specific task.

Property Description Type Value
javaSpaceTemplate The JavaSpaces template Reference  
uidFactory The Task includes a unique identifier. This ensures that each client gets an appropriate Result object in return. Reference  
synchronous Whether the client should wait until the Master returns a result before continuing. When running in asynchronous mode, while the Result has not been sent back from the worker, the client waits a specified time period, as defined in the timeoutMillis parameter, provided that a matching result does not exists in the space. boolean true, false
timeoutMillis Time [in ms] to wait for a matching result to be found in the space (take timeout times). long  
serializableTarget Causes this target to be passed to the space in a RunnableMethodEntry. Reference  


org.springframework.aop.framework.ProxyFactoryBean is the client-side proxy.

Property Description Type Values
interceptorNames Definition of the Spring AOP interceptor chain. The spaceInterceptor must be the last interceptor, as there is no local target to invoke. Any number of other interceptors can be added, for example, to monitor performance, add security or other functionality. list javaSpaceInterceptorPerformanceMonitorInterceptor
proxyInterfaces   list com.gigaspaces.spring.examples.remote.ITask

Application Context File

<?xml version="1.0" encoding="UTF-8"?>

<!-- Root application context -->

	<!-- Declaration of GigaSpaces factory bean -->
	<bean id="gigaspace"
		<property name="urls">

	<!--  Declaration of GigaSpaces uid factory -->
	<bean id="gigaSpacesUidFactory"
		<property name="space" ref="gigaspace"/>

	<!-- Declaration of GigaSpace template-->
	<bean id="gigaspacesTemplate"
		<property name="space" ref="gigaspace" />
	<bean id="testBeanWorker"
		class=" org.springmodules.javaspaces.DelegatingWorker"
		singleton="false" >
		<property name="javaSpaceTemplate" ref="gigaspacesTemplate"/>
		<property name="delegate"><ref local="taskBean"/></property>
		<property name="businessInterface"><value>com.gigaspaces.spring.examples.
	<bean id="javaSpaceInterceptor"
		class=" org.springmodules.javaspaces.gigaspaces.GigaSpacesInterceptor">
		<property name="javaSpaceTemplate" ref="gigaspacesTemplate"/>
		<property name="uidFactory" ref="gigaSpacesUidFactory"/>
		<property name="synchronous"><value>true</value></property>
		The Time for waiting to take the result from the space by the master
		<property name="timeoutMillis"><value>3000</value></property>

			Comment out this property for "service seeking" behavior 
			where the endpoint is assumed to host a service to invoke.
		<property name="serializableTarget" ref="taskBean">
		This is the client-side proxy.
	<bean id="proxy"
		<property name="interceptorNames">
		<property name="proxyInterfaces">
		Simple test target
	<bean id="taskBean" class="com.gigaspaces.spring.examples.remote.Task" >

Wiki Content Tree

Your Feedback Needed!

We need your help to improve this wiki site. If you have any suggestions or corrections, write to us at Please provide a link to the wiki page you are referring to.