GridGain™ 2.0.3
Java API Specification

org.gridgain.grid.spi
Class GridSpiAdapter

java.lang.Object
  extended by org.gridgain.grid.spi.GridSpiAdapter
All Implemented Interfaces:
GridSpi, GridSpiManagementMBean
Direct Known Subclasses:
GridAdaptiveLoadBalancingSpi, GridAffinityLoadBalancingSpi, GridAlwaysFailoverSpi, GridAttributesTopologySpi, GridBasicTopologySpi, GridCoherenceCheckpointSpi, GridCoherenceCommunicationSpi, GridCoherenceDiscoverySpi, GridCoherenceLoadBalancingSpi, GridFifoQueueCollisionSpi, GridGigaSpacesCheckpointSpi, GridJbossDiscoverySpi, GridJdkLocalMetricsSpi, GridJgroupsCommunicationSpi, GridJgroupsDiscoverySpi, GridJmsCommunicationSpi, GridJmsDiscoverySpi, GridJobStealingCollisionSpi, GridJobStealingFailoverSpi, GridJxinsightTracingSpi, GridLocalDeploymentSpi, GridMailCommunicationSpi, GridMailDiscoverySpi, GridMemoryEventStorageSpi, GridMuleCommunicationSpi, GridMuleDiscoverySpi, GridMulticastDiscoverySpi, GridNeverFailoverSpi, GridPriorityQueueCollisionSpi, GridRoundRobinLoadBalancingSpi, GridSharedFsCheckpointSpi, GridTcpCommunicationSpi, GridUriDeploymentSpi, GridWeightedRandomLoadBalancingSpi

public abstract class GridSpiAdapter
extends Object
implements GridSpi, GridSpiManagementMBean

This class provides convenient adapter for SPI implementations.



See Also:

  Documentation
  Email Support
  Online Forums
  Issue Tracking

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

 

Constructor Summary
protected GridSpiAdapter()
          Creates new adapter and initializes it from the current (this) class.
 
Method Summary
protected  void assertParameter(boolean cond, String condDescr)
          Throws exception with uniform error message if given parameter's assertion condition is false.
protected  void checkConfigurationConsistency(GridNode node)
          Checks remote node SPI configuration and prints warnings if necessary.
protected  String configInfo(String name, Object value)
          Gets uniformed string for configuration parameter.
 String getAuthor()
          Gets SPI provider's author.
 String getGridGainHome()
          Gets Gridgain installation home folder.
 UUID getLocalNodeId()
          Gets ID of the local node.
 Map<String,Serializable> getNodeAttributes()
          This method is called before SPI starts (before method GridSpi.spiStart(String) is called).
protected  GridSpiContext getSpiContext()
          Gets SPI context.
 long getStartTimestamp()
          Get start timestamp of this SPI.
 String getStartTimestampFormatted()
          Gets string presentation of the start timestamp.
 long getUpTime()
          Gets up-time of this SPI.
 String getUpTimeFormatted()
          Gets string presentation of up-time for this SPI.
 String getVendorEmail()
          Gets vendor's email (info or support).
 String getVendorUrl()
          Gets vendor's URL.
 String getVersion()
          Gets SPI implementation version.
 void onContextDestroyed()
          Callback invoked prior to stopping grid before SPI context is destroyed.
 void onContextInitialized(GridSpiContext spiCtx)
          Callback invoked when SPI context is initialized.
protected
<T extends GridSpiManagementMBean>
void
registerMBean(String gridName, T impl, Class<T> mbeanItf)
          Registers SPI MBean.
protected  void setSpiContext(GridSpiContext spiCtx)
          Sets SPI context.
protected  String startInfo()
          Gets uniformly formatted message for SPI start.
protected  void startStopwatch()
          Starts startup stopwatch.
protected  String stopInfo()
          Gets uniformly format message for SPI stop.
protected  void unregisterMBean()
          Unregisters MBean.
protected  void warnSpi(String spiName, Class<? extends GridSpi> spiCls, String attrName)
          Checks if dependent SPI is the same as expected.
protected  void warnSpiParameter(String param, String attrName, GridNode rmtNode)
          Check if remote node has the same attribute value as local node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.gridgain.grid.spi.GridSpi
spiStart, spiStop
 

Constructor Detail

GridSpiAdapter

protected GridSpiAdapter()
Creates new adapter and initializes it from the current (this) class.

Method Detail

startStopwatch

protected void startStopwatch()
Starts startup stopwatch.


getAuthor

public final String getAuthor()
Gets SPI provider's author.

Specified by:
getAuthor in interface GridSpiManagementMBean
Returns:
SPI provider's author.

getVendorUrl

public final String getVendorUrl()
Gets vendor's URL.

Specified by:
getVendorUrl in interface GridSpiManagementMBean
Returns:
Vendor's URL.

getVendorEmail

public final String getVendorEmail()
Gets vendor's email (info or support).

Specified by:
getVendorEmail in interface GridSpiManagementMBean
Returns:
Vendor's email (info or support).

getVersion

public final String getVersion()
Gets SPI implementation version.

Specified by:
getVersion in interface GridSpiManagementMBean
Returns:
SPI implementation version.

getStartTimestampFormatted

public final String getStartTimestampFormatted()
Gets string presentation of the start timestamp.

Specified by:
getStartTimestampFormatted in interface GridSpiManagementMBean
Returns:
String presentation of the start timestamp.

getUpTimeFormatted

public final String getUpTimeFormatted()
Gets string presentation of up-time for this SPI.

Specified by:
getUpTimeFormatted in interface GridSpiManagementMBean
Returns:
String presentation of up-time for this SPI.

getStartTimestamp

public final long getStartTimestamp()
Get start timestamp of this SPI.

Specified by:
getStartTimestamp in interface GridSpiManagementMBean
Returns:
Start timestamp of this SPI.

getUpTime

public final long getUpTime()
Gets up-time of this SPI.

Specified by:
getUpTime in interface GridSpiManagementMBean
Returns:
Up-time of this SPI.

getLocalNodeId

public UUID getLocalNodeId()
Gets ID of the local node.

Specified by:
getLocalNodeId in interface GridSpiManagementMBean
Returns:
ID of the local node.

getGridGainHome

public final String getGridGainHome()
Gets Gridgain installation home folder.

Specified by:
getGridGainHome in interface GridSpiManagementMBean
Returns:
Gridgain installation home folder.

onContextInitialized

public void onContextInitialized(GridSpiContext spiCtx)
                          throws GridSpiException
Callback invoked when SPI context is initialized. SPI implementation may store SPI context for future access.

This method is invoked after GridSpi.spiStart(String) method is completed, so SPI should be fully functional at this point. Use this method for post-start initialization, such as subscribing a discovery listener, sending a message to remote node, etc...

Specified by:
onContextInitialized in interface GridSpi
Throws:
GridSpiException - If context initialization failed (grid will be stopped).
Parameters:
spiCtx - Spi context.

onContextDestroyed

public void onContextDestroyed()
Callback invoked prior to stopping grid before SPI context is destroyed. Once this method is complete, grid will begin shutdown sequence. Use this callback for de-initialization logic that may involve SPI context. Note that invoking SPI context after this callback is complete is considered illegal and may produce unknown results.

If GridSpiAdapter is used for SPI implementation, then it will replace actual context with dummy no-op context which is usually good-enough since grid is about to shut down.

Specified by:
onContextDestroyed in interface GridSpi

setSpiContext

protected void setSpiContext(GridSpiContext spiCtx)
Sets SPI context.

Parameters:
spiCtx - SPI context.

getSpiContext

protected GridSpiContext getSpiContext()
Gets SPI context.

Returns:
SPI context.

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
Throws:
GridSpiException - Throws in case of any error.
Returns:
Map of local node attributes this SPI wants to add.

assertParameter

protected final void assertParameter(boolean cond,
                                     String condDescr)
                              throws GridSpiException
Throws exception with uniform error message if given parameter's assertion condition is false.

Throws:
GridSpiException - Thrown if given condition is false
Parameters:
cond - Assertion condition to check.
condDescr - Description of failed condition. Note that this description should include JavaBean name of the property (not a variable name) as well condition in Java syntax like, for example:
      assertParameter(dirPath != null, "dirPath != null");
      
Note that in case when variable name is the same as JavaBean property you can just copy Java condition expression into description as a string.

startInfo

protected final String startInfo()
                          throws GridSpiException
Gets uniformly formatted message for SPI start.

Throws:
GridSpiException - If SPI is missing GridSpiInfo annotation.
Returns:
Uniformly formatted message for SPI start.

stopInfo

protected final String stopInfo()
Gets uniformly format message for SPI stop.

Returns:
Uniformly format message for SPI stop.

configInfo

protected final String configInfo(String name,
                                  Object value)
Gets uniformed string for configuration parameter.

Parameters:
name - Parameter name.
value - Parameter value.
Returns:
Uniformed string for configuration parameter.

warnSpiParameter

protected final void warnSpiParameter(String param,
                                      String attrName,
                                      GridNode rmtNode)
Check if remote node has the same attribute value as local node.

Parameters:
param - Name of the configuration parameter.
attrName - Name of the node attribute.
rmtNode - Remote node.

warnSpi

protected final void warnSpi(String spiName,
                             Class<? extends GridSpi> spiCls,
                             String attrName)
Checks if dependent SPI is the same as expected.

Parameters:
spiName - SPI configuration name.
spiCls - Expected SPI class.
attrName - SPI attribute name.

registerMBean

protected final <T extends GridSpiManagementMBean> void registerMBean(String gridName,
                                                                      T impl,
                                                                      Class<T> mbeanItf)
                            throws GridSpiException
Registers SPI MBean. Note that SPI can only register one MBean.

Throws:
GridSpiException - If registration failed.
Type Parameters:
T - Type of the MBean
Parameters:
gridName - Grid name. If null, then name will be empty.
impl - MBean implementation.
mbeanItf - MBean interface (if null, then standard JMX naming conventions are used.

unregisterMBean

protected final void unregisterMBean()
                              throws GridSpiException
Unregisters MBean.

Throws:
GridSpiException - If bean could not be unregistered.

checkConfigurationConsistency

protected void checkConfigurationConsistency(GridNode node)
Checks remote node SPI configuration and prints warnings if necessary.

Parameters:
node - Remote node.

GridGain™ 2.0.3
Java API Specification

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