org.apache.ignite.spi.swapspace

## Interface SwapSpaceSpi

All Superinterfaces:
  IgniteSpi

All Known Implementing Classes:
  FileSwapSpaceSpi, NoopSwapSpaceSpi

    public interface SwapSpaceSpi
    extends IgniteSpi

Provides a mechanism in grid for storing data on disk. Ignite cache uses swap space to overflow data to disk if it cannot fit in memory. It's also possible to use swap space directly by calling `Ignite` API swap-related methods. Logically storage is organized into independent 'spaces' in which data is stored.

All swap space implementations can be configured to prevent infinite growth and evict oldest entries.

The default swap space SPI is `FileSwapSpaceSpi` which stores values on disk in files and keeps keys in memory.

Ignite provides the following `GridSwapSpaceSpi` implementations:

- `FileSwapSpaceSpi` - pure Java implementation with in-memory keys. This SPI is used by default.
- `NoopSwapSpaceSpi` - no-op SPI mainly for testing.

NOTE: this SPI (i.e. methods in this interface) should never be used directly. SPIs provide internal view on the subsystem and is used internally by Ignite kernal. In rare use cases when access to a specific implementation of this SPI is required - an instance of this SPI can be obtained via `Ignite.configuration()` method to check its configuration properties or call other non-SPI methods. Note again that calling methods from this interface on the obtained instance can lead to undefined behavior and explicitly not supported.

### Method Summary

Methods
`void` `clear(String spaceName)` Entirely clears data space with given name, if any.
`long` `count(String spaceName)` Gets number of stored entries (keys) in data space with given name.
`long` `count(String spaceName, Set<Integer> parts)` Gets number of stored entries (keys) in data space with given name.
`<K> IgniteSpiCloseableIterator<K>` `keyIterator(String spaceName, SwapContext ctx)` Gets iterator over space keys.
`Collection<Integer>` `partitions(String spaceName)` Gets partitions IDs that are stored in the passed in space.
`IgniteSpiCloseableIterator<Map.Entry<byte[],byte[]>>` `rawIterator(String spaceName)` Gets raw iterator over space entries.
`IgniteSpiCloseableIterator<Map.Entry<byte[],byte[]>>` `rawIterator(String spaceName, int part)` Gets raw iterator over space entries.
`byte[]` `read(String spaceName, SwapKey key, SwapContext ctx)` Reads stored value as array of bytes by key from data space with given name.
`Map<SwapKey,byte[]>` `readAll(String spaceName, Iterable<SwapKey> keys, SwapContext ctx)` Reads stored values as array of bytes by all passed keys from data space with given name.
`void` `remove(String spaceName, SwapKey key, IgniteInClosure<byte[]> c, SwapContext ctx)` Removes value stored in data space with given name corresponding to specified key.
`void` `removeAll(String spaceName, Collection<SwapKey> keys, IgniteBiInClosure<SwapKey,byte[]> c, SwapContext ctx)` Removes values stored in data space with given name corresponding to specified keys.
`void` `setListener(SwapSpaceSpiListener evictLsnr)` Sets eviction listener to receive notifications on evicted swap entries.
`long` `size(String spaceName)` Gets size in bytes for data space with given name.
`void` `store(String spaceName, SwapKey key, byte[] val, SwapContext ctx)` Stores value as array of bytes with given key into data space with given name.
`void` `storeAll(String spaceName, Map<SwapKey,byte[]> pairs, SwapContext ctx)` Stores key-value pairs (both keys and values are arrays of bytes) into data space with given name.

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

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

### Method Detail

#### clear

    void clear(@Nullable
             String spaceName)
               throws IgniteSpiException

Entirely clears data space with given name, if any.

Parameters:
  `spaceName` - Space name to clear.
Throws:
  `IgniteSpiException` - In case of any errors.

#### size

    long size(@Nullable
            String spaceName)
              throws IgniteSpiException

Gets size in bytes for data space with given name. If specified space does not exist this method returns `0`.

Parameters:
  `spaceName` - Space name to get size for.
Returns:
  Size in bytes.
Throws:
  `IgniteSpiException` - In case of any errors.

#### count

    long count(@Nullable
             String spaceName)
               throws IgniteSpiException

Gets number of stored entries (keys) in data space with given name. If specified space does not exist this method returns `0`.

Parameters:
  `spaceName` - Space name to get number of entries for.
Returns:
  Number of stored entries in specified space.
Throws:
  `IgniteSpiException` - In case of any errors.

#### count

    long count(@Nullable
             String spaceName,
             Set<Integer> parts)
               throws IgniteSpiException

Gets number of stored entries (keys) in data space with given name. If specified space does not exist this method returns `0`.

Parameters:
  `spaceName` - Space name to get number of entries for.
  `parts` - Partitions.
Returns:
  Number of stored entries in specified space.
Throws:
  `IgniteSpiException` - In case of any errors.

#### read

    @Nullable
    byte[] read(@Nullable
                       String spaceName,
                       SwapKey key,
                       SwapContext ctx)
                throws IgniteSpiException

Reads stored value as array of bytes by key from data space with given name. If specified space does not exist this method returns `null`.

Parameters:
  `spaceName` - Name of the data space to read from.
  `key` - Key used to read value from data space.
  `ctx` - Swap context.
Returns:
  Value as array of bytes stored in specified data space that matches to given key.
Throws:
  `IgniteSpiException` - In case of any errors.

#### readAll

    Map<SwapKey,byte[]> readAll(@Nullable
                              String spaceName,
                              Iterable<SwapKey> keys,
                              SwapContext ctx)
                                throws IgniteSpiException

Reads stored values as array of bytes by all passed keys from data space with given name. If specified space does not exist this method returns empty map.

Parameters:
  `spaceName` - Name of the data space to read from.
  `keys` - Keys used to read values from data space.
  `ctx` - Swap context.
Returns:
  Map in which keys are the ones passed into method and values are corresponding values read from swap storage.
Throws:
  `IgniteSpiException` - In case of any errors.

#### remove

    void remove(@Nullable
              String spaceName,
              SwapKey key,
              @Nullable
              IgniteInClosure<byte[]> c,
              SwapContext ctx)
                throws IgniteSpiException

Removes value stored in data space with given name corresponding to specified key.

Parameters:
  `spaceName` - Space name to remove value from.
  `key` - Key to remove value in the specified space for.
  `c` - Optional closure that takes removed value and executes after actual removing. If there was no value in storage the closure is not executed.
  `ctx` - Swap context.
Throws:
  `IgniteSpiException` - In case of any errors.

#### removeAll

    void removeAll(@Nullable
                 String spaceName,
                 Collection<SwapKey> keys,
                 @Nullable
                 IgniteBiInClosure<SwapKey,byte[]> c,
                 SwapContext ctx)
                   throws IgniteSpiException

Removes values stored in data space with given name corresponding to specified keys.

Parameters:
  `spaceName` - Space name to remove values from.
  `keys` - Keys to remove value in the specified space for.
  `c` - Optional closure that takes removed value and executes after actual removing. If there was no value in storage the closure is not executed.
  `ctx` - Swap context.
Throws:
  `IgniteSpiException` - In case of any errors.

#### store

    void store(@Nullable
             String spaceName,
             SwapKey key,
             @Nullable
             byte[] val,
             SwapContext ctx)
               throws IgniteSpiException

Stores value as array of bytes with given key into data space with given name.

Parameters:
  `spaceName` - Space name to store key-value pair into.
  `key` - Key to store given value for. This key can be used further to read or remove stored value.
  `val` - Some value as array of bytes to store into specified data space.
  `ctx` - Swap context.
Throws:
  `IgniteSpiException` - In case of any errors.

#### storeAll

    void storeAll(@Nullable
                String spaceName,
                Map<SwapKey,byte[]> pairs,
                SwapContext ctx)
                  throws IgniteSpiException

Stores key-value pairs (both keys and values are arrays of bytes) into data space with given name.

Parameters:
  `spaceName` - Space name to store key-value pairs into.
  `pairs` - Map of stored key-value pairs where each one is an array of bytes.
  `ctx` - Swap context.
Throws:
  `IgniteSpiException` - In case of any errors.

#### setListener

    void setListener(@Nullable
                   SwapSpaceSpiListener evictLsnr)

Sets eviction listener to receive notifications on evicted swap entries.

Parameters:
  `evictLsnr` - Eviction listener (`null` to stop receiving notifications).

#### partitions

    @Nullable
    Collection<Integer> partitions(@Nullable
                                          String spaceName)
                                   throws IgniteSpiException

Gets partitions IDs that are stored in the passed in space.

Parameters:
  `spaceName` - Space name.
Returns:
  Partitions IDs or `null` if space is unknown.
Throws:
  `IgniteSpiException` - If failed.

#### keyIterator

    @Nullable
    <K> IgniteSpiCloseableIterator<K> keyIterator(@Nullable
                                                         String spaceName,
                                                         SwapContext ctx)
                                              throws IgniteSpiException

Gets iterator over space keys.

Parameters:
  `spaceName` - Space name.
  `ctx` - Swap context.
Returns:
  Iterator over space entries or `null` if space is unknown.
Throws:
  `IgniteSpiException` - If failed.

#### rawIterator

    @Nullable
    IgniteSpiCloseableIterator<Map.Entry<byte[],byte[]>> rawIterator(@Nullable
                                                                            String spaceName)
                                                                     throws IgniteSpiException

Gets raw iterator over space entries.

Parameters:
  `spaceName` - Space name.
Returns:
  Iterator over space entries or `null` if space is unknown.
Throws:
  `IgniteSpiException` - If failed.

#### rawIterator

    @Nullable
    IgniteSpiCloseableIterator<Map.Entry<byte[],byte[]>> rawIterator(@Nullable
                                                                            String spaceName,
                                                                            int part)
                                                                     throws IgniteSpiException

Gets raw iterator over space entries.

Parameters:
  `spaceName` - Space name.
  `part` - Partition.
Returns:
  Iterator over space entries or `null` if space is unknown.
Throws:
  `IgniteSpiException` - If failed.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

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