This example does the following:
- Splits given string into individual words and creates grid jobs for each word.
- Every job will save in storage the word passed into it, print it and return the number of letters in that word.
Starting Remote Nodes
To try this example you should start remote grid instances. You can start as many as you like by executing the following script (which simply invokes GridJbossCacheExampleNodeLoader.java): GRIDGAIN_HOME/examples/jbosscache/start-node.bat|sh
Once remote instances are started, you can execute this example from Eclipse, Idea, or NetBeans (or any other IDE) by simply hitting run button. You will witness that all nodes discover each other and will participate in task execution.
Full Source Code
GridResourcesExample.java
package org.gridgain.examples.resources; import org.gridgain.grid.*; public final class GridResourcesExample { /** * Ensure singleton. */ private GridResourcesExample() { // No-op. } /** * Execute <tt>Resources</tt> example on the grid. * * @param args Command line arguments, none required but if provided * first one should point to the Spring XML configuration file. See * <tt>"examples/config/"</tt> for configuration file examples. * @throws Exception If example execution failed. */ public static void main(String[] args) throws Exception { if (args.length == 0) { GridFactory.start(); } else { GridFactory.start(args[0]); } try { Grid grid = GridFactory.getGrid(); // Execute task. GridTaskFuture<Integer> future = grid.execute(GridResourcesTask.class, "Grid Computing Made Simple with GridGain"); // Wait for task completion. int phraseLen = future.get(); System.out.println(">>>"); System.out.println(">>> Finished executing Grid \"Grid Computing Made Simple with GridGain\" " + "example with custom task."); System.out.println(">>> Total number of characters in the phrase is '" + phraseLen + "'."); System.out.println(">>> You should see print out of 'Hello' on one node and 'World' on another node."); System.out.println(">>> Check all nodes for output (this node is also part of the grid)."); System.out.println(">>>"); } finally { GridFactory.stop(true); } } }
