Hi all,
I wrote a TaskExecutor for GridGain. GridGain is the easiest way to set up a grid computer for Java applications.
With this implementation you can send Runnable objects over the network for execution. GridGain will take care of classloading issues and the like, works like a charm.
To use the TaskExecutor follow these steps:
1) Configure the class in Spring. The default configuration should be fine but you can customize your node through the gridConfiguration property.
2) Set the GRIDGAIN_HOME environment variable.
3) Use the TaskExecutor object as usual. The only constraint is that any objects contained by Runnable instances must be Serializable.
Here's the implementation:
Enjoy.Code:package gridgain; import org.gridgain.grid.Grid; import org.gridgain.grid.GridConfiguration; import org.gridgain.grid.GridFactory; import org.gridgain.grid.gridify.GridifyArgument; import org.gridgain.grid.gridify.GridifyArgumentAdapter; import org.gridgain.grid.kernal.GridifyDefaultTask; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.task.TaskExecutor; public class GridGrainTaskExecutor implements TaskExecutor, InitializingBean, DisposableBean { private Grid grid; public void setGrid(Grid grid) { this.grid = grid; } private GridConfiguration gridConfiguration; public void setGridConfiguration(GridConfiguration gridConfiguration) { this.gridConfiguration = gridConfiguration; } public void execute(Runnable runnable) { if (runnable != null) { GridifyArgument argument = new GridifyArgumentAdapter( runnable.getClass(), "run", new Class[] {}, new Object[] {}, runnable); grid.execute(GridifyDefaultTask.class.getName(), argument, 0); } } private boolean gridCreated = false; public void afterPropertiesSet() throws Exception { if (grid == null) { if (gridConfiguration != null) { grid = GridFactory.start(gridConfiguration); } else { grid = GridFactory.start(); } gridCreated = true; } } public void destroy() throws Exception { if (gridCreated) { GridFactory.stop(true); } } }
Tentacle


