GridGain™ 2.1.0
Java API Specification

org.gridgain.grid
Class GridSpringBean

java.lang.Object
  extended by org.gridgain.grid.GridSpringBean
All Implemented Interfaces:
Grid, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware

public class GridSpringBean
extends Object
implements Grid, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware

Grid Spring bean allows to bypass GridFactory methods. In other words, this bean class allows to inject new grid instance from Spring configuration file directly without invoking static GridFactory methods. This class can be wired directly from Spring and can be referenced from within other Spring beans. By virtue of implementing DisposableBean and InitializingBean interfaces, GridSpringBean automatically starts and stops underlying grid instance.

GridSpringBean has following configuration parameters.

Configuration

Mandatory

This bean has no mandatory configuration parameters.

Optional

The following configuration parameters are optional:

Spring Configuration Example

Here is a typical example of describing it in Spring file:
 <bean id="mySpringBean" class="org.gridgain.grid.GridSpringBean" scope="singleton">
     <property name="configuration">
         <bean id="grid.cfg" class="org.gridgain.grid.GridConfigurationAdapter" scope="singleton">
             <property name="gridName" value="mySpringGrid"/>
         </bean>
     </property>
 </bean>
 
Or use default configuration:
 <bean id="mySpringBean" class="org.gridgain.grid.GridSpringBean" scope="singleton"/>
 

Java Example

Here is how you may access this bean from code:
 AbstractApplicationContext ctx = new FileSystemXmlApplicationContext("/path/to/spring/file");

 // Register Spring hook to destroy bean automatically.
 ctx.registerShutdownHook();

 Grid grid = (Grid)ctx.getBean("mySpringBean");
 





See Also:

  Documentation
  Email Support
  Online Forums
  Issue Tracking

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

 

Constructor Summary
GridSpringBean()
           
 
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 afterPropertiesSet()
          
 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.
 void destroy()
          
<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.
 GridConfiguration getConfiguration()
          Gets grid configuration.
 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 the name of the grid this grid instance (and correspondently its local node) belongs to.
 GridNode getNode(UUID nodeId)
          Gets a node instance based on its ID.
 Collection<GridNode> getNodes(GridNodeFilter filter)
          Gets all grid nodes accepted by the filter.
 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 setApplicationContext(org.springframework.context.ApplicationContext ctx)
          
 void setConfiguration(GridConfiguration cfg)
          Sets grid configuration.
 void undeployTask(String taskName)
          Makes the best attempt to undeploy a task from the whole grid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GridSpringBean

public GridSpringBean()
Method Detail

getConfiguration

public GridConfiguration getConfiguration()
Gets grid configuration.

Returns:
Grid Configuration.

setConfiguration

public void setConfiguration(GridConfiguration cfg)
Sets grid configuration.

Parameters:
cfg - Grid configuration.

addDiscoveryListener

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

Specified by:
addDiscoveryListener in interface Grid
Parameters:
listener - Listener to discovery events.

addLocalEventListener

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

Specified by:
addLocalEventListener in interface Grid
Parameters:
listener - Event listener for local events.
See Also:
GridEventType

addMessageListener

public 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.

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

deployTask

public 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.

Specified by:
deployTask in interface Grid
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

public 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.

Specified by:
deployTask in interface Grid
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

execute

public <T,R> GridTaskFuture<R> execute(String taskName,
                                       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).

Specified by:
execute in interface Grid
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

public <T,R> GridTaskFuture<R> execute(String taskName,
                                       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).

Specified by:
execute in interface Grid
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

public <T,R> GridTaskFuture<R> execute(String taskName,
                                       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).

Specified by:
execute in interface Grid
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

public <T,R> GridTaskFuture<R> execute(String taskName,
                                       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).

Specified by:
execute in interface Grid
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, then the system will wait indefinitely for execution completion.
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

public <T,R> GridTaskFuture<R> execute(Class<? extends GridTask<T,R>> taskCls,
                                       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.

Specified by:
execute in interface Grid
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

public <T,R> GridTaskFuture<R> execute(Class<? extends GridTask<T,R>> taskCls,
                                       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.

Specified by:
execute in interface Grid
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

public <T,R> GridTaskFuture<R> execute(Class<? extends GridTask<T,R>> taskCls,
                                       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.

Specified by:
execute in interface Grid
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

public <T,R> GridTaskFuture<R> execute(Class<? extends GridTask<T,R>> taskCls,
                                       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.

Specified by:
execute in interface Grid
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, then the system will wait indefinitely for execution completion.
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

public <T,R> GridTaskFuture<R> execute(GridTask<T,R> task,
                                       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.

Specified by:
execute in interface Grid
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

public <T,R> GridTaskFuture<R> execute(GridTask<T,R> task,
                                       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.

Specified by:
execute in interface Grid
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

public <T,R> GridTaskFuture<R> execute(GridTask<T,R> task,
                                       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.

Specified by:
execute in interface Grid
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

public <T,R> GridTaskFuture<R> execute(GridTask<T,R> task,
                                       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.

Specified by:
execute in interface Grid
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, then the system will wait indefinitely for execution completion.
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.

getAllNodes

public 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.

Specified by:
getAllNodes in interface Grid
Returns:
Collection of remote grid nodes.
See Also:
Grid.getLocalNode(), Grid.getRemoteNodes(), GridDiscoverySpi

getAllTopologyHash

public 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.

Specified by:
getAllTopologyHash in interface Grid
Returns:
8-byte topology hash value.

getLocalNode

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

Specified by:
getLocalNode in interface Grid
Returns:
Local grid node.
See Also:
GridDiscoverySpi

getLocalTasks

public 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.

Specified by:
getLocalTasks in interface Grid
Returns:
All locally deployed tasks.

getName

public String getName()
Gets the name of the grid this grid instance (and correspondently its local node) belongs to. Note that single Java VM can have multiple grid instances all belonging to different grids. Grid name allows to indicate to what grid this particular grid instance (i.e. grid runtime and its local node) belongs to.

If default grid instance is used, then null is returned. Refer to GridFactory documentation for information on how to start named grids.

Specified by:
getName in interface Grid
Returns:
Name of the grid, or null for default grid.

getNode

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

Specified by:
getNode in interface Grid
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

getNodes

public Collection<GridNode> getNodes(GridNodeFilter filter)
Gets all grid nodes accepted by the filter.

Specified by:
getNodes in interface Grid
Parameters:
filter - Filter for grid nodes.
Returns:
Grid nodes accepted by the filter.

getRemoteNodes

public 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.

Specified by:
getRemoteNodes in interface Grid
Returns:
Collection of remote grid nodes.
See Also:
Grid.getLocalNode(), Grid.getAllNodes(), GridDiscoverySpi

getTopologyHash

public 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.

Specified by:
getTopologyHash in interface Grid
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.

newGridExecutorService

public 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.

The typical Java example could be:

 ExecutorService exec = grid.newGridExecutorService();

 Future<String> future = exec.submit(new MyCallable());
 ...
 String res = future.get();
 

Specified by:
newGridExecutorService in interface Grid
Returns:
ExecutorService which delegates all calls to grid.

pingNode

public 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.

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

queryEvents

public 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.

Starting with version 2.1 peer-class-loading is enabled for event filters. You can simply call this method and your event filter will be automatically loaded and executed on all remote nodes. You no longer need to manually add it to the class path on all remote nodes.

Specified by:
queryEvents in interface Grid
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, 0 to wait forever.
Returns:
Collection of grid events returned from specified nodes.

queryLocalEvents

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

Specified by:
queryLocalEvents in interface Grid
Parameters:
filter - Filter used to query events on remote nodes.
Returns:
Collection of grid events found on local node.

removeDiscoveryListener

public boolean removeDiscoveryListener(GridDiscoveryListener listener)
Removes discovery event listener.

Specified by:
removeDiscoveryListener in interface Grid
Parameters:
listener - Discovery event listener to remove.
Returns:
True if listener was removed, false otherwise.

removeLocalEventListener

public boolean removeLocalEventListener(GridLocalEventListener listener)
Removes local event listener.

Specified by:
removeLocalEventListener in interface Grid
Parameters:
listener - Local event listener to remove.
Returns:
true if listener was removed, false otherwise.

removeMessageListener

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

Specified by:
removeMessageListener in interface Grid
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)

sendMessage

public 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.

Specified by:
sendMessage in interface Grid
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

public 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.

Specified by:
sendMessage in interface Grid
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)

undeployTask

public 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.

Specified by:
undeployTask in interface Grid
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.

destroy

public void destroy()
             throws Exception

Specified by:
destroy in interface org.springframework.beans.factory.DisposableBean
Throws:
Exception

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception

Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
Exception

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext ctx)
                           throws org.springframework.beans.BeansException

Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware
Throws:
org.springframework.beans.BeansException

GridGain™ 2.1.0
Java API Specification

GridGain™ - Grid Computing Made Simple, ver. 2.1.0.19122008
2005-2008 Copyright © GridGain Systems. All Rights Reserved.