Over a million developers have joined DZone.
Gold Partner

Get Productive With GridGain

· Java Zone

From the get go we put developers productivity as one of our main goals without sacrificing any enterprise grid computing features. But then you would think – how easy can it really get, any product can be installed and set up relatively easy. Here is a good analogy for you – think IPhone. I never thought that using my Motorola cell phone was hard, but IPhone just makes my life a lot easier. I can now check weather or flight status within seconds (things I didn’t even bother doing on my old cell phone). The same kind of productivity boost you get with GridGain. Take a look at some of the GridGain features that make it so easy to use and work with.

Uniform Programing Model

This basicaly means that your application should produce the same results wthether there is no grid, 1 node in the grid, or a 1000 nodes in the grid (of course the more nodes you add, the faster and more scalable your application should become). When writing your boiler plate code you should not worry about grid-enabling it. However, if you ever do need to grid-enable it, grid-enabling logic should be orthogonal to your business logic. GridGain provides two ways you can grid-enable your code.

Transparent Grid-Enabling

With transparent grid enabling you can move execution of your code to the grid by simply attaching @Gridify annotation to it, like so:

public class BizLogic {
public Object process(Object arg) throws ProcessException {
// Perform bizness logic here.

Without GridGain, method process(..) above would simply run locally, as usual. However, by simply attaching @Gridify annotation, the execution of this method will be taken to a remote grid node. This alone can significantly improve scalability of your application, as now you have automatic fail-over, node topology management, and load balancing provided to you by GridGain out of the box.

Now, if you decided that your method process(..) takes too long and you need to split its execution, you would need to implement GridTask interface to tell GridGain how your logic will be split. However, the only change you would need to make to your main code is specify which task it should use like so:

@Gridify(taskClass = MyProcessTask.class)

API-based Grid Enabling

If you would like to use direct API calls instead of @Gridify annotation or if you need to wait for results asynchronously, GridGain allows you to do it as well. Simply invoke any of the Grid.execute(..) methods directly as following:

Grid grid = GridFactory.start(); 

// Execute.
GridTaskFuture<Object> future =
grid.execute(MyProcessTask.class, /*task argument*/someArg);

// Wait for result.
Object result = future.get();

GridTaskListener resultListener = new MyProcessTaskResultListener(); 

grid.execute(MyProcessTask.class, someArg, resultListener);

public MyGridTest extends TestCase {
// Simple test case.
public void testGrid() throws Exception {
GridConfiguration cfg1 = new GridConfigurationAdapter();
GridConfiguration cfg2 = new GridConfigurationAdapter();


try {
Grid grid1 = GridFactory.start(cfg1);
Grid grid2 = GridFactory.start(cfg2);

GridTaskFuture<Object> future = grid1.execute(MyTestTask.class, ...);

Object result = future.get();

finally {
GridFactory.stop("grid1", true);
GridFactory.stop("grid2", true);


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}