org.apache.ignite.internal.processors.cache.distributed.dht

## Class GridDhtCacheAdapter<K,V>

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.GridCacheAdapter<K,V>
  - - org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheAdapter<K,V>
    - - org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter<K,V>

All Implemented Interfaces:
  Externalizable, Serializable, Iterable<javax.cache.Cache.Entry<K,V>>, GridCache<K,V>, CacheProjection<K,V>, GridCacheProjectionEx<K,V>

Direct Known Subclasses:
  GridDhtAtomicCache, GridDhtTransactionalCacheAdapter

    public abstract class GridDhtCacheAdapter<K,V>
    extends GridDistributedCacheAdapter<K,V>

DHT cache adapter.

See Also:
  Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from class org.apache.ignite.internal.processors.cache.GridCacheAdapter

`GridCacheAdapter.AsyncOp<T>, GridCacheAdapter.CacheExpiryPolicy, GridCacheAdapter.FutureHolder, GridCacheAdapter.UpdateGetTimeStatClosure<T>, GridCacheAdapter.UpdatePutAndGetTimeStatClosure<T>, GridCacheAdapter.UpdatePutTimeStatClosure<T>, GridCacheAdapter.UpdateRemoveTimeStatClosure<T>, GridCacheAdapter.UpdateTimeStatClosure<T>`

### Field Summary

Fields
`protected GridCachePreloader<K,V>` `preldr` Preloader.

### Fields inherited from class org.apache.ignite.internal.processors.cache.GridCacheAdapter

`cacheCfg, CLEAR_ALL_SPLIT_THRESHOLD, ctx, gridCfg, keyCheck, lastFut, locNodeId, log, map, metrics, mxBean`

### Constructor Summary

Constructors
`protected` `GridDhtCacheAdapter()` Empty constructor required for `Externalizable`.
`protected` `GridDhtCacheAdapter(GridCacheContext<K,V> ctx)`
`protected` `GridDhtCacheAdapter(GridCacheContext<K,V> ctx, GridCacheConcurrentMap<K,V> map)` Constructor used for near-only cache.

### Method Summary

Methods
`long` `beginMultiUpdate()` Starts multi-update lock.
`GridDhtPreloader<K,V>` `dhtPreloader()`
`void` `endMultiUpdate()` Ends multi-update lock.
`javax.cache.Cache.Entry<K,V>` `entry(K key)` Gets entry from cache with the specified key.
`GridCacheEntryEx<K,V>` `entryEx(K key, boolean touch)`
`GridCacheEntryEx<K,V>` `entryEx(K key, long topVer)`
`GridDhtCacheEntry<K,V>` `entryExx(K key)`
`GridDhtCacheEntry<K,V>` `entryExx(K key, long topVer)`
`GridCacheEntryEx<K,V>` `entryExx(K key, long topVer, boolean allowDetached, boolean touch)` Gets or creates entry for given key.
`Set<javax.cache.Cache.Entry<K,V>>` `entrySet(int part)` Gets set containing cache entries that belong to provided partition or `null` if partition is not found locally.
`IgniteInternalFuture<Map<K,V>>` `getAllAsync(Collection<? extends K> keys, boolean forcePrimary, boolean skipTx, GridCacheEntryEx<K,V> entry, UUID subjId, String taskName, boolean deserializePortable, boolean skipVals)` This method is used internally.
`GridDhtFuture<Collection<GridCacheEntryInfo<K,V>>>` `getDhtAsync(UUID reader, long msgId, LinkedHashMap<? extends K,Boolean> keys, boolean readThrough, boolean reload, long topVer, UUID subjId, int taskNameHash, boolean deserializePortable, IgniteCacheExpiryPolicy expiry, boolean skipVals)`
`protected void` `init()` Post constructor initialization for subclasses.
`void` `loadCache(IgniteBiPredicate<K,V> p, long ttl, Object[] args)` Delegates to `CacheStore.loadCache(org.apache.ignite.lang.IgniteBiInClosure,Object...)` method to load state from the underlying persistent storage.
`Iterator<javax.cache.Cache.Entry<K,V>>` `localEntriesIterator(boolean primary, boolean backup)`
`void` `localLoad(Collection<? extends K> keys, javax.cache.expiry.ExpiryPolicy plc)`
`IgniteInternalFuture<?>` `multiUpdateFinishFuture(long topVer)` Creates multi update finish future.
`GridDhtTopologyFuture` `multiUpdateTopologyFuture()`
`abstract GridNearCacheAdapter<K,V>` `near()`
`void` `onDeferredDelete(GridCacheEntryEx<K,V> entry, GridCacheVersion ver)`
`void` `onKernalStart()` Kernal start callback.
`void` `onKernalStop()` Kernal stop callback.
`GridDhtCacheEntry<K,V>` `peekExx(K key)`
`GridCachePreloader<K,V>` `preloader()`
`int` `primarySize()` Gets the number of all primary entries cached on this node.
`void` `printMemoryStats()` Prints memory stats.
`protected void` `processNearGetRequest(UUID nodeId, GridNearGetRequest<K,V> req)`
`V` `reload(K key)` Reloads a single key from persistent storage.
`void` `sendTtlUpdateRequest(IgniteCacheExpiryPolicy expiryPlc)`
`List<GridCacheClearAllRunnable<K,V>>` `splitClearLocally()` Split clearLocally all task into multiple runnables.
`void` `start()` Starts this cache.
`void` `stop()` Stops this cache.
`GridDhtPartitionTopology<K,V>` `topology()`
`String` `toString()`
`void` `unlockAll(Collection<? extends K> keys, IgnitePredicate<javax.cache.Cache.Entry<K,V>>[] filter)` Unlocks given keys only if current thread owns the locks.

### Methods inherited from class org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheAdapter

`lockAllAsync, lockAllAsync, removeAll, removeAllAsync, removeVersionedEntry, txLockAsync`

### Methods inherited from class org.apache.ignite.internal.processors.cache.GridCacheAdapter

`affinity, allEntries, asyncOp, asyncOpAcquire, asyncOpRelease, awaitLastFut, cache, checkJta, clear, clear, clearAsync, clearLocally, clearLocally, clearLocally, clearLocally0, clearLocally0, commitTxAsync, compact, compact, compactAll, compactAll, configuration, containsKey, containsKeyAsync, containsKeys, containsKeysAsync, containsValue, context, entries, entryEx, entryExSafe, entrySet, entrySet, entrySet, entrySetx, evict, evict, evictAll, evictAll, evictAll, expiry, expiryPolicy, flags, flagsOff, flagsOn, forAll, forceRepartition, forEach, forSubjectId, get, get, get, getAll, getAll, getAllAsync, getAllAsync, getAllAsync, getAllOutTx, getAllOutTxAsync, getAsync, getAsync, getForcePrimary, getForcePrimaryAsync, globalPrimarySize, globalSize, gridProjection, igfsDataSpaceMax, igfsDataSpaceUsed, igniteIterator, invoke, invokeAll, invokeAll, invokeAllAsync, invokeAllAsync, invokeAsync, isColocated, isDht, isDhtAtomic, isEmpty, isIgfsDataCache, isLocal, isLocked, isLockedByThread, isMongoDataCache, isMongoMetaCache, isNear, iterator, iterator, keepPortable, keepPortable0, keySet, keySet, loadAll, loadCacheAsync, localEntries, localPeek, localSize, lock, lockAll, lockAsync, log, map, metrics, metrics0, mxBean, name, nearSize, offHeapAllocatedSize, offHeapEntriesCount, offHeapIterator, onIgfsDataSizeChanged, onUndeploy, overflowSize, peek, peek, peek, peek0, peek0, peek0, peekAll, peekAll0, peekAll0, peekEx, predicate, primaryEntrySet, primaryEntrySet, primaryEntrySetx, primaryKeySet, primaryKeySet, primaryValues, primaryValues, projection, projection, projection, promote, promote, promoteAll, put, put, putAll, putAllAsync, putAllDr, putAllDrAsync, putAsync, putAsync, putIfAbsent, putIfAbsentAsync, putx, putx, putxAsync, putxAsync, putxIfAbsent, putxIfAbsentAsync, queries, randomEntry, readExternal, readResolve, readThroughAllAsync, reloadAll, reloadAll, reloadAll, reloadAllAsync, reloadAllAsync, reloadAllAsync, reloadAsync, remove, remove, remove, removeAll, removeAllAsync, removeAllAsync, removeAllDr, removeAllDrAsync, removeAsync, removeAsync, removeAsync, removeEntry, removeIfObsolete, removex, removex, removex, removexAsync, removexAsync, removexAsync, replace, replace, replaceAsync, replaceAsync, replacex, replacex, replacexAsync, replacexAsync, saveFuture, size, size, sizeAsync, startInfo, stopInfo, swapIterator, swapKeys, swapSize, toMap, tx, txStart, txStart, txStart, txStartEx, txSynchronizations, txSynchronize, txUnsynchronize, unlock, validateCacheKey, validateCacheKeys, values, values, withExpiryPolicy, writeExternal`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### preldr

    protected GridCachePreloader<K,V> preldr

Preloader.

### Constructor Detail

#### GridDhtCacheAdapter

    protected GridDhtCacheAdapter()

Empty constructor required for `Externalizable`.

#### GridDhtCacheAdapter

    protected GridDhtCacheAdapter(GridCacheContext<K,V> ctx)

Parameters:
  `ctx` - Context.

#### GridDhtCacheAdapter

    protected GridDhtCacheAdapter(GridCacheContext<K,V> ctx,
                       GridCacheConcurrentMap<K,V> map)

Constructor used for near-only cache.

Parameters:
  `ctx` - Cache context.
  `map` - Cache map.

### Method Detail

#### init

    protected void init()

Post constructor initialization for subclasses.

Overrides:
  `init` in class `GridCacheAdapter<K,V>`

#### start

    public void start()
               throws IgniteCheckedException

Starts this cache. Child classes should override this method to provide custom start-up behavior.

Overrides:
  `start` in class `GridCacheAdapter<K,V>`
Throws:
  `IgniteCheckedException` - If start failed.

#### stop

    public void stop()

Stops this cache. Child classes should override this method to provide custom stop behavior.

Overrides:
  `stop` in class `GridCacheAdapter<K,V>`

#### onKernalStart

    public void onKernalStart()
                       throws IgniteCheckedException

Kernal start callback.

Overrides:
  `onKernalStart` in class `GridCacheAdapter<K,V>`
Throws:
  `IgniteCheckedException` - If callback failed.

#### onKernalStop

    public void onKernalStop()

Kernal stop callback.

Overrides:
  `onKernalStop` in class `GridCacheAdapter<K,V>`

#### printMemoryStats

    public void printMemoryStats()

Prints memory stats.

Overrides:
  `printMemoryStats` in class `GridCacheAdapter<K,V>`

#### near

    public abstract GridNearCacheAdapter<K,V> near()

Returns:
  Near cache.

#### topology

    public GridDhtPartitionTopology<K,V> topology()

Returns:
  Partition topology.

#### preloader

    public GridCachePreloader<K,V> preloader()

Specified by:
  `preloader` in class `GridCacheAdapter<K,V>`
Returns:
  Preloader.

#### dhtPreloader

    public GridDhtPreloader<K,V> dhtPreloader()

Returns:
  DHT preloader.

#### multiUpdateTopologyFuture

    @Nullable
    public GridDhtTopologyFuture multiUpdateTopologyFuture()

Returns:
  Topology version future registered for multi-update.

#### beginMultiUpdate

    public long beginMultiUpdate()
                          throws IgniteCheckedException

Starts multi-update lock. Will wait for topology future is ready.

Returns:
  Topology version.
Throws:
  `IgniteCheckedException` - If failed.

#### endMultiUpdate

    public void endMultiUpdate()
                        throws IgniteCheckedException

Ends multi-update lock.

Throws:
  `IgniteCheckedException` - If failed.

#### multiUpdateFinishFuture

    @Nullable
    public IgniteInternalFuture<?> multiUpdateFinishFuture(long topVer)

Creates multi update finish future. Will return `null` if no multi-update locks are found.

Parameters:
  `topVer` - Topology version.
Returns:
  Finish future.

#### peekExx

    @Nullable
    public GridDhtCacheEntry<K,V> peekExx(K key)

Parameters:
  `key` - Key.
Returns:
  DHT entry.

#### entry

    public javax.cache.Cache.Entry<K,V> entry(K key)
                                       throws GridDhtInvalidPartitionException

Gets entry from cache with the specified key. The returned entry can be used even after entry key has been removed from cache. In that case, every operation on returned entry will result in creation of a new entry.

Note that this method can return `null` if projection is configured as pre-filtered and entry key and value don't pass key-value filter of the projection.

Specified by:
  `entry` in interface `CacheProjection<K,V>`
Overrides:
  `entry` in class `GridCacheAdapter<K,V>`
Parameters:
  `key` - Entry key.
Returns:
  Cache entry or `null` if projection pre-filtering was not passed.
Throws:
  `GridDhtInvalidPartitionException` - If partition for the key is no longer valid.

#### entryEx

    public GridCacheEntryEx<K,V> entryEx(K key,
                                boolean touch)
                                  throws GridDhtInvalidPartitionException

Overrides:
  `entryEx` in class `GridCacheAdapter<K,V>`
Parameters:
  `key` - Entry key.
  `touch` - Whether created entry should be touched.
Returns:
  Entry (never `null`).
Throws:
  `GridDhtInvalidPartitionException` - If partition for the key is no longer valid.

#### entryEx

    public GridCacheEntryEx<K,V> entryEx(K key,
                                long topVer)
                                  throws GridDhtInvalidPartitionException

Overrides:
  `entryEx` in class `GridCacheAdapter<K,V>`
Parameters:
  `key` - Entry key.
  `topVer` - Topology version.
Returns:
  Entry (never `null`).
Throws:
  `GridDhtInvalidPartitionException` - If partition for the key is no longer valid.

#### entryExx

    public GridDhtCacheEntry<K,V> entryExx(K key)
                                    throws GridDhtInvalidPartitionException

Parameters:
  `key` - Key.
Returns:
  DHT entry.
Throws:
  `GridDhtInvalidPartitionException` - If partition for the key is no longer valid.

#### entryExx

    public GridDhtCacheEntry<K,V> entryExx(K key,
                                  long topVer)
                                    throws GridDhtInvalidPartitionException

Parameters:
  `key` - Key.
  `topVer` - Topology version.
Returns:
  DHT entry.
Throws:
  `GridDhtInvalidPartitionException` - If partition for the key is no longer valid.

#### entryExx

    public GridCacheEntryEx<K,V> entryExx(K key,
                                 long topVer,
                                 boolean allowDetached,
                                 boolean touch)

Gets or creates entry for given key. If key belongs to local node, dht entry will be returned, otherwise if `allowDetached` is `true`, detached entry will be returned, otherwise exception will be thrown.

Parameters:
  `key` - Key for which entry should be returned.
  `allowDetached` - Whether to allow detached entries.
  `touch` - `True` if entry should be passed to eviction policy.
Returns:
  Cache entry.
Throws:
  `GridDhtInvalidPartitionException` - if entry does not belong to this node and `allowDetached` is `false`.

#### localLoad

    public void localLoad(Collection<? extends K> keys,
                 javax.cache.expiry.ExpiryPolicy plc)
                   throws IgniteCheckedException

Overrides:
  `localLoad` in class `GridCacheAdapter<K,V>`
Parameters:
  `keys` - Keys to load.
  `plc` - Optional expiry policy.
Throws:
  `IgniteCheckedException` - If failed.

#### loadCache

    public void loadCache(IgniteBiPredicate<K,V> p,
                 long ttl,
                 Object[] args)
                   throws IgniteCheckedException

Delegates to `CacheStore.loadCache(org.apache.ignite.lang.IgniteBiInClosure,Object...)` method to load state from the underlying persistent storage. The loaded values will then be given to the optionally passed in predicate, and, if the predicate returns `true`, will be stored in cache. If predicate is `null`, then all loaded values will be stored in cache.

Note that this method does not receive keys as a parameter, so it is up to `CacheStore` implementation to provide all the data to be loaded.

This method is not transactional and may end up loading a stale value into cache if another thread has updated the value immediately after it has been loaded. It is mostly useful when pre-loading the cache from underlying data store before start, or for read-only caches.

Specified by:
  `loadCache` in interface `GridCache<K,V>`
Overrides:
  `loadCache` in class `GridCacheAdapter<K,V>`
Parameters:
  `p` - Optional predicate (may be `null`). If provided, will be used to filter values to be put into cache.
  `ttl` - Time to live for loaded entries (`0` for infinity).
  `args` - Optional user arguments to be passed into `CacheStore.loadCache(org.apache.ignite.lang.IgniteBiInClosure, Object...)` method.
Throws:
  `IgniteCheckedException` - If loading failed.

#### primarySize

    public int primarySize()

Gets the number of all primary entries cached on this node. For `CacheMode.LOCAL` non-distributed cache mode, this method is identical to `CacheProjection.size()`.

For `CacheMode.PARTITIONED` and `CacheMode.REPLICATED` modes, this method will return number of primary entries cached on this node (excluding any backups). The complexity of this method is O(P), where P is the total number of partitions.

NOTE: this operation is not distributed and returns only the number of primary entries cached on this node.

Specified by:
  `primarySize` in interface `CacheProjection<K,V>`
Overrides:
  `primarySize` in class `GridCacheAdapter<K,V>`
Returns:
  Number of primary entries in cache.

#### getAllAsync

    public IgniteInternalFuture<Map<K,V>> getAllAsync(@Nullable
                                             Collection<? extends K> keys,
                                             boolean forcePrimary,
                                             boolean skipTx,
                                             @Nullable
                                             GridCacheEntryEx<K,V> entry,
                                             @Nullable
                                             UUID subjId,
                                             String taskName,
                                             boolean deserializePortable,
                                             boolean skipVals)

This method is used internally. Use `getDhtAsync(UUID, long, LinkedHashMap, boolean, boolean, long, UUID, int, boolean, IgniteCacheExpiryPolicy, boolean)` method instead to retrieve DHT value.

Overrides:
  `getAllAsync` in class `GridCacheAdapter<K,V>`
Parameters:
  `keys` -
  `forcePrimary` -
  `skipTx` -
Returns:

#### reload

    public V reload(K key)
             throws IgniteCheckedException

Reloads a single key from persistent storage. This method delegates to `CacheStore#load(Transaction, Object)` method.

## Transactions

This method does not participate in transactions, however it does not violate cache integrity and can be used safely with or without transactions.

Specified by:
  `reload` in interface `CacheProjection<K,V>`
Overrides:
  `reload` in class `GridCacheAdapter<K,V>`
Parameters:
  `key` - Key.
Returns:
  Reloaded value.
Throws:
  `IgniteCheckedException` - If failed.

#### getDhtAsync

    public GridDhtFuture<Collection<GridCacheEntryInfo<K,V>>> getDhtAsync(UUID reader,
                                                                 long msgId,
                                                                 LinkedHashMap<? extends K,Boolean> keys,
                                                                 boolean readThrough,
                                                                 boolean reload,
                                                                 long topVer,
                                                                 @Nullable
                                                                 UUID subjId,
                                                                 int taskNameHash,
                                                                 boolean deserializePortable,
                                                                 @Nullable
                                                                 IgniteCacheExpiryPolicy expiry,
                                                                 boolean skipVals)

Parameters:
  `reader` - Reader node ID.
  `msgId` - Message ID.
  `keys` - Keys to get.
  `readThrough` - Read through flag.
  `reload` - Reload flag.
  `topVer` - Topology version.
  `subjId` - Subject ID.
  `taskNameHash` - Task name hash code.
  `deserializePortable` - Deserialize portable flag.
  `expiry` - Expiry policy.
Returns:
  DHT future.

#### processNearGetRequest

    protected void processNearGetRequest(UUID nodeId,
                             GridNearGetRequest<K,V> req)

Parameters:
  `nodeId` - Node ID.
  `req` - Get request.

#### sendTtlUpdateRequest

    public void sendTtlUpdateRequest(@Nullable
                            IgniteCacheExpiryPolicy expiryPlc)

Parameters:
  `expiryPlc` - Expiry policy.

#### unlockAll

    public void unlockAll(Collection<? extends K> keys,
                 IgnitePredicate<javax.cache.Cache.Entry<K,V>>[] filter)

Unlocks given keys only if current thread owns the locks. Only the keys that have been locked by calling thread and pass through the filter (if any) will be unlocked. If none of the key locks is owned by current thread, then this method will do nothing.

## Transactions

Locks are not transactional and should not be used from within transactions. If you do need explicit locking within transaction, then you should use `TransactionConcurrency.PESSIMISTIC` concurrency control for transaction which will acquire explicit locks for relevant cache operations.

## Cache Flags

This method is not available if any of the following flags are set on projection: `CacheFlag.LOCAL`, `CacheFlag.READ`.

Parameters:
  `keys` - Keys to unlock.
  `filter` - Optional filter which needs to pass for individual entries to be unlocked.

#### entrySet

    public Set<javax.cache.Cache.Entry<K,V>> entrySet(int part)

Gets set containing cache entries that belong to provided partition or `null` if partition is not found locally.

NOTE: this operation is not distributed and returns only the entries cached on this node.

Specified by:
  `entrySet` in interface `CacheProjection<K,V>`
Overrides:
  `entrySet` in class `GridCacheAdapter<K,V>`
Parameters:
  `part` - Partition.
Returns:
  Set containing partition's entries or `null` if partition is not found locally.

#### toString

    public String toString()

Overrides:
  `toString` in class `GridDistributedCacheAdapter<K,V>`

#### splitClearLocally

    public List<GridCacheClearAllRunnable<K,V>> splitClearLocally()

Split clearLocally all task into multiple runnables.

Overrides:
  `splitClearLocally` in class `GridCacheAdapter<K,V>`
Returns:
  Split runnables.

#### onDeferredDelete

    public void onDeferredDelete(GridCacheEntryEx<K,V> entry,
                        GridCacheVersion ver)

Specified by:
  `onDeferredDelete` in class `GridCacheAdapter<K,V>`
Parameters:
  `entry` - Entry.
  `ver` - Version.

#### localEntriesIterator

    public Iterator<javax.cache.Cache.Entry<K,V>> localEntriesIterator(boolean primary,
                                                              boolean backup)

Parameters:
  `primary` - If `true` includes primary entries.
  `backup` - If `true` includes backup entries.
Returns:
  Local entries iterator.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0-RC1
Release Date | : February 17 2015