org.apache.ignite.spi

## Interface IgniteSpi

All Known Subinterfaces:
  CheckpointSpi, CollisionSpi, CommunicationSpi<T>, DeploymentSpi, DiscoverySpi, EventStorageSpi, FailoverSpi, IndexingSpi, LoadBalancingSpi, SwapSpaceSpi

All Known Implementing Classes:
  AdaptiveLoadBalancingSpi, AlwaysFailoverSpi, CacheCheckpointSpi, FifoQueueCollisionSpi, FileSwapSpaceSpi, IgniteSpiAdapter, JdbcCheckpointSpi, JobStealingCollisionSpi, JobStealingFailoverSpi, LocalDeploymentSpi, MemoryEventStorageSpi, NeverFailoverSpi, NoopCheckpointSpi, NoopCollisionSpi, NoopIndexingSpi, NoopSwapSpaceSpi, PriorityQueueCollisionSpi, RoundRobinLoadBalancingSpi, SharedFsCheckpointSpi, TcpClientDiscoverySpi, TcpCommunicationSpi, TcpDiscoverySpi, WeightedRandomLoadBalancingSpi

    public interface IgniteSpi

This interface defines life-cycle of SPI implementation. Every SPI implementation should implement this interface. Kernal will not load SPI that doesn't implement this interface.

Grid SPI's can be injected using IoC (dependency injection) with ignite resources. Both, field and method based injection are supported. The following ignite resources can be injected:

- `LoggerResource`
- `SpringApplicationContextResource`
- `SpringResource`

Refer to corresponding resource documentation for more information.

### Method Summary

Methods
`String` `getName()` Gets SPI name.
`Map<String,Object>` `getNodeAttributes()` This method is called before SPI starts (before method `spiStart(String)` is called).
`void` `onContextDestroyed()` Callback invoked prior to stopping grid before SPI context is destroyed.
`void` `onContextInitialized(IgniteSpiContext spiCtx)` Callback invoked when SPI context is initialized.
`void` `spiStart(String gridName)` This method is called to start SPI.
`void` `spiStop()` This method is called to stop SPI.

### Method Detail

#### getName

    String getName()

Gets SPI name.

Returns:
  SPI name.

#### getNodeAttributes

    Map<String,Object> getNodeAttributes()
                                         throws IgniteSpiException

This method is called before SPI starts (before method `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.

Returns:
  Map of local node attributes this SPI wants to add.
Throws:
  `IgniteSpiException` - Throws in case of any error.

#### spiStart

    void spiStart(@Nullable
                String gridName)
                  throws IgniteSpiException

This method is called to start SPI. After this method returns successfully kernel assumes that SPI is fully operational.

Parameters:
  `gridName` - Name of grid instance this SPI is being started for (`null` for default grid).
Throws:
  `IgniteSpiException` - Throws in case of any error during SPI start.

#### onContextInitialized

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

Parameters:
  `spiCtx` - Spi context.
Throws:
  `IgniteSpiException` - If context initialization failed (grid will be stopped).

#### onContextDestroyed

    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.

#### spiStop

    void spiStop()
                 throws IgniteSpiException

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.

Throws:
  `IgniteSpiException` - Thrown in case of any error during SPI stop.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0-RC3
Release Date | : March 24 2015