GridGain™ 3.6.0e
Enterprise Edition

org.gridgain.grid
Interface GridRichNode

All Superinterfaces:
Comparable<GridRichNode>, GridMetadataAware, GridNode, GridProjection, GridTypedProduct<GridRichNode>, Iterable<GridRichNode>, Serializable

public interface GridRichNode
extends GridProjection, GridNode, Comparable<GridRichNode>, GridTypedProduct<GridRichNode>

Defines a "rich" node as a single node-based grid projection.

All main grid entities such as grid, projection and a node instances can be viewed as collection of grid nodes (in case of the grid node this collection consist of only one element). As such they all share the same set of operations that can be performed on a set grid nodes. These operations are defined in GridProjection interface and called monadic as they are equally defined on any arbitrary set of nodes.

Thread Safety

Implementation of this interface provides necessary thread synchronization.

Nullable and Monads

Many methods in this interface accepts nullable parameters. Although it may seem counter intuitive for some of them - it is done to promote monadic usage of this interface. Java doesn't support natively concepts like Option in Scala and returning, accepting, and properly handling null values is Java's way to support such monadic invocations.

All methods that accept null values (for monadic purposes) will gracefully handle it by either returning a finished future, or empty collection, null value, or combination of the above. Most method calls therefore can be chained without an explicit checks for nulls.

The downside of this approach that inadvertent errors of passing null will not result in NullPointerException and may be harder to catch.

Wiki & Forum:


Wiki
Forum

 

Method Summary
<R> R
call(Callable<R> job)
          Convenient shortcut that executes given closure on this node.
<R> Collection<R>
call(Collection<? extends Callable<R>> jobs)
          Convenient shortcut that executes given closures on this node.
<R> GridFuture<R>
callAsync(Callable<R> job)
          Convenient shortcut that asynchronously executes given closure on this node.
<R> GridFuture<Collection<R>>
callAsync(Collection<? extends Callable<R>> jobs)
          Convenient shortcut that asynchronously executes given closures on this node.
<R1,R2> R2
forkjoin(Collection<? extends Callable<R1>> jobs, GridReducer<R1,R2> rdc)
          Convenient shortcut that executes given jobs on this node and reduces their results.
<R1,R2> GridFuture<R2>
forkjoinAsync(Collection<? extends Callable<R1>> jobs, GridReducer<R1,R2> rdc)
          Convenient shortcut that asynchronously executes given jobs on this node.
 String gridName()
          Gets name of the grid this node belongs to.
 String id8()
          Gets first 8 characters from node ID.
 boolean isDaemon()
          Tests whether or not this node is a daemon.
 boolean isLocal()
          Tests whether or not this node is a local node.
 GridProjection neighbors()
          Gets the projection on all nodes that reside on the same physical computer as this node.
 GridProjection neighborsAndMe()
          Gets the projection on all nodes that reside on the same physical computer as this node.
<T> T
nodeLocalCall(Object key, GridClosure<Object,T> c)
          Runs given closure on this node using value from node local storage of this node.
<T> GridFuture<T>
nodeLocalCallAsync(Object key, GridClosure<Object,T> c)
          Runs given closure on this node using value from node local storage of this node.
<T> T
nodeLocalGet(Object key)
          Gets node local value from this node with given key.
<T> GridFuture<T>
nodeLocalGetAsync(Object key)
          Gets node local value from this node with given key.
<T> T
nodeLocalPut(Object key, Object val)
          Puts value into node local storage of this node.
<T> GridFuture<T>
nodeLocalPutAsync(Object key, Object val)
          Puts value into node local storage of this node.
 void nodeLocalRun(Object key, GridInClosure<Object> c)
          Runs given closure on this node using value from node local storage of this node.
 GridFuture<?> nodeLocalRunAsync(Object key, GridInClosure<Object> c)
          Runs given closure on this node using value from node local storage of this node.
 GridNode originalNode()
          Gets the original grid node wrapped by this rich interface.
 GridProjection others(GridPredicate<? super GridRichNode>... p)
          Gets projection of all other nodes in the grid excluding this node.
 boolean ping()
          Pings this node.
 void run(Collection<? extends Runnable> jobs)
          Convenient shortcut that executes given closures on this node.
 void run(Runnable job)
          Convenient shortcut that executes given closure on this node.
 GridFuture<?> runAsync(Collection<? extends Runnable> jobs)
          Convenient shortcut that asynchronously executes given closures on this node.
 GridFuture<?> runAsync(Runnable job)
          Convenient shortcut that asynchronously executes given closure on this node.
 
Methods inherited from interface org.gridgain.grid.GridProjection
affinityCall, affinityCall, affinityCallAsync, affinityCallAsync, affinityRun, affinityRun, affinityRunAsync, affinityRunAsync, call, call, call, call, call, call, call, callAsync, callAsync, callAsync, callAsync, callAsync, callAsync, callAsync, callOptimistic, callOptimisticAsync, contains, contains, cpus, cross, cross, cross0, daemonNodes, dynamic, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, execute, executeSync, executeSync, executeSync, executor, grid, gridify, gridify, gridify, gridify, gridify, gridify, gridify, gridify, gridify, gridify, gridify, gridify, hasLocalNode, hasRemoteNodes, hosts, isEmpty, isEmptyFor, listen, mapKeysToNodes, mapKeysToNodes, mapKeyToNode, mapKeyToNode, mapreduce, mapreduce, mapreduce, mapreduce, mapreduceAsync, mapreduceAsync, mapreduceAsync, mapreduceAsync, merge, neighborhood, node, nodeId8, nodes, nodes, oldest, oldestx, parent, predicate, projectionForAttribute, projectionForCaches, projectionForNodeIds, projectionForNodeIds, projectionForNodes, projectionForNodes, projectionForPredicate, projectionMetrics, random, randomx, reduce, reduce, reduce, reduce, reduceAsync, reduceAsync, reduceAsync, reduceAsync, remoteEvents, remoteEventsAsync, remoteListenAsync, remoteListenAsync, remoteListenAsync, remoteNodes, remoteProjection, restartNodes, restartNodes, restartNodes, run, run, run, run, run, run, run, runAsync, runAsync, runAsync, runAsync, runAsync, runAsync, runAsync, runOptimistic, runOptimisticAsync, send, send, size, split, startNodes, startNodes, stopNodes, stopNodes, stopNodes, topologyHash, withCheckpointSpi, withFailoverSpi, withLoadBalancingSpi, withName, withResultClosure, withTopologySpi, youngest, youngestx
 
Methods inherited from interface org.gridgain.grid.GridNode
attribute, attributes, externalAddresses, id, internalAddresses, metrics, order
 
Methods inherited from interface org.gridgain.grid.GridMetadataAware
addMeta, addMetaIfAbsent, addMetaIfAbsent, allMeta, copyMeta, copyMeta, hasMeta, hasMeta, meta, putMetaIfAbsent, putMetaIfAbsent, removeMeta, removeMeta, replaceMeta
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface org.gridgain.grid.lang.GridTypedProduct
arity, part
 
Methods inherited from interface java.lang.Iterable
iterator
 

Method Detail

neighbors

GridProjection neighbors()
Gets the projection on all nodes that reside on the same physical computer as this node. This node is excluded. Note that this method returns an empty projection when this node is the only node on its host.

Detection of the same physical computer is based on comparing set of network interface MACs. If two nodes have the same set of MACs, GridGain considers these nodes running on the same physical computer. Note that this same logic is used in license management.

Knowing your neighbors can be very important when performing a dynamic split since nodes on the same computer will often bypass network when communicating with each other leading to much better performance for certain use cases. Conversely, one would like to avoid loading the nodes from the same physical computer with tasks as these nodes share CPU and memory between them resulting in reduced performance comparing to a no-neighboring split.

Returns:
Project containing all nodes that reside on the same physical computer as this node (excluding this node). This method never returns null but may return an empty projection.
See Also:
GridProjection.neighborhood(), GridRichNode.neighborsAndMe()

neighborsAndMe

GridProjection neighborsAndMe()
Gets the projection on all nodes that reside on the same physical computer as this node. This node is included. Note that this method will never returns an empty projection.

Detection of the same physical computer is based on comparing set of network interface MACs. If two nodes have the same set of MACs, GridGain considers these nodes running on the same physical computer. Note that this same logic is used in license management.

Knowing your neighbors can be very important when performing a dynamic split since nodes on the same computer will often bypass network when communicating with each other leading to much better performance for certain use cases. Conversely, one would like to avoid loading the nodes from the same physical computer with tasks as these nodes share CPU and memory between them resulting in reduced performance comparing to a no-neighboring split.

Returns:
Project containing all nodes that reside on the same physical computer as this node (including this node). This method never returns null or an empty projection.
See Also:
GridProjection.neighborhood(), GridRichNode.neighbors()

others

GridProjection others(@Nullable
                      GridPredicate<? super GridRichNode>... p)
Gets projection of all other nodes in the grid excluding this node. This method returns an empty projection when this is the only node in the topology.

Parameters:
p - Optional filtering predicate. Only nodes that evaluate to true or all given predicate will be included into resulting projection.
Returns:
Projection of all other nodes in the grid excluding this node. This method never returns null but returns an empty projection when this is the only node in the topology.

originalNode

GridNode originalNode()
Gets the original grid node wrapped by this rich interface. This should almost never be used in application code and exist only for internal purposes.

Returns:
Original grid node.

isLocal

boolean isLocal()
Tests whether or not this node is a local node.

Returns:
True if this node is a local node, false otherwise.

isDaemon

boolean isDaemon()
Tests whether or not this node is a daemon.

Daemon nodes are the usual grid nodes that participate in topology but not visible on the main APIs, i.e. they are not part of any projections. The only way to see daemon nodes is to use GridProjection.daemonNodes(GridPredicate[]) method.

Daemon nodes are used primarily for management and monitoring functionality that is build on GridGain and needs to participate in the topology but should be excluded from "normal" topology so that it won't participate in task execution or data grid.

Application code should never use daemon nodes.

Returns:
True if this node is a daemon, false otherwise.

gridName

@Nullable
String gridName()
Gets name of the grid this node belongs to.

Returns:
Name of the grid this node belongs to. Note that default grid has null name.

ping

boolean ping()
Pings this node.

Discovery SPIs usually have some latency in discovering failed nodes. Hence, communication to remote nodes may fail at times if an attempt was made to establish communication with a failed node. This method can be used to check if communication has failed due to node failure or due to some other reason.

Returns:
true if node for a given ID is alive, false otherwise.
See Also:
Grid.pingNode(UUID)

id8

String id8()
Gets first 8 characters from node ID. This is non-unique ID can be used for informational purposes where it is more convenient that a longer but guaranteed unique node ID.

Returns:
8-character non-unique node ID.

callAsync

<R> GridFuture<R> callAsync(@Nullable
                            Callable<R> job)
                        throws GridException
Convenient shortcut that asynchronously executes given closure on this node.

Unlike its sibling method GridRichNode.call(Callable) this method does not block and returns immediately with future. All default SPI implementations configured for this grid instance will be used (i.e. failover, load balancing, collision resolution, etc.). Note that if you need greater control on any aspects of Java code execution on the grid you should implement GridTask which will provide you with full control over the execution.

Note that class GridAbsClosure implements Runnable and class GridOutClosure implements Callable interface. Note also that class GridFunc and typedefs provide rich APIs and functionality for closures and predicates based processing in GridGain. While Java interfaces Runnable and Callable allow for lowest common denominator for APIs - it is advisable to use richer Functional Programming support provided by GridGain available in org.gridgain.grid.lang package.

Notice that Runnable and Callable implementations must support serialization as required by the configured marshaller. For example, JDK marshaller will require that implementations would be serializable. Other marshallers, e.g. JBoss marshaller, may not have this limitation. Please consult with specific marshaller implementation for the details. Note that all closures and predicates in org.gridgain.grid.lang package are serializable and can be freely used in the distributed context with all marshallers currently shipped with GridGain.

Throws:
GridException - Thrown in case of any error.
Type Parameters:
R - Type of the closure return value.
Parameters:
job - Closure to invoke. If null - this method is no-op.
Returns:
Non-cancellable closure result future.
See Also:
PN, GridProjection.call(GridClosureCallMode, Callable, GridPredicate[])

callAsync

<R> GridFuture<Collection<R>> callAsync(@Nullable
                                        Collection<? extends Callable<R>> jobs)
                                    throws GridException
Convenient shortcut that asynchronously executes given closures on this node.

Unlike its sibling method GridRichNode.call(Collection) this method does not block and returns immediately with future. All default SPI implementations configured for this grid instance will be used (i.e. failover, load balancing, collision resolution, etc.). Note that if you need greater control on any aspects of Java code execution on the grid you should implement GridTask which will provide you with full control over the execution.

Note that class GridAbsClosure implements Runnable and class GridOutClosure implements Callable interface. Note also that class GridFunc and typedefs provide rich APIs and functionality for closures and predicates based processing in GridGain. While Java interfaces Runnable and Callable allow for lowest common denominator for APIs - it is advisable to use richer Functional Programming support provided by GridGain available in org.gridgain.grid.lang package.

Notice that Runnable and Callable implementations must support serialization as required by the configured marshaller. For example, JDK marshaller will require that implementations would be serializable. Other marshallers, e.g. JBoss marshaller, may not have this limitation. Please consult with specific marshaller implementation for the details. Note that all closures and predicates in org.gridgain.grid.lang package are serializable and can be freely used in the distributed context with all marshallers currently shipped with GridGain.

Throws:
GridException - Thrown in case of any error.
Type Parameters:
R - Type of the closure return value.
Parameters:
jobs - Closures to invoke. If null or empty - this method is no-op.
Returns:
Future collection of closure results. Order is undefined.
See Also:
PN

forkjoinAsync

<R1,R2> GridFuture<R2> forkjoinAsync(@Nullable
                                     Collection<? extends Callable<R1>> jobs,
                                     @Nullable
                                     GridReducer<R1,R2> rdc)
                             throws GridException
Convenient shortcut that asynchronously executes given jobs on this node.

Unlike its sibling method GridRichNode.forkjoin(Collection, GridReducer) this method does not block and returns immediately with future. All default SPI implementations configured for this grid instance will be used (i.e. failover, load balancing, collision resolution, etc.). Note that if you need greater control on any aspects of Java code execution on the grid you should implement GridTask which will provide you with full control over the execution.

Note that class GridAbsClosure implements Runnable and class GridOutClosure implements Callable interface. Note also that class GridFunc and typedefs provide rich APIs and functionality for closures and predicates based processing in GridGain. While Java interfaces Runnable and Callable allow for lowest common denominator for APIs - it is advisable to use richer Functional Programming support provided by GridGain available in org.gridgain.grid.lang package.

Notice that Runnable and Callable implementations must support serialization as required by the configured marshaller. For example, JDK marshaller will require that implementations would be serializable. Other marshallers, e.g. JBoss marshaller, may not have this limitation. Please consult with specific marshaller implementation for the details. Note that all closures and predicates in org.gridgain.grid.lang package are serializable and can be freely used in the distributed context with all marshallers currently shipped with GridGain.

Throws:
GridException - Thrown in case of any error.
Type Parameters:
R1 - Closure result type.
R2 - Type of the reduced value.
Parameters:
jobs - Closures to executes. If null or empty - this method is no-op.
rdc - Result reducing closure If null - this method is no-op.
Returns:
Future value produced by reducing closure.
See Also:
PN

runAsync

GridFuture<?> runAsync(@Nullable
                       Runnable job)
                       throws GridException
Convenient shortcut that asynchronously executes given closure on this node.

Unlike its sibling method GridRichNode.run(Runnable) this method does not block and returns immediately with future. All default SPI implementations configured for this grid instance will be used (i.e. failover, load balancing, collision resolution, etc.). Note that if you need greater control on any aspects of Java code execution on the grid you should implement GridTask which will provide you with full control over the execution.

Note that class GridAbsClosure implements Runnable and class GridOutClosure implements Callable interface. Note also that class GridFunc and typedefs provide rich APIs and functionality for closures and predicates based processing in GridGain. While Java interfaces Runnable and Callable allow for lowest common denominator for APIs - it is advisable to use richer Functional Programming support provided by GridGain available in org.gridgain.grid.lang package.

Notice that Runnable and Callable implementations must support serialization as required by the configured marshaller. For example, JDK marshaller will require that implementations would be serializable. Other marshallers, e.g. JBoss marshaller, may not have this limitation. Please consult with specific marshaller implementation for the details. Note that all closures and predicates in org.gridgain.grid.lang package are serializable and can be freely used in the distributed context with all marshallers currently shipped with GridGain.

Throws:
GridException - Thrown in case of any error.
Parameters:
job - Job closure to execute. If null - this method is no-op.
Returns:
Non-cancellable future of this execution.
See Also:
PN, GridProjection.run(GridClosureCallMode, Runnable, GridPredicate[])

runAsync

GridFuture<?> runAsync(@Nullable
                       Collection<? extends Runnable> jobs)
                       throws GridException
Convenient shortcut that asynchronously executes given closures on this node.

Unlike its sibling method GridRichNode.run(Collection) this method does not block and returns immediately with future. All default SPI implementations configured for this grid instance will be used (i.e. failover, load balancing, collision resolution, etc.). Note that if you need greater control on any aspects of Java code execution on the grid you should implement GridTask which will provide you with full control over the execution.

Note that class GridAbsClosure implements Runnable and class GridOutClosure implements Callable interface. Note also that class GridFunc and typedefs provide rich APIs and functionality for closures and predicates based processing in GridGain. While Java interfaces Runnable and Callable allow for lowest common denominator for APIs - it is advisable to use richer Functional Programming support provided by GridGain available in org.gridgain.grid.lang package.

Notice that Runnable and Callable implementations must support serialization as required by the configured marshaller. For example, JDK marshaller will require that implementations would be serializable. Other marshallers, e.g. JBoss marshaller, may not have this limitation. Please consult with specific marshaller implementation for the details. Note that all closures and predicates in org.gridgain.grid.lang package are serializable and can be freely used in the distributed context with all marshallers currently shipped with GridGain.

Throws:
GridException - Thrown in case of any error.
Parameters:
jobs - Job closures to execute. If null or empty - this method is no-op.
Returns:
Non-cancellable future of this execution.
See Also:
PN, GridProjection.run(GridClosureCallMode, Collection, GridPredicate[])

run

void run(@Nullable
         Runnable job)
         throws GridException
Convenient shortcut that executes given closure on this node. This method simply delegates to GridProjection.run(GridClosureCallMode, Runnable, GridPredicate[]).

This method will block until the execution is complete. All default SPI implementations configured for this grid instance will be used (i.e. failover, load balancing, collision resolution, etc.). Note that if you need greater control on any aspects of Java code execution on the grid you should implement GridTask which will provide you with full control over the execution.

Here's a general example of the Java method that takes a text message, splits it into individual words and prints each word on an individual grid node using typedefs, functional APIs and closure execution on the grid:

 public static void sayIt(String phrase) throws GridException {
     G.grid().call(SPREAD, F.yield(phrase.split(" "), F.<String>printf("%s")));
 }
 

Note that class GridAbsClosure implements Runnable and class GridOutClosure implements Callable interface. Note also that class GridFunc and typedefs provide rich APIs and functionality for closures and predicates based processing in GridGain. While Java interfaces Runnable and Callable allow for lowest common denominator for APIs - it is advisable to use richer Functional Programming support provided by GridGain available in org.gridgain.grid.lang package.

Notice that Runnable and Callable implementations must support serialization as required by the configured marshaller. For example, JDK marshaller will require that implementations would be serializable. Other marshallers, e.g. JBoss marshaller, may not have this limitation. Please consult with specific marshaller implementation for the details. Note that all closures and predicates in org.gridgain.grid.lang package are serializable and can be freely used in the distributed context with all marshallers currently shipped with GridGain.

Throws:
GridException - Thrown in case of any error.
GridInterruptedException - Subclass of GridException thrown if the wait was interrupted.
GridFutureCancelledException - Subclass of GridException throws if computation was cancelled.
Parameters:
job - Job closure to execute. If null - this method is no-op.

run

void run(@Nullable
         Collection<? extends Runnable> jobs)
         throws GridException
Convenient shortcut that executes given closures on this node. This method simply delegates to GridProjection.run(GridClosureCallMode, Collection, GridPredicate[]).

This method will block until the execution is complete. All default SPI implementations configured for this grid instance will be used (i.e. failover, load balancing, collision resolution, etc.). Note that if you need greater control on any aspects of Java code execution on the grid you should implement GridTask which will provide you with full control over the execution.

Here's a general example of the Java method that takes a text message, splits it into individual words and prints each word on an individual grid node using typedefs, functional APIs and closure execution on the grid:

 public static void sayIt(String phrase) throws GridException {
     G.grid().call(SPREAD, F.yield(phrase.split(" "), F.<String>printf("%s")));
 }
 

Note that class GridAbsClosure implements Runnable and class GridOutClosure implements Callable interface. Note also that class GridFunc and typedefs provide rich APIs and functionality for closures and predicates based processing in GridGain. While Java interfaces Runnable and Callable allow for lowest common denominator for APIs - it is advisable to use richer Functional Programming support provided by GridGain available in org.gridgain.grid.lang package.

Notice that Runnable and Callable implementations must support serialization as required by the configured marshaller. For example, JDK marshaller will require that implementations would be serializable. Other marshallers, e.g. JBoss marshaller, may not have this limitation. Please consult with specific marshaller implementation for the details. Note that all closures and predicates in org.gridgain.grid.lang package are serializable and can be freely used in the distributed context with all marshallers currently shipped with GridGain.

Throws:
GridException - Thrown in case of any error.
GridInterruptedException - Subclass of GridException thrown if the wait was interrupted.
GridFutureCancelledException - Subclass of GridException throws if computation was cancelled.
Parameters:
jobs - Job closures to execute. If null or empty - this method is no-op.

call

<R> R call(@Nullable
           Callable<R> job)
       throws GridException
Convenient shortcut that executes given closure on this node. This method simply delegates to GridProjection.call(GridClosureCallMode, Callable, org.gridgain.grid.lang.GridPredicate[]).

This method will block until the execution is complete. All default SPI implementations configured for this grid instance will be used (i.e. failover, load balancing, collision resolution, etc.). Note that if you need greater control on any aspects of Java code execution on the grid you should implement GridTask which will provide you with full control over the execution.

Here's a general example of the Java method that takes a text message, splits it into individual words and prints each word on an individual grid node using typedefs, functional APIs and closure execution on the grid:

 public static void sayIt(String phrase) throws GridException {
     G.grid().call(SPREAD, F.yield(phrase.split(" "), F.<String>printf("%s")));
 }
 

Note that class GridAbsClosure implements Runnable and class GridOutClosure implements Callable interface. Note also that class GridFunc and typedefs provide rich APIs and functionality for closures and predicates based processing in GridGain. While Java interfaces Runnable and Callable allow for lowest common denominator for APIs - it is advisable to use richer Functional Programming support provided by GridGain available in org.gridgain.grid.lang package.

Notice that Runnable and Callable implementations must support serialization as required by the configured marshaller. For example, JDK marshaller will require that implementations would be serializable. Other marshallers, e.g. JBoss marshaller, may not have this limitation. Please consult with specific marshaller implementation for the details. Note that all closures and predicates in org.gridgain.grid.lang package are serializable and can be freely used in the distributed context with all marshallers currently shipped with GridGain.

Throws:
GridException - Thrown in case of any error.
GridInterruptedException - Subclass of GridException thrown if the wait was interrupted.
GridFutureCancelledException - Subclass of GridException throws if computation was cancelled.
Type Parameters:
R - Type of the closure return value.
Parameters:
job - Closure to invoke. If null - this method is no-op.
Returns:
Closure result.

call

<R> Collection<R> call(@Nullable
                       Collection<? extends Callable<R>> jobs)
                   throws GridException
Convenient shortcut that executes given closures on this node. This method simply delegates to GridProjection.call(GridClosureCallMode, Collection, GridPredicate[])

This method will block until the execution is complete. All default SPI implementations configured for this grid instance will be used (i.e. failover, load balancing, collision resolution, etc.). Note that if you need greater control on any aspects of Java code execution on the grid you should implement GridTask which will provide you with full control over the execution.

Here's a general example of the Java method that takes a text message, splits it into individual words and prints each word on an individual grid node using typedefs, functional APIs and closure execution on the grid:

 public static void sayIt(String phrase) throws GridException {
     G.grid().call(SPREAD, F.yield(phrase.split(" "), F.<String>printf("%s")));
 }
 

Note that class GridAbsClosure implements Runnable and class GridOutClosure implements Callable interface. Note also that class GridFunc and typedefs provide rich APIs and functionality for closures and predicates based processing in GridGain. While Java interfaces Runnable and Callable allow for lowest common denominator for APIs - it is advisable to use richer Functional Programming support provided by GridGain available in org.gridgain.grid.lang package.

Notice that Runnable and Callable implementations must support serialization as required by the configured marshaller. For example, JDK marshaller will require that implementations would be serializable. Other marshallers, e.g. JBoss marshaller, may not have this limitation. Please consult with specific marshaller implementation for the details. Note that all closures and predicates in org.gridgain.grid.lang package are serializable and can be freely used in the distributed context with all marshallers currently shipped with GridGain.

Throws:
GridException - Thrown in case of any error.
GridInterruptedException - Subclass of GridException thrown if the wait was interrupted.
GridFutureCancelledException - Subclass of GridException throws if computation was cancelled.
Type Parameters:
R - Type of the closure return value.
Parameters:
jobs - Closures to invoke. If null or empty - this method is no-op.
Returns:
Collection of closure results. Order is undefined.

forkjoin

<R1,R2> R2 forkjoin(@Nullable
                    Collection<? extends Callable<R1>> jobs,
                    @Nullable
                    GridReducer<R1,R2> rdc)
            throws GridException
Convenient shortcut that executes given jobs on this node and reduces their results. This method simply delegates to GridProjection.reduce(GridClosureCallMode, Collection, GridReducer, GridPredicate[]).

This method will block until its execution is complete or an exception is thrown. All default SPI implementations configured for this grid instance will be used (i.e. failover, load balancing, collision resolution, etc.). Note that if you need greater control on any aspects of Java code execution on the grid you should implement GridTask which will provide you with full control over the execution.

Here's a general example of the Java method that takes a text message and calculates its length by splitting it by spaces, calculating the length of each word on individual (remote) grid node and then summing (reducing) results from all nodes to produce the final length of the input string using function APIs, typedefs, and execution closures on the grid:

 public static int length(final String msg) throws GridException {
     return G.grid().reduce(SPREAD,
         F.yield(
             msg.split(" "),
             new C1<String, Integer>() {
                 @Override public Integer apply(String e) { return e.length(); }
             }
         ),
         new R1<Integer, Integer>() {
             private int len = 0;

             @Override public void apply(Integer e) { len += e + 1; }
             @Override public Integer reduce() { return len - 1; }
         }
     );
 }
 

Note that class GridAbsClosure implements Runnable and class GridOutClosure implements Callable interface. Note also that class GridFunc and typedefs provide rich APIs and functionality for closures and predicates based processing in GridGain. While Java interfaces Runnable and Callable allow for lowest common denominator for APIs - it is advisable to use richer Functional Programming support provided by GridGain available in org.gridgain.grid.lang package.

Notice that Runnable and Callable implementations must support serialization as required by the configured marshaller. For example, JDK marshaller will require that implementations would be serializable. Other marshallers, e.g. JBoss marshaller, may not have this limitation. Please consult with specific marshaller implementation for the details. Note that all closures and predicates in org.gridgain.grid.lang package are serializable and can be freely used in the distributed context with all marshallers currently shipped with GridGain.

Throws:
GridException - Thrown in case of any error.
GridInterruptedException - Subclass of GridException thrown if the wait was interrupted.
GridFutureCancelledException - Subclass of GridException throws if computation was cancelled.
Type Parameters:
R1 - Closure result type.
R2 - Type of the reduced value.
Parameters:
jobs - Closures to executes. If null or empty - this method is no-op.
rdc - Result reducing closure. If null - this method is no-op.
Returns:
Value produced by reducing closure.

nodeLocalGet

<T> T nodeLocalGet(Object key)
               throws GridException
Gets node local value from this node with given key. If this node is remote the value will be fetched from the remote node. Note that this method will block until the value is retrieved. Note also that key must serializable as per current marshaller.

Note that for the local node this method will be optimized to avoid unnecessary distribution overhead and operation will be performed in a local context.

Throws:
GridException - Thrown in case of any failure.
GridInterruptedException - Subclass of GridException thrown if the wait was interrupted.
GridFutureCancelledException - Subclass of GridException throws if computation was cancelled.
Type Parameters:
T - Type of the value.
Parameters:
key - Node local ket.
Returns:
Node local value from this node.
See Also:
GridRichNode.nodeLocalGetAsync(Object)

nodeLocalGetAsync

<T> GridFuture<T> nodeLocalGetAsync(Object key)
                                throws GridException
Gets node local value from this node with given key. If this node is remote the value will be fetched from the remote node. Note that unlike its sibling GridRichNode.nodeLocalGet(Object) this method will not block and will return immediately with future. Note also that key must be serializable as per current marshaller.

Note that for the local node this method will be optimized to avoid unnecessary distribution overhead and operation will be performed in a local context.

Throws:
GridException - Thrown in case of any failure.
Type Parameters:
T - Type of the value.
Parameters:
key - Node local ket.
Returns:
Future of node local value from this node.
See Also:
GridRichNode.nodeLocalGet(Object)

nodeLocalPut

<T> T nodeLocalPut(Object key,
                   @Nullable
                   Object val)
               throws GridException
Puts value into node local storage of this node. If this node is remote the value will be transfered to remote node and put there in remote node's local storage. Note that unlike its sibling GridRichNode.nodeLocalPutAsync(Object, Object) this method will block until operation is complete. Note also that key and value must be serializable as per current marshaller.

Note that for the local node this method will be optimized to avoid unnecessary distribution overhead and operation will be performed in a local context.

Throws:
GridException - Thrown in case of any failure.
Type Parameters:
T - Type of the previous value, if any.
Parameters:
key - Node local key.
val - Node local value.
Returns:
Previous value or null.

nodeLocalPutAsync

<T> GridFuture<T> nodeLocalPutAsync(Object key,
                                    @Nullable
                                    Object val)
                                throws GridException
Puts value into node local storage of this node. If this node is remote the value will be transfered to remote node and put there in remote node's local storage. Note that unlike its sibling GridRichNode.nodeLocalPut(Object, Object) this method will not block and will return with the future. Note also that key and value must be serializable as per current marshaller.

Note that for the local node this method will be optimized to avoid unnecessary distribution overhead and operation will be performed in a local context.

Throws:
GridException - Thrown in case of any failure.
Type Parameters:
T - Type of the previous value, if any.
Parameters:
key - Node local key.
val - Node local value.
Returns:
Future of previous value.

nodeLocalRun

void nodeLocalRun(Object key,
                  @Nullable
                  GridInClosure<Object> c)
                  throws GridException
Runs given closure on this node using value from node local storage of this node. Note that unlike its sibling GridRichNode.nodeLocalRunAsync(Object, GridInClosure) this method will block until operation is complete. Note also that key must be serializable as per current marshaller.

Note that for the local node this method will be optimized to avoid unnecessary distribution overhead and operation will be performed in a local context.

Throws:
GridException - Thrown in case of any failure.
Parameters:
key - Node local key.
c - Closure to run. If null - this method is no-op.
See Also:
GridRichNode.run(Runnable)

nodeLocalRunAsync

GridFuture<?> nodeLocalRunAsync(Object key,
                                @Nullable
                                GridInClosure<Object> c)
                                throws GridException
Runs given closure on this node using value from node local storage of this node. Note that unlike its sibling GridRichNode.nodeLocalRun(Object, GridInClosure) this method will not block and will return with the future. Note also that key must be serializable as per current marshaller.

Note that for the local node this method will be optimized to avoid unnecessary distribution overhead and operation will be performed in a local context.

Throws:
GridException - Thrown in case of any failure.
Parameters:
key - Node local key.
c - Closure to run. If null - this method is no-op.
Returns:
Future.
See Also:
GridRichNode.runAsync(Runnable)

nodeLocalCall

<T> T nodeLocalCall(Object key,
                    @Nullable
                    GridClosure<Object,T> c)
                throws GridException
Runs given closure on this node using value from node local storage of this node. Note that unlike its sibling GridRichNode.nodeLocalCallAsync(Object, GridClosure) this method will block until operation is complete. Note also that key must be serializable as per current marshaller.

Note that for the local node this method will be optimized to avoid unnecessary distribution overhead and operation will be performed in a local context.

Throws:
GridException - Thrown in case of any failure.
Type Parameters:
T - Type of the closure return value.
Parameters:
key - Node local key.
c - Closure to run. If null - this method is no-op.
Returns:
Closure result.
See Also:
GridRichNode.call(Callable)

nodeLocalCallAsync

<T> GridFuture<T> nodeLocalCallAsync(Object key,
                                     @Nullable
                                     GridClosure<Object,T> c)
                                 throws GridException
Runs given closure on this node using value from node local storage of this node. Note that unlike its sibling GridRichNode.nodeLocalCall(Object, GridClosure) this method will not block and will return with the future. Note also that key must be serializable as per current marshaller.

Note that for the local node this method will be optimized to avoid unnecessary distribution overhead and operation will be performed in a local context.

Throws:
GridException - Thrown in case of any failure.
Type Parameters:
T - Type of the closure return value.
Parameters:
key - Node local key.
c - Closure to run. If null - this method is no-op.
Returns:
Future of closure result.
See Also:
GridRichNode.callAsync(Callable)

GridGain™ 3.6.0e
Enterprise Edition

GridGain - Real Time Big Data
Enterprise Edition, ver. 3.6.0e.13012012
2012 Copyright © GridGain Systems
Follow us:   Follow GridGain on Github Follow GridGain on Facebook Join GridGain User Group Follow GridGain on Twitter Follow GridGain on YouTube