GridGain™ 2.1.0
Java API Specification

org.gridgain.grid.spi.failover.always
Class GridAlwaysFailoverSpi

java.lang.Object
  extended by org.gridgain.grid.spi.GridSpiAdapter
      extended by org.gridgain.grid.spi.failover.always.GridAlwaysFailoverSpi
All Implemented Interfaces:
GridAlwaysFailoverSpiMBean, GridFailoverSpi, GridSpi, GridSpiManagementMBean

@GridSpiInfo(author="GridGain Systems",
             url="www.gridgain.org",
             email="support@gridgain.com",
             version="x.x")
@GridSpiMultipleInstancesSupport(value=true)
public class GridAlwaysFailoverSpi
extends GridSpiAdapter
implements GridFailoverSpi, GridAlwaysFailoverSpiMBean

Failover SPI that always reroutes a failed job to another node. Note, that at first an attempt will be made to reroute the failed job to a node that was not part of initial split for a better chance of success. If no such nodes are available, then an attempt will be made to reroute the failed job to the nodes in the initial split minus the node the job is failed on. If none of the above attempts succeeded, then the job will not be failed over and null will be returned.

Configuration

This SPI is default failover SPI and does not have to be explicitly configured unless configuration parameters need to be changed.

Mandatory

This SPI has no mandatory configuration parameters.

Optional

This SPI has following optional configuration parameters: Here is a Java example how to configure grid with GridAlwaysFailoverSpi failover SPI.
 GridAlwaysFailoverSpi spi = new GridAlwaysFailoverSpi();

 // Override maximum failover attempts.
 spi.setMaximumFailoverAttempts(5);

 GridConfigurationAdapter cfg = new GridConfigurationAdapter();

 // Override default failover SPI.
 cfg.setFailoverSpiSpi(spi);

 // Start grid.
 GridFactory.start(cfg);
 
Here is an example of how to configure GridAlwaysFailoverSpi from Spring XML configuration file.
 <property name="failoverSpi">
     <bean class="org.gridgain.grid.spi.failover.always.GridAlwaysFailoverSpi">
         <property name="maximumFailoverAttempts" value="5"/>
     </bean>
 </property>
 


For information about Spring framework visit www.springframework.org



See Also:

  Documentation
  Email Support
  Online Forums
  Issue Tracking

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

See Also:
GridFailoverSpi
 

Field Summary
static int DFLT_MAX_FAILOVER_ATTEMPTS
          Maximum number of attempts to execute a failed job on another node (default is 5).
static String FAILED_NODE_LIST_ATTR
          Name of job context attribute containing all nodes a job failed on.
static String MAX_FAILOVER_ATTEMPT_ATTR
          Maximum attempts attribute key should be the same on all nodes.
 
Constructor Summary
GridAlwaysFailoverSpi()
           
 
Method Summary
 GridNode failover(GridFailoverContext ctx, List<GridNode> top)
          This method is called when method GridTask.result(GridJobResult, List) returns value GridJobResultPolicy.FAILOVER policy indicating that the result of job execution must be failed over.
protected  List<String> getConsistentAttributeNames()
          Returns back list of attributes that should be consistent for this SPI.
 int getMaximumFailoverAttempts()
          Gets maximum number of attempts to execute a failed job on another node.
 Map<String,Serializable> getNodeAttributes()
          This method is called before SPI starts (before method GridSpi.spiStart(String) is called). It allows SPI implementation to add attributes to a local node. Kernel collects these attributes from all SPI implementations loaded up and then passes it to discovery SPI so that they can be exchanged with other nodes.
 int getTotalFailoverJobsCount()
          Get total number of jobs that were failed over.
 void setMaximumFailoverAttempts(int maxFailoverAttempts)
          Sets maximum number of attempts to execute a failed job on another node.
 void spiStart(String gridName)
          This method is called to start SPI.
 void spiStop()
          This method is called to stop SPI.
 String toString()
          
 
Methods inherited from class org.gridgain.grid.spi.GridSpiAdapter
assertParameter, configInfo, createSpiAttributeName, getAuthor, getGridGainHome, getLocalNodeId, getName, getSpiContext, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion, onContextDestroyed, onContextInitialized, registerMBean, setName, setSpiContext, startInfo, startStopwatch, stopInfo, unregisterMBean
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.gridgain.grid.spi.GridSpi
getName, onContextDestroyed, onContextInitialized
 
Methods inherited from interface org.gridgain.grid.spi.GridSpiManagementMBean
getAuthor, getGridGainHome, getLocalNodeId, getName, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, getVendorEmail, getVendorUrl, getVersion
 

Field Detail

DFLT_MAX_FAILOVER_ATTEMPTS

public static final int DFLT_MAX_FAILOVER_ATTEMPTS
Maximum number of attempts to execute a failed job on another node (default is 5).

See Also:
Constant Field Values

FAILED_NODE_LIST_ATTR

public static final String FAILED_NODE_LIST_ATTR
Name of job context attribute containing all nodes a job failed on.

See Also:
GridJobContext, Constant Field Values

MAX_FAILOVER_ATTEMPT_ATTR

public static final String MAX_FAILOVER_ATTEMPT_ATTR
Maximum attempts attribute key should be the same on all nodes.

See Also:
Constant Field Values
Constructor Detail

GridAlwaysFailoverSpi

public GridAlwaysFailoverSpi()
Method Detail

getMaximumFailoverAttempts

public int getMaximumFailoverAttempts()
Gets maximum number of attempts to execute a failed job on another node. If not specified, GridAlwaysFailoverSpi.DFLT_MAX_FAILOVER_ATTEMPTS value will be used.

Specified by:
getMaximumFailoverAttempts in interface GridAlwaysFailoverSpiMBean
Returns:
Maximum number of attempts to execute a failed job on another node.

setMaximumFailoverAttempts

@GridSpiConfiguration(optional=true)
public void setMaximumFailoverAttempts(int maxFailoverAttempts)
Sets maximum number of attempts to execute a failed job on another node. If not specified, GridAlwaysFailoverSpi.DFLT_MAX_FAILOVER_ATTEMPTS value will be used.

Parameters:
maxFailoverAttempts - Maximum number of attempts to execute a failed job on another node.

getTotalFailoverJobsCount

public int getTotalFailoverJobsCount()
Get total number of jobs that were failed over.

Specified by:
getTotalFailoverJobsCount in interface GridAlwaysFailoverSpiMBean
Returns:
Total number of failed over jobs.

getNodeAttributes

public Map<String,Serializable> getNodeAttributes()
                                           throws GridSpiException
This method is called before SPI starts (before method GridSpi.spiStart(String) is called). It allows SPI implementation to add attributes to a local node. Kernel collects these attributes from all SPI implementations loaded up and then passes it to discovery SPI so that they can be exchanged with other nodes.

Specified by:
getNodeAttributes in interface GridSpi
Overrides:
getNodeAttributes in class GridSpiAdapter
Throws:
GridSpiException - Throws in case of any error.
Returns:
Map of local node attributes this SPI wants to add.

spiStart

public void spiStart(String gridName)
              throws GridSpiException
This method is called to start SPI. After this method returns successfully kernel assumes that SPI is fully operational.

Specified by:
spiStart in interface GridSpi
Throws:
GridSpiException - Throws in case of any error during SPI start.
Parameters:
gridName - Name of grid instance this SPI is being started for (null for default grid).

spiStop

public void spiStop()
             throws GridSpiException
This method is called to stop SPI. After this method returns kernel assumes that this SPI is finished and all resources acquired by it are released. Note that this method can be called at any point including during recovery of failed start. It should make no assumptions on what state SPI will be in when this method is called.

Specified by:
spiStop in interface GridSpi
Throws:
GridSpiException - Thrown in case of any error during SPI stop.

failover

public GridNode failover(GridFailoverContext ctx,
                         List<GridNode> top)
This method is called when method GridTask.result(GridJobResult, List) returns value GridJobResultPolicy.FAILOVER policy indicating that the result of job execution must be failed over. Implementation of this method should examine failover context and choose one of the grid nodes from supplied topology to retry job execution on it. For best performance it is advised that GridFailoverContext.getBalancedNode(List) method is used to select node for execution of failed job.

Specified by:
failover in interface GridFailoverSpi
Parameters:
ctx - Failover context.
top - Collection of all grid nodes within task topology (may include failed node).
Returns:
New node to route this job to or null if new node cannot be picked. If job failover fails (returns null) the whole task will be failed.

getConsistentAttributeNames

protected List<String> getConsistentAttributeNames()
Returns back list of attributes that should be consistent for this SPI. Consistency means that remote node has to have the same attribute with the same value.

Overrides:
getConsistentAttributeNames in class GridSpiAdapter
Returns:
List or attribute names.

toString

public String toString()

Overrides:
toString in class Object

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.