org.apache.ignite.internal.processors.affinity

## Class GridAffinityProcessor

- java.lang.Object
- - org.apache.ignite.internal.processors.GridProcessorAdapter
  - - org.apache.ignite.internal.processors.affinity.GridAffinityProcessor

All Implemented Interfaces:
  GridComponent, GridProcessor

    public class GridAffinityProcessor
    extends GridProcessorAdapter

Data affinity processor.

### Nested Class Summary

### Nested classes/interfaces inherited from interface org.apache.ignite.internal.GridComponent

`GridComponent.DiscoveryDataExchangeType`

### Field Summary

### Fields inherited from class org.apache.ignite.internal.processors.GridProcessorAdapter

`ctx, log`

### Constructor Summary

Constructors
Constructor and Description
`GridAffinityProcessor(GridKernalContext ctx)`

### Method Summary

Methods
`Object` `affinityKey(String cacheName, Object key)` Gets affinity key for cache key.
`<K> org.apache.ignite.internal.processors.affinity.GridAffinityProcessor.CacheAffinityProxy<K>` `affinityProxy(String cacheName)`
`<K> Map<ClusterNode,Collection<K>>` `mapKeysToNodes(String cacheName, Collection<? extends K> keys)` Maps keys to nodes for given cache.
`<K> ClusterNode` `mapKeyToNode(String cacheName, K key)` Maps single key to a node.
`<K> ClusterNode` `mapKeyToNode(String cacheName, K key, AffinityTopologyVersion topVer)` Maps single key to a node.
`<K> List<ClusterNode>` `mapKeyToPrimaryAndBackups(String cacheName, K key, AffinityTopologyVersion topVer)` Map single key to primary and backup nodes.
`void` `onKernalStop(boolean cancel)` Callback to notify that kernal is about to stop.
`int` `partition(String cacheName, Object key)`
`int` `partition(String cacheName, Object key, org.apache.ignite.internal.processors.affinity.GridAffinityProcessor.AffinityInfo aff)`
`int` `partition0(String cacheName, Object key, org.apache.ignite.internal.processors.affinity.GridAffinityProcessor.AffinityInfo aff)`
`void` `printMemoryStats()` Prints memory statistics (sizes of internal structures, etc.).
`void` `start()` Starts grid component.

### Methods inherited from class org.apache.ignite.internal.processors.GridProcessorAdapter

`assertParameter, collectDiscoveryData, discoveryDataType, onDisconnected, onDiscoveryDataReceived, onKernalStart, onReconnected, stop, toString, validateNode`

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

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

### Constructor Detail

#### GridAffinityProcessor

    public GridAffinityProcessor(GridKernalContext ctx)

Parameters:
  `ctx` - Context.

### Method Detail

#### start

    public void start()
               throws IgniteCheckedException

Starts grid component.

Specified by:
  `start` in interface `GridComponent`
Overrides:
  `start` in class `GridProcessorAdapter`
Throws:
  `IgniteCheckedException` - Throws in case of any errors.

#### onKernalStop

    public void onKernalStop(boolean cancel)

Callback to notify that kernal is about to stop.

Specified by:
  `onKernalStop` in interface `GridComponent`
Overrides:
  `onKernalStop` in class `GridProcessorAdapter`
Parameters:
  `cancel` - Flag indicating whether jobs should be canceled.

#### partition

    public int partition(@Nullable
                String cacheName,
                Object key)
                  throws IgniteCheckedException

Parameters:
  `cacheName` - Cache name.
  `key` - Key.
Returns:
  Key partition.
Throws:
  `IgniteCheckedException` - If failed.

#### partition

    public int partition(@Nullable
                String cacheName,
                Object key,
                @Nullable
                org.apache.ignite.internal.processors.affinity.GridAffinityProcessor.AffinityInfo aff)
                  throws IgniteCheckedException

Parameters:
  `cacheName` - Cache name (needed only if `aff` is not provided.
  `key` - Key.
  `aff` - Affinity information.
Returns:
  Key partition.
Throws:
  `IgniteCheckedException` - If failed.

#### partition0

    public int partition0(@Nullable
                 String cacheName,
                 Object key,
                 @Nullable
                 org.apache.ignite.internal.processors.affinity.GridAffinityProcessor.AffinityInfo aff)
                   throws IgniteCheckedException

Parameters:
  `cacheName` - Cache name (needed only if `aff` is not provided.
  `key` - Key.
  `aff` - Affinity.
Returns:
  Key partition.
Throws:
  `IgniteCheckedException` - If failed.

#### mapKeysToNodes

    public <K> Map<ClusterNode,Collection<K>> mapKeysToNodes(@Nullable
                                                    String cacheName,
                                                    @Nullable
                                                    Collection<? extends K> keys)
                                                  throws IgniteCheckedException

Maps keys to nodes for given cache.

Parameters:
  `cacheName` - Cache name.
  `keys` - Keys to map.
Returns:
  Map of nodes to keys.
Throws:
  `IgniteCheckedException` - If failed.

#### mapKeyToNode

    @Nullable
    public <K> ClusterNode mapKeyToNode(@Nullable
                                        String cacheName,
                                        K key)
                             throws IgniteCheckedException

Maps single key to a node.

Parameters:
  `cacheName` - Cache name.
  `key` - Key to map.
Returns:
  Picked node.
Throws:
  `IgniteCheckedException` - If failed.

#### mapKeyToNode

    @Nullable
    public <K> ClusterNode mapKeyToNode(@Nullable
                                        String cacheName,
                                        K key,
                                        AffinityTopologyVersion topVer)
                             throws IgniteCheckedException

Maps single key to a node.

Parameters:
  `cacheName` - Cache name.
  `key` - Key to map.
Returns:
  Picked node.
Throws:
  `IgniteCheckedException` - If failed.

#### mapKeyToPrimaryAndBackups

    public <K> List<ClusterNode> mapKeyToPrimaryAndBackups(@Nullable
                                                  String cacheName,
                                                  K key,
                                                  AffinityTopologyVersion topVer)
                                                throws IgniteCheckedException

Map single key to primary and backup nodes.

Parameters:
  `cacheName` - Cache name.
  `key` - Key to map.
  `topVer` - Topology version.
Returns:
  Affinity nodes, primary first.
Throws:
  `IgniteCheckedException` - If failed.

#### affinityKey

    @Nullable
    public Object affinityKey(@Nullable
                              String cacheName,
                              @Nullable
                              Object key)
                       throws IgniteCheckedException

Gets affinity key for cache key.

Parameters:
  `cacheName` - Cache name.
  `key` - Cache key.
Returns:
  Affinity key.
Throws:
  `IgniteCheckedException` - In case of error.

#### affinityProxy

    public <K> org.apache.ignite.internal.processors.affinity.GridAffinityProcessor.CacheAffinityProxy<K> affinityProxy(String cacheName)

Parameters:
  `cacheName` - Cache name.
Returns:
  Cache affinity.

#### printMemoryStats

    public void printMemoryStats()

Prints memory statistics (sizes of internal structures, etc.). NOTE: this method is for testing and profiling purposes only.

Specified by:
  `printMemoryStats` in interface `GridComponent`
Overrides:
  `printMemoryStats` in class `GridProcessorAdapter`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.7.0
Release Date | : August 1 2016