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>>, IgniteInternalCache<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.TopologyVersionAwareJob, GridCacheAdapter.UpdateGetTimeStatClosure<T>, GridCacheAdapter.UpdatePutAndGetTimeStatClosure<T>, GridCacheAdapter.UpdatePutTimeStatClosure<T>, GridCacheAdapter.UpdateRemoveTimeStatClosure<T>, GridCacheAdapter.UpdateTimeStatClosure<T>`

### Field Summary

Fields
`protected GridCachePreloader` `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, MAX_RETRIES, metrics, mxBean, RET2NULL`

### Constructor Summary

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

### Method Summary

Methods
`AffinityTopologyVersion` `beginMultiUpdate()` Starts multi-update lock.
`protected GridDistributedCacheEntry` `createEntry(KeyCacheObject key)`
`GridDhtPreloader` `dhtPreloader()`
`void` `endMultiUpdate()` Ends multi-update lock.
`GridCacheEntryEx` `entryEx(KeyCacheObject key, AffinityTopologyVersion topVer)`
`GridCacheEntryEx` `entryEx(KeyCacheObject key, boolean touch)`
`GridDhtCacheEntry` `entryExx(KeyCacheObject key)`
`GridDhtCacheEntry` `entryExx(KeyCacheObject key, AffinityTopologyVersion topVer)`
`GridCacheEntryEx` `entryExx(KeyCacheObject key, AffinityTopologyVersion 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, UUID subjId, String taskName, boolean deserializeBinary, boolean skipVals, boolean canRemap)` This method is used internally.
`GridDhtFuture<Collection<GridCacheEntryInfo>>` `getDhtAsync(UUID reader, long msgId, Map<KeyCacheObject,Boolean> keys, boolean readThrough, AffinityTopologyVersion topVer, UUID subjId, int taskNameHash, IgniteCacheExpiryPolicy expiry, boolean skipVals)`
`protected void` `init()` Post constructor initialization for subclasses.
`Iterator<javax.cache.Cache.Entry<K,V>>` `localEntriesIterator(boolean primary, boolean backup)`
`void` `localLoad(Collection<? extends K> keys, javax.cache.expiry.ExpiryPolicy plc)`
`void` `localLoadCache(IgniteBiPredicate<K,V> p, Object[] args)` Delegates to `CacheStore.loadCache(org.apache.ignite.lang.IgniteBiInClosure,Object...)` method to load state from the underlying persistent storage.
`IgniteInternalFuture<?>` `multiUpdateFinishFuture(AffinityTopologyVersion topVer)` Creates multi update finish future.
`GridDhtTopologyFuture` `multiUpdateTopologyFuture()`
`abstract GridNearCacheAdapter<K,V>` `near()`
`protected boolean` `needRemap(AffinityTopologyVersion expVer, AffinityTopologyVersion curVer)`
`void` `onDeferredDelete(GridCacheEntryEx entry, GridCacheVersion ver)`
`void` `onKernalStart()` Kernal start callback.
`void` `onKernalStop()` Kernal stop callback.
`void` `onReconnected()`
`GridDhtCacheEntry` `peekExx(KeyCacheObject key)`
`GridCachePreloader` `preloader()`
`int` `primarySize()` Gets the number of all primary entries cached on this node.
`long` `primarySizeLong()` Gets the number of all primary entries cached on this node as a long value.
`void` `printMemoryStats()` Prints memory stats.
`protected void` `processNearGetRequest(UUID nodeId, GridNearGetRequest req)`
`protected void` `processNearGetResponse(UUID nodeId, GridNearGetResponse res)`
`protected void` `processNearSingleGetRequest(UUID nodeId, GridNearSingleGetRequest req)`
`protected void` `processNearSingleGetResponse(UUID nodeId, GridNearSingleGetResponse res)`
`void` `sendTtlUpdateRequest(IgniteCacheExpiryPolicy expiryPlc)`
`List<GridCacheClearAllRunnable<K,V>>` `splitClearLocally(boolean srv, boolean near, boolean readers)` Split clearLocally all task into multiple runnables.
`void` `start()` Starts this cache.
`void` `stop()` Stops this cache.
`GridDhtPartitionTopology` `topology()`
`String` `toString()`
`void` `unlockAll(Collection<? extends K> keys)` 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, clearAll, clearAllAsync, clearAsync, clearAsync, clearLocally, clearLocally, clearLocally, clearLocallyAll, commitTxAsync, configuration, containsKey, containsKeyAsync, containsKeys, containsKeysAsync, context, entries, entryEx, entryEx, entryExSafe, entrySet, entrySet, entrySetx, evict, evictAll, expiry, expiryPolicy, forSubjectId, get, get, getAll, getAll, getAllAsync, getAllAsync, getAllAsync, getAllAsync0, getAllOutTx, getAllOutTxAsync, getAndPut, getAndPut, getAndPutAsync, getAndPutAsync, getAndPutAsync0, getAndPutIfAbsent, getAndPutIfAbsentAsync, getAndRemove, getAndRemoveAsync, getAndReplace, getAndReplaceAsync, getAsync, getAsync, getAsync, getForcePrimary, getForcePrimaryAsync, getTopologySafe, igfsDataSpaceMax, igfsDataSpaceUsed, igniteIterator, invoke, invoke, invokeAll, invokeAll, invokeAllAsync, invokeAllAsync, invokeAsync, isColocated, isDht, isDhtAtomic, isEmpty, isIgfsDataCache, isLocal, isLocked, isLockedByThread, isMongoDataCache, isMongoMetaCache, isNear, iterator, iterator, keepBinary, keySet, keySet, keySetx, keySetx, loadAll, localEntries, localLoadCacheAsync, localPeek, localRemoveAll, localSize, localSizeLong, lock, lockAll, lockAsync, log, map, metrics, metrics0, mxBean, name, nearSize, offHeapAllocatedSize, offHeapEntriesCount, onIgfsDataSizeChanged, onUndeploy, overflowSize, peekEx, peekEx, primaryEntrySet, primaryKeySet, primaryKeySet, promote, promoteAll, put, put, putAll, putAllAsync, putAllConflict, putAllConflictAsync, putAsync, putAsync, putAsync0, putIfAbsent, putIfAbsentAsync, randomEntry, readExternal, readResolve, rebalance, remove, remove, removeAll, removeAllAsync, removeAllConflict, removeAllConflictAsync, removeAsync, removeAsync, removeAsync, removeEntry, removeIfObsolete, removex, removexAsync, replace, replace, replaceAsync, replaceAsync, replacex, replacexAsync, saveFuture, setSkipStore, size, size, sizeAsync, sizeLong, sizeLong, sizeLongAsync, skipStore, startInfo, stopInfo, swapKeys, swapSize, tryPutIfAbsent, tx, txStart, txStart, txStartEx, 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 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 map)

Constructor used for near-only cache.

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

### Method Detail

#### processNearGetResponse

    protected final void processNearGetResponse(UUID nodeId,
                              GridNearGetResponse res)

Parameters:
  `nodeId` - Sender node ID.
  `res` - Near get response.

#### processNearSingleGetResponse

    protected void processNearSingleGetResponse(UUID nodeId,
                                    GridNearSingleGetResponse res)

Parameters:
  `nodeId` - Sender node ID.
  `res` - Near get response.

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

#### onReconnected

    public void onReconnected()

Overrides:
  `onReconnected` 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 topology()

Returns:
  Partition topology.

#### preloader

    public GridCachePreloader preloader()

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

#### dhtPreloader

    public GridDhtPreloader dhtPreloader()

Returns:
  DHT preloader.

#### multiUpdateTopologyFuture

    @Nullable
    public GridDhtTopologyFuture multiUpdateTopologyFuture()

Returns:
  Topology version future registered for multi-update.

#### beginMultiUpdate

    public AffinityTopologyVersion 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(AffinityTopologyVersion 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 peekExx(KeyCacheObject key)

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

#### entryEx

    public GridCacheEntryEx entryEx(KeyCacheObject 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 entryEx(KeyCacheObject key,
                           AffinityTopologyVersion 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 entryExx(KeyCacheObject key)
                               throws GridDhtInvalidPartitionException

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

#### entryExx

    public GridDhtCacheEntry entryExx(KeyCacheObject key,
                             AffinityTopologyVersion 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 entryExx(KeyCacheObject key,
                            AffinityTopologyVersion 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`.

#### createEntry

    protected GridDistributedCacheEntry createEntry(KeyCacheObject key)

Parameters:
  `key` - Key for which entry should be returned.
Returns:
  Cache entry.

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

#### localLoadCache

    public void localLoadCache(IgniteBiPredicate<K,V> p,
                      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:
  `localLoadCache` in interface `IgniteInternalCache<K,V>`
Overrides:
  `localLoadCache` 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.
  `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 `IgniteInternalCache.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 `IgniteInternalCache<K,V>`
Overrides:
  `primarySize` in class `GridCacheAdapter<K,V>`
Returns:
  Number of primary entries in cache.

#### primarySizeLong

    public long primarySizeLong()

Gets the number of all primary entries cached on this node as a long value. For `CacheMode.LOCAL` non-distributed cache mode, this method is identical to `IgniteInternalCache.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:
  `primarySizeLong` in interface `IgniteInternalCache<K,V>`
Overrides:
  `primarySizeLong` 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
                                             UUID subjId,
                                             String taskName,
                                             boolean deserializeBinary,
                                             boolean skipVals,
                                             boolean canRemap)

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

Overrides:
  `getAllAsync` in class `GridCacheAdapter<K,V>`
Parameters:
  `keys` - Keys.
  `forcePrimary` - Force primary.
  `skipTx` - Skip tx.
  `subjId` - Subj Id.
  `taskName` - Task name.
  `deserializeBinary` - Deserialize binary.
  `skipVals` - Skip values.
  `canRemap` - Can remap flag.
Returns:
  Future for the get operation.
See Also:
  `GridCacheAdapter.getAllAsync(Collection)`

#### getDhtAsync

    public GridDhtFuture<Collection<GridCacheEntryInfo>> getDhtAsync(UUID reader,
                                                            long msgId,
                                                            Map<KeyCacheObject,Boolean> keys,
                                                            boolean readThrough,
                                                            AffinityTopologyVersion topVer,
                                                            @Nullable
                                                            UUID subjId,
                                                            int taskNameHash,
                                                            @Nullable
                                                            IgniteCacheExpiryPolicy expiry,
                                                            boolean skipVals)

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

#### processNearSingleGetRequest

    protected void processNearSingleGetRequest(UUID nodeId,
                                   GridNearSingleGetRequest req)

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

#### processNearGetRequest

    protected void processNearGetRequest(UUID nodeId,
                             GridNearGetRequest 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)

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.

Parameters:
  `keys` - Keys to unlock.

#### 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 `IgniteInternalCache<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(boolean srv,
                                                         boolean near,
                                                         boolean readers)

Split clearLocally all task into multiple runnables.

Overrides:
  `splitClearLocally` in class `GridCacheAdapter<K,V>`
Parameters:
  `srv` - Whether to clear server cache.
  `near` - Whether to clear near cache.
  `readers` - Whether to clear readers.
Returns:
  Split runnables.

#### onDeferredDelete

    public void onDeferredDelete(GridCacheEntryEx entry,
                        GridCacheVersion ver)

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

#### needRemap

    protected final boolean needRemap(AffinityTopologyVersion expVer,
                    AffinityTopologyVersion curVer)

Parameters:
  `expVer` - Expected topology version.
  `curVer` - Current topology version.
Returns:
  `True` if cache affinity changed and operation should be remapped.

#### 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.5.0.final
Release Date | : December 29 2015