GridGain™ 2.0.3
Java API Specification

org.gridgain.grid
Interface Grid


@Apache20LicenseCompatible
public interface Grid

Start Here This interface defines main GridGain API available on a local grid node.

You can obtain an instance of Grid through GridFactory.getGrid(), or for named grids you can use GridFactory.getGrid(String) . Note that you can have multiple instances of Grid running in the same VM. For information on how to start or stop Grid please refer to GridFactory class.

GridGain Grid allows you to perform the following major functions:

Execution of grid tasks is the most important functionality this interface provides. Task execution can be either synchronous or asynchronous. Synchronous task execution is done through following methods:

Asynchronous task execution is done through following methods: Prior to executing grid task on grid it needs to be deployed. Refer to GridTask documentation for more information about implicit and explicit deploying and executing grid tasks.

For more information see Grid Interface on Wiki.



See Also:

  Documentation
  Email Support
  Online Forums
  Issue Tracking

Author:   2005-2008 Copyright © GridGain Systems. All Rights Reserved. ver. 2.0.3

 

Method Summary
 void addDiscoveryListener(GridDiscoveryListener listener)
          Adds a listener for discovery events.
 void addLocalEventListener(GridLocalEventListener listener)
          Adds an event listener for local events.
 void addMessageListener(GridMessageListener listener)
          Register a message listener to receive messages sent by remote nodes.
 void deployTask(Class<? extends GridTask> taskCls)
          Explicitely deploys given grid task on the local node.
 void deployTask(Class<? extends GridTask> taskCls, ClassLoader clsLoader)
          Explicitely deploys given grid task on the local node.
<T,R> GridTaskFuture<R>
execute(Class<? extends GridTask<T,R>> taskCls, T arg)
          Executes a task on the grid.
<T,R> GridTaskFuture<R>
execute(Class<? extends GridTask<T,R>> taskCls, T arg, GridTaskListener listener)
          Asynchronously executes a task on the grid.
<T,R> GridTaskFuture<R>
execute(Class<? extends GridTask<T,R>> taskCls, T arg, long timeout)
          Executes a task on the grid.
<T,R> GridTaskFuture<R>
execute(Class<? extends GridTask<T,R>> taskCls, T arg, long timeout, GridTaskListener listener)
          Asynchronously executes a task on the grid.
<T,R> GridTaskFuture<R>
execute(GridTask<T,R> task, T arg)
          Executes a task on the grid.
<T,R> GridTaskFuture<R>
execute(GridTask<T,R> task, T arg, GridTaskListener listener)
          Asynchronously executes a task on the grid.
<T,R> GridTaskFuture<R>
execute(GridTask<T,R> task, T arg, long timeout)
          Executes a task on the grid.
<T,R> GridTaskFuture<R>
execute(GridTask<T,R> task, T arg, long timeout, GridTaskListener listener)
          Asynchronously executes a task on the grid.
<T,R> GridTaskFuture<R>
execute(String taskName, T arg)
          Executes a task on the grid.
<T,R> GridTaskFuture<R>
execute(String taskName, T arg, GridTaskListener listener)
          Asynchronously executes a task on the grid.
<T,R> GridTaskFuture<R>
execute(String taskName, T arg, long timeout)
          Executes a task on the grid.
<T,R> GridTaskFuture<R>
execute(String taskName, T arg, long timeout, GridTaskListener listener)
          Asynchronously executes a task on the grid.
 Collection<GridNode> getAllNodes()
          Gets a collection of all grid nodes.
 long getAllTopologyHash()
          This method calculates hash all the nodes in the topology.
 GridNode getLocalNode()
          Gets local grid node.
 Map<String,Class<? extends GridTask<?,?>>> getLocalTasks()
          Gets map of all locally deployed tasks keyed by their task name.
 String getName()
          Gets name of the grid instance.
 GridNode getNode(UUID nodeId)
          Gets a node instance based on its ID.
 Collection<GridNode> getRemoteNodes()
          Gets a collection of remote grid nodes.
 long getTopologyHash(Collection<GridNode> nodes)
          This method calculates hash value of the given set of nodes (a topology).
 ExecutorService newGridExecutorService()
          Creates ExecutorService which will execute all submitted Callable and Runnable tasks on the grid.
 boolean pingNode(UUID nodeId)
          Pings a remote node.
 List<GridEvent> queryEvents(GridEventFilter filter, Collection<GridNode> nodes, long timeout)
          Queries all remote nodes for events using passed in filter for event selection.
 List<GridEvent> queryLocalEvents(GridEventFilter filter)
          Queries local node for events using passed in filter for event selection.
 boolean removeDiscoveryListener(GridDiscoveryListener listener)
          Removes discovery event listener.
 boolean removeLocalEventListener(GridLocalEventListener listener)
          Removes local event listener.
 boolean removeMessageListener(GridMessageListener listener)
          Removes a previously registered message listener.
 void sendMessage(Collection<GridNode> nodes, Serializable msg)
          Sends a message to a group of remote nodes.
 void sendMessage(GridNode node, Serializable msg)
          Sends a message to a remote node.
 void undeployTask(String taskName)
          Makes the best attempt to undeploy a task from the whole grid.
 

Method Detail

getTopologyHash

long getTopologyHash(Collection<GridNode> nodes)
This method calculates hash value of the given set of nodes (a topology). Topology hash can be used in applications with optimistic locking scenario that relying on unchanged topology during a long operation.

Note that since GridGain topology architecture is peer-to-peer (without centralized coordination) there is still a small window in which different nodes would have different version for the same topology. Therefore, this version cannot be used in strict ACID context. Values returned by this method are not guaranteed to be sequential. Standard implementation uses CRC32 hash method.

Parameters:
nodes - Collection of grid nodes. Note that this can be either full topology or any subset of it.
Returns:
8-byte topology hash value.

getAllTopologyHash

long getAllTopologyHash()
This method calculates hash all the nodes in the topology. Topology hash can be used in applications with optimistic locking scenario that relying on unchanged topology during a long operation. This is a shortcut method for Grid.getTopologyHash(Collection) with all grid nodes.

Note that since GridGain topology architecture is peer-to-peer (without centralized coordination) there is still a small window in which different nodes would have different version for the same topology. Therefore, this version cannot be used in strict ACID context. Values returned by this method are not guaranteed to be sequential. Standard implementation uses CRC32 hash method.

Returns:
8-byte topology hash value.

addLocalEventListener

void addLocalEventListener(GridLocalEventListener listener)
Adds an event listener for local events. Refer to GridEventType for a set of all possible events.

Parameters:
listener - Event listener for local events.
See Also:
GridEventType

removeLocalEventListener

boolean removeLocalEventListener(GridLocalEventListener listener)
Removes local event listener.

Parameters:
listener - Local event listener to remove.
Returns:
true if listener was removed, false otherwise.

addDiscoveryListener

void addDiscoveryListener(GridDiscoveryListener listener)
Adds a listener for discovery events. Refer to GridDiscoveryEventType for a set of all possible discovery events.

Parameters:
listener - Listener to discovery events.

removeDiscoveryListener

boolean removeDiscoveryListener(GridDiscoveryListener listener)
Removes discovery event listener.

Parameters:
listener - Discovery event listener to remove.
Returns:
True if listener was removed, false otherwise.

sendMessage

void sendMessage(GridNode node,
                 Serializable msg)
                 throws GridException
Sends a message to a remote node. The underlying communication mechanism is defined by GridCommunicationSpi implementation used.

This method can be used by jobs to communicate with other nodes in the grid. Remote nodes can receive messages by registering a listener through Grid.addMessageListener(GridMessageListener) method.

Throws:
GridException - If failed to send a message to remote node.
Parameters:
node - Node to send a message to.
msg - Message to send.
See Also:
GridCommunicationSpi, Grid.addMessageListener(GridMessageListener), Grid.removeMessageListener(GridMessageListener)

sendMessage

void sendMessage(Collection<GridNode> nodes,
                 Serializable msg)
                 throws GridException
Sends a message to a group of remote nodes. The underlying communication mechanism is defined by GridCommunicationSpi implementation used.

This method can be used by jobs to communicate with other nodes in the grid. Remote nodes can receive messages by registering a listener through Grid.addMessageListener(GridMessageListener) method.

Throws:
GridException - If failed to send a message to any of the remote nodes.
Parameters:
nodes - Group of nodes to send a message to.
msg - Message to send.
See Also:
GridCommunicationSpi, Grid.addMessageListener(GridMessageListener), Grid.removeMessageListener(GridMessageListener)

addMessageListener

void addMessageListener(GridMessageListener listener)
Register a message listener to receive messages sent by remote nodes. The underlying communication mechanism is defined by GridCommunicationSpi implementation used.

This method can be used by jobs to communicate with other nodes in the grid. Remote nodes can send messages by calling Grid.sendMessage(GridNode, Serializable) or Grid.sendMessage(Collection, Serializable) methods.

Parameters:
listener - Message listener to register.
See Also:
GridCommunicationSpi, Grid.sendMessage(GridNode, Serializable), Grid.sendMessage(Collection, Serializable), Grid.removeMessageListener(GridMessageListener)

removeMessageListener

boolean removeMessageListener(GridMessageListener listener)
Removes a previously registered message listener.

Parameters:
listener - Message listener to remove.
Returns:
true of message listener was removed, false if it was not previously registered.
See Also:
Grid.addMessageListener(GridMessageListener)

getNode

GridNode getNode(UUID nodeId)
Gets a node instance based on its ID.

Parameters:
nodeId - ID of a node to get.
Returns:
Node for a given ID or null is such not has not been discovered.
See Also:
GridDiscoverySpi

pingNode

boolean pingNode(UUID nodeId)
Pings a remote node. The underlying communication is provided via GridDiscoverySpi.pingNode(UUID) implementation.

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.

Parameters:
nodeId - ID of a node to ping.
Returns:
true if node for a given ID is alive, false otherwise.
See Also:
GridDiscoverySpi

getRemoteNodes

Collection<GridNode> getRemoteNodes()
Gets a collection of remote grid nodes. Remote nodes are discovered via underlying GridDiscoverySpi implementation used. Unlike Grid.getAllNodes(), this method does not include local grid node.

Returns:
Collection of remote grid nodes.
See Also:
Grid.getLocalNode(), Grid.getAllNodes(), GridDiscoverySpi

getAllNodes

Collection<GridNode> getAllNodes()
Gets a collection of all grid nodes. Remote nodes are discovered via underlying GridDiscoverySpi implementation used. Unlike Grid.getRemoteNodes(), this method does include local grid node.

Returns:
Collection of remote grid nodes.
See Also:
Grid.getLocalNode(), Grid.getRemoteNodes(), GridDiscoverySpi

getLocalNode

GridNode getLocalNode()
Gets local grid node. Instance of local node is provided by underlying GridDiscoverySpi implementation used.

Returns:
Local grid node.
See Also:
GridDiscoverySpi

deployTask

void deployTask(Class<? extends GridTask> taskCls)
                throws GridException
Explicitely deploys given grid task on the local node. Upon completion of this method, a task can immediately be executed on the grid, considering that all participating remote nodes also have this task deployed. If peer-class-loading is enabled (see GridConfiguration.isPeerClassLoadingEnabled()), then other nodes will automatically deploy task upon execution request from the originating node without having to manually deploy it.

Another way of class deployment which is supported is deployment from local class path. Class from local class path has a priority over P2P deployed. Following describes task class deployment:

Note that this is an alternative deployment method additionally to deployment SPI that provides more formal method of deploying a task, e.g. deployment of GAR files and/or URI-based deployment. See GridDeploymentSpi for detailed information about grid task deployment.

Note that class can be deployed multiple times on remote nodes, i.e. re-deployed. GridGain maintains internal version of deployment for each instance of deployment (analogous to class and class loader in Java). Execution happens always on the latest deployed instance (latest that is on the node where execution request is originated). This allows a very convenient development model when a developer can execute a task on the grid from IDE, then realize that he made a mistake, stop his node in IDE, fix mistake and re-execute the task. Grid will automatically detect that task got renewed and redeploy it on all remote nodes upon execution.

This method has no effect if the class passed in was already deployed. Implementation checks for this condition and returns immediately.

Throws:
GridException - If task is invalid and cannot be deployed.
Parameters:
taskCls - Task class to deploy. If task class has GridTaskName annotation, then task will be deployed under a name specified within annotation. Otherwise, full class name will be used as task's name.
See Also:
GridDeploymentSpi

deployTask

void deployTask(Class<? extends GridTask> taskCls,
                ClassLoader clsLoader)
                throws GridException
Explicitely deploys given grid task on the local node. Upon completion of this method, a task can immediately be executed on the grid, considering that all participating remote nodes also have this task deployed. If peer-class-loading is enabled (see GridConfiguration.isPeerClassLoadingEnabled()), then other nodes will automatically deploy task upon execution request from the originating node without having to manually deploy it.

Another way of class deployment which is supported is deployment from local class path. Class from local class path has a priority over P2P deployed. Following describes task class deployment:

Note that this is an alternative deployment method additionally to deployment SPI that provides more formal method of deploying a task, e.g. deployment of GAR files and/or URI-based deployment. See GridDeploymentSpi for detailed information about grid task deployment.

Note that class can be deployed multiple times on remote nodes, i.e. re-deployed. GridGain maintains internal version of deployment for each instance of deployment (analogous to class and class loader in Java). Execution happens always on the latest deployed instance (latest that is on the node where execution request is originated). This allows a very convenient development model when a developer can execute a task on the grid from IDE, then realize that he made a mistake, stop his node in IDE, fix mistake and re-execute the task. Grid will automatically detect that task got renewed and redeploy it on all remote nodes upon execution.

This method has no effect if the class passed in was already deployed. Implementation checks for this condition and returns immediately.

Throws:
GridException - If task is invalid and cannot be deployed.
Parameters:
taskCls - Task class to deploy. If task class has GridTaskName annotation, then task will be deployed under a name specified within annotation. Otherwise, full class name will be used as task's name.
clsLoader - Task resources/classes class loader. This class loader is in charge of loading all necessary resources.
See Also:
GridDeploymentSpi

getLocalTasks

Map<String,Class<? extends GridTask<?,?>>> getLocalTasks()
Gets map of all locally deployed tasks keyed by their task name. If no tasks were locally deployed, then empty map is returned.

Returns:
All locally deployed tasks.

undeployTask

void undeployTask(String taskName)
                  throws GridException
Makes the best attempt to undeploy a task from the whole grid. Note that this method returns immediately and does not wait until the task will actually be undeployed on every node.

Note that GridGain maintains internal versions for grid tasks in case of redeployment. This method will attempt to undeploy all versions on the grid task with given name.

Throws:
GridException - Thrown if undeploy failed.
Parameters:
taskName - Name of the task to undeploy. If task class has GridTaskName annotation, then task was deployed under a name specified within annotation. Otherwise, full class name should be used as task's name.

execute

<T,R> GridTaskFuture<R> execute(String taskName,
                                @Nullable
                                T arg)
Executes a task on the grid. For information on how task gets split into remote jobs and how results are reduced back into one see GridTask documentation.

This method assumes indefinite wait for task completion. To provide a timeout, use Grid.execute(String, Object, long) method. It is always recommended to specify explicit task timeout.

If task for given name has not been deployed yet, then taskName will be used as task class name to auto-deploy the task (see Grid#deployTask() method for deployment algorithm).

Type Parameters:
T - Type of the task's argument.
R - Type of the task result returning from GridTask.reduce(List) method.
Parameters:
taskName - Name of the task to execute. If task class has GridTaskName annotation, then task is deployed under a name specified within annotation. Otherwise, full class name is used as task's name.
arg - Optional argument of task execution, can be null.
Returns:
Task future.
See Also:
for information about task execution.

execute

<T,R> GridTaskFuture<R> execute(String taskName,
                                @Nullable
                                T arg,
                                long timeout)
Executes a task on the grid. For information on how task gets split into remote jobs and how results are reduced back into one see GridTask documentation.

If task for given name has not been deployed yet, then taskName will be used as task class name to auto-deploy the task(see Grid#deployTask() method for deployment algorithm).

Type Parameters:
T - Type of the task's argument.
R - Type of the task result returning from GridTask.reduce(List) method.
Parameters:
taskName - Name of the task to execute. If task class has GridTaskName annotation, then task is deployed under a name specified within annotation. Otherwise, full class name is used as task's name.
arg - Optional argument of task execution, can be null.
timeout - Optional timeout for this task execution in milliseconds. If 0 the system will wait indefinitely for execution completion.
Returns:
Task future.
See Also:
for information about task execution.

execute

<T,R> GridTaskFuture<R> execute(String taskName,
                                @Nullable
                                T arg,
                                GridTaskListener listener)
Asynchronously executes a task on the grid. For information on how task gets split into remote jobs and how results are reduced back into one see GridTask documentation. Once task execution is complete, GridTaskListener.onFinished(GridTaskFuture) gets called. In that case GridTaskFuture.isDone() will always return true.

This method assumes indefinite wait for task completion. To provide a timeout, use Grid.execute(String, Object, long, GridTaskListener) method. It is always recommended to specify explicit task timeout.

If task for given name has not been deployed yet, then taskName will be used as task class name to auto-deploy the task(see Grid#deployTask() method for deployment algorithm).

Type Parameters:
T - Type of the task's argument.
R - Type of the task result returning from GridTask.reduce(List) method.
Parameters:
taskName - Name of the task to execute. If task class has GridTaskName annotation, then task is deployed under a name specified within annotation. Otherwise, full class name is used as task's name.
arg - Optional argument of task execution, can be null.
listener - Grid task result listener that will be called once the execution is completed (successfully or not).
Returns:
Task future.
See Also:
for information about task execution.

execute

<T,R> GridTaskFuture<R> execute(String taskName,
                                @Nullable
                                T arg,
                                long timeout,
                                GridTaskListener listener)
Asynchronously executes a task on the grid. For information on how task gets split into remote jobs and how results are reduced back into one see GridTask documentation. Once task execution is complete, GridTaskListener.onFinished(GridTaskFuture) gets called. In that case GridTaskFuture.isDone() will always return true.

If task for given name has not been deployed yet, then taskName will be used as task class name to auto-deploy the task(see Grid#deployTask() method for deployment algorithm).

Type Parameters:
T - Type of the task's argument.
R - Type of the task result returning from GridTask.reduce(List) method.
Parameters:
taskName - Name of the task to execute. If task class has GridTaskName annotation, then task is deployed under a name specified within annotation. Otherwise, full class name is used as task's name.
arg - Optional argument of task execution, can be null.
listener - Grid task result listener that will be called once the execution is completed (successfully or not).
timeout - Optional timeout for this task execution in milliseconds. If 0, then the system will wait indefinitely for execution completion.
Returns:
Task future.
See Also:
for information about task execution.

execute

<T,R> GridTaskFuture<R> execute(Class<? extends GridTask<T,R>> taskCls,
                                @Nullable
                                T arg)
Executes a task on the grid. For information on how task gets split into remote jobs and how results are reduced back into one see GridTask documentation.

This method assumes indefinite wait for task completion. To provide a timeout, use Grid.execute(String, Object, long) method. It is always recommended to specify explicit task timeout.

This method is extremely useful when task class is already loaded, for example, in J2EE application server environment. Since application servers already support deployment and hot-redeployment, it is convenient to deploy all task related classes via standard J2EE deployment and then use task classes directly.

When using this method task will be deployed automatically, so no explicit deployment step is required.

Type Parameters:
T - Type of the task's argument.
R - Type of the task result returning from GridTask.reduce(List) method.
Parameters:
taskCls - Class of the task to execute. If class has GridTaskName annotation, then task is deployed under a name specified within annotation. Otherwise, full class name is used as task's name.
arg - Optional argument of task execution, can be null.
Returns:
Task future.
See Also:
for information about task execution.

execute

<T,R> GridTaskFuture<R> execute(Class<? extends GridTask<T,R>> taskCls,
                                @Nullable
                                T arg,
                                long timeout)
Executes a task on the grid. For information on how task gets split into remote jobs and how results are reduced back into one see GridTask documentation.

This method is extremely useful when task class is already loaded, for example, in J2EE application server environment. Since application servers already support deployment and hot-redeployment, it is convenient to deploy all task related classes via standard J2EE deployment and then use task classes directly.

When using this method task will be deployed automatically, so no explicit deployment step is required.

Type Parameters:
T - Type of the task's argument.
R - Type of the task result returning from GridTask.reduce(List) method.
Parameters:
taskCls - Class of the task to execute. If class has GridTaskName annotation, then task is deployed under a name specified within annotation. Otherwise, full class name is used as task's name.
arg - Optional argument of task execution, can be null.
timeout - Optional timeout for this task execution in milliseconds. If 0 the system will wait indefinitely for execution completion.
Returns:
Task future.
See Also:
for information about task execution.

execute

<T,R> GridTaskFuture<R> execute(Class<? extends GridTask<T,R>> taskCls,
                                @Nullable
                                T arg,
                                GridTaskListener listener)
Asynchronously executes a task on the grid. For information on how task gets split into remote jobs and how results are reduced back into one see GridTask documentation. Once task execution is complete, GridTaskListener.onFinished(GridTaskFuture) gets called. In that case GridTaskFuture.isDone() will always return true.

This method assumes indefinite wait for task completion. To provide a timeout, use Grid.execute(String, Object, long, GridTaskListener) method. It is always recommended to specify explicit task timeout.

This method is extremely useful when task class is already loaded, for example, in J2EE application server environment. Since application servers already support deployment and hot-redeployment, it is convenient to deploy all task related classes via standard J2EE deployment and then use task classes directly.

When using this method task will be deployed automatically, so no explicit deployment step is required.

Type Parameters:
T - Type of the task argument.
R - Type of the task result returning from GridTask.reduce(List) method.
Parameters:
taskCls - Class of the task to execute. If class has GridTaskName annotation, then task is deployed under a name specified within annotation. Otherwise, full class name is used as task's name.
arg - Optional argument of task execution, can be null.
listener - Grid task result listener that will be called once the execution is completed (successfully or not).
Returns:
Task future.
See Also:
for information about task execution.

execute

<T,R> GridTaskFuture<R> execute(Class<? extends GridTask<T,R>> taskCls,
                                @Nullable
                                T arg,
                                long timeout,
                                GridTaskListener listener)
Asynchronously executes a task on the grid. For information on how task gets split into remote jobs and how results are reduced back into one see GridTask documentation. Once task execution is complete, GridTaskListener.onFinished(GridTaskFuture) gets called. In that case GridTaskFuture.isDone() will always return true.

This method is extremely useful when task class is already loaded, for example, in J2EE application server environment. Since application servers already support deployment and hot-redeployment, it is convenient to deploy all task related classes via standard J2EE deployment and then use task classes directly.

When using this method task will be deployed automatically, so no explicit deployment step is required.

Type Parameters:
T - Type of the task's argument.
R - Type of the task result returning from GridTask.reduce(List) method.
Parameters:
taskCls - Class of the task to execute. If class has GridTaskName annotation, then task is deployed under a name specified within annotation. Otherwise, full class name is used as task's name.
arg - Optional argument of task execution, can be null.
listener - Grid task result listener that will be called once the execution is completed (successfully or not).
timeout - Optional timeout for this task execution in milliseconds. If 0, then the system will wait indefinitely for execution completion.
Returns:
Task future.
See Also:
for information about task execution.

execute

<T,R> GridTaskFuture<R> execute(GridTask<T,R> task,
                                @Nullable
                                T arg)
Executes a task on the grid. For information on how task gets split into remote jobs and how results are reduced back into one see GridTask documentation.

This method assumes indefinite wait for task completion. To provide a timeout, use Grid.execute(String, Object, long) method. It is always recommended to specify explicit task timeout.

This method is extremely useful when task class is already loaded, for example, in J2EE application server environment. Since application servers already support deployment and hot-redeployment, it is convenient to deploy all task related classes via standard J2EE deployment and then use task classes directly.

When using this method task will be deployed automatically, so no explicit deployment step is required.

Type Parameters:
T - Type of the task's argument.
R - Type of the task result returning from GridTask.reduce(List) method.
Parameters:
task - Instance of task to execute. If task class has GridTaskName annotation, then task is deployed under a name specified within annotation. Otherwise, full class name is used as task's name.
arg - Optional argument of task execution, can be null.
Returns:
Task future.
See Also:
for information about task execution.

execute

<T,R> GridTaskFuture<R> execute(GridTask<T,R> task,
                                @Nullable
                                T arg,
                                long timeout)
Executes a task on the grid. For information on how task gets split into remote jobs and how results are reduced back into one see GridTask documentation.

This method is extremely useful when task class is already loaded, for example, in J2EE application server environment. Since application servers already support deployment and hot-redeployment, it is convenient to deploy all task related classes via standard J2EE deployment and then use task classes directly.

When using this method task will be deployed automatically, so no explicit deployment step is required.

Type Parameters:
T - Type of the task's argument.
R - Type of the task result returning from GridTask.reduce(List) method.
Parameters:
task - Instance of task to execute. If task class has GridTaskName annotation, then task is deployed under a name specified within annotation. Otherwise, full class name is used as task's name.
arg - Optional argument of task execution, can be null.
timeout - Optional timeout for this task execution in milliseconds. If 0 the system will wait indefinitely for execution completion.
Returns:
Task future.
See Also:
for information about task execution.

execute

<T,R> GridTaskFuture<R> execute(GridTask<T,R> task,
                                @Nullable
                                T arg,
                                GridTaskListener listener)
Asynchronously executes a task on the grid. For information on how task gets split into remote jobs and how results are reduced back into one see GridTask documentation. Once task execution is complete, GridTaskListener.onFinished(GridTaskFuture) gets called. In that case GridTaskFuture.isDone() will always return true.

This method assumes indefinite wait for task completion. To provide a timeout, use Grid.execute(String, Object, long, GridTaskListener) method. It is always recommended to specify explicit task timeout.

This method is extremely useful when task class is already loaded, for example, in J2EE application server environment. Since application servers already support deployment and hot-redeployment, it is convenient to deploy all task related classes via standard J2EE deployment and then use task classes directly.

When using this method task will be deployed automatically, so no explicit deployment step is required.

Type Parameters:
T - Type of the task's argument.
R - Type of the task result returning from GridTask.reduce(List) method.
Parameters:
task - Instance of task to execute. If task class has GridTaskName annotation, then task is deployed under a name specified within annotation. Otherwise, full class name is used as task's name.
arg - Optional argument of task execution, can be null.
listener - Grid task result listener that will be called once the execution is completed (successfully or not).
Returns:
Task future.
See Also:
for information about task execution.

execute

<T,R> GridTaskFuture<R> execute(GridTask<T,R> task,
                                @Nullable
                                T arg,
                                long timeout,
                                GridTaskListener listener)
Asynchronously executes a task on the grid. For information on how task gets split into remote jobs and how results are reduced back into one see GridTask documentation. Once task execution is complete, GridTaskListener.onFinished(GridTaskFuture) gets called. In that case GridTaskFuture.isDone() will always return true.

This method is extremely useful when task class is already loaded, for example, in J2EE application server environment. Since application servers already support deployment and hot-redeployment, it is convenient to deploy all task related classes via standard J2EE deployment and then use task classes directly.

When using this method task will be deployed automatically, so no explicit deployment step is required.

Type Parameters:
T - Type of the task's argument.
R - Type of the task result returning from GridTask.reduce(List) method.
Parameters:
task - Instance of task to execute. If task class has GridTaskName annotation, then task is deployed under a name specified within annotation. Otherwise, full class name is used as task's name.
arg - Optional argument of task execution, can be null.
listener - Grid task result listener that will be called once the execution is completed (successfully or not).
timeout - Optional timeout for this task execution in milliseconds. If 0, then the system will wait indefinitely for execution completion.
Returns:
Task future.
See Also:
for information about task execution.

queryLocalEvents

List<GridEvent> queryLocalEvents(GridEventFilter filter)
Queries local node for events using passed in filter for event selection.

Parameters:
filter - Filter used to query events on remote nodes.
Returns:
Collection of grid events found on local node.

queryEvents

List<GridEvent> queryEvents(GridEventFilter filter,
                            Collection<GridNode> nodes,
                            long timeout)
                            throws GridException
Queries all remote nodes for events using passed in filter for event selection. This operation is distributed and hence can fail on communication layer and generally should take longer than local event notifications.

Note, that peer-class-loading is not enabled for event filters yet, so in order to execute remote event query, you must make sure that GridEventFilter implementation is on the class path of every node.

Throws:
GridException - If query failed to execute.
Parameters:
filter - Filter used to query events on remote nodes (must implement Serializable.
nodes - Nodes to query.
timeout - Maximum time to wait for result, if 0, then wait until result is received.
Returns:
Collection of grid events returned from remote nodes.

getName

String getName()
Gets name of the grid instance. If default grid instance is used, then null is returned. Refer to GridFactory documentation for information on how to start named grids.

Returns:
Name of this grid instance, null for default instance.

newGridExecutorService

ExecutorService newGridExecutorService()
Creates ExecutorService which will execute all submitted Callable and Runnable tasks on the grid. User may run Callable and Runnable tasks just like normally with java.util.ExecutorService, but these tasks must implement Serializable interface.

The execution will happen either locally or remotely, depending on configuration of GridLoadBalancingSpi and GridTopologySpi.

Returns:
ExecutorService which delegates all calls to grid.

GridGain™ 2.0.3
Java API Specification