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

## Class GridDhtColocatedCache<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>
      - - org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTransactionalCacheAdapter<K,V>
        - - org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache<K,V>

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

    public class GridDhtColocatedCache<K,V>
    extends GridDhtTransactionalCacheAdapter<K,V>

Colocated cache.

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 inherited from class org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter

`preldr`

### 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
Constructor and Description
`GridDhtColocatedCache()` Empty constructor required for `Externalizable`
`GridDhtColocatedCache(GridCacheContext<K,V> ctx)`
`GridDhtColocatedCache(GridCacheContext<K,V> ctx, GridCacheConcurrentMap map)` Creates colocated cache with specified map.

### Method Summary

Methods
`protected GridCacheEntryEx` `entryExSafe(KeyCacheObject key, AffinityTopologyVersion topVer)`
`GridDistributedCacheEntry` `entryExx(KeyCacheObject key, AffinityTopologyVersion topVer, boolean allowDetached)` Gets or creates entry for given key and given topology version.
`IgniteInternalFuture<Map<K,V>>` `getAllAsync(Collection<? extends K> keys, boolean forcePrimary, boolean skipTx, GridCacheEntryEx entry, UUID subjId, String taskName, boolean deserializePortable, boolean skipVals)` This method is used internally.
`protected void` `init()` Post constructor initialization for subclasses.
`boolean` `isColocated()`
`boolean` `isLocked(K key)` Checks if any node owns a lock for this key.
`boolean` `isLockedByThread(K key)` Checks if current thread owns a lock on this key.
`IgniteInternalFuture<Map<K,V>>` `loadAsync(Collection<KeyCacheObject> keys, boolean readThrough, boolean reload, boolean forcePrimary, AffinityTopologyVersion topVer, UUID subjId, String taskName, boolean deserializePortable, IgniteCacheExpiryPolicy expiryPlc, boolean skipVals)`
`IgniteInternalFuture<Boolean>` `lockAllAsync(Collection<KeyCacheObject> keys, long timeout, IgniteTxLocalEx tx, boolean isInvalidate, boolean isRead, boolean retval, TransactionIsolation isolation, long accessTtl)` This is an entry point to pessimistic locking within transaction.
`GridNearTransactionalCache<K,V>` `near()`
`void` `removeLocks(long threadId, GridCacheVersion ver, Collection<KeyCacheObject> keys)` Removes locks regardless of whether they are owned or not for given version and keys.
`void` `start()` Starts this cache.
`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.dht.GridDhtTransactionalCacheAdapter

`lockAllAsync, lockAllAsyncInternal, processDhtLockRequest, processDhtLockRequest0, processDhtUnlockRequest, removeLocks`

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

`beginMultiUpdate, createEntry, dhtPreloader, endMultiUpdate, entryEx, entryEx, entryExx, entryExx, entryExx, entrySet, getDhtAsync, localEntriesIterator, localLoad, localLoadCache, multiUpdateFinishFuture, multiUpdateTopologyFuture, needRemap, onDeferredDelete, onKernalStart, onKernalStop, peekExx, preloader, primarySize, printMemoryStats, processNearGetRequest, sendTtlUpdateRequest, splitClearLocally, stop, topology`

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

`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, clearAsync, clearAsync, clearAsync, clearLocally, clearLocally, clearLocally, clearLocally0, clearLocally0, clearLocallyAll, commitTxAsync, configuration, containsKey, containsKeyAsync, containsKeys, containsKeysAsync, context, entries, entryEx, entryEx, 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, getForcePrimary, getForcePrimaryAsync, igfsDataSpaceMax, igfsDataSpaceUsed, igniteIterator, invoke, invokeAll, invokeAll, invokeAllAsync, invokeAllAsync, invokeAsync, isDht, isDhtAtomic, isEmpty, isIgfsDataCache, isLocal, isMongoDataCache, isMongoMetaCache, isNear, iterator, iterator, keepPortable, keySet, keySet, keySetx, keySetx, loadAll, localEntries, localLoadCacheAsync, localPeek, localRemoveAll, localSize, 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, readThroughAllAsync, rebalance, reloadAllAsync0, remove, remove, removeAll, removeAllAsync, removeAllConflict, removeAllConflictAsync, removeAsync, removeAsync, removeAsync, removeEntry, removeIfObsolete, removex, removexAsync, replace, replace, replaceAsync, replaceAsync, replacex, replacexAsync, saveFuture, setSkipStore, size, size, sizeAsync, 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`

### Constructor Detail

#### GridDhtColocatedCache

    public GridDhtColocatedCache()

Empty constructor required for `Externalizable`

#### GridDhtColocatedCache

    public GridDhtColocatedCache(GridCacheContext<K,V> ctx)

Parameters:
  `ctx` - Cache context.

#### GridDhtColocatedCache

    public GridDhtColocatedCache(GridCacheContext<K,V> ctx,
                         GridCacheConcurrentMap map)

Creates colocated cache with specified map.

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

### Method Detail

#### isColocated

    public boolean isColocated()

Overrides:
  `isColocated` in class `GridCacheAdapter<K,V>`
Returns:
  `True` if cache is colocated.

#### init

    protected void init()

Post constructor initialization for subclasses.

Overrides:
  `init` in class `GridDhtCacheAdapter<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 `GridDhtTransactionalCacheAdapter<K,V>`
Throws:
  `IgniteCheckedException` - If start failed.

#### entryExx

    public GridDistributedCacheEntry entryExx(KeyCacheObject key,
                                     AffinityTopologyVersion topVer,
                                     boolean allowDetached)

Gets or creates entry for given key and given topology version.

Parameters:
  `key` - Key for entry.
  `topVer` - Topology version.
  `allowDetached` - Whether to allow detached entries. If `true` and node is not primary for given key, a new detached entry will be created. Otherwise, entry will be obtained from dht cache map.
Returns:
  Cache entry.
Throws:
  `GridDhtInvalidPartitionException` - If `allowDetached` is false and node is not primary for given key.

#### isLocked

    public boolean isLocked(K key)

Checks if any node owns a lock for this key.

This is a local in-VM operation and does not involve any network trips or access to persistent storage in any way.

Specified by:
  `isLocked` in interface `IgniteInternalCache<K,V>`
Overrides:
  `isLocked` in class `GridCacheAdapter<K,V>`
Parameters:
  `key` - Key to check.
Returns:
  `True` if lock is owned by some node.

#### isLockedByThread

    public boolean isLockedByThread(K key)

Checks if current thread owns a lock on this key.

This is a local in-VM operation and does not involve any network trips or access to persistent storage in any way.

Specified by:
  `isLockedByThread` in interface `IgniteInternalCache<K,V>`
Overrides:
  `isLockedByThread` in class `GridCacheAdapter<K,V>`
Parameters:
  `key` - Key to check.
Returns:
  `True` if key is locked by current thread.

#### getAllAsync

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

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

Overrides:
  `getAllAsync` in class `GridDhtCacheAdapter<K,V>`
Parameters:
  `keys` - Keys.
  `forcePrimary` - Force primary.
  `skipTx` - Skip tx.
  `entry` - Entry.
  `subjId` - Subj Id.
  `taskName` - Task name.
  `deserializePortable` - Deserialize portable.
  `skipVals` - Skip values.
Returns:
  Future for the get operation.
See Also:
  `GridCacheAdapter.getAllAsync(Collection)`

#### entryExSafe

    protected GridCacheEntryEx entryExSafe(KeyCacheObject key,
                               AffinityTopologyVersion topVer)

Overrides:
  `entryExSafe` in class `GridCacheAdapter<K,V>`
Parameters:
  `key` - Key.
  `topVer` - Topology version.
Returns:
  Entry.

#### loadAsync

    public IgniteInternalFuture<Map<K,V>> loadAsync(@Nullable
                                           Collection<KeyCacheObject> keys,
                                           boolean readThrough,
                                           boolean reload,
                                           boolean forcePrimary,
                                           AffinityTopologyVersion topVer,
                                           @Nullable
                                           UUID subjId,
                                           String taskName,
                                           boolean deserializePortable,
                                           @Nullable
                                           IgniteCacheExpiryPolicy expiryPlc,
                                           boolean skipVals)

Parameters:
  `keys` - Keys to load.
  `readThrough` - Read through flag.
  `reload` - Reload flag.
  `forcePrimary` - Force get from primary node flag.
  `topVer` - Topology version.
  `subjId` - Subject ID.
  `taskName` - Task name.
  `deserializePortable` - Deserialize portable flag.
  `expiryPlc` - Expiry policy.
  `skipVals` - Skip values flag.
Returns:
  Loaded values.

#### lockAllAsync

    public IgniteInternalFuture<Boolean> lockAllAsync(Collection<KeyCacheObject> keys,
                                             long timeout,
                                             @Nullable
                                             IgniteTxLocalEx tx,
                                             boolean isInvalidate,
                                             boolean isRead,
                                             boolean retval,
                                             @Nullable
                                             TransactionIsolation isolation,
                                             long accessTtl)

This is an entry point to pessimistic locking within transaction.

Overrides:
  `lockAllAsync` in class `GridDhtTransactionalCacheAdapter<K,V>`
Parameters:
  `keys` - Keys to lock.
  `timeout` - Timeout.
  `tx` - Transaction
  `isInvalidate` - Invalidation flag.
  `isRead` - Indicates whether value is read or written.
  `retval` - Flag to return value.
  `isolation` - Transaction isolation.
  `accessTtl` - TTL for read operation.
Returns:
  Future for locks.

#### near

    public GridNearTransactionalCache<K,V> near()

Specified by:
  `near` in class `GridDhtTransactionalCacheAdapter<K,V>`
Returns:
  Near cache.

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

Specified by:
  `unlockAll` in interface `IgniteInternalCache<K,V>`
Overrides:
  `unlockAll` in class `GridDhtCacheAdapter<K,V>`
Parameters:
  `keys` - Keys to unlock.

#### removeLocks

    public void removeLocks(long threadId,
                   GridCacheVersion ver,
                   Collection<KeyCacheObject> keys)

Removes locks regardless of whether they are owned or not for given version and keys.

Parameters:
  `threadId` - Thread ID.
  `ver` - Lock version.
  `keys` - Keys.

#### toString

    public String toString()

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

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.3.0-incubating
Release Date | : July 10 2015