Dmitriy Setrakyan manages daily operations of GridGain Systems and brings over 12 years of experience to GridGain Systems which spans all areas of application software development from design and architecture to team management and quality assurance. His experience includes architecture and leadership in development of distributed middleware platforms, financial trading systems, CRM applications, and more. Dmitriy is a DZone MVB and is not an employee of DZone and has posted 57 posts at DZone. You can read more from them at their website. View Full User Profile

Get Productive With GridGain

08.14.2008
| 5501 views |
  • submit to reddit

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 {
@Gridify
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();

cfg1.setGridName("grid1");
cfg2.setGridName("grid2");

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

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

Object result = future.get();

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

Published at DZone with permission of Dmitriy Setrakyan, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Dmitriy Setrakyan replied on Thu, 2008/08/14 - 5:34pm

For some odd reason (I am sure by accident) this article got cut in half.

Please read the full version here: Get Productive With GridGain

Best,
Dmitriy Setrakyan
GridGain Systems - Grid Computing Made Simple

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.