IGNITE-575 - Renaimings

Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/4ba0b01a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/4ba0b01a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/4ba0b01a

Branch: refs/heads/ignite-573
Commit: 4ba0b01a4c5e2511039b38332a862eed65d1ed24
Parents: 740d4be
Author: Valentin Kulichenko <vkuliche...@gridgain.com>
Authored: Tue Mar 24 20:43:32 2015 -0700
Committer: Valentin Kulichenko <vkuliche...@gridgain.com>
Committed: Tue Mar 24 20:43:34 2015 -0700

----------------------------------------------------------------------
 .../examples/datagrid/CacheQueryExample.java    |  38 +-
 .../examples/ScalarCacheQueryExample.scala      |  12 +-
 .../ClientAbstractMultiThreadedSelfTest.java    |   2 +-
 .../ClientAbstractMultiNodeSelfTest.java        |   2 +-
 .../ignite/jdbc/JdbcComplexQuerySelfTest.java   |  13 +-
 .../ignite/jdbc/JdbcMetadataSelfTest.java       |  13 +-
 .../src/test/resources/spring-server-node.xml   |   2 +-
 .../test/resources/spring-server-ssl-node.xml   |   2 +-
 .../src/main/java/org/apache/ignite/Ignite.java |   2 +-
 .../java/org/apache/ignite/IgniteCache.java     |   2 +-
 .../java/org/apache/ignite/IgniteCluster.java   |   4 +-
 .../org/apache/ignite/IgniteJdbcDriver.java     |   3 +-
 .../apache/ignite/cache/CacheMemoryMode.java    |   6 +-
 .../java/org/apache/ignite/cache/CacheMode.java |   5 +-
 .../apache/ignite/cache/CacheRebalanceMode.java |   3 +-
 .../apache/ignite/cache/affinity/Affinity.java  | 246 ++++++
 .../ignite/cache/affinity/AffinityFunction.java | 110 +++
 .../cache/affinity/AffinityFunctionContext.java |  72 ++
 .../ignite/cache/affinity/AffinityKey.java      | 189 +++++
 .../cache/affinity/AffinityKeyMapped.java       | 110 +++
 .../cache/affinity/AffinityKeyMapper.java       |  62 ++
 .../AffinityNodeAddressHashResolver.java        |  39 +
 .../affinity/AffinityNodeHashResolver.java      |  43 +
 .../affinity/AffinityNodeIdHashResolver.java    |  40 +
 .../ignite/cache/affinity/CacheAffinity.java    | 246 ------
 .../cache/affinity/CacheAffinityFunction.java   | 110 ---
 .../affinity/CacheAffinityFunctionContext.java  |  72 --
 .../ignite/cache/affinity/CacheAffinityKey.java | 189 -----
 .../cache/affinity/CacheAffinityKeyMapped.java  | 110 ---
 .../cache/affinity/CacheAffinityKeyMapper.java  |  62 --
 .../CacheAffinityNodeAddressHashResolver.java   |  39 -
 .../affinity/CacheAffinityNodeHashResolver.java |  43 -
 .../CacheAffinityNodeIdHashResolver.java        |  40 -
 .../CacheCentralizedAffinityFunction.java       |  31 -
 .../affinity/CentralizedAffinityFunction.java   |  31 +
 .../fair/CachePartitionFairAffinity.java        | 777 -------------------
 .../affinity/fair/FairAffinityFunction.java     | 777 +++++++++++++++++++
 .../CacheRendezvousAffinityFunction.java        | 501 ------------
 .../rendezvous/RendezvousAffinityFunction.java  | 500 ++++++++++++
 .../cache/eviction/CacheEvictableEntry.java     |  96 ---
 .../cache/eviction/CacheEvictionFilter.java     |  43 -
 .../cache/eviction/CacheEvictionPolicy.java     |  50 --
 .../ignite/cache/eviction/EvictableEntry.java   |  96 +++
 .../ignite/cache/eviction/EvictionFilter.java   |  43 +
 .../ignite/cache/eviction/EvictionPolicy.java   |  54 ++
 .../eviction/fifo/CacheFifoEvictionPolicy.java  | 192 -----
 .../fifo/CacheFifoEvictionPolicyMBean.java      |  50 --
 .../cache/eviction/fifo/FifoEvictionPolicy.java | 191 +++++
 .../eviction/fifo/FifoEvictionPolicyMBean.java  |  50 ++
 .../eviction/igfs/CacheIgfsEvictionFilter.java  |  38 -
 .../CacheIgfsPerBlockLruEvictionPolicy.java     | 378 ---------
 ...acheIgfsPerBlockLruEvictionPolicyMXBean.java |  93 ---
 .../cache/eviction/igfs/IgfsEvictionFilter.java |  38 +
 .../igfs/IgfsPerBlockLruEvictionPolicy.java     | 376 +++++++++
 .../IgfsPerBlockLruEvictionPolicyMXBean.java    |  93 +++
 .../eviction/lru/CacheLruEvictionPolicy.java    | 199 -----
 .../lru/CacheLruEvictionPolicyMBean.java        |  50 --
 .../cache/eviction/lru/LruEvictionPolicy.java   | 198 +++++
 .../eviction/lru/LruEvictionPolicyMBean.java    |  50 ++
 .../random/CacheRandomEvictionPolicy.java       | 115 ---
 .../random/CacheRandomEvictionPolicyMBean.java  |  42 -
 .../eviction/random/RandomEvictionPolicy.java   | 114 +++
 .../random/RandomEvictionPolicyMBean.java       |  42 +
 .../configuration/CacheConfiguration.java       |  36 +-
 .../configuration/NearCacheConfiguration.java   |   6 +-
 .../apache/ignite/internal/IgniteKernal.java    |   2 +-
 .../org/apache/ignite/internal/IgnitionEx.java  |   4 +-
 .../affinity/GridAffinityAssignmentCache.java   |  14 +-
 .../GridAffinityFunctionContextImpl.java        |  83 ++
 .../affinity/GridAffinityProcessor.java         |  22 +-
 .../processors/affinity/GridAffinityUtils.java  |   7 +-
 .../GridCacheAffinityFunctionContextImpl.java   |  83 --
 .../cache/CacheEvictableEntryImpl.java          |   2 +-
 .../processors/cache/CacheObjectContext.java    |   6 +-
 .../processors/cache/CacheProjection.java       |   6 +-
 .../internal/processors/cache/GridCache.java    |   7 +-
 .../processors/cache/GridCacheAdapter.java      |   4 +-
 .../processors/cache/GridCacheAttributes.java   |  12 +-
 .../processors/cache/GridCacheContext.java      |  12 +-
 .../GridCacheDefaultAffinityKeyMapper.java      |  14 +-
 .../processors/cache/GridCacheEntryEx.java      |   2 +-
 .../cache/GridCacheEvictionManager.java         |   4 +-
 .../processors/cache/GridCacheMapEntry.java     |   4 +-
 .../cache/GridCachePreloaderAdapter.java        |   2 +-
 .../processors/cache/GridCacheProcessor.java    |  36 +-
 .../processors/cache/GridCacheProxyImpl.java    |   4 +-
 .../processors/cache/GridCacheUtils.java        |   4 +-
 .../cache/affinity/GridCacheAffinityImpl.java   |   2 +-
 .../cache/affinity/GridCacheAffinityProxy.java  |   6 +-
 .../GridDhtPartitionsExchangeFuture.java        |   4 +-
 .../processors/cache/query/CacheQuery.java      |   3 +-
 .../GridCacheInternalKeyImpl.java               |   2 +-
 .../datastructures/GridCacheQueueAdapter.java   |   2 +-
 .../datastructures/GridCacheSetImpl.java        |   2 +-
 .../processors/igfs/IgfsDataManager.java        |   2 +-
 .../processors/igfs/IgfsHelperImpl.java         |  16 +-
 .../internal/processors/igfs/IgfsImpl.java      |   8 +-
 .../internal/processors/igfs/IgfsProcessor.java |   4 +-
 .../cache/VisorCacheAffinityConfiguration.java  |   6 +-
 .../cache/VisorCacheEvictionConfiguration.java  |   2 +-
 .../visor/cache/VisorCacheSwapBackupsTask.java  |   2 +-
 .../internal/visor/util/VisorTaskUtils.java     |  14 +-
 .../resources/META-INF/classnames.properties    |  32 +-
 .../core/src/test/config/discovery-stress.xml   |   2 +-
 .../config/load/dsi-49-server-production.xml    |   4 +-
 .../src/test/config/load/dsi-load-server.xml    |   2 +-
 .../core/src/test/config/spring-cache-swap.xml  |   2 +-
 .../src/test/config/spring-cache-teststore.xml  |   2 +-
 .../core/src/test/config/spring-multicache.xml  |  16 +-
 .../GridCacheAffinityBackupsSelfTest.java       |   8 +-
 .../ignite/IgniteCacheAffinitySelfTest.java     |  20 +-
 ...CachePartitionFairAffinityNodesSelfTest.java | 242 ------
 .../GridCachePartitionFairAffinitySelfTest.java | 264 -------
 .../GridFairAffinityFunctionNodesSelfTest.java  | 242 ++++++
 .../fair/GridFairAffinityFunctionSelfTest.java  | 264 +++++++
 .../ignite/internal/GridAffinityMappedTest.java |   4 +-
 .../internal/GridAffinityP2PSelfTest.java       |   4 +-
 .../GridJobMasterLeaveAwareSelfTest.java        |   6 +-
 .../internal/GridMultipleJobsSelfTest.java      |   2 +-
 .../GridAffinityProcessorAbstractSelfTest.java  |   2 +-
 ...GridAffinityProcessorRendezvousSelfTest.java |   4 +-
 ...cheNearUpdateTopologyChangeAbstractTest.java |   2 +-
 .../cache/GridCacheAbstractFullApiSelfTest.java |   6 +-
 ...acheAbstractUsersAffinityMapperSelfTest.java |   4 +-
 .../cache/GridCacheAffinityApiSelfTest.java     |  48 +-
 .../cache/GridCacheAffinityMapperSelfTest.java  |  14 +-
 .../cache/GridCacheAffinityRoutingSelfTest.java |   2 +-
 .../cache/GridCacheAlwaysEvictionPolicy.java    |   4 +-
 .../GridCacheAtomicMessageCountSelfTest.java    |   2 +-
 .../GridCacheConcurrentTxMultiNodeTest.java     |  28 +-
 ...idCacheConfigurationConsistencySelfTest.java |  56 +-
 ...ridCacheConfigurationValidationSelfTest.java |   6 +-
 .../GridCacheInterceptorAbstractSelfTest.java   |   6 +-
 .../processors/cache/GridCacheLeakTest.java     |   2 +-
 .../cache/GridCacheLifecycleAwareSelfTest.java  |  12 +-
 .../cache/GridCacheMemoryModeSelfTest.java      |   3 +-
 .../cache/GridCacheObjectToStringSelfTest.java  |  18 +-
 .../processors/cache/GridCacheOffHeapTest.java  |   2 +-
 .../GridCachePartitionedAffinitySpreadTest.java |   4 +-
 .../cache/GridCacheReloadSelfTest.java          |   2 +-
 .../processors/cache/GridCacheTestEntryEx.java  |   2 +-
 .../cache/IgniteCachePeekModesAbstractTest.java |  10 +-
 .../cache/IgniteCacheTxPreloadNoWriteTest.java  |   4 +-
 .../IgniteClientAffinityAssignmentSelfTest.java |   8 +-
 .../processors/cache/IgniteTxAbstractTest.java  |   4 +-
 .../cache/IgniteTxMultiNodeAbstractTest.java    |   2 +-
 ...GridCachePartitionedNodeRestartSelfTest.java |   2 +-
 ...dCachePartitionedQueueEntryMoveSelfTest.java |   8 +-
 .../GridCacheAtomicTimeoutSelfTest.java         |   2 +-
 .../GridCacheClientModesAbstractSelfTest.java   |   2 +-
 .../GridCacheModuloAffinityFunction.java        |   4 +-
 ...dCachePartitionedAffinityFilterSelfTest.java |   6 +-
 ...chePartitionedReloadAllAbstractSelfTest.java |   2 +-
 ...GridCachePreloadRestartAbstractSelfTest.java |   4 +-
 .../GridCacheTransformEventSelfTest.java        |   4 +-
 ...heAbstractTransformWriteThroughSelfTest.java |   2 +-
 .../dht/GridCacheAtomicNearCacheSelfTest.java   |  18 +-
 .../dht/GridCacheColocatedDebugTest.java        |   2 +-
 .../dht/GridCacheDhtEntrySelfTest.java          |   4 +-
 ...GridCacheDhtEvictionNearReadersSelfTest.java |   4 +-
 .../dht/GridCacheDhtEvictionSelfTest.java       |   4 +-
 .../dht/GridCacheDhtInternalEntrySelfTest.java  |   5 +-
 .../dht/GridCacheDhtPreloadBigDataSelfTest.java |   2 +-
 .../dht/GridCacheDhtPreloadDelayedSelfTest.java |   4 +-
 .../GridCacheDhtPreloadDisabledSelfTest.java    |   2 +-
 .../GridCacheDhtPreloadMessageCountTest.java    |   2 +-
 ...ridCacheDhtPreloadMultiThreadedSelfTest.java |   2 +-
 .../dht/GridCacheDhtPreloadSelfTest.java        |   8 +-
 .../GridCacheDhtPreloadStartStopSelfTest.java   |   6 +-
 .../dht/GridCacheDhtPreloadUnloadSelfTest.java  |   2 +-
 .../distributed/dht/GridCacheDhtTestUtils.java  |   9 +-
 ...idCachePartitionedPreloadEventsSelfTest.java |   6 +-
 ...dCachePartitionedTopologyChangeSelfTest.java |   6 +-
 ...ridCachePartitionedUnloadEventsSelfTest.java |   2 +-
 ...eAtomicInvalidPartitionHandlingSelfTest.java |   2 +-
 .../atomic/GridCacheAtomicPreloadSelfTest.java  |   2 +-
 ...unctionExcludeNeighborsAbstractSelfTest.java |   6 +-
 ...eAtomicNearOnlyMultiNodeFullApiSelfTest.java |   2 +-
 .../near/GridCacheNearMultiGetSelfTest.java     |   2 +-
 .../near/GridCacheNearMultiNodeSelfTest.java    |   6 +-
 .../near/GridCacheNearTxMultiNodeSelfTest.java  |   2 +-
 ...AffinityExcludeNeighborsPerformanceTest.java |  10 +-
 ...rtitionedAffinityHashIdResolverSelfTest.java |   6 +-
 .../GridCachePartitionedAffinitySelfTest.java   |   6 +-
 .../GridCachePartitionedEvictionSelfTest.java   |   6 +-
 .../GridCachePartitionedFullApiSelfTest.java    |   2 +-
 .../GridCachePartitionedLoadCacheSelfTest.java  |   2 +-
 ...achePartitionedMultiNodeCounterSelfTest.java |   6 +-
 ...achePartitionedMultiNodeFullApiSelfTest.java |   6 +-
 ...ePartitionedMultiThreadedPutGetSelfTest.java |   2 +-
 .../GridCachePartitionedNodeRestartTest.java    |   2 +-
 ...ePartitionedOptimisticTxNodeRestartTest.java |   2 +-
 .../GridCachePartitionedTxSalvageSelfTest.java  |   2 +-
 ...idCacheRendezvousAffinityClientSelfTest.java |   4 +-
 ...ffinityFunctionExcludeNeighborsSelfTest.java |   4 +-
 ...dezvousAffinityMultiNodeFullApiSelfTest.java |   4 +-
 .../GridCacheReplicatedPreloadSelfTest.java     |   4 +-
 .../GridCacheBatchEvictUnswapSelfTest.java      |   2 +-
 ...heConcurrentEvictionConsistencySelfTest.java |  26 +-
 .../GridCacheConcurrentEvictionsSelfTest.java   |   6 +-
 .../GridCacheDistributedEvictionsSelfTest.java  |   2 +-
 .../GridCacheEmptyEntriesAbstractSelfTest.java  |   8 +-
 .../eviction/GridCacheEvictionAbstractTest.java |  12 +-
 .../GridCacheEvictionFilterSelfTest.java        |  12 +-
 .../GridCacheEvictionLockUnlockSelfTest.java    |   4 +-
 .../GridCacheEvictionTouchSelfTest.java         |  24 +-
 .../cache/eviction/GridCacheMockEntry.java      |   3 +-
 ...cheSynchronousEvictionsFailoverSelfTest.java |   4 +-
 .../GridCacheFifoEvictionPolicySelfTest.java    |  20 +-
 .../lru/GridCacheLruEvictionPolicySelfTest.java |  22 +-
 .../GridCacheLruNearEvictionPolicySelfTest.java |   2 +-
 ...heNearOnlyLruNearEvictionPolicySelfTest.java |   2 +-
 .../GridCacheRandomEvictionPolicySelfTest.java  |  12 +-
 .../IgniteCacheLoadAllAbstractTest.java         |   2 +-
 .../DataStreamProcessorSelfTest.java            |   2 +-
 ...sCachePerBlockLruEvictionPolicySelfTest.java |   4 +-
 ...idOffHeapPartitionedMapAbstractSelfTest.java |   2 +-
 ...apPartitionedMapPerformanceAbstractTest.java |   2 +-
 ...GridUnsafePartitionedMapPerformanceTest.java |   2 +-
 .../loadtests/GridCacheMultiNodeLoadTest.java   |   2 +-
 .../capacity/spring-capacity-cache.xml          |   2 +-
 .../loadtests/colocation/GridTestKey.java       |   2 +-
 .../loadtests/colocation/spring-colocation.xml  |   2 +-
 .../GridCachePartitionedAtomicLongLoadTest.java |   4 +-
 .../ignite/loadtests/dsi/GridDsiPerfJob.java    |   2 +-
 .../ignite/loadtests/dsi/GridDsiRequest.java    |   2 +-
 .../ignite/loadtests/dsi/GridDsiResponse.java   |   4 +-
 .../ignite/loadtests/dsi/GridDsiSession.java    |   2 +-
 ...apPartitionedMapPerformanceAbstractTest.java |   2 +-
 ...GridUnsafePartitionedMapPerformanceTest.java |   2 +-
 .../swap/GridSwapEvictAllBenchmark.java         |   2 +-
 .../ignite/testframework/junits/IgniteMock.java |   2 +-
 .../junits/common/GridCommonAbstractTest.java   |  14 +-
 .../ignite/testsuites/IgniteCacheTestSuite.java |   2 +-
 .../tests/p2p/GridExternalAffinityFunction.java |   4 +-
 .../p2p/GridExternalAffinityKeyMapper.java      |   2 +-
 .../hibernate/HibernateL2CacheSelfTest.java     |   6 +-
 .../GridCacheAbstractFieldsQuerySelfTest.java   |  34 +-
 .../cache/GridIndexingWithNoopSwapSelfTest.java |   2 +-
 .../IgniteCacheAbstractFieldsQuerySelfTest.java |  26 +-
 .../IgniteCacheQueryMultiThreadedSelfTest.java  |   2 +-
 ...GridCachePartitionedFieldsQuerySelfTest.java |   6 +-
 ...dCacheAbstractReduceFieldsQuerySelfTest.java |  22 +-
 .../ignite/schema/generator/CodeGenerator.java  |   2 +-
 .../ignite/schema/ui/SchemaImportApp.java       |   4 +-
 .../org/apache/ignite/IgniteSpringBean.java     |   2 +-
 .../org/apache/ignite/yardstick/IgniteNode.java |   2 +-
 247 files changed, 4802 insertions(+), 4810 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
----------------------------------------------------------------------
diff --git 
a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
 
b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
index 5c5168e..75c5b7e 100644
--- 
a/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
+++ 
b/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheQueryExample.java
@@ -40,7 +40,7 @@ import java.util.*;
  * <ul>
  *     <li>
  *         Joins will work correctly only if joined objects are stored in
- *         collocated mode. Refer to {@link CacheAffinityKey} javadoc for more 
details.
+ *         collocated mode. Refer to {@link AffinityKey} javadoc for more 
details.
  *     </li>
  *     <li>
  *         Note that if you created query on to replicated cache, all data will
@@ -75,7 +75,7 @@ public class CacheQueryExample {
             cfg.setName(CACHE_NAME);
             cfg.setIndexedTypes(
                 UUID.class, Organization.class,
-                CacheAffinityKey.class, Person.class
+                AffinityKey.class, Person.class
             );
 
             try (IgniteCache<?, ?> cache = ignite.createCache(cfg)) {
@@ -110,22 +110,22 @@ public class CacheQueryExample {
      * Example for SQL queries based on salary ranges.
      */
     private static void sqlQuery() {
-        IgniteCache<CacheAffinityKey<UUID>, Person> cache = 
Ignition.ignite().cache(CACHE_NAME);
+        IgniteCache<AffinityKey<UUID>, Person> cache = 
Ignition.ignite().cache(CACHE_NAME);
 
         // SQL clause which selects salaries based on range.
         String sql = "salary > ? and salary <= ?";
 
         // Execute queries for salary ranges.
         print("People with salaries between 0 and 1000: ",
-            cache.query(new SqlQuery<CacheAffinityKey<UUID>, 
Person>(Person.class, sql).
+            cache.query(new SqlQuery<AffinityKey<UUID>, Person>(Person.class, 
sql).
                 setArgs(0, 1000)).getAll());
 
         print("People with salaries between 1000 and 2000: ",
-            cache.query(new SqlQuery<CacheAffinityKey<UUID>, 
Person>(Person.class, sql).
+            cache.query(new SqlQuery<AffinityKey<UUID>, Person>(Person.class, 
sql).
                 setArgs(1000, 2000)).getAll());
 
         print("People with salaries greater than 2000: ",
-            cache.query(new SqlQuery<CacheAffinityKey<UUID>, 
Person>(Person.class, sql).
+            cache.query(new SqlQuery<AffinityKey<UUID>, Person>(Person.class, 
sql).
                 setArgs(2000, Integer.MAX_VALUE)).getAll());
     }
 
@@ -133,7 +133,7 @@ public class CacheQueryExample {
      * Example for SQL queries based on all employees working for a specific 
organization.
      */
     private static void sqlQueryWithJoin() {
-        IgniteCache<CacheAffinityKey<UUID>, Person> cache = 
Ignition.ignite().cache(CACHE_NAME);
+        IgniteCache<AffinityKey<UUID>, Person> cache = 
Ignition.ignite().cache(CACHE_NAME);
 
         // SQL clause query which joins on 2 types to select people for a 
specific organization.
         String joinSql =
@@ -143,10 +143,10 @@ public class CacheQueryExample {
 
         // Execute queries for find employees for different organizations.
         print("Following people are 'GridGain' employees: ",
-            cache.query(new SqlQuery<CacheAffinityKey<UUID>, 
Person>(Person.class, joinSql).
+            cache.query(new SqlQuery<AffinityKey<UUID>, Person>(Person.class, 
joinSql).
                 setArgs("GridGain")).getAll());
         print("Following people are 'Other' employees: ",
-            cache.query(new SqlQuery<CacheAffinityKey<UUID>, 
Person>(Person.class, joinSql).
+            cache.query(new SqlQuery<AffinityKey<UUID>, Person>(Person.class, 
joinSql).
                 setArgs("Other")).getAll());
     }
 
@@ -154,15 +154,15 @@ public class CacheQueryExample {
      * Example for TEXT queries using LUCENE-based indexing of people's 
resumes.
      */
     private static void textQuery() {
-        IgniteCache<CacheAffinityKey<UUID>, Person> cache = 
Ignition.ignite().cache(CACHE_NAME);
+        IgniteCache<AffinityKey<UUID>, Person> cache = 
Ignition.ignite().cache(CACHE_NAME);
 
         //  Query for all people with "Master Degree" in their resumes.
-        QueryCursor<Cache.Entry<CacheAffinityKey<UUID>, Person>> masters =
-            cache.query(new TextQuery<CacheAffinityKey<UUID>, 
Person>(Person.class, "Master"));
+        QueryCursor<Cache.Entry<AffinityKey<UUID>, Person>> masters =
+            cache.query(new TextQuery<AffinityKey<UUID>, Person>(Person.class, 
"Master"));
 
         // Query for all people with "Bachelor Degree" in their resumes.
-        QueryCursor<Cache.Entry<CacheAffinityKey<UUID>, Person>> bachelors =
-            cache.query(new TextQuery<CacheAffinityKey<UUID>, 
Person>(Person.class, "Bachelor"));
+        QueryCursor<Cache.Entry<AffinityKey<UUID>, Person>> bachelors =
+            cache.query(new TextQuery<AffinityKey<UUID>, Person>(Person.class, 
"Bachelor"));
 
         print("Following people have 'Master Degree' in their resumes: ", 
masters.getAll());
         print("Following people have 'Bachelor Degree' in their resumes: ", 
bachelors.getAll());
@@ -172,7 +172,7 @@ public class CacheQueryExample {
      * Example for SQL queries to calculate average salary for a specific 
organization.
      */
     private static void sqlQueryWithAggregation() {
-        IgniteCache<CacheAffinityKey<UUID>, Person> cache = 
Ignition.ignite().cache(CACHE_NAME);
+        IgniteCache<AffinityKey<UUID>, Person> cache = 
Ignition.ignite().cache(CACHE_NAME);
 
         // Calculate average of salary of all persons in GridGain.
         QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("select 
avg(salary) from Person, " +
@@ -192,7 +192,7 @@ public class CacheQueryExample {
 
         // Create query to get names of all employees.
         QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("select 
concat(firstName, ' ', " +
-            "lastName) from Person"));
+            "" + "lastName) from Person"));
 
         // Execute query to get collection of rows. In this particular
         // case each row will have one element with full name of an employees.
@@ -312,7 +312,7 @@ public class CacheQueryExample {
         private double salary;
 
         /** Custom cache key to guarantee that person is always collocated 
with its organization. */
-        private transient CacheAffinityKey<UUID> key;
+        private transient AffinityKey<UUID> key;
 
         /**
          * Constructs person record.
@@ -341,9 +341,9 @@ public class CacheQueryExample {
          *
          * @return Custom affinity key to guarantee that person is always 
collocated with organization.
          */
-        public CacheAffinityKey<UUID> key() {
+        public AffinityKey<UUID> key() {
             if (key == null)
-                key = new CacheAffinityKey<>(id, orgId);
+                key = new AffinityKey<>(id, orgId);
 
             return key;
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarCacheQueryExample.scala
----------------------------------------------------------------------
diff --git 
a/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarCacheQueryExample.scala
 
b/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarCacheQueryExample.scala
index d471b35..50b68ca 100644
--- 
a/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarCacheQueryExample.scala
+++ 
b/examples/src/main/scala/org/apache/ignite/scalar/examples/ScalarCacheQueryExample.scala
@@ -20,7 +20,7 @@ package org.apache.ignite.scalar.examples
 import java.util._
 
 import org.apache.ignite.cache.CacheMode._
-import org.apache.ignite.cache.affinity.CacheAffinityKey
+import org.apache.ignite.cache.affinity.AffinityKey
 import org.apache.ignite.configuration.CacheConfiguration
 import org.apache.ignite.scalar.scalar
 import org.apache.ignite.scalar.scalar._
@@ -49,7 +49,7 @@ object ScalarCacheQueryExample {
     def main(args: Array[String]) {
         scalar(CONFIG) {
             val cache = createCache$(NAME, indexedTypes = Seq(classOf[UUID], 
classOf[Organization],
-                classOf[CacheAffinityKey[_]], classOf[Person]))
+                classOf[AffinityKey[_]], classOf[Person]))
 
             try {
                 example(ignite$)
@@ -70,12 +70,12 @@ object ScalarCacheQueryExample {
         initialize()
 
         // Cache instance shortcut.
-        val cache = mkCache[CacheAffinityKey[UUID], Person]
+        val cache = mkCache[AffinityKey[UUID], Person]
 
         // Using distributed queries for partitioned cache and local queries 
for replicated cache.
         // Since in replicated caches data is available on all nodes, 
including local one,
         // it is enough to just query the local node.
-        val prj = if 
(cache.getConfiguration(classOf[CacheConfiguration[CacheAffinityKey[UUID], 
Person]]).getCacheMode == PARTITIONED)
+        val prj = if 
(cache.getConfiguration(classOf[CacheConfiguration[AffinityKey[UUID], 
Person]]).getCacheMode == PARTITIONED)
             ignite.cluster().forRemotes()
         else
             ignite.cluster().forLocal()
@@ -114,7 +114,7 @@ object ScalarCacheQueryExample {
         orgCache += (org2.id -> org2)
 
         // Person cache projection.
-        val prnCache = mkCache[CacheAffinityKey[UUID], Person]
+        val prnCache = mkCache[AffinityKey[UUID], Person]
 
         // People.
         val p1 = Person(org1, "John", "Doe", 2000, "John Doe has Master 
Degree.")
@@ -181,7 +181,7 @@ private case class Person(
     val orgId = org.id
 
     /** Affinity key for this person. */
-    val key = new CacheAffinityKey[UUID](id, org.id)
+    val key = new AffinityKey[UUID](id, org.id)
 
     /**
      * `toString` implementation.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/clients/src/test/java/org/apache/ignite/internal/client/ClientAbstractMultiThreadedSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/internal/client/ClientAbstractMultiThreadedSelfTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/internal/client/ClientAbstractMultiThreadedSelfTest.java
index 41df0da..f1898df 100644
--- 
a/modules/clients/src/test/java/org/apache/ignite/internal/client/ClientAbstractMultiThreadedSelfTest.java
+++ 
b/modules/clients/src/test/java/org/apache/ignite/internal/client/ClientAbstractMultiThreadedSelfTest.java
@@ -180,7 +180,7 @@ public abstract class ClientAbstractMultiThreadedSelfTest 
extends GridCommonAbst
     private CacheConfiguration cacheConfiguration(@Nullable String cacheName) 
throws Exception {
         CacheConfiguration cfg = defaultCacheConfiguration();
 
-        cfg.setAffinity(new CacheRendezvousAffinityFunction());
+        cfg.setAffinity(new RendezvousAffinityFunction());
 
         cfg.setAtomicityMode(TRANSACTIONAL);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractMultiNodeSelfTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractMultiNodeSelfTest.java
index 1d010e6..cf1b735 100644
--- 
a/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractMultiNodeSelfTest.java
+++ 
b/modules/clients/src/test/java/org/apache/ignite/internal/client/integration/ClientAbstractMultiNodeSelfTest.java
@@ -192,7 +192,7 @@ public abstract class ClientAbstractMultiNodeSelfTest 
extends GridCommonAbstract
 
         
cfg.setWriteSynchronizationMode(REPLICATED_ASYNC_CACHE_NAME.equals(cacheName) ? 
FULL_ASYNC : FULL_SYNC);
 
-        cfg.setAffinity(new CacheRendezvousAffinityFunction());
+        cfg.setAffinity(new RendezvousAffinityFunction());
 
         return cfg;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcComplexQuerySelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcComplexQuerySelfTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcComplexQuerySelfTest.java
index ade888e..a9bc246 100644
--- 
a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcComplexQuerySelfTest.java
+++ 
b/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcComplexQuerySelfTest.java
@@ -57,10 +57,7 @@ public class JdbcComplexQuerySelfTest extends 
GridCommonAbstractTest {
         cache.setBackups(1);
         cache.setWriteSynchronizationMode(FULL_SYNC);
         cache.setAtomicityMode(TRANSACTIONAL);
-        cache.setIndexedTypes(
-            String.class, Organization.class,
-            CacheAffinityKey.class, Person.class
-        );
+        cache.setIndexedTypes(String.class, Organization.class, 
AffinityKey.class, Person.class);
 
         cfg.setCacheConfiguration(cache);
 
@@ -86,13 +83,13 @@ public class JdbcComplexQuerySelfTest extends 
GridCommonAbstractTest {
         orgCache.put("o1", new Organization(1, "A"));
         orgCache.put("o2", new Organization(2, "B"));
 
-        IgniteCache<CacheAffinityKey<String>, Person> personCache = 
grid(0).cache(null);
+        IgniteCache<AffinityKey<String>, Person> personCache = 
grid(0).cache(null);
 
         assert personCache != null;
 
-        personCache.put(new CacheAffinityKey<>("p1", "o1"), new Person(1, 
"John White", 25, 1));
-        personCache.put(new CacheAffinityKey<>("p2", "o1"), new Person(2, "Joe 
Black", 35, 1));
-        personCache.put(new CacheAffinityKey<>("p3", "o2"), new Person(3, 
"Mike Green", 40, 2));
+        personCache.put(new AffinityKey<>("p1", "o1"), new Person(1, "John 
White", 25, 1));
+        personCache.put(new AffinityKey<>("p2", "o1"), new Person(2, "Joe 
Black", 35, 1));
+        personCache.put(new AffinityKey<>("p3", "o2"), new Person(3, "Mike 
Green", 40, 2));
 
         Class.forName("org.apache.ignite.IgniteJdbcDriver");
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcMetadataSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcMetadataSelfTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcMetadataSelfTest.java
index 39d2799..e1318d6 100644
--- 
a/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcMetadataSelfTest.java
+++ 
b/modules/clients/src/test/java/org/apache/ignite/jdbc/JdbcMetadataSelfTest.java
@@ -54,10 +54,7 @@ public class JdbcMetadataSelfTest extends 
GridCommonAbstractTest {
         cache.setCacheMode(PARTITIONED);
         cache.setBackups(1);
         cache.setWriteSynchronizationMode(FULL_SYNC);
-        cache.setIndexedTypes(
-            String.class, Organization.class,
-            CacheAffinityKey.class, Person.class
-        );
+        cache.setIndexedTypes(String.class, Organization.class, 
AffinityKey.class, Person.class);
 
         cfg.setCacheConfiguration(cache);
 
@@ -83,13 +80,13 @@ public class JdbcMetadataSelfTest extends 
GridCommonAbstractTest {
         orgCache.put("o1", new Organization(1, "A"));
         orgCache.put("o2", new Organization(2, "B"));
 
-        IgniteCache<CacheAffinityKey<String>, Person> personCache = 
grid(0).cache(null);
+        IgniteCache<AffinityKey<String>, Person> personCache = 
grid(0).cache(null);
 
         assert personCache != null;
 
-        personCache.put(new CacheAffinityKey<>("p1", "o1"), new Person("John 
White", 25, 1));
-        personCache.put(new CacheAffinityKey<>("p2", "o1"), new Person("Joe 
Black", 35, 1));
-        personCache.put(new CacheAffinityKey<>("p3", "o2"), new Person("Mike 
Green", 40, 2));
+        personCache.put(new AffinityKey<>("p1", "o1"), new Person("John 
White", 25, 1));
+        personCache.put(new AffinityKey<>("p2", "o1"), new Person("Joe Black", 
35, 1));
+        personCache.put(new AffinityKey<>("p3", "o2"), new Person("Mike 
Green", 40, 2));
 
         Class.forName("org.apache.ignite.IgniteJdbcDriver");
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/clients/src/test/resources/spring-server-node.xml
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/resources/spring-server-node.xml 
b/modules/clients/src/test/resources/spring-server-node.xml
index efc55e9..b6f18d0 100644
--- a/modules/clients/src/test/resources/spring-server-node.xml
+++ b/modules/clients/src/test/resources/spring-server-node.xml
@@ -118,7 +118,7 @@
                     <property name="writeSynchronizationMode" 
value="FULL_SYNC"/>
 
                     <property name="affinity">
-                        <bean 
class="org.apache.ignite.cache.affinity.rendezvous.CacheRendezvousAffinityFunction">
+                        <bean 
class="org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction">
                             <constructor-arg value="1"/>
                         </bean>
                     </property>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/clients/src/test/resources/spring-server-ssl-node.xml
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/resources/spring-server-ssl-node.xml 
b/modules/clients/src/test/resources/spring-server-ssl-node.xml
index a7bac02..61b4a4b 100644
--- a/modules/clients/src/test/resources/spring-server-ssl-node.xml
+++ b/modules/clients/src/test/resources/spring-server-ssl-node.xml
@@ -120,7 +120,7 @@
                     <property name="writeSynchronizationMode" 
value="FULL_SYNC"/>
 
                     <property name="affinity">
-                        <bean 
class="org.apache.ignite.cache.affinity.rendezvous.CacheRendezvousAffinityFunction">
+                        <bean 
class="org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction">
                             <constructor-arg value="1"/>
                         </bean>
                     </property>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/Ignite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/Ignite.java 
b/modules/core/src/main/java/org/apache/ignite/Ignite.java
index 5d4061d..36b6011 100644
--- a/modules/core/src/main/java/org/apache/ignite/Ignite.java
+++ b/modules/core/src/main/java/org/apache/ignite/Ignite.java
@@ -426,5 +426,5 @@ public interface Ignite extends AutoCloseable {
      * @param <K> Cache key type.
      * @return Affinity.
      */
-    public <K> CacheAffinity<K> affinity(String cacheName);
+    public <K> Affinity<K> affinity(String cacheName);
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java 
b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
index f5ce8a6..b176f38 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
@@ -507,7 +507,7 @@ public interface IgniteCache<K, V> extends 
javax.cache.Cache<K, V>, IgniteAsyncS
      * the left nodes, and that nodes are restarted before
      * {@link CacheConfiguration#getRebalanceDelay() rebalanceDelay} expires. 
To place nodes
      * on the same place in consistent hash ring, use
-     * {@link 
CacheRendezvousAffinityFunction#setHashIdResolver(CacheAffinityNodeHashResolver)}
 to make sure that
+     * {@link 
RendezvousAffinityFunction#setHashIdResolver(AffinityNodeHashResolver)} to make 
sure that
      * a node maps to the same hash ID if re-started.
      * <p>
      * See {@link CacheConfiguration#getRebalanceDelay()} for more information 
on how to configure

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/IgniteCluster.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCluster.java 
b/modules/core/src/main/java/org/apache/ignite/IgniteCluster.java
index c24ba5e..47930b1 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteCluster.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCluster.java
@@ -110,7 +110,7 @@ public interface IgniteCluster extends ClusterGroup, 
IgniteAsyncSupport {
      * <ul>
      * <li>For local caches it returns only local node mapped to all keys.</li>
      * <li>
-     *      For fully replicated caches, {@link CacheAffinityFunction} is
+     *      For fully replicated caches, {@link AffinityFunction} is
      *      used to determine which keys are mapped to which groups of nodes.
      * </li>
      * <li>For partitioned caches, the returned map represents node-to-key 
affinity.</li>
@@ -133,7 +133,7 @@ public interface IgniteCluster extends ClusterGroup, 
IgniteAsyncSupport {
      * <ul>
      * <li>For local caches it returns only local node ID.</li>
      * <li>
-     *      For fully replicated caches first node ID returned by {@link 
CacheAffinityFunction}
+     *      For fully replicated caches first node ID returned by {@link 
AffinityFunction}
      *      is returned.
      * </li>
      * <li>For partitioned caches, the returned node ID is the primary node 
for the key.</li>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java 
b/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java
index d061c8f..a7c2eae 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteJdbcDriver.java
@@ -18,6 +18,7 @@
 package org.apache.ignite;
 
 
+import org.apache.ignite.cache.affinity.*;
 import org.apache.ignite.internal.jdbc.*;
 
 import java.sql.*;
@@ -40,7 +41,7 @@ import java.util.logging.*;
  *     <li>
  *         Joins will work correctly only if joined objects are stored in
  *         collocated mode. Refer to
- *         {@link org.apache.ignite.cache.affinity.CacheAffinityKey}
+ *         {@link AffinityKey}
  *         javadoc for more details.
  *     </li>
  *     <li>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/cache/CacheMemoryMode.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/cache/CacheMemoryMode.java 
b/modules/core/src/main/java/org/apache/ignite/cache/CacheMemoryMode.java
index 914a2e2..7a67fa5 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/CacheMemoryMode.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheMemoryMode.java
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.cache;
 
+import org.apache.ignite.cache.eviction.*;
+
 /**
  * Defines set of memory modes. Memory modes help control whether cache 
entries are
  * stored on heap memory, offheap memory, or in swap space.
@@ -37,7 +39,7 @@ public enum CacheMemoryMode {
      * </li>
      * </nl>
      * <p>
-     * <b>Note</b> that heap memory evictions are handled by configured {@link 
org.apache.ignite.cache.eviction.CacheEvictionPolicy}
+     * <b>Note</b> that heap memory evictions are handled by configured {@link 
EvictionPolicy}
      * implementation. By default, no eviction policy is enabled, so entries 
never leave heap
      * memory space unless explicitly removed.
      */
@@ -53,7 +55,7 @@ public enum CacheMemoryMode {
     /**
      * Entry keys will be stored on heap memory, and values will be stored in 
offheap memory. Note
      * that in this mode entries can be evicted only to swap. The evictions 
will happen according
-     * to configured {@link 
org.apache.ignite.cache.eviction.CacheEvictionPolicy}.
+     * to configured {@link EvictionPolicy}.
      */
     OFFHEAP_VALUES,
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/cache/CacheMode.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/CacheMode.java 
b/modules/core/src/main/java/org/apache/ignite/cache/CacheMode.java
index fab1c82..56d31fb 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/CacheMode.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheMode.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.cache;
 
+import org.apache.ignite.cache.affinity.*;
 import org.apache.ignite.configuration.*;
 import org.jetbrains.annotations.*;
 
@@ -40,7 +41,7 @@ public enum CacheMode {
     /**
      * Specifies fully replicated cache behavior. In this mode all the keys 
are distributed
      * to all participating nodes. User still has affinity control
-     * over subset of nodes for any given key via {@link 
org.apache.ignite.cache.affinity.CacheAffinityFunction}
+     * over subset of nodes for any given key via {@link AffinityFunction}
      * configuration.
      */
     REPLICATED,
@@ -49,7 +50,7 @@ public enum CacheMode {
      * Specifies partitioned cache behaviour. In this mode the overall
      * key set will be divided into partitions and all partitions will be split
      * equally between participating nodes. User has affinity
-     * control over key assignment via {@link 
org.apache.ignite.cache.affinity.CacheAffinityFunction}
+     * control over key assignment via {@link AffinityFunction}
      * configuration.
      * <p>
      * Note that partitioned cache is always fronted by local

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/cache/CacheRebalanceMode.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/cache/CacheRebalanceMode.java 
b/modules/core/src/main/java/org/apache/ignite/cache/CacheRebalanceMode.java
index 90d9ba4..79d22f9 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/CacheRebalanceMode.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/CacheRebalanceMode.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.cache;
 
+import org.apache.ignite.cache.affinity.*;
 import org.jetbrains.annotations.*;
 
 /**
@@ -26,7 +27,7 @@ import org.jetbrains.annotations.*;
  * explicitly, then {@link 
org.apache.ignite.configuration.CacheConfiguration#DFLT_REBALANCE_MODE} is used.
  * <p>
  * Replicated caches will try to load the full set of cache entries from other 
nodes (or as defined by
- * pluggable {@link org.apache.ignite.cache.affinity.CacheAffinityFunction}), 
while partitioned caches will only load the entries for which
+ * pluggable {@link AffinityFunction}), while partitioned caches will only 
load the entries for which
  * current node is primary or back up.
  * <p>
  * Note that rebalance mode only makes sense for {@link CacheMode#REPLICATED} 
and {@link CacheMode#PARTITIONED}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/cache/affinity/Affinity.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/cache/affinity/Affinity.java 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/Affinity.java
new file mode 100644
index 0000000..835e142
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/cache/affinity/Affinity.java
@@ -0,0 +1,246 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity;
+
+import org.apache.ignite.cluster.*;
+import org.jetbrains.annotations.*;
+
+import java.util.*;
+
+/**
+ * Provides affinity information to detect which node is primary and which 
nodes are
+ * backups for a partitioned cache. You can get an instance of this interface 
by calling
+ * {@code Cache.affinity()} method.
+ * <p>
+ * Mapping of a key to a node is a three-step operation. First step will get 
an affinity key for given key
+ * using {@link AffinityKeyMapper}. If mapper is not specified, the original 
key will be used. Second step
+ * will map affinity key to partition using {@link 
AffinityFunction#partition(Object)} method. Third step
+ * will map obtained partition to nodes for current grid topology version.
+ * <p>
+ * Interface provides various {@code 'mapKeysToNodes(..)'} methods which 
provide node affinity mapping for
+ * given keys. All {@code 'mapKeysToNodes(..)'} methods are not transactional 
and will not enlist
+ * keys into ongoing transaction.
+ */
+public interface Affinity<K> {
+    /**
+     * Gets number of partitions in cache according to configured affinity 
function.
+     *
+     * @return Number of cache partitions.
+     * @see AffinityFunction
+     * @see org.apache.ignite.configuration.CacheConfiguration#getAffinity()
+     * @see 
org.apache.ignite.configuration.CacheConfiguration#setAffinity(AffinityFunction)
+     */
+    public int partitions();
+
+    /**
+     * Gets partition id for the given key.
+     *
+     * @param key Key to get partition id for.
+     * @return Partition id.
+     * @see AffinityFunction
+     * @see org.apache.ignite.configuration.CacheConfiguration#getAffinity()
+     * @see 
org.apache.ignite.configuration.CacheConfiguration#setAffinity(AffinityFunction)
+     */
+    public int partition(K key);
+
+    /**
+     * Returns {@code true} if given node is the primary node for given key.
+     *
+     * @param n Node to check.
+     * @param key Key to check.
+     * @return {@code True} if local node is the primary node for given key.
+     */
+    public boolean isPrimary(ClusterNode n, K key);
+
+    /**
+     * Returns {@code true} if local node is one of the backup nodes for given 
key.
+     *
+     * @param n Node to check.
+     * @param key Key to check.
+     * @return {@code True} if local node is one of the backup nodes for given 
key.
+     */
+    public boolean isBackup(ClusterNode n, K key);
+
+    /**
+     * Returns {@code true} if local node is primary or one of the backup nodes
+     * <p>
+     * This method is essentially equivalent to calling
+     * <i>"{@link #isPrimary(org.apache.ignite.cluster.ClusterNode, Object)} ||
+     *      {@link #isBackup(org.apache.ignite.cluster.ClusterNode, 
Object)})"</i>,
+     * however it is more efficient as it makes both checks at once.
+     *
+     * @param n Node to check.
+     * @param key Key to check.
+     * @return {@code True} if local node is primary or backup for given key.
+     */
+    public boolean isPrimaryOrBackup(ClusterNode n, K key);
+
+    /**
+     * Gets partition ids for which nodes of the given projection has primary
+     * ownership.
+     * <p>
+     * Note that since {@link org.apache.ignite.cluster.ClusterNode} 
implements {@link org.apache.ignite.cluster.ClusterGroup},
+     * to find out primary partitions for a single node just pass
+     * a single node into this method.
+     * <p>
+     * This method may return an empty array if none of nodes in the projection
+     * have nearOnly disabled.
+     *
+     * @param n Grid node.
+     * @return Partition ids for which given projection has primary ownership.
+     * @see AffinityFunction
+     * @see org.apache.ignite.configuration.CacheConfiguration#getAffinity()
+     * @see 
org.apache.ignite.configuration.CacheConfiguration#setAffinity(AffinityFunction)
+     */
+    public int[] primaryPartitions(ClusterNode n);
+
+    /**
+     * Gets partition ids for which nodes of the given projection has backup
+     * ownership. Note that you can find a back up at a certain level, e.g.
+     * {@code first} backup or {@code third} backup by specifying the
+     * {@code 'levels} parameter. If no {@code 'level'} is specified then
+     * all backup partitions are returned.
+     * <p>
+     * Note that since {@link org.apache.ignite.cluster.ClusterNode} 
implements {@link org.apache.ignite.cluster.ClusterGroup},
+     * to find out backup partitions for a single node, just pass that single
+     * node into this method.
+     * <p>
+     * This method may return an empty array if none of nodes in the projection
+     * have nearOnly disabled.
+     *
+     * @param n Grid node.
+     * @return Partition ids for which given projection has backup ownership.
+     * @see AffinityFunction
+     * @see org.apache.ignite.configuration.CacheConfiguration#getAffinity()
+     * @see 
org.apache.ignite.configuration.CacheConfiguration#setAffinity(AffinityFunction)
+     */
+    public int[] backupPartitions(ClusterNode n);
+
+    /**
+     * Gets partition ids for which nodes of the given projection has ownership
+     * (either primary or backup).
+     * <p>
+     * Note that since {@link org.apache.ignite.cluster.ClusterNode} 
implements {@link org.apache.ignite.cluster.ClusterGroup},
+     * to find out all partitions for a single node, just pass that single
+     * node into this method.
+     * <p>
+     * This method may return an empty array if none of nodes in the projection
+     * have nearOnly disabled.
+     *
+     * @param n Grid node.
+     * @return Partition ids for which given projection has ownership.
+     * @see AffinityFunction
+     * @see org.apache.ignite.configuration.CacheConfiguration#getAffinity()
+     * @see 
org.apache.ignite.configuration.CacheConfiguration#setAffinity(AffinityFunction)
+     */
+    public int[] allPartitions(ClusterNode n);
+
+    /**
+     * Maps passed in key to a key which will be used for node affinity. The 
affinity
+     * key may be different from actual key if some field in the actual key was
+     * designated for affinity mapping via {@link AffinityKeyMapped} annotation
+     * or if a custom {@link AffinityKeyMapper} was configured.
+     *
+     * @param key Key to map.
+     * @return Key to be used for node-to-affinity mapping (may be the same
+     *      key as passed in).
+     */
+    public Object affinityKey(K key);
+
+    /**
+     * This method provides ability to detect which keys are mapped to which 
nodes.
+     * Use it to determine which nodes are storing which keys prior to sending
+     * jobs that access these keys.
+     * <p>
+     * This method works as following:
+     * <ul>
+     * <li>For local caches it returns only local node mapped to all keys.</li>
+     * <li>
+     *      For fully replicated caches {@link AffinityFunction} is
+     *      used to determine which keys are mapped to which nodes.
+     * </li>
+     * <li>For partitioned caches, the returned map represents node-to-key 
affinity.</li>
+     * </ul>
+     *
+     * @param keys Keys to map to nodes.
+     * @return Map of nodes to keys or empty map if there are no alive nodes 
for this cache.
+     */
+    public Map<ClusterNode, Collection<K>> mapKeysToNodes(@Nullable 
Collection<? extends K> keys);
+
+    /**
+     * This method provides ability to detect to which primary node the given 
key
+     * is mapped. Use it to determine which nodes are storing which keys prior 
to sending
+     * jobs that access these keys.
+     * <p>
+     * This method works as following:
+     * <ul>
+     * <li>For local caches it returns only local node ID.</li>
+     * <li>
+     *      For fully replicated caches first node ID returned by {@link 
AffinityFunction}
+     *      is returned.
+     * </li>
+     * <li>For partitioned caches, primary node for the given key is 
returned.</li>
+     * </ul>
+     *
+     * @param key Keys to map to a node.
+     * @return Primary node for the key or {@code null} if there are no alive 
nodes for this cache.
+     */
+    @Nullable public ClusterNode mapKeyToNode(K key);
+
+    /**
+     * Gets primary and backup nodes for the key. Note that primary node is 
always
+     * first in the returned collection.
+     *
+     * @param key Key to get affinity nodes for.
+     * @return Collection of primary and backup nodes for the key with primary 
node
+     *      always first.
+     */
+    public Collection<ClusterNode> mapKeyToPrimaryAndBackups(K key);
+
+    /**
+     * Gets primary node for the given partition.
+     *
+     * @param part Partition id.
+     * @return Primary node for the given partition.
+     * @see AffinityFunction
+     * @see org.apache.ignite.configuration.CacheConfiguration#getAffinity()
+     * @see 
org.apache.ignite.configuration.CacheConfiguration#setAffinity(AffinityFunction)
+     */
+    public ClusterNode mapPartitionToNode(int part);
+
+    /**
+     * Gets primary nodes for the given partitions.
+     *
+     * @param parts Partition ids.
+     * @return Mapping of given partitions to their primary nodes.
+     * @see AffinityFunction
+     * @see org.apache.ignite.configuration.CacheConfiguration#getAffinity()
+     * @see 
org.apache.ignite.configuration.CacheConfiguration#setAffinity(AffinityFunction)
+     */
+    public Map<Integer, ClusterNode> mapPartitionsToNodes(Collection<Integer> 
parts);
+
+    /**
+     * Gets primary and backup nodes for partition. Note that primary node is 
always
+     * first in the returned collection.
+     *
+     * @param part Partition to get affinity nodes for.
+     * @return Collection of primary and backup nodes for partition with 
primary node
+     *      always first.
+     */
+    public Collection<ClusterNode> mapPartitionToPrimaryAndBackups(int part);
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityFunction.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityFunction.java
 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityFunction.java
new file mode 100644
index 0000000..3278502
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityFunction.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity;
+
+import org.apache.ignite.cluster.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Cache key affinity which maps keys to nodes. This interface is utilized for
+ * both, replicated and partitioned caches. Cache affinity can be configured
+ * for individual caches via {@link 
org.apache.ignite.configuration.CacheConfiguration#getAffinity()} method.
+ * <p>
+ * Whenever a key is given to cache, it is first passed to a pluggable
+ * {@link AffinityKeyMapper} which may potentially map this key to an alternate
+ * key which should be used for affinity. The key returned from
+ * {@link AffinityKeyMapper#affinityKey(Object)} method is then passed to
+ * {@link #partition(Object) partition(Object)} method to find out the 
partition for the key.
+ * On each topology change, partition-to-node mapping is calculated using
+ * {@link #assignPartitions(AffinityFunctionContext)} method, which assigns a 
collection
+ * of nodes to each partition.
+ * This collection of nodes is used for node affinity. In {@link 
org.apache.ignite.cache.CacheMode#REPLICATED REPLICATED}
+ * cache mode the key will be cached on all returned nodes; generally, all 
caching nodes
+ * participate in caching every key in replicated mode. In {@link 
org.apache.ignite.cache.CacheMode#PARTITIONED PARTITIONED}
+ * mode, only primary and backup nodes are returned with primary node always 
in the
+ * first position. So if there is {@code 1} backup node, then the returned 
collection will
+ * have {@code 2} nodes in it - {@code primary} node in first position, and 
{@code backup}
+ * node in second.
+ * <p>
+ * For more information about cache affinity and examples refer to {@link 
AffinityKeyMapper} and
+ * {@link AffinityKeyMapped @AffinityKeyMapped} documentation.
+ * @see AffinityKeyMapped
+ * @see AffinityKeyMapper
+ */
+public interface AffinityFunction extends Serializable {
+    /**
+     * Resets cache affinity to its initial state. This method will be called 
by
+     * the system any time the affinity has been sent to remote node where
+     * it has to be reinitialized. If your implementation of affinity function
+     * has no initialization logic, leave this method empty.
+     */
+    public void reset();
+
+    /**
+     * Gets total number of partitions available. All caches should always 
provide
+     * correct partition count which should be the same on all participating 
nodes.
+     * Note that partitions should always be numbered from {@code 0} 
inclusively to
+     * {@code N} exclusively without any gaps.
+     *
+     * @return Total partition count.
+     */
+    public int partitions();
+
+    /**
+     * Gets partition number for a given key starting from {@code 0}. 
Partitioned caches
+     * should make sure that keys are about evenly distributed across all 
partitions
+     * from {@code 0} to {@link #partitions() partition count} for best 
performance.
+     * <p>
+     * Note that for fully replicated caches it is possible to segment key 
sets among different
+     * grid node groups. In that case each node group should return a unique 
partition
+     * number. However, unlike partitioned cache, mappings of keys to nodes in
+     * replicated caches are constant and a node cannot migrate from one 
partition
+     * to another.
+     *
+     * @param key Key to get partition for.
+     * @return Partition number for a given key.
+     */
+    public int partition(Object key);
+
+    /**
+     * Gets affinity nodes for a partition. In case of replicated cache, all 
returned
+     * nodes are updated in the same manner. In case of partitioned cache, the 
returned
+     * list should contain only the primary and back up nodes with primary 
node being
+     * always first.
+     * <p>
+     * Note that partitioned affinity must obey the following contract: given 
that node
+     * <code>N</code> is primary for some key <code>K</code>, if any other 
node(s) leave
+     * grid and no node joins grid, node <code>N</code> will remain primary 
for key <code>K</code>.
+     *
+     * @param affCtx Affinity function context. Will provide all required 
information to calculate
+     *      new partition assignments.
+     * @return Unmodifiable list indexed by partition number. Each element of 
array is a collection in which
+     *      first node is a primary node and other nodes are backup nodes.
+     */
+    public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext 
affCtx);
+
+    /**
+     * Removes node from affinity. This method is called when it is safe to 
remove left node from
+     * affinity mapping.
+     *
+     * @param nodeId ID of node to remove.
+     */
+    public void removeNode(UUID nodeId);
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityFunctionContext.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityFunctionContext.java
 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityFunctionContext.java
new file mode 100644
index 0000000..9d22833
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityFunctionContext.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity;
+
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.events.*;
+import org.apache.ignite.internal.processors.affinity.*;
+import org.jetbrains.annotations.*;
+
+import java.util.*;
+
+/**
+ * Affinity function context. This context is passed to {@link 
AffinityFunction} for
+ * partition reassignment on every topology change event.
+ */
+public interface AffinityFunctionContext {
+    /**
+     * Gets affinity assignment for given partition on previous topology 
version. First node in returned list is
+     * a primary node, other nodes are backups.
+     *
+     * @param part Partition to get previous assignment for.
+     * @return List of nodes assigned to given partition on previous topology 
version or {@code null}
+     *      if this information is not available.
+     */
+    @Nullable public List<ClusterNode> previousAssignment(int part);
+
+    /**
+     * Gets number of backups for new assignment.
+     *
+     * @return Number of backups for new assignment.
+     */
+    public int backups();
+
+    /**
+     * Gets current topology snapshot. Snapshot will contain only nodes on 
which particular cache is configured.
+     * List of passed nodes is guaranteed to be sorted in a same order on all 
nodes on which partition assignment
+     * is performed.
+     *
+     * @return Cache topology snapshot.
+     */
+    public List<ClusterNode> currentTopologySnapshot();
+
+    /**
+     * Gets current topology version number.
+     *
+     * @return Current topology version number.
+     */
+    public AffinityTopologyVersion currentTopologyVersion();
+
+    /**
+     * Gets discovery event caused topology change.
+     *
+     * @return Discovery event caused latest topology change or {@code null} 
if this information is
+     *      not available.
+     */
+    @Nullable public DiscoveryEvent discoveryEvent();
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKey.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKey.java 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKey.java
new file mode 100644
index 0000000..4e840f9
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKey.java
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity;
+
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.util.tostring.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+
+import java.io.*;
+
+/**
+ * Optional wrapper for cache keys to provide support
+ * for custom affinity mapping. The value returned by
+ * {@link #affinityKey(Object)} method will be used for key-to-node
+ * affinity.
+ * <p>
+ * Note that the {@link #equals(Object)} and {@link #hashCode()} methods
+ * delegate directly to the wrapped cache key provided by {@link #key()}
+ * method.
+ * <p>
+ * This class is optional and does not have to be used. It only provides
+ * extra convenience whenever custom affinity mapping is required. Here is
+ * an example of how {@code Person} objects can be collocated with
+ * {@code Company} objects they belong to:
+ * <pre name="code" class="java">
+ * Object personKey = new AffinityKey(myPersonId, myCompanyId);
+ *
+ * // Both, the company and the person objects will be cached on the same node.
+ * cache.put(myCompanyId, new Company(..));
+ * cache.put(personKey, new Person(..));
+ * </pre>
+ * <p>
+ * For more information and examples of cache affinity refer to
+ * {@link AffinityKeyMapper} and {@link AffinityKeyMapped @AffinityKeyMapped}
+ * documentation.
+ * @see AffinityKeyMapped
+ * @see AffinityKeyMapper
+ * @see AffinityFunction
+ */
+public class AffinityKey<K> implements Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Key. */
+    @GridToStringInclude
+    private K key;
+
+    /** Affinity key. */
+    @GridToStringInclude
+    private Object affKey;
+
+    /**
+     * Empty constructor.
+     */
+    public AffinityKey() {
+        // No-op.
+    }
+
+    /**
+     * Initializes key wrapper for a given key. If affinity key
+     * is not initialized, then this key will be used for affinity.
+     *
+     * @param key Key.
+     */
+    public AffinityKey(K key) {
+        A.notNull(key, "key");
+
+        this.key = key;
+    }
+
+    /**
+     * Initializes key together with its affinity key counter-part.
+     *
+     * @param key Key.
+     * @param affKey Affinity key.
+     */
+    public AffinityKey(K key, Object affKey) {
+        A.notNull(key, "key");
+
+        this.key = key;
+        this.affKey = affKey;
+    }
+
+    /**
+     * Gets wrapped key.
+     *
+     * @return Wrapped key.
+     */
+    public K key() {
+        return key;
+    }
+
+    /**
+     * Sets wrapped key.
+     *
+     * @param key Wrapped key.
+     */
+    public void key(K key) {
+        this.key = key;
+    }
+
+    /**
+     * Gets affinity key to use for affinity mapping. If affinity key is not 
provided,
+     * then {@code key} value will be returned.
+     * <p>
+     * This method is annotated with {@link AffinityKeyMapped} and will be 
picked up
+     * by {@link GridCacheDefaultAffinityKeyMapper} automatically.
+     *
+     * @return Affinity key to use for affinity mapping.
+     */
+    @AffinityKeyMapped
+    @SuppressWarnings({"unchecked"})
+    public <T> T affinityKey() {
+        A.notNull(key, "key");
+
+        return (T)(affKey == null ? key : affKey);
+    }
+
+    /**
+     * Sets affinity key to use for affinity mapping. If affinity key is not 
provided,
+     * then {@code key} value will be returned.
+     *
+     * @param affKey Affinity key to use for affinity mapping.
+     */
+    public void affinityKey(Object affKey) {
+        this.affKey = affKey;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(key);
+        out.writeObject(affKey);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, 
ClassNotFoundException {
+        key = (K)in.readObject();
+        affKey = in.readObject();
+    }
+
+    /**
+     * Hash code implementation which delegates to the underlying {@link 
#key()}. Note, however,
+     * that different subclasses of {@link AffinityKey} will produce different 
hash codes.
+     * <p>
+     * Users should override this method if different behavior is desired.
+     *
+     * @return Hash code.
+     */
+    @Override public int hashCode() {
+        A.notNull(key, "key");
+
+        return 31 * key.hashCode() + getClass().getName().hashCode();
+    }
+
+    /**
+     * Equality check which delegates to the underlying key equality. Note, 
however, that
+     * different subclasses of {@link AffinityKey} will never be equal.
+     * <p>
+     * Users should override this method if different behavior is desired.
+     *
+     * @param obj Object to check for equality.
+     * @return {@code True} if objects are equal.
+     */
+    @Override public boolean equals(Object obj) {
+        A.notNull(key, "key");
+
+        return obj != null && getClass() == obj.getClass() && 
key.equals(((AffinityKey)obj).key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(AffinityKey.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKeyMapped.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKeyMapped.java
 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKeyMapped.java
new file mode 100644
index 0000000..4464972
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKeyMapped.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity;
+
+import java.lang.annotation.*;
+import java.util.concurrent.*;
+
+/**
+ * Optional annotation to specify custom key-to-node affinity. Affinity key is 
a key
+ * which will be used to determine a node on which given cache key will be 
stored. This
+ * annotation allows to mark a field or a method in the cache key object that 
will be
+ * used as an affinity key (instead of the entire cache key object that is 
used for
+ * affinity by default). Note that a class can have only one field or method 
annotated
+ * with {@code @AffinityKeyMapped} annotation.
+ * <p>
+ * One of the major use cases for this annotation is the routing of grid 
computations
+ * to the nodes where the data for this computation is cached, the concept
+ * otherwise known as {@code Collocation Of Computations And Data}.
+ * <p>
+ * <h1 class="header">Mapping Cache Keys</h1>
+ * The default implementation of {@link AffinityKeyMapper}, which will be used
+ * if no explicit affinity mapper is specified in cache configuration, will 
first look
+ * for any field or method annotated with {@code @AffinityKeyMapped} 
annotation.
+ * If such field or method is not found, then the cache key itself will be 
used for
+ * key-to-node affinity (this means that all objects with the same cache key 
will always
+ * be routed to the same node). If such field or method is found, then the 
value of this
+ * field or method will be used for key-to-node affinity. This allows to 
specify alternate
+ * affinity key, other than the cache key itself, whenever needed.
+ * <p>
+ * For example, if a {@code Person} object is always accessed together with a 
{@code Company} object
+ * for which this person is an employee, then for better performance and 
scalability it makes sense to
+ * collocate {@code Person} objects together with their {@code Company} object 
when storing them in
+ * cache. To achieve that, cache key used to cache {@code Person} objects 
should have a field or method
+ * annotated with {@code @AffinityKeyMapped} annotation, which will provide 
the value of
+ * the company key for which that person works, like so:
+ * <pre name="code" class="java">
+ * public class PersonKey {
+ *     // Person ID used to identify a person.
+ *     private String personId;
+ *
+ *     // Company ID which will be used for affinity.
+ *     &#64;AffinityKeyMapped
+ *     private String companyId;
+ *     ...
+ * }
+ * ...
+ * // Instantiate person keys.
+ * Object personKey1 = new PersonKey("myPersonId1", "myCompanyId");
+ * Object personKey2 = new PersonKey("myPersonId2", "myCompanyId");
+ *
+ * // Both, the company and the person objects will be cached on the same node.
+ * cache.put("myCompanyId", new Company(..));
+ * cache.put(personKey1, new Person(..));
+ * cache.put(personKey2, new Person(..));
+ * </pre>
+ * <p>
+ * <h2 class="header">AffinityKey</h2>
+ * For convenience, you can also optionally use {@link AffinityKey} class. 
Here is how a
+ * {@code PersonKey} defined above would look using {@link AffinityKey}:
+ * <pre name="code" class="java">
+ * Object personKey1 = new AffinityKey("myPersonId1", "myCompanyId");
+ * Object personKey2 = new AffinityKey("myPersonId2", "myCompanyId");
+ *
+ * // Both, the company and the person objects will be cached on the same node.
+ * cache.put(myCompanyId, new Company(..));
+ * cache.put(personKey1, new Person(..));
+ * cache.put(personKey2, new Person(..));
+ * </pre>
+ * <p>
+ * <h1 class="header">Collocating Computations And Data</h1>
+ * It is also possible to route computations to the nodes where the data is 
cached. This concept
+ * is otherwise known as {@code Collocation Of Computations And Data}. In this 
case,
+ * {@code @AffinityKeyMapped} annotation allows to specify a routing affinity 
key for a
+ * {@link org.apache.ignite.compute.ComputeJob} or any other grid computation, 
such as {@link Runnable},
+ * {@link Callable}, or {@link org.apache.ignite.lang.IgniteClosure}. It 
should be attached to a method or
+ * field that provides affinity key for the computation. Only one annotation 
per class is allowed.
+ * Whenever such annotation is detected, then {@link 
org.apache.ignite.spi.loadbalancing.LoadBalancingSpi}
+ * will be bypassed, and computation will be routed to the grid node where the 
specified affinity key is cached.
+ * <p>
+ * For more information about cache affinity also see {@link 
AffinityKeyMapper} and
+ * {@link AffinityFunction} documentation.
+ * Affinity for a key can be found from any node, regardless of whether it has 
cache started
+ * or not. If cache is not started, affinity function will be fetched from the 
remote node
+ * which does have the cache running.
+ *
+ * @see AffinityFunction
+ * @see AffinityKeyMapper
+ * @see AffinityKey
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.METHOD})
+public @interface AffinityKeyMapped {
+    // No-op.
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKeyMapper.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKeyMapper.java
 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKeyMapper.java
new file mode 100644
index 0000000..69835c8
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityKeyMapper.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity;
+
+import java.io.*;
+
+/**
+ * Affinity mapper which maps cache key to an affinity key. Affinity key is a 
key which will be
+ * used to determine a node on which this key will be cached. Every cache key 
will first be passed
+ * through {@link #affinityKey(Object)} method, and the returned value of this 
method
+ * will be given to {@link AffinityFunction} implementation to find out 
key-to-node affinity.
+ * <p>
+ * The default implementation, which will be used if no explicit affinity 
mapper is specified
+ * in cache configuration, will first look for any field or method annotated 
with
+ * {@link AffinityKeyMapped @AffinityKeyMapped} annotation. If such field or 
method
+ * is not found, then the cache key itself will be returned from {@link 
#affinityKey(Object) affinityKey(Object)}
+ * method (this means that all objects with the same cache key will always be 
routed to the same node).
+ * If such field or method is found, then the value of this field or method 
will be returned from
+ * {@link #affinityKey(Object) affinityKey(Object)} method. This allows to 
specify alternate affinity key, other
+ * than the cache key itself, whenever needed.
+ * <p>
+ * A custom (other than default) affinity mapper can be provided
+ * via {@link 
org.apache.ignite.configuration.CacheConfiguration#getAffinityMapper()} 
configuration property.
+ * <p>
+ * For more information on affinity mapping and examples refer to {@link 
AffinityFunction} and
+ * {@link AffinityKeyMapped @AffinityKeyMapped} documentation.
+ * @see AffinityFunction
+ * @see AffinityKeyMapped
+ */
+public interface AffinityKeyMapper extends Serializable {
+    /**
+     * Maps passed in key to an alternate key which will be used for node 
affinity.
+     *
+     * @param key Key to map.
+     * @return Key to be used for node-to-affinity mapping (may be the same
+     *      key as passed in).
+     */
+    public Object affinityKey(Object key);
+
+    /**
+     * 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.
+     */
+    public void reset();
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityNodeAddressHashResolver.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityNodeAddressHashResolver.java
 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityNodeAddressHashResolver.java
new file mode 100644
index 0000000..7ce49ec
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityNodeAddressHashResolver.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity;
+
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+
+/**
+ * Node hash resolver which uses {@link 
org.apache.ignite.cluster.ClusterNode#consistentId()} as alternate hash value.
+ */
+public class AffinityNodeAddressHashResolver implements 
AffinityNodeHashResolver {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** {@inheritDoc} */
+    @Override public Object resolve(ClusterNode node) {
+        return node.consistentId();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(AffinityNodeAddressHashResolver.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityNodeHashResolver.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityNodeHashResolver.java
 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityNodeHashResolver.java
new file mode 100644
index 0000000..d00b043
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityNodeHashResolver.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity;
+
+import org.apache.ignite.cluster.*;
+
+import java.io.*;
+
+/**
+ * Resolver which is used to provide node hash value for affinity function.
+ * <p>
+ * Node IDs constantly change when nodes get restarted, which causes affinity 
mapping to change between restarts,
+ * and hence causing redundant repartitioning. Providing an alternate node 
hash value, which survives node restarts,
+ * will help to map keys to the same nodes whenever possible.
+ * <p>
+ * Note that on case clients exist they will query this object from the server 
and use it for affinity calculation.
+ * Therefore you must ensure that server and clients can marshal and unmarshal 
this object in portable format,
+ * i.e. all parties have object class(es) configured as portable.
+ */
+public interface AffinityNodeHashResolver extends Serializable {
+    /**
+     * Resolve alternate hash value for the given Grid node.
+     *
+     * @param node Grid node.
+     * @return Resolved hash ID.
+     */
+    public Object resolve(ClusterNode node);
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4ba0b01a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityNodeIdHashResolver.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityNodeIdHashResolver.java
 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityNodeIdHashResolver.java
new file mode 100644
index 0000000..65c6f13
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/cache/affinity/AffinityNodeIdHashResolver.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cache.affinity;
+
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+
+/**
+ * Node hash resolver which uses generated node ID as node hash value. As new 
node ID is generated
+ * on each node start, this resolver do not provide ability to map keys to the 
same nodes after restart.
+ */
+public class AffinityNodeIdHashResolver implements AffinityNodeHashResolver {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** {@inheritDoc} */
+    @Override public Object resolve(ClusterNode node) {
+        return node.id();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(AffinityNodeIdHashResolver.class, this);
+    }
+}

Reply via email to