org.apache.ignite.spi.checkpoint.cache

## Class CacheCheckpointSpi

- java.lang.Object
- - org.apache.ignite.spi.IgniteSpiAdapter
  - - org.apache.ignite.spi.checkpoint.cache.CacheCheckpointSpi

All Implemented Interfaces:
  CacheCheckpointSpiMBean, CheckpointSpi, IgniteSpi, IgniteSpiManagementMBean

    @IgniteSpiMultipleInstancesSupport(value=true)
    public class CacheCheckpointSpi
    extends IgniteSpiAdapter
    implements CheckpointSpi, CacheCheckpointSpiMBean

This class defines cache-based implementation for checkpoint SPI.

# Configuration

## Mandatory

This SPI has no mandatory configuration parameters.

## Optional

This SPI has following optional configuration parameters:

- Cache name (see `setCacheName(String)`)

## Java Example

`CacheCheckpointSpi` can be configured as follows:

     IgniteConfiguration cfg = new IgniteConfiguration();

     String cacheName = "checkpoints";

     GridCacheConfiguration cacheConfig = new GridCacheConfiguration();

     cacheConfig.setName(cacheName);

     GridCacheCheckpointSpi spi = new GridCacheCheckpointSpi();

     spi.setCacheName(cacheName);

     cfg.setCacheConfiguration(cacheConfig);

     // Override default checkpoint SPI.
     cfg.setCheckpointSpi(cpSpi);

     // Start grid.
     G.start(cfg);

## Spring Example

`CacheCheckpointSpi` can be configured from Spring XML configuration file:

     <bean id="grid.custom.cfg" class="org.apache.ignite.configuration.IgniteConfiguration" singleton="true">
         ...
             <!-- Cache configuration. -->
             <property name="cacheConfiguration">
                 <list>
                     <bean class="org.apache.ignite.cache.CacheConfiguration">
                         <property name="name" value="CACHE_NAME"/>
                     </bean>
                 </list>
             </property>

             <!-- SPI configuration. -->
             <property name="checkpointSpi">
                 <bean class="org.apache.ignite.spi.checkpoint.cache.CacheCheckpointSpi">
                     <property name="cacheName" value="CACHE_NAME"/>
                 </bean>
             </property>
         ...
     </bean>

For information about Spring framework visit www.springframework.org

See Also:
  `CheckpointSpi`

### Field Summary

Fields
`static String` `DFLT_CACHE_NAME` Default cache name (value is `checkpoints`).

### Fields inherited from class org.apache.ignite.spi.IgniteSpiAdapter

`gridName, ignite`

### Constructor Summary

Constructors
Constructor and Description
`CacheCheckpointSpi()`

### Method Summary

Methods
`String` `getCacheName()` Gets cache name to be used by this SPI..
`byte[]` `loadCheckpoint(String key)` Loads checkpoint from storage by its unique key.
`protected void` `onContextDestroyed0()` Method to be called in the beginning of onContextDestroyed() method.
`protected void` `onContextInitialized0(IgniteSpiContext spiCtx)` Method to be called in the end of onContextInitialized method.
`boolean` `removeCheckpoint(String key)` This method instructs the checkpoint provider to clean saved data for a given `key`.
`boolean` `saveCheckpoint(String key, byte[] state, long timeout, boolean overwrite)` Saves checkpoint to the storage.
`void` `setCacheName(String cacheName)` Sets cache name to be used by this SPI.
`void` `setCheckpointListener(CheckpointListener lsnr)` Sets the checkpoint listener.
`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.apache.ignite.spi.IgniteSpiAdapter

`addTimeoutObject, assertParameter, checkConfigurationConsistency0, configInfo, createSpiAttributeName, failureDetectionTimeout, failureDetectionTimeoutEnabled, failureDetectionTimeoutEnabled, getConsistentAttributeNames, getExceptionRegistry, getIgniteHome, getLocalNode, getLocalNodeId, getName, getNodeAttributes, getSpiContext, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, initFailureDetectionTimeout, injectables, injectResources, isNodeStopping, onClientDisconnected, onClientReconnected, onContextDestroyed, onContextInitialized, registerMBean, removeTimeoutObject, setName, 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.apache.ignite.spi.IgniteSpi

`getName, getNodeAttributes, onClientDisconnected, onClientReconnected, onContextDestroyed, onContextInitialized`

### Methods inherited from interface org.apache.ignite.spi.IgniteSpiManagementMBean

`getIgniteHome, getLocalNodeId, getName, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted`

### Field Detail

#### DFLT_CACHE_NAME

    public static final String DFLT_CACHE_NAME

Default cache name (value is `checkpoints`).

See Also:
  Constant Field Values

### Constructor Detail

#### CacheCheckpointSpi

    public CacheCheckpointSpi()

### Method Detail

#### setCacheName

    @IgniteSpiConfiguration(optional=true)
    public void setCacheName(String cacheName)

Sets cache name to be used by this SPI.

If cache name is not provided `DFLT_CACHE_NAME` is used.

Parameters:
  `cacheName` - Cache name.

#### getCacheName

    public String getCacheName()

Gets cache name to be used by this SPI..

Specified by:
  `getCacheName` in interface `CacheCheckpointSpiMBean`
Returns:
  Cache name to be used by this SPI.

#### spiStart

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

Specified by:
  `spiStart` in interface `IgniteSpi`
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.

#### onContextInitialized0

    protected void onContextInitialized0(IgniteSpiContext spiCtx)
                                  throws IgniteSpiException

Method to be called in the end of onContextInitialized method.

Overrides:
  `onContextInitialized0` in class `IgniteSpiAdapter`
Parameters:
  `spiCtx` - SPI context.
Throws:
  `IgniteSpiException` - In case of errors.

#### spiStop

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

Specified by:
  `spiStop` in interface `IgniteSpi`
Throws:
  `IgniteSpiException` - Thrown in case of any error during SPI stop.

#### onContextDestroyed0

    protected void onContextDestroyed0()

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

Overrides:
  `onContextDestroyed0` in class `IgniteSpiAdapter`

#### loadCheckpoint

    @Nullable
    public byte[] loadCheckpoint(String key)
                          throws IgniteSpiException

Loads checkpoint from storage by its unique key.

Specified by:
  `loadCheckpoint` in interface `CheckpointSpi`
Parameters:
  `key` - Checkpoint key.
Returns:
  Loaded data or `null` if there is no data for a given key.
Throws:
  `IgniteSpiException` - Thrown in case of any error while loading checkpoint data. Note that in case when given `key` is not found this method will return `null`.

#### saveCheckpoint

    public boolean saveCheckpoint(String key,
                         byte[] state,
                         long timeout,
                         boolean overwrite)
                           throws IgniteSpiException

Saves checkpoint to the storage.

Specified by:
  `saveCheckpoint` in interface `CheckpointSpi`
Parameters:
  `key` - Checkpoint unique key.
  `state` - Saved data.
  `timeout` - Every intermediate data stored by checkpoint provider should have a timeout. Timeout allows for effective resource management by checkpoint provider by cleaning saved data that are not needed anymore. Generally, the user should choose the minimum possible timeout to avoid long-term resource acquisition by checkpoint provider. Value `0` means that timeout will never expire.
  `overwrite` - Whether or not overwrite checkpoint if it already exists.
Returns:
  `true` if checkpoint has been actually saved, `false` otherwise.
Throws:
  `IgniteSpiException` - Thrown in case of any error while saving checkpoint data.

#### removeCheckpoint

    public boolean removeCheckpoint(String key)

This method instructs the checkpoint provider to clean saved data for a given `key`.

Specified by:
  `removeCheckpoint` in interface `CheckpointSpi`
Parameters:
  `key` - Key for the checkpoint to remove.
Returns:
  `true` if data has been actually removed, `false` otherwise.

#### setCheckpointListener

    public void setCheckpointListener(CheckpointListener lsnr)

Sets the checkpoint listener.

Specified by:
  `setCheckpointListener` in interface `CheckpointSpi`
Parameters:
  `lsnr` - The listener to set or `null`.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.5.0.final
Release Date | : December 29 2015