org.apache.ignite.internal.processors.cache

## Class GridCacheDefaultAffinityKeyMapper

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper

All Implemented Interfaces:
  Serializable, AffinityKeyMapper

Direct Known Subclasses:
  CacheDefaultBinaryAffinityKeyMapper, CacheDefaultBinaryAffinityKeyMapper, IgfsGroupDataBlocksKeyMapper

    public class GridCacheDefaultAffinityKeyMapper
    extends Object
    implements AffinityKeyMapper

Default key affinity mapper. If key class has annotation `AffinityKeyMapped`, then the value of annotated method or field will be used to get affinity value instead of the key itself. If there is no annotation, then the key is used as is.

Convenience affinity key adapter, `AffinityKey` can be used in conjunction with this mapper to automatically provide custom affinity keys for cache keys.

If non-default affinity mapper is used, is should be provided via `CacheConfiguration.getAffinityMapper()` configuration property.

See Also:
  Serialized Form

### Field Summary

Fields
`protected Ignite` `ignite` Injected ignite instance.
`protected IgniteLogger` `log` Logger.

### Constructor Summary

Constructors
Constructor and Description
`GridCacheDefaultAffinityKeyMapper()`

### Method Summary

Methods
`Object` `affinityKey(Object key)` If key class has annotation `AffinityKeyMapped`, then the value of annotated method or field will be used to get affinity value instead of the key itself.
`void` `ignite(Ignite ignite)`
`void` `reset()` Resets cache affinity mapper to its initial state.

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

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

### Field Detail

#### ignite

    protected transient Ignite ignite

Injected ignite instance.

#### log

    @LoggerResource
    protected transient IgniteLogger log

Logger.

### Constructor Detail

#### GridCacheDefaultAffinityKeyMapper

    public GridCacheDefaultAffinityKeyMapper()

### Method Detail

#### affinityKey

    public Object affinityKey(Object key)

If key class has annotation `AffinityKeyMapped`, then the value of annotated method or field will be used to get affinity value instead of the key itself. If there is no annotation, then the key is returned as is.

Specified by:
  `affinityKey` in interface `AffinityKeyMapper`
Parameters:
  `key` - Key to get affinity key for.
Returns:
  Affinity key for given key.

#### ignite

    @IgniteInstanceResource
    public void ignite(Ignite ignite)

Parameters:
  `ignite` - Ignite.

#### reset

    public void reset()

Resets cache affinity mapper to its initial state. This method will be called by the system any time the affinity mapper has been sent to remote node where it has to be reinitialized. If your implementation of affinity mapper has no initialization logic, leave this method empty.

Specified by:
  `reset` in interface `AffinityKeyMapper`

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.5.0.final
Release Date | : December 29 2015