Grid-enabling is a process of making a piece of Java code to execute on the grid. In GridGain, there are two ways to do grid-enabling:
| Direct Execution vs. Annotation-Based AOP There is no better or worse between these two methods. They both have their areas of applicability. When creating grid task you basically have the same programming and development model as in JEE: you create a component, deploy it and execute it. With annotation-based grid-enabling you have an extra option of transparently attaching grid-enabling logic to existing code without modifying it (except for additional annotation). |
API-Based Grid Task Execution
This method allows to grid-enable any arbitrary Java code. You have a full control on split and aggregate logic and all other aspects of grid task execution. Here is an example of direct grid task execution:
public static void main(String[] args) throws GridException { GridFactory.start(); try { Grid grid = GridFactory.getGrid(); // Execute task. GridTaskFuture<String> future = grid.execute(FooBarTask.class, "Argument"); // Wait for task completion. String result = fugure.get(); // Print out task result. System.out.println("Task result: " + result); } finally { GridFactory.stop(true); } }
Refer to HelloWorld - Basic Grid Task for more coding examples.
Annotate Existing Method With Gridify Annotation
The only difference of this method vs. directly executing grid task is that you can annotate a regular Java method and it will become grid-enabled. Using this technique you can still have custom grid task that will handle annotation-based grid-enabling (including split & aggregate logic or passing state to remote jobs) but you will be limited to the boundaries of the method you are grid-enabling. Here is an example of such usage:
@Gridify(taskClass = FooBarTask.class, timeout = 3000) public void sayIt(String arg) { // Some business logic. }
Refer to HelloWorld - Gridify With Custom Task for more coding examples.
For information on how to configure AOP, refer to AOP Configuration section.
| Serializable State Note that when using @Gridify |
