org.apache.ignite.spi

## Class IgniteSpiAdapter

- java.lang.Object
- - org.apache.ignite.spi.IgniteSpiAdapter

All Implemented Interfaces:
  IgniteSpi, IgniteSpiManagementMBean

Direct Known Subclasses:
  AdaptiveLoadBalancingSpi, AlwaysFailoverSpi, CacheCheckpointSpi, FifoQueueCollisionSpi, FileSwapSpaceSpi, JdbcCheckpointSpi, JobStealingCollisionSpi, JobStealingFailoverSpi, LocalDeploymentSpi, MemoryEventStorageSpi, NeverFailoverSpi, NoopCheckpointSpi, NoopCollisionSpi, NoopIndexingSpi, NoopSwapSpaceSpi, PriorityQueueCollisionSpi, RoundRobinLoadBalancingSpi, SharedFsCheckpointSpi, TcpCommunicationSpi, TcpDiscoverySpi, WeightedRandomLoadBalancingSpi

    public abstract class IgniteSpiAdapter
    extends Object
    implements IgniteSpi, IgniteSpiManagementMBean

This class provides convenient adapter for SPI implementations.

### Field Summary

Fields
`protected String` `gridName` Grid instance name.
`protected Ignite` `ignite` Ignite instance.

### Constructor Summary

Constructors
`protected` `IgniteSpiAdapter()` Creates new adapter and initializes it from the current (this) class.

### Method Summary

Methods
`protected void` `addTimeoutObject(IgniteSpiTimeoutObject obj)`
`protected void` `assertParameter(boolean cond, String condDesc)` Throws exception with uniform error message if given parameter's assertion condition is `false`.
`protected void` `checkConfigurationConsistency0(IgniteSpiContext spiCtx, ClusterNode node, boolean starting)` Method which is called in the end of checkConfigurationConsistency() method.
`protected String` `configInfo(String name, Object val)` Gets uniformed string for configuration parameter.
`protected String` `createSpiAttributeName(String attrName)` Creates new name for the given attribute.
`long` `failureDetectionTimeout()` Returns failure detection timeout set to use for network related operations.
`boolean` `failureDetectionTimeoutEnabled()` Checks whether failure detection timeout is enabled for this `IgniteSpi`.
`void` `failureDetectionTimeoutEnabled(boolean enabled)` Enables or disables failure detection timeout.
`protected List<String>` `getConsistentAttributeNames()` Returns back a list of attributes that should be consistent for this SPI.
`IgniteExceptionRegistry` `getExceptionRegistry()` Gets Exception registry.
`String` `getIgniteHome()` Gets Ignite installation home folder (i.e.
`protected ClusterNode` `getLocalNode()`
`UUID` `getLocalNodeId()` Gets ID of the local node.
`String` `getName()` Gets SPI name.
`Map<String,Object>` `getNodeAttributes()` This method is called before SPI starts (before method `IgniteSpi.spiStart(String)` is called).
`IgniteSpiContext` `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.
`protected void` `initFailureDetectionTimeout()` Initiates and checks failure detection timeout value.
`Collection<Object>` `injectables()` This method returns SPI internal instances that need to be injected as well.
`protected void` `injectResources(Ignite ignite)` Inject ignite instance.
`protected boolean` `isNodeStopping()`
`void` `onBeforeStart()` This method is called by built-in managers implementation to avoid repeating SPI start attempts.
`void` `onClientDisconnected(IgniteFuture<?> reconnectFut)` Client node disconnected callback.
`void` `onClientReconnected(boolean clusterRestarted)` Client node reconnected callback.
`void` `onContextDestroyed()` Callback invoked prior to stopping grid before SPI context is destroyed.
`protected void` `onContextDestroyed0()` Method to be called in the beginning of onContextDestroyed() method.
`void` `onContextInitialized(IgniteSpiContext spiCtx)` Callback invoked when SPI context is initialized.
`protected void` `onContextInitialized0(IgniteSpiContext spiCtx)` Method to be called in the end of onContextInitialized method.
`protected <T extends IgniteSpiManagementMBean> void` `registerMBean(String gridName, T impl, Class<T> mbeanItf)` Registers SPI MBean.
`protected void` `removeTimeoutObject(IgniteSpiTimeoutObject obj)`
`void` `setName(String name)` Sets SPI name.
`boolean` `started()` Checks if `onBeforeStart()` has been called on this SPI instance.
`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.apache.ignite.spi.IgniteSpi

`spiStart, spiStop`

### Field Detail

#### ignite

    protected Ignite ignite

Ignite instance.

#### gridName

    protected String gridName

Grid instance name.

### Constructor Detail

#### IgniteSpiAdapter

    protected IgniteSpiAdapter()

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.

#### onBeforeStart

    public final void onBeforeStart()

This method is called by built-in managers implementation to avoid repeating SPI start attempts.

#### started

    public final boolean started()

Checks if `onBeforeStart()` has been called on this SPI instance.

Returns:
  `True` if `onBeforeStart()` has already been called.

#### getStartTimestampFormatted

    public final String getStartTimestampFormatted()

Gets string presentation of the start timestamp.

Specified by:
  `getStartTimestampFormatted` in interface `IgniteSpiManagementMBean`
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 `IgniteSpiManagementMBean`
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 `IgniteSpiManagementMBean`
Returns:
  Start timestamp of this SPI.

#### getUpTime

    public final long getUpTime()

Gets up-time of this SPI in ms.

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

#### getLocalNodeId

    public UUID getLocalNodeId()

Gets ID of the local node.

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

#### getLocalNode

    protected ClusterNode getLocalNode()

Returns:
  Local node.

#### getIgniteHome

    public final String getIgniteHome()

Gets Ignite installation home folder (i.e. ${IGNITE_HOME});

Specified by:
  `getIgniteHome` in interface `IgniteSpiManagementMBean`
Returns:
  Ignite installation home folder.

#### getName

    public String getName()

Gets SPI name.

Specified by:
  `getName` in interface `IgniteSpi`
Specified by:
  `getName` in interface `IgniteSpiManagementMBean`
Returns:
  SPI name.

#### setName

    @IgniteSpiConfiguration(optional=true)
    public void setName(String name)

Sets SPI name.

Parameters:
  `name` - SPI name.

#### onContextInitialized

    public final void onContextInitialized(IgniteSpiContext spiCtx)
                                    throws IgniteSpiException

Callback invoked when SPI context is initialized. SPI implementation may store SPI context for future access.

This method is invoked after `IgniteSpi.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 `IgniteSpi`
Parameters:
  `spiCtx` - Spi context.
Throws:
  `IgniteSpiException` - If context initialization failed (grid will be stopped).

#### onContextInitialized0

    protected void onContextInitialized0(IgniteSpiContext spiCtx)
                                  throws IgniteSpiException

Method to be called in the end of onContextInitialized method.

Parameters:
  `spiCtx` - SPI context.
Throws:
  `IgniteSpiException` - In case of errors.

#### onContextDestroyed

    public final 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 `IgniteSpiAdapter` 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 `IgniteSpi`

#### onClientDisconnected

    public void onClientDisconnected(IgniteFuture<?> reconnectFut)

Client node disconnected callback.

Specified by:
  `onClientDisconnected` in interface `IgniteSpi`
Parameters:
  `reconnectFut` - Future that will be completed when client reconnected.

#### onClientReconnected

    public void onClientReconnected(boolean clusterRestarted)

Client node reconnected callback.

Specified by:
  `onClientReconnected` in interface `IgniteSpi`
Parameters:
  `clusterRestarted` - `True` if all cluster nodes restarted while client was disconnected.

#### injectResources

    @IgniteInstanceResource
    protected void injectResources(Ignite ignite)

Inject ignite instance.

Parameters:
  `ignite` - Ignite instance.

#### onContextDestroyed0

    protected void onContextDestroyed0()

Method to be called in the beginning of onContextDestroyed() method.

#### injectables

    public Collection<Object> injectables()

This method returns SPI internal instances that need to be injected as well. Usually these will be instances provided to SPI externally by user, e.g. during SPI configuration.

Returns:
  Internal SPI objects that also need to be injected.

#### getSpiContext

    public IgniteSpiContext getSpiContext()

Gets SPI context.

Returns:
  SPI context.

#### getExceptionRegistry

    public IgniteExceptionRegistry getExceptionRegistry()

Gets Exception registry.

Returns:
  Exception registry.

#### getNodeAttributes

    public Map<String,Object> getNodeAttributes()
                                         throws IgniteSpiException

This method is called before SPI starts (before method `IgniteSpi.spiStart(String)` is called). It allows SPI implementation to add attributes to a local node. Kernal 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 `IgniteSpi`
Returns:
  Map of local node attributes this SPI wants to add.
Throws:
  `IgniteSpiException` - Throws in case of any error.

#### assertParameter

    protected final void assertParameter(boolean cond,
                       String condDesc)
                                  throws IgniteSpiException

Throws exception with uniform error message if given parameter's assertion condition is `false`.

Parameters:
  `cond` - Assertion condition to check.
  `condDesc` - 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.
Throws:
  `IgniteSpiException` - Thrown if given condition is `false`

#### startInfo

    protected final String startInfo()

Gets uniformly formatted message for SPI start.

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 val)

Gets uniformed string for configuration parameter.

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

#### registerMBean

    protected final <T extends IgniteSpiManagementMBean> void registerMBean(String gridName,
                                                          T impl,
                                                          Class<T> mbeanItf)
                                throws IgniteSpiException

Registers SPI MBean. Note that SPI can only register one MBean.

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.
Throws:
  `IgniteSpiException` - If registration failed.

#### unregisterMBean

    protected final void unregisterMBean()
                                  throws IgniteSpiException

Unregisters MBean.

Throws:
  `IgniteSpiException` - If bean could not be unregistered.

#### isNodeStopping

    protected final boolean isNodeStopping()

Returns:
  `True` if node is stopping.

#### checkConfigurationConsistency0

    protected void checkConfigurationConsistency0(IgniteSpiContext spiCtx,
                                      ClusterNode node,
                                      boolean starting)
                                           throws IgniteSpiException

Method which is called in the end of checkConfigurationConsistency() method. May be overriden in SPIs.

Parameters:
  `spiCtx` - SPI context.
  `node` - Remote node.
  `starting` - If this node is starting or not.
Throws:
  `IgniteSpiException` - in case of errors.

#### getConsistentAttributeNames

    protected List<String> getConsistentAttributeNames()

Returns back a 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.

#### addTimeoutObject

    protected void addTimeoutObject(IgniteSpiTimeoutObject obj)

Parameters:
  `obj` - Timeout object.
See Also:
  `IgniteSpiContext.addTimeoutObject(IgniteSpiTimeoutObject)`

#### removeTimeoutObject

    protected void removeTimeoutObject(IgniteSpiTimeoutObject obj)

Parameters:
  `obj` - Timeout object.
See Also:
  `IgniteSpiContext.removeTimeoutObject(IgniteSpiTimeoutObject)`

#### initFailureDetectionTimeout

    protected void initFailureDetectionTimeout()

Initiates and checks failure detection timeout value.

#### failureDetectionTimeoutEnabled

    public void failureDetectionTimeoutEnabled(boolean enabled)

Enables or disables failure detection timeout.

Parameters:
  `enabled` - `true` if enable, `false` otherwise.

#### failureDetectionTimeoutEnabled

    public boolean failureDetectionTimeoutEnabled()

Checks whether failure detection timeout is enabled for this `IgniteSpi`.

Returns:
  `true` if enabled, `false` otherwise.

#### failureDetectionTimeout

    public long failureDetectionTimeout()

Returns failure detection timeout set to use for network related operations.

Returns:
  failure detection timeout in milliseconds or `0` if the timeout is disabled.

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.9.0
Release Date | : March 2 2017