GridGain™ 2.1.0
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, GridDatabaseCheckpointSpi, GridFifoQueueCollisionSpi, GridGigaSpacesCheckpointSpi, GridJbossDiscoverySpi, GridJdkLocalMetricsSpi, GridJgroupsCommunicationSpi, GridJgroupsDiscoverySpi, GridJmsCommunicationSpi, GridJmsDiscoverySpi, GridJobStealingCollisionSpi, GridJobStealingFailoverSpi, GridJxinsightTracingSpi, GridLocalDeploymentSpi, GridMailCommunicationSpi, GridMailDiscoverySpi, GridMemoryEventStorageSpi, GridMuleCommunicationSpi, GridMuleCommunicationSpi, GridMuleDiscoverySpi, GridMuleDiscoverySpi, GridMulticastDiscoverySpi, GridNeverFailoverSpi, GridNodeFilterTopologySpi, 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.1.0

 

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  String configInfo(String name, Object value)
          Gets uniformed string for configuration parameter.
protected  String createSpiAttributeName(String attrName)
          Creates new name for the given attribute.
 String getAuthor()
          Gets SPI provider's author.
protected  List<String> getConsistentAttributeNames()
          Returns back list of attributes that should be consistent for this SPI.
 String getGridGainHome()
          Gets Gridgain installation home folder (i.e.
 UUID getLocalNodeId()
          Gets ID of the local node.
 String getName()
          Gets SPI name.
 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 in ms.
 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.
 void setName(String name)
          Sets SPI name.
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.
 
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. SPI name will be initialized to the simple name of the class (see Class.getSimpleName()).

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 in ms.

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 (i.e. ${GRIDGAIN_HOME});

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

getName

public String getName()
Gets SPI name.

Specified by:
getName in interface GridSpi
Specified by:
getName in interface GridSpiManagementMBean
Returns:
SPI name.

setName

@GridSpiConfiguration(optional=true)
public void setName(String name)
Sets SPI name.

Parameters:
name - SPI name.

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.

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.

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.

Returns:
List or attribute names.

createSpiAttributeName

protected String createSpiAttributeName(String attrName)
Creates new name for the given attribute. Name contains SPI name prefix.

Parameters:
attrName - SPI attribute name.
Returns:
New name with SPI name prefix.

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.