@GridSpiMultipleInstancesSupport(value=true) public class GridFileSwapSpaceSpi extends GridSpiAdapter implements GridSwapSpaceSpi, GridFileSwapSpaceSpiMBean
100 bytes, otherwise it will not
have any positive effect.
NOTE: This SPI does not support swap eviction currently, manual removes needed to reduce disk space consumption.
Every space has a name and when used in combination with in-memory data grid name and local node ID,
space name represents the actual cache name associated with this swap space. Default name is null
which is represented by DFLT_SPACE_NAME.
setBaseDirectory(String)).setMaximumSparsity(float)).setWriteBufferSize(int)).setMaxWriteQueueSize(int)).setReadStripesNumber(int)).
GridFileSwapSpaceSpi spi = new GridFileSwapSpaceSpi();
// Configure root folder path.
spi.setBaseDirectory("/path/to/swap/folder");
GridConfiguration cfg = new GridConfiguration();
// Override default swap space SPI.
cfg.setSwapSpaceSpi(spi);
// Starts grid.
G.start(cfg);
<bean id="grid.cfg" class="org.gridgain.grid.GridConfiguration" scope="singleton">
...
<property name="swapSpaceSpi">
<bean class="org.gridgain.grid.spi.swapspace.file.GridFileSwapSpaceSpi">
<property name="baseDirectory" value="/path/to/swap/folder"/>
</bean>
</property>
...
</bean>
For information about Spring framework visit www.springframework.org
GridSwapSpaceSpi| Modifier and Type | Field and Description |
|---|---|
static String |
DFLT_BASE_DIR
Default base directory.
|
static int |
DFLT_BUF_SIZE
Default write buffer size in bytes.
|
static float |
DFLT_MAX_SPARSITY
Default maximum sparsity.
|
static int |
DFLT_QUE_SIZE
Default write queue size in bytes.
|
static String |
DFLT_SPACE_NAME
Name for
null space. |
| Constructor and Description |
|---|
GridFileSwapSpaceSpi() |
| Modifier and Type | Method and Description |
|---|---|
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.
|
String |
getBaseDirectory()
Gets base directory.
|
float |
getMaximumSparsity()
Gets maximum sparsity.
|
int |
getMaxWriteQueueSize()
Gets max write queue size in bytes.
|
int |
getReadStripesNumber()
Gets read pool size.
|
int |
getWriteBufferSize()
Gets write buffer size in bytes.
|
<K> GridSpiCloseableIterator<K> |
keyIterator(String spaceName,
GridSwapContext ctx)
Gets iterator over space keys.
|
Collection<Integer> |
partitions(String spaceName)
Gets partitions IDs that are stored in the passed in space.
|
GridSpiCloseableIterator<Map.Entry<byte[],byte[]>> |
rawIterator(String spaceName)
Gets raw iterator over space entries.
|
GridSpiCloseableIterator<Map.Entry<byte[],byte[]>> |
rawIterator(String spaceName,
int part)
Gets raw iterator over space entries.
|
byte[] |
read(String spaceName,
GridSwapKey key,
GridSwapContext ctx)
Reads stored value as array of bytes by key from data space with given name.
|
Map<GridSwapKey,byte[]> |
readAll(String spaceName,
Iterable<GridSwapKey> keys,
GridSwapContext ctx)
Reads stored values as array of bytes by all passed keys from data space with
given name.
|
void |
remove(String spaceName,
GridSwapKey key,
GridInClosure<byte[]> c,
GridSwapContext ctx)
Removes value stored in data space with given name corresponding to specified key.
|
void |
removeAll(String spaceName,
Collection<GridSwapKey> keys,
GridBiInClosure<GridSwapKey,byte[]> c,
GridSwapContext ctx)
Removes values stored in data space with given name corresponding to specified keys.
|
void |
setBaseDirectory(String baseDir)
Sets base directory.
|
void |
setListener(GridSwapSpaceSpiListener evictLsnr)
Sets eviction listener to receive notifications on evicted swap entries.
|
void |
setMaximumSparsity(float maxSparsity)
Sets maximum sparsity.
|
void |
setMaxWriteQueueSize(int maxWriteQueSize)
Sets max write queue size in bytes.
|
void |
setReadStripesNumber(int readStripesNum)
Sets read stripe size.
|
void |
setWriteBufferSize(int writeBufSize)
Sets write buffer size in bytes.
|
long |
size(String spaceName)
Gets size in bytes for data space with given name.
|
void |
spiStart(String gridName)
This method is called to start SPI.
|
void |
spiStop()
This method is called to stop SPI.
|
void |
store(String spaceName,
GridSwapKey key,
byte[] val,
GridSwapContext ctx)
Stores value as array of bytes with given key into data space with given name.
|
void |
storeAll(String spaceName,
Map<GridSwapKey,byte[]> pairs,
GridSwapContext ctx)
Stores key-value pairs (both keys and values are arrays of bytes) into data
space with given name.
|
String |
toString() |
assertParameter, checkConfigurationConsistency0, configInfo, createSpiAttributeName, getConsistentAttributeNames, getGridGainHome, getLocalNodeId, getName, getNodeAttributes, getSpiContext, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormatted, injectables, onContextDestroyed, onContextDestroyed0, onContextInitialized, onContextInitialized0, registerMBean, setName, startInfo, startStopwatch, stopInfo, unregisterMBeanclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetName, getNodeAttributes, onContextDestroyed, onContextInitializedgetGridGainHome, getLocalNodeId, getName, getStartTimestamp, getStartTimestampFormatted, getUpTime, getUpTimeFormattedpublic static final String DFLT_BASE_DIR
GRIDGAIN_HOME/work folder
if GRIDGAIN_HOME system or environment variable specified, otherwise it is relative to
work folder under system java.io.tmpdir folder.public static final float DFLT_MAX_SPARSITY
public static final int DFLT_BUF_SIZE
public static final int DFLT_QUE_SIZE
public static final String DFLT_SPACE_NAME
null space.public String getBaseDirectory()
getBaseDirectory in interface GridFileSwapSpaceSpiMBean@GridSpiConfiguration(optional=true) public void setBaseDirectory(String baseDir)
baseDir - Base directory.public float getMaximumSparsity()
getMaximumSparsity in interface GridFileSwapSpaceSpiMBeanpublic void setMaximumSparsity(float maxSparsity)
maxSparsity - Maximum sparsity. Must be between 0 and 1, default is DFLT_MAX_SPARSITY.public int getWriteBufferSize()
getWriteBufferSize in interface GridFileSwapSpaceSpiMBeanpublic void setWriteBufferSize(int writeBufSize)
DFLT_BUF_SIZE.writeBufSize - Write buffer size in bytes.public int getMaxWriteQueueSize()
getMaxWriteQueueSize in interface GridFileSwapSpaceSpiMBeanpublic void setMaxWriteQueueSize(int maxWriteQueSize)
store(String, GridSwapKey, byte[], GridSwapContext) operation. Default is
DFLT_QUE_SIZE.maxWriteQueSize - Max write queue size in bytes.public int getReadStripesNumber()
getReadStripesNumber in interface GridFileSwapSpaceSpiMBeanpublic void setReadStripesNumber(int readStripesNum)
readStripesNum - Read stripe number.public void spiStart(@Nullable String gridName) throws GridSpiException
spiStart in interface GridSpigridName - Name of grid instance this SPI is being started for
(null for default grid).GridSpiException - Throws in case of any error during SPI start.public void spiStop()
throws GridSpiException
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.
spiStop in interface GridSpiGridSpiException - Thrown in case of any error during SPI stop.public void clear(@Nullable String spaceName) throws GridSpiException
clear in interface GridSwapSpaceSpispaceName - Space name to clear.GridSpiException - In case of any errors.public long size(@Nullable String spaceName) throws GridSpiException
0.size in interface GridSwapSpaceSpispaceName - Space name to get size for.GridSpiException - In case of any errors.public long count(@Nullable String spaceName) throws GridSpiException
0.count in interface GridSwapSpaceSpispaceName - Space name to get number of entries for.GridSpiException - In case of any errors.@Nullable public byte[] read(@Nullable String spaceName, GridSwapKey key, GridSwapContext ctx) throws GridSpiException
null.read in interface GridSwapSpaceSpispaceName - Name of the data space to read from.key - Key used to read value from data space.ctx - Swap context.GridSpiException - In case of any errors.public Map<GridSwapKey,byte[]> readAll(@Nullable String spaceName, Iterable<GridSwapKey> keys, GridSwapContext ctx) throws GridSpiException
readAll in interface GridSwapSpaceSpispaceName - Name of the data space to read from.keys - Keys used to read values from data space.ctx - Swap context.GridSpiException - In case of any errors.public void remove(@Nullable String spaceName, GridSwapKey key, @Nullable GridInClosure<byte[]> c, GridSwapContext ctx) throws GridSpiException
remove in interface GridSwapSpaceSpispaceName - 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.GridSpiException - In case of any errors.public void removeAll(@Nullable String spaceName, Collection<GridSwapKey> keys, @Nullable GridBiInClosure<GridSwapKey,byte[]> c, GridSwapContext ctx) throws GridSpiException
removeAll in interface GridSwapSpaceSpispaceName - 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.GridSpiException - In case of any errors.public void store(@Nullable String spaceName, GridSwapKey key, @Nullable byte[] val, GridSwapContext ctx) throws GridSpiException
store in interface GridSwapSpaceSpispaceName - 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.GridSpiException - In case of any errors.public void storeAll(@Nullable String spaceName, Map<GridSwapKey,byte[]> pairs, GridSwapContext ctx) throws GridSpiException
storeAll in interface GridSwapSpaceSpispaceName - 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.GridSpiException - In case of any errors.public void setListener(@Nullable GridSwapSpaceSpiListener evictLsnr)
setListener in interface GridSwapSpaceSpievictLsnr - Eviction listener (null to stop receiving notifications).@Nullable public Collection<Integer> partitions(@Nullable String spaceName) throws GridSpiException
partitions in interface GridSwapSpaceSpispaceName - Space name.null if space is unknown.GridSpiException - If failed.@Nullable public <K> GridSpiCloseableIterator<K> keyIterator(@Nullable String spaceName, GridSwapContext ctx) throws GridSpiException
keyIterator in interface GridSwapSpaceSpispaceName - Space name.ctx - Swap context.null if space is unknown.GridSpiException - If failed.@Nullable public GridSpiCloseableIterator<Map.Entry<byte[],byte[]>> rawIterator(@Nullable String spaceName) throws GridSpiException
rawIterator in interface GridSwapSpaceSpispaceName - Space name.null if space is unknown.GridSpiException - If failed.@Nullable public GridSpiCloseableIterator<Map.Entry<byte[],byte[]>> rawIterator(@Nullable String spaceName, int part) throws GridSpiException
rawIterator in interface GridSwapSpaceSpispaceName - Space name.part - Partition.null if space is unknown.GridSpiException - If failed.Copyright © 2014. All rights reserved.