org.apache.ignite.internal.processors.cache

## Class GridCacheAffinityManager<K,V>

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.GridCacheManagerAdapter<K,V>
  - - org.apache.ignite.internal.processors.cache.GridCacheAffinityManager<K,V>

All Implemented Interfaces:
  GridCacheManager<K,V>

    public class GridCacheAffinityManager<K,V>
    extends GridCacheManagerAdapter<K,V>

Cache affinity manager.

### Field Summary

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

`cctx, log`

### Constructor Summary

Constructors
Constructor and Description
`GridCacheAffinityManager()`

### Method Summary

Methods
`IgniteInternalFuture<Long>` `affinityReadyFuture(long topVer)` Gets affinity ready future, a future that will be completed after affinity with given topology version is calculated.
`IgniteInternalFuture<Long>` `affinityReadyFuturex(long topVer)` Gets affinity ready future that will be completed after affinity with given topology version is calculated.
`long` `affinityTopologyVersion()`
`List<List<ClusterNode>>` `assignments(long topVer)`
`Set<Integer>` `backupPartitions(UUID nodeId, long topVer)`
`Collection<ClusterNode>` `backups(int part, long topVer)`
`Collection<ClusterNode>` `backups(K key, long topVer)`
`boolean` `belongs(ClusterNode node, int part, long topVer)`
`boolean` `belongs(ClusterNode node, K key, long topVer)`
`List<List<ClusterNode>>` `calculateAffinity(long topVer, DiscoveryEvent discoEvt)` Calculates affinity cache for given topology version.
`void` `cleanUpCache(long topVer)` Clean up outdated cache items.
`void` `initializeAffinity(long topVer, List<List<ClusterNode>> affAssignment)` Initializes affinity for joined node.
`boolean` `localNode(int part, long topVer)`
`boolean` `localNode(K key, long topVer)`
`List<ClusterNode>` `nodes(int part, long topVer)`
`List<ClusterNode>` `nodes(K key, long topVer)`
`protected void` `onKernalStart0()`
`protected void` `onKernalStop0(boolean cancel)`
`<T> int` `partition(T key)` NOTE: Use this method always when you need to calculate partition id for a key provided by user.
`GridPartitionLockKey` `partitionAffinityKey(int partId)` Gets partition affinity key for given partition id.
`int` `partitions()`
`boolean` `primary(ClusterNode n, int part, long topVer)`
`boolean` `primary(ClusterNode n, K key, long topVer)`
`ClusterNode` `primary(int part, long topVer)`
`ClusterNode` `primary(K key, long topVer)`
`Set<Integer>` `primaryPartitions(UUID nodeId, long topVer)`
`Collection<ClusterNode>` `remoteNodes(Iterable<? extends K> keys, long topVer)`
`void` `start0()`
`protected void` `stop0(boolean cancel)`

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

`context, kernalStartInfo, kernalStopInfo, log, onKernalStart, onKernalStop, printMemoryStats, start, startInfo, stop, stopInfo, toString`

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

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

### Constructor Detail

#### GridCacheAffinityManager

    public GridCacheAffinityManager()

### Method Detail

#### start0

    public void start0()
                throws IgniteCheckedException

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

#### onKernalStart0

    protected void onKernalStart0()
                           throws IgniteCheckedException

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

#### onKernalStop0

    protected void onKernalStop0(boolean cancel)

Overrides:
  `onKernalStop0` in class `GridCacheManagerAdapter<K,V>`
Parameters:
  `cancel` - Cancel flag.

#### stop0

    protected void stop0(boolean cancel)

Overrides:
  `stop0` in class `GridCacheManagerAdapter<K,V>`
Parameters:
  `cancel` - Cancel flag.

#### affinityReadyFuture

    public IgniteInternalFuture<Long> affinityReadyFuture(long topVer)

Gets affinity ready future, a future that will be completed after affinity with given topology version is calculated.

Parameters:
  `topVer` - Topology version to wait.
Returns:
  Affinity ready future.

#### affinityReadyFuturex

    @Nullable
    public IgniteInternalFuture<Long> affinityReadyFuturex(long topVer)

Gets affinity ready future that will be completed after affinity with given topology version is calculated. Will return `null` if topology with given version is ready by the moment method is invoked.

Parameters:
  `topVer` - Topology version to wait.
Returns:
  Affinity ready future or `null`.

#### cleanUpCache

    public void cleanUpCache(long topVer)

Clean up outdated cache items.

Parameters:
  `topVer` - Actual topology version, older versions will be removed.

#### initializeAffinity

    public void initializeAffinity(long topVer,
                          List<List<ClusterNode>> affAssignment)

Initializes affinity for joined node.

Parameters:
  `topVer` - Topology version.
  `affAssignment` - Affinity assignment for this topology version.

#### assignments

    public List<List<ClusterNode>> assignments(long topVer)

Parameters:
  `topVer` - Topology version.
Returns:
  Affinity assignments.

#### calculateAffinity

    public List<List<ClusterNode>> calculateAffinity(long topVer,
                                            DiscoveryEvent discoEvt)

Calculates affinity cache for given topology version.

Parameters:
  `topVer` - Topology version to calculate affinity for.
  `discoEvt` - Discovery event that causes this topology change.

#### partitions

    public int partitions()

Returns:
  Partition count.

#### partitionAffinityKey

    public GridPartitionLockKey partitionAffinityKey(int partId)

Gets partition affinity key for given partition id. Partition affinity keys are precalculated on manager start.

Parameters:
  `partId` - Partition ID.
Returns:
  Affinity key.

#### partition

    public <T> int partition(T key)

NOTE: Use this method always when you need to calculate partition id for a key provided by user. It's required since we should apply affinity mapper logic in order to find a key that will eventually be passed to affinity function.

Parameters:
  `key` - Key.
Returns:
  Partition.

#### nodes

    public List<ClusterNode> nodes(K key,
                          long topVer)

Parameters:
  `key` - Key.
  `topVer` - Topology version.
Returns:
  Affinity nodes.

#### nodes

    public List<ClusterNode> nodes(int part,
                          long topVer)

Parameters:
  `part` - Partition.
  `topVer` - Topology version.
Returns:
  Affinity nodes.

#### primary

    @Nullable
    public ClusterNode primary(K key,
                               long topVer)

Parameters:
  `key` - Key to check.
  `topVer` - Topology version.
Returns:
  Primary node for given key.

#### primary

    @Nullable
    public ClusterNode primary(int part,
                               long topVer)

Parameters:
  `part` - Partition.
  `topVer` - Topology version.
Returns:
  Primary node for given key.

#### primary

    public boolean primary(ClusterNode n,
                  K key,
                  long topVer)

Parameters:
  `n` - Node to check.
  `key` - Key to check.
  `topVer` - Topology version.
Returns:
  `True` if checked node is primary for given key.

#### primary

    public boolean primary(ClusterNode n,
                  int part,
                  long topVer)

Parameters:
  `n` - Node to check.
  `part` - Partition.
  `topVer` - Topology version.
Returns:
  `True` if checked node is primary for given key.

#### backups

    public Collection<ClusterNode> backups(K key,
                                  long topVer)

Parameters:
  `key` - Key to check.
  `topVer` - Topology version.
Returns:
  Backup nodes.

#### backups

    public Collection<ClusterNode> backups(int part,
                                  long topVer)

Parameters:
  `part` - Partition.
  `topVer` - Topology version.
Returns:
  Backup nodes.

#### remoteNodes

    public Collection<ClusterNode> remoteNodes(Iterable<? extends K> keys,
                                      long topVer)

Parameters:
  `keys` - keys.
  `topVer` - Topology version.
Returns:
  Nodes for the keys.

#### localNode

    public boolean localNode(K key,
                    long topVer)

Parameters:
  `key` - Key to check.
  `topVer` - Topology version.
Returns:
  `true` if given key belongs to local node.

#### localNode

    public boolean localNode(int part,
                    long topVer)

Parameters:
  `part` - Partition number to check.
  `topVer` - Topology version.
Returns:
  `true` if given partition belongs to local node.

#### belongs

    public boolean belongs(ClusterNode node,
                  int part,
                  long topVer)

Parameters:
  `node` - Node.
  `part` - Partition number to check.
  `topVer` - Topology version.
Returns:
  `true` if given partition belongs to specified node.

#### belongs

    public boolean belongs(ClusterNode node,
                  K key,
                  long topVer)

Parameters:
  `node` - Node.
  `key` - Key to check.
  `topVer` - Topology version.
Returns:
  `true` if given key belongs to specified node.

#### primaryPartitions

    public Set<Integer> primaryPartitions(UUID nodeId,
                                 long topVer)

Parameters:
  `nodeId` - Node ID.
  `topVer` - Topology version to calculate affinity.
Returns:
  Partitions for which given node is primary.

#### backupPartitions

    public Set<Integer> backupPartitions(UUID nodeId,
                                long topVer)

Parameters:
  `nodeId` - Node ID.
  `topVer` - Topology version to calculate affinity.
Returns:
  Partitions for which given node is backup.

#### affinityTopologyVersion

    public long affinityTopologyVersion()

Returns:
  Affinity-ready topology version.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

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