ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [14/16] incubator-ignite git commit: # ignite-51
Date Wed, 04 Mar 2015 20:55:55 GMT
# ignite-51


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

Branch: refs/heads/ignite-51
Commit: b876320ecac810f592920a3c7a2b6b7c781565b4
Parents: 832d1ee
Author: sboikov <sboikov@gridgain.com>
Authored: Wed Mar 4 23:12:24 2015 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Wed Mar 4 23:23:40 2015 +0300

----------------------------------------------------------------------
 .../communication/GridIoMessageFactory.java     |   2 +-
 .../affinity/GridAffinityAssignmentCache.java   |  11 +-
 .../affinity/GridAffinityProcessor.java         |  35 +++--
 .../cache/CacheEntryPredicateContainsValue.java |   5 +-
 .../processors/cache/CacheEvictionEntry.java    |   2 +-
 .../cache/CacheInvokeDirectResult.java          |   4 +-
 .../internal/processors/cache/CacheObject.java  |   8 +-
 .../processors/cache/CacheObjectAdapter.java    |   4 +-
 .../processors/cache/CacheObjectContext.java    |  42 ++++-
 .../processors/cache/CacheObjectImpl.java       |  18 +--
 .../processors/cache/EvictableEntryImpl.java    |  10 +-
 .../processors/cache/GridCacheAdapter.java      |  22 +--
 .../cache/GridCacheConcurrentMap.java           |   2 +-
 .../processors/cache/GridCacheContext.java      |  28 ++--
 .../GridCacheDefaultAffinityKeyMapper.java      |  44 +++---
 .../cache/GridCacheDeploymentManager.java       |   2 +-
 .../processors/cache/GridCacheEntryInfo.java    |   4 +-
 .../processors/cache/GridCacheEventManager.java |   6 +-
 .../cache/GridCacheEvictionRequest.java         |   2 +-
 .../processors/cache/GridCacheMapEntry.java     |  58 ++++---
 .../processors/cache/GridCacheMessage.java      |  10 +-
 .../processors/cache/GridCacheProcessor.java    |  29 ++--
 .../processors/cache/GridCacheStoreManager.java |  20 +--
 .../processors/cache/GridCacheSwapManager.java  |  65 +++++---
 .../processors/cache/GridCacheUtils.java        |   7 +-
 .../processors/cache/KeyCacheObjectImpl.java    |  14 +-
 .../cache/KeyCacheObjectTransferImpl.java       |   8 +-
 .../processors/cache/UserCacheObjectImpl.java   |   4 +-
 .../cache/UserKeyCacheObjectImpl.java           |  12 +-
 .../cache/affinity/GridCacheAffinityImpl.java   |  10 +-
 .../CacheDataStructuresManager.java             |   2 +-
 .../distributed/dht/GridDhtCacheAdapter.java    |   2 +-
 .../distributed/dht/GridDhtTxPrepareFuture.java |   4 +-
 .../dht/atomic/GridDhtAtomicCache.java          |  14 +-
 .../dht/atomic/GridNearAtomicUpdateFuture.java  |   4 +-
 .../atomic/GridNearAtomicUpdateResponse.java    |   2 +-
 .../distributed/near/CacheVersionedValue.java   | 157 +++++++++++++++++++
 .../distributed/near/GridNearCacheEntry.java    |   2 +-
 .../distributed/near/GridNearGetFuture.java     |   4 +-
 .../cache/distributed/near/GridNearTxLocal.java |   4 +-
 .../near/GridNearTxPrepareFuture.java           |   6 +-
 .../near/GridNearTxPrepareResponse.java         |  18 +--
 .../near/NearTxPrepareResponseOwnedValue.java   | 157 -------------------
 .../local/atomic/GridLocalAtomicCache.java      |  13 +-
 .../cache/query/GridCacheQueryManager.java      |   2 +-
 .../continuous/CacheContinuousQueryEntry.java   |   6 +-
 .../continuous/CacheContinuousQueryEvent.java   |   2 +-
 .../continuous/CacheContinuousQueryManager.java |   6 +-
 .../cache/transactions/IgniteTxAdapter.java     |   2 +-
 .../cache/transactions/IgniteTxEntry.java       |   2 +-
 .../cache/transactions/IgniteTxKey.java         |   2 +-
 .../transactions/IgniteTxLocalAdapter.java      |  28 +---
 .../cache/transactions/TxEntryValueHolder.java  |   2 +-
 .../dataload/GridDataLoadUpdateJob.java         |   4 +-
 .../dataload/IgniteDataLoaderEntry.java         |   4 +-
 .../dataload/IgniteDataLoaderImpl.java          |  11 +-
 .../datastructures/DataStructuresProcessor.java |   4 +-
 .../IgniteCacheObjectProcessorAdapter.java      |  19 ++-
 .../cache/GridCacheAbstractFullApiSelfTest.java |   3 +-
 .../cache/GridCacheOffHeapSelfTest.java         |   2 +-
 ...actQueueFailoverDataConsistencySelfTest.java |   2 +-
 ...achePartitionedMultiNodeCounterSelfTest.java |   4 +-
 .../processors/query/h2/IgniteH2Indexing.java   |   3 +-
 .../cache/GridCacheOffHeapAndSwapSelfTest.java  |   4 +-
 .../cache/spring/SpringDynamicCacheManager.java |   2 +-
 65 files changed, 526 insertions(+), 465 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
index 7c4f949..05679ee 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
@@ -560,7 +560,7 @@ public class GridIoMessageFactory implements MessageFactory {
                 break;
 
             case 102:
-                msg = new NearTxPrepareResponseOwnedValue();
+                msg = new CacheVersionedValue();
 
                 break;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
index 40fa43a..316aefc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
@@ -93,6 +93,10 @@ public class GridAffinityAssignmentCache {
         CacheAffinityKeyMapper affMapper,
         int backups)
     {
+        assert ctx != null;
+        assert aff != null;
+        assert affMapper != null;
+
         this.ctx = ctx;
         this.aff = aff;
         this.affMapper = affMapper;
@@ -296,10 +300,6 @@ public class GridAffinityAssignmentCache {
      * @return Partition.
      */
     public int partition(Object key) {
-        // TODO IGNITE-51.
-        if (key instanceof CacheObject)
-            key = ((CacheObject)key).value(ctx, false);
-
         return aff.partition(affinityKey(key));
     }
 
@@ -311,6 +311,9 @@ public class GridAffinityAssignmentCache {
      * @return Affinity key.
      */
     private Object affinityKey(Object key) {
+        if (key instanceof CacheObject)
+            key = ((CacheObject)key).value(ctx.cacheObjectContext(), false);
+
         return (key instanceof GridCacheInternal ? ctx.defaultAffMapper() : affMapper).affinityKey(key);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java
index d7d0391..7458078 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityProcessor.java
@@ -225,8 +225,8 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
         if (affInfo == null || affInfo.mapper == null)
             return null;
 
-        if (affInfo.portableEnabled)
-            key = ctx.portable().marshalToPortable(key);
+        if (key instanceof CacheObject)
+            key = ((CacheObject)key).value(affInfo.cacheObjCtx, false);
 
         return affInfo.mapper.affinityKey(key);
     }
@@ -282,6 +282,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
 
     /**
      * @param cacheName Cache name.
+     * @param topVer Topology version.
      * @return Affinity cache.
      * @throws IgniteCheckedException In case of error.
      */
@@ -304,7 +305,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
                 cctx.config().getAffinity(),
                 cctx.config().getAffinityMapper(),
                 new GridAffinityAssignment(topVer, cctx.affinity().assignments(topVer)),
-                cctx.portableEnabled());
+                cctx.cacheObjectContext());
 
             IgniteInternalFuture<AffinityInfo> old = affMap.putIfAbsent(key, new GridFinishedFuture<>(ctx, info));
 
@@ -402,6 +403,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
      * {@link CacheAffinityKeyMapper} from remote node.
      *
      * @param cacheName Name of cache on which affinity is requested.
+     * @param topVer Topology version.
      * @param n Node from which affinity is requested.
      * @return Affinity cached function.
      * @throws IgniteCheckedException If either local or remote node cannot get deployment for affinity objects.
@@ -420,9 +422,7 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
         f.reset();
         m.reset();
 
-        Boolean portableEnabled = ctx.portable().portableEnabled(n, cacheName);
-
-        return new AffinityInfo(f, m, t.get3(), portableEnabled != null && portableEnabled);
+        return new AffinityInfo(f, m, t.get3(), ctx.portable().contextForCache(n, cacheName));
     }
 
     /**
@@ -471,6 +471,9 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
      * @throws IgniteCheckedException In case of error.
      */
     private <K> ClusterNode primary(AffinityInfo aff, K key) throws IgniteCheckedException {
+        if (key instanceof CacheObject)
+            key = ((CacheObject)key).value(aff.cacheObjCtx, false);
+
         int part = aff.affFunc.partition(aff.mapper.affinityKey(key));
 
         Collection<ClusterNode> nodes = aff.assignment.get(part);
@@ -487,6 +490,9 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
      * @return Primary and backup nodes.
      */
     private <K> List<ClusterNode> primaryAndBackups(AffinityInfo aff, K key) {
+        if (key instanceof CacheObject)
+            key = ((CacheObject) key).value(aff.cacheObjCtx, false);
+
         int part = aff.affFunc.partition(aff.mapper.affinityKey(key));
 
         return aff.assignment.get(part);
@@ -512,21 +518,23 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
         /** Assignment. */
         private GridAffinityAssignment assignment;
 
-        /** Portable enabled flag. */
-        private boolean portableEnabled;
+        /** */
+        private CacheObjectContext cacheObjCtx;
 
         /**
          * @param affFunc Affinity function.
          * @param mapper Affinity key mapper.
          * @param assignment Partition assignment.
-         * @param portableEnabled Portable enabled flag.
+         * @param cacheObjCtx Cache objects context.
          */
-        private AffinityInfo(CacheAffinityFunction affFunc, CacheAffinityKeyMapper mapper,
-            GridAffinityAssignment assignment, boolean portableEnabled) {
+        private AffinityInfo(CacheAffinityFunction affFunc,
+            CacheAffinityKeyMapper mapper,
+            GridAffinityAssignment assignment,
+            CacheObjectContext cacheObjCtx) {
             this.affFunc = affFunc;
             this.mapper = mapper;
             this.assignment = assignment;
-            this.portableEnabled = portableEnabled;
+            this.cacheObjCtx = cacheObjCtx;
         }
 
         /**
@@ -745,6 +753,9 @@ public class GridAffinityProcessor extends GridProcessorAdapter {
             ctx.gateway().readLock();
 
             try {
+                if (key instanceof CacheObject)
+                    key = ((CacheObject)key).value(cache().cacheObjCtx, false);
+
                 return cache().keyMapper().affinityKey(key);
             }
             catch (IgniteCheckedException e) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateContainsValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateContainsValue.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateContainsValue.java
index 412b685..0765930 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateContainsValue.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateContainsValue.java
@@ -55,7 +55,8 @@ public class CacheEntryPredicateContainsValue implements CacheEntryPredicate {
         try {
             CacheObject val = entry.rawGetOrUnmarshal(true);
 
-            return F.eq(this.val.value(entry.context(), false), CU.value(val, entry.context(), false));
+            return F.eq(this.val.value(entry.context().cacheObjectContext(), false),
+                CU.value(val, entry.context(), false));
         }
         catch (IgniteCheckedException e) {
             throw new IgniteException(e);
@@ -64,7 +65,7 @@ public class CacheEntryPredicateContainsValue implements CacheEntryPredicate {
 
     /** {@inheritDoc} */
     @Override public void finishUnmarshal(GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException {
-        val.finishUnmarshal(ctx, ldr);
+        val.finishUnmarshal(ctx.cacheObjectContext(), ldr);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictionEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictionEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictionEntry.java
index a5576f9..da3d975 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictionEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictionEntry.java
@@ -97,7 +97,7 @@ public class CacheEvictionEntry implements Message {
      * @throws IgniteCheckedException If failed.
      */
     public void finishUnmarshal(GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException {
-        key.finishUnmarshal(ctx, ldr);
+        key.finishUnmarshal(ctx.cacheObjectContext(), ldr);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeDirectResult.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeDirectResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeDirectResult.java
index 02a297f..3c5c5c7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeDirectResult.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeDirectResult.java
@@ -105,13 +105,13 @@ public class CacheInvokeDirectResult implements Message {
 
     /** {@inheritDoc} */
     public void finishUnmarshal(GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException {
-        key.finishUnmarshal(ctx, ldr);
+        key.finishUnmarshal(ctx.cacheObjectContext(), ldr);
 
         if (errBytes != null)
             err = ctx.marshaller().unmarshal(errBytes, ldr);
 
         if (res != null)
-            res.finishUnmarshal(ctx, ldr);
+            res.finishUnmarshal(ctx.cacheObjectContext(), ldr);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
index ba5a1fe..b231d89 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
@@ -30,7 +30,7 @@ public interface CacheObject extends Message {
      * @param cpy If {@code true} need to copy value.
      * @return Value.
      */
-    @Nullable public <T> T value(GridCacheContext ctx, boolean cpy);
+    @Nullable public <T> T value(CacheObjectContext ctx, boolean cpy);
 
     /**
      * @param name Field name.
@@ -54,19 +54,19 @@ public interface CacheObject extends Message {
      * @return Value bytes.
      * @throws IgniteCheckedException If failed.
      */
-    public byte[] valueBytes(GridCacheContext ctx) throws IgniteCheckedException;
+    public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException;
 
     /**
      * @param ctx Context.
      * @param ldr Class loader.
      * @throws IgniteCheckedException If failed.
      */
-    public void finishUnmarshal(GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException;
+    public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException;
 
     /**
      * @param ctx Cache context.
      *
      * @return Instance to store in cache.
      */
-    public CacheObject prepareForCache(GridCacheContext ctx);
+    public CacheObject prepareForCache(CacheObjectContext ctx);
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
index b8ca690..4d8572a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectAdapter.java
@@ -46,8 +46,8 @@ public abstract class CacheObjectAdapter implements CacheObject, Externalizable
      * @param ctx Context.
      * @return {@code True} need to copy value returned to user.
      */
-    protected boolean needCopy(GridCacheContext ctx) {
-        return ctx.config().isCopyOnGet() && val != null && !ctx.portable().immutable(val);
+    protected boolean needCopy(CacheObjectContext ctx) {
+        return ctx.copyOnGet() && val != null && !ctx.processor().immutable(val);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
index b2a79f2..a61be98 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.internal.processors.cache;
 
+import org.apache.ignite.cache.affinity.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.portable.*;
 
@@ -30,16 +31,55 @@ public class CacheObjectContext {
     /** */
     private GridPortableProcessor proc;
 
+    /** */
+    private CacheAffinityKeyMapper dfltAffMapper;
+
+    /** */
+    private boolean cpyOnGet;
+
+    /** */
+    private boolean unmarshalVals;
+
     /**
      * @param kernalCtx Kernal context.
+     * @param dfltAffMapper Default affinity mapper.
+     * @param cpyOnGet Copy on get flag.
+     * @param unmarshalVals Unmarshal values flag.
      */
-    public CacheObjectContext(GridKernalContext kernalCtx) {
+    public CacheObjectContext(GridKernalContext kernalCtx,
+        CacheAffinityKeyMapper dfltAffMapper,
+        boolean cpyOnGet,
+        boolean unmarshalVals) {
         this.kernalCtx = kernalCtx;
+        this.dfltAffMapper = dfltAffMapper;
+        this.cpyOnGet = cpyOnGet;
+        this.unmarshalVals = unmarshalVals;
 
         proc = kernalCtx.portable();
     }
 
     /**
+     * @return Copy on get flag.
+     */
+    public boolean copyOnGet() {
+        return cpyOnGet;
+    }
+
+    /**
+     * @return Unmarshal values flag.
+     */
+    public boolean unmarshalValues() {
+        return unmarshalVals;
+    }
+
+    /**
+     * @return Default affinity mapper.
+     */
+    public CacheAffinityKeyMapper defaultAffMapper() {
+        return dfltAffMapper;
+    }
+
+    /**
      * @return Kernal context.
      */
     public GridKernalContext kernalContext() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
index 87ff779..ebc5de7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectImpl.java
@@ -49,7 +49,7 @@ public class CacheObjectImpl extends CacheObjectAdapter {
 
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
-    @Nullable @Override public <T> T value(GridCacheContext ctx, boolean cpy) {
+    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
         cpy = cpy && needCopy(ctx);
 
         try {
@@ -59,7 +59,7 @@ public class CacheObjectImpl extends CacheObjectAdapter {
                 if (byteArray())
                     return (T)Arrays.copyOf(bytes, bytes.length);
                 else
-                    return (T)ctx.portable().unmarshal(ctx.cacheObjectContext(), valBytes, U.gridClassLoader());
+                    return (T)ctx.processor().unmarshal(ctx, valBytes, ctx.kernalContext().config().getClassLoader());
             }
 
             if (val != null)
@@ -67,7 +67,7 @@ public class CacheObjectImpl extends CacheObjectAdapter {
 
             assert valBytes != null;
 
-            val = ctx.portable().unmarshal(ctx.cacheObjectContext(), valBytes, U.gridClassLoader());
+            val = ctx.processor().unmarshal(ctx, valBytes, ctx.kernalContext().config().getClassLoader());
         }
         catch (IgniteCheckedException e) {
             throw new IgniteException("Failed to unmarshal object.", e);
@@ -82,12 +82,12 @@ public class CacheObjectImpl extends CacheObjectAdapter {
     }
 
     /** {@inheritDoc} */
-    @Override public byte[] valueBytes(GridCacheContext ctx) throws IgniteCheckedException {
+    @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
         if (byteArray())
             return (byte[])val;
 
         if (valBytes == null)
-            valBytes = ctx.portable().marshal(ctx.cacheObjectContext(), val);
+            valBytes = ctx.processor().marshal(ctx, val);
 
         return valBytes;
     }
@@ -101,11 +101,11 @@ public class CacheObjectImpl extends CacheObjectAdapter {
     }
 
     /** {@inheritDoc} */
-    @Override public void finishUnmarshal(GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
         assert val != null || valBytes != null;
 
-        if (val == null && ctx.isUnmarshalValues())
-            val = ctx.portable().unmarshal(ctx.cacheObjectContext(), valBytes, ldr);
+        if (val == null && ctx.unmarshalValues())
+            val = ctx.processor().unmarshal(ctx, valBytes, ldr);
     }
 
     /** {@inheritDoc} */
@@ -201,7 +201,7 @@ public class CacheObjectImpl extends CacheObjectAdapter {
     }
 
     /** {@inheritDoc} */
-    @Override public CacheObject prepareForCache(GridCacheContext ctx) {
+    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
         return this;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/EvictableEntryImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/EvictableEntryImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/EvictableEntryImpl.java
index 81abb7c..8f451a8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/EvictableEntryImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/EvictableEntryImpl.java
@@ -46,7 +46,7 @@ public class EvictableEntryImpl<K, V> implements EvictableEntry<K, V> {
 
     /** {@inheritDoc} */
     @Override public K getKey() throws IllegalStateException {
-        return cached.key().value(cached.context(), false);
+        return cached.key().value(cached.context().cacheObjectContext(), false);
     }
 
     /** {@inheritDoc} */
@@ -79,7 +79,7 @@ public class EvictableEntryImpl<K, V> implements EvictableEntry<K, V> {
         try {
             CacheObject val = cached.peek(GridCachePeekMode.GLOBAL);
 
-            return val != null ? val.<V>value(cached.context(), false) : null;
+            return val != null ? val.<V>value(cached.context().cacheObjectContext(), false) : null;
         }
         catch (GridCacheEntryRemovedException e) {
             return null;
@@ -96,13 +96,13 @@ public class EvictableEntryImpl<K, V> implements EvictableEntry<K, V> {
                 GridTuple<CacheObject> peek = tx.peek(cached.context(), false, cached.key(), null);
 
                 if (peek != null)
-                    return peek.get().value(cached.context(), false);
+                    return peek.get().value(cached.context().cacheObjectContext(), false);
             }
 
             if (cached.detached()) {
                 CacheObject val = cached.rawGet();
 
-                return val != null ? val.<V>value(cached.context(), false) : null;
+                return val != null ? val.<V>value(cached.context().cacheObjectContext(), false) : null;
             }
 
             for (;;) {
@@ -114,7 +114,7 @@ public class EvictableEntryImpl<K, V> implements EvictableEntry<K, V> {
                 try {
                     CacheObject val = e.peek(GridCachePeekMode.GLOBAL, CU.empty0());
 
-                    return val != null ? val.<V>value(cached.context(), false) : null;
+                    return val != null ? val.<V>value(cached.context().cacheObjectContext(), false) : null;
                 }
                 catch (GridCacheEntryRemovedException ignored) {
                     // No-op.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 98a5cb4..c897477 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -839,7 +839,7 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>,
             else
                 cacheVal = localCachePeek0(cacheKey, modes.heap, modes.offheap, modes.swap, plc);
 
-            Object val = cacheVal != null ? cacheVal.value(ctx, true) : null;
+            Object val = CU.value(cacheVal, ctx, true);
 
             if (ctx.portableEnabled())
                 val = ctx.unwrapPortableIfNeeded(val, ctx.keepPortable());
@@ -948,7 +948,7 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>,
                 if (peek != null) {
                     CacheObject v = peek.get();
 
-                    Object val0 = v.value(ctx, true);
+                    Object val0 = v.value(ctx.cacheObjectContext(), true);
 
                     if (ctx.portableEnabled())
                         val0 = ctx.unwrapPortableIfNeeded(v, ctx.keepPortable());
@@ -1038,7 +1038,7 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>,
                 }
 
                 if (val != null)
-                    return F.t((V)val.get().value(ctx, true));
+                    return F.t((V)val.get().value(ctx.cacheObjectContext(), true));
             }
         }
         catch (GridCacheEntryRemovedException ignore) {
@@ -1751,11 +1751,11 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>,
 
                                     if (map != null) {
                                         if (set || wasNew)
-                                            map.put(key.<K>value(ctx, false), (V)val);
+                                            map.put(key.<K>value(ctx.cacheObjectContext(), false), (V)val);
                                         else {
                                             try {
                                                 // TODO IGNITE-51.
-                                                K k = key.<K>value(ctx, false);
+                                                K k = key.<K>value(ctx.cacheObjectContext(), false);
 
                                                 GridTuple<V> v = peek0(false, k, GLOBAL);
 
@@ -4057,7 +4057,7 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>,
         long topVer,
         boolean replicate,
         long ttl) {
-        if (p != null && !p.apply(key.value(ctx, false), val))
+        if (p != null && !p.apply(key.value(ctx.cacheObjectContext(), false), val))
             return;
 
         CacheObject cacheVal = ctx.toCacheObject(val);
@@ -4487,7 +4487,7 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>,
 
         CacheObject val = unswapped.value();
 
-        Object val0 = val != null ? val.value(ctx, true) : null;
+        Object val0 = val != null ? val.value(ctx.cacheObjectContext(), true) : null;
 
         if (ctx.portableEnabled())
             return (V)ctx.unwrapPortableIfNeeded(val0, !deserializePortable);
@@ -5302,7 +5302,7 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>,
 
                 CacheObject val = entryEx(cacheKey).innerReload();
 
-                return (V)(val != null ? val.value(ctx, true) : null);
+                return (V)(val != null ? val.value(ctx.cacheObjectContext(), true) : null);
             }
             catch (GridCacheEntryRemovedException ignored) {
                 if (log.isDebugEnabled())
@@ -5535,8 +5535,8 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>,
 
             KeyCacheObject key = entry.key();
 
-            Object key0 = key.value(ctx, true);
-            Object val0 = val.value(ctx, true);
+            Object key0 = key.value(ctx.cacheObjectContext(), true);
+            Object val0 = val.value(ctx.cacheObjectContext(), true);
 
             if (deserializePortable && ctx.portableEnabled()) {
                 key0 = ctx.unwrapPortableIfNeeded(key0, true);
@@ -6287,7 +6287,7 @@ public abstract class GridCacheAdapter<K, V> implements GridCache<K, V>,
         {
             assert ver != null;
 
-            if (p != null && !p.apply(key.<K>value(ctx, false), (V)val))
+            if (p != null && !p.apply(key.<K>value(ctx.cacheObjectContext(), false), (V)val))
                 return;
 
             long ttl = 0;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
index d9dce4d..eb1124f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheConcurrentMap.java
@@ -2174,7 +2174,7 @@ public class GridCacheConcurrentMap {
 
         /** {@inheritDoc} */
         @Override public K next() {
-            return it.next().key().value(it.ctx, true);
+            return it.next().key().value(it.ctx.cacheObjectContext(), true);
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
index be22b85..0827ef7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
@@ -156,9 +156,6 @@ public class GridCacheContext<K, V> implements Externalizable {
     /** Cached local rich node. */
     private ClusterNode locNode;
 
-    /** Default cache affinity mapper. */
-    private CacheAffinityKeyMapper affMapper;
-
     /**
      * Thread local projection. If it's set it means that method call was initiated
      * by child projection of initial cache.
@@ -292,8 +289,6 @@ public class GridCacheContext<K, V> implements Externalizable {
 
         cacheName = cacheCfg.getName();
 
-        cacheObjCtx = ctx.portable().contextForCache(null, cacheName);
-
         if (cacheName != null) {
             int hash = cacheName.hashCode();
 
@@ -1003,14 +998,16 @@ public class GridCacheContext<K, V> implements Externalizable {
      * @return Default affinity key mapper.
      */
     public CacheAffinityKeyMapper defaultAffMapper() {
-        return affMapper;
+        return cacheObjCtx.defaultAffMapper();
     }
 
     /**
-     * Sets default affinity key mapper.
+     * Sets cache object context.
+     *
+     * @param cacheObjCtx Cache object context.
      */
-    public void defaultAffMapper(CacheAffinityKeyMapper dfltAffMapper) {
-        this.affMapper = dfltAffMapper;
+    public void cacheObjectContext(CacheObjectContext cacheObjCtx) {
+        this.cacheObjCtx = cacheObjCtx;
     }
 
     /**
@@ -1421,13 +1418,6 @@ public class GridCacheContext<K, V> implements Externalizable {
     }
 
     /**
-     * @return {@code True} if values should be always unmarshalled.
-     */
-    public boolean isUnmarshalValues() {
-        return cacheCfg.isQueryIndexEnabled();
-    }
-
-    /**
      * @return {@code True} if deployment enabled.
      */
     public boolean deploymentEnabled() {
@@ -1871,8 +1861,8 @@ public class GridCacheContext<K, V> implements Externalizable {
         assert val != null;
 
         if (!keepCacheObjects) {
-            Object key0 = key.value(this, false);
-            Object val0 = skipVals ? true : val.value(this, cpy);
+            Object key0 = key.value(cacheObjCtx, false);
+            Object val0 = skipVals ? true : val.value(cacheObjCtx, cpy);
 
             if (portableEnabled() && deserializePortable) {
                 key0 = unwrapPortableIfNeeded(key0, false);
@@ -1899,7 +1889,7 @@ public class GridCacheContext<K, V> implements Externalizable {
         evictMgr = null;
         qryMgr = null;
         dataStructuresMgr = null;
-        affMapper = null;
+        cacheObjCtx = null;
 
         mgrs.clear();
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDefaultAffinityKeyMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDefaultAffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDefaultAffinityKeyMapper.java
index 2b6bfc9..f52bf46 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDefaultAffinityKeyMapper.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDefaultAffinityKeyMapper.java
@@ -46,7 +46,7 @@ public class GridCacheDefaultAffinityKeyMapper implements CacheAffinityKeyMapper
 
     /** Injected ignite instance. */
     @IgniteInstanceResource
-    private Ignite ignite;
+    protected Ignite ignite;
 
     /** Reflection cache. */
     private GridReflectionCache reflectCache = new GridReflectionCache(
@@ -76,7 +76,7 @@ public class GridCacheDefaultAffinityKeyMapper implements CacheAffinityKeyMapper
 
     /** Logger. */
     @LoggerResource
-    private transient IgniteLogger log;
+    protected transient IgniteLogger log;
 
     /**
      * If key class has annotation {@link CacheAffinityKeyMapped},
@@ -89,32 +89,26 @@ public class GridCacheDefaultAffinityKeyMapper implements CacheAffinityKeyMapper
     @Override public Object affinityKey(Object key) {
         GridArgumentCheck.notNull(key, "key");
 
-        IgniteKernal kernal = (IgniteKernal)ignite;
+        try {
+            Object o = reflectCache.firstFieldValue(key);
 
-        if (kernal.context().portable().isPortableObject(key))
-            return kernal.context().portable().affinityKey(key);
-        else {
-            try {
-                Object o = reflectCache.firstFieldValue(key);
-
-                if (o != null)
-                    return o;
-            }
-            catch (IgniteCheckedException e) {
-                U.error(log, "Failed to access affinity field for key [field=" +
-                    reflectCache.firstField(key.getClass()) + ", key=" + key + ']', e);
-            }
+            if (o != null)
+                return o;
+        }
+        catch (IgniteCheckedException e) {
+            U.error(log, "Failed to access affinity field for key [field=" +
+                reflectCache.firstField(key.getClass()) + ", key=" + key + ']', e);
+        }
 
-            try {
-                Object o = reflectCache.firstMethodValue(key);
+        try {
+            Object o = reflectCache.firstMethodValue(key);
 
-                if (o != null)
-                    return o;
-            }
-            catch (IgniteCheckedException e) {
-                U.error(log, "Failed to invoke affinity method for key [mtd=" +
-                    reflectCache.firstMethod(key.getClass()) + ", key=" + key + ']', e);
-            }
+            if (o != null)
+                return o;
+        }
+        catch (IgniteCheckedException e) {
+            U.error(log, "Failed to invoke affinity method for key [mtd=" +
+                reflectCache.firstMethod(key.getClass()) + ", key=" + key + ']', e);
         }
 
         return key;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java
index b365b45..8485f28 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java
@@ -316,7 +316,7 @@ public class GridCacheDeploymentManager<K, V> extends GridCacheSharedManagerAdap
 
         assert key != null : "Key cannot be null for cache entry: " + e;
 
-        Object key0 = key.value(cache.context(), false);
+        Object key0 = key.value(cache.context().cacheObjectContext(), false);
         Object val0 = CU.value(v, cache.context(), false);
 
         ClassLoader keyLdr = U.detectObjectClassLoader(key0);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java
index 0179ad0..9b08714 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java
@@ -351,10 +351,10 @@ public class GridCacheEntryInfo implements Externalizable, Message {
      * @throws IgniteCheckedException If unmarshalling failed.
      */
     public void unmarshal(GridCacheContext ctx, ClassLoader clsLdr) throws IgniteCheckedException {
-        key.finishUnmarshal(ctx, clsLdr);
+        key.finishUnmarshal(ctx.cacheObjectContext(), clsLdr);
 
         if (val != null)
-            val.finishUnmarshal(ctx, clsLdr);
+            val.finishUnmarshal(ctx.cacheObjectContext(), clsLdr);
 // TODO IGNITE-51
 //        Marshaller mrsh = ctx.marshaller();
 //

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
index d87a224..90ae04b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEventManager.java
@@ -244,12 +244,12 @@ public class GridCacheEventManager extends GridCacheManagerAdapter {
                 type,
                 part,
                 cctx.isNear(),
-                key.value(cctx, false),
+                key.value(cctx.cacheObjectContext(), false),
                 xid,
                 lockId,
-                newVal != null ? newVal.value(cctx, false) : null,
+                CU.value(newVal, cctx, false),
                 hasNewVal,
-                oldVal != null ? oldVal.value(cctx, false) : null,
+                CU.value(oldVal, cctx, false),
                 hasOldVal,
                 subjId,
                 cloClsName,

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionRequest.java
index 661bb06..c892148 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionRequest.java
@@ -88,7 +88,7 @@ public class GridCacheEvictionRequest extends GridCacheMessage implements GridCa
                 e.prepareMarshal(cctx);
 
                 if (depEnabled)
-                    prepareObject(e.key().value(cctx, false), ctx);
+                    prepareObject(e.key().value(cctx.cacheObjectContext(), false), ctx);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
index b2a2e04..0c492d9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java
@@ -186,7 +186,8 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
         assert Thread.holdsLock(this);
 
         // In case we deal with IGFS cache, count updated data
-        if (cctx.cache().isIgfsDataCache() && cctx.kernalContext().igfsHelper().isIgfsBlockKey(key.value(cctx, false))) {
+        if (cctx.cache().isIgfsDataCache() &&
+            cctx.kernalContext().igfsHelper().isIgfsBlockKey(key.value(cctx.cacheObjectContext(), false))) {
             int newSize = valueLength0(val, null);
             int oldSize = valueLength0(this.val, (this.val == null && valPtr != 0) ? valueBytes0() : null);
 
@@ -207,7 +208,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
                     Object val0 = null;
 
                     if (val != null) {
-                        val0 = val.value(cctx, false);
+                        val0 = val.value(cctx.cacheObjectContext(), false);
 
                         if (val0 != null)
                             cctx.gridDeploy().deploy(val0.getClass(), val0.getClass().getClassLoader());
@@ -226,7 +227,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
                 if (val != null) {
                     boolean valIsByteArr = val.byteArray();
 
-                    valPtr = mem.putOffHeap(valPtr, val.valueBytes(cctx), valIsByteArr);
+                    valPtr = mem.putOffHeap(valPtr, val.valueBytes(cctx.cacheObjectContext()), valIsByteArr);
                 }
                 else {
                     mem.removeOffHeap(valPtr);
@@ -263,7 +264,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
      * @return Length of value.
      */
     private int valueLength0(@Nullable CacheObject val, @Nullable IgniteBiTuple<byte[], Boolean> valBytes) {
-        byte[] bytes = val != null ? (byte[])val.value(cctx, false) : null;
+        byte[] bytes = val != null ? (byte[])val.value(cctx.cacheObjectContext(), false) : null;
 
         return bytes != null ? bytes.length :
             (valBytes == null) ? 0 : valBytes.get1().length - (valBytes.get2() ? 0 : 6);
@@ -551,8 +552,10 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
 
             IgniteUuid valClsLdrId = null;
 
-            if (val != null)
-                valClsLdrId = cctx.deploy().getClassLoaderId(val.value(cctx, false).getClass().getClassLoader());
+            if (val != null) {
+                valClsLdrId = cctx.deploy().getClassLoaderId(
+                    val.value(cctx.cacheObjectContext(), false).getClass().getClassLoader());
+            }
 
             IgniteBiTuple<byte[], Boolean> valBytes = valueBytes0();
 
@@ -562,7 +565,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
                 ver,
                 ttlExtras(),
                 expireTime,
-                cctx.deploy().getClassLoaderId(U.detectObjectClassLoader(key.value(cctx, false))),
+                cctx.deploy().getClassLoaderId(U.detectObjectClassLoader(key.value(cctx.cacheObjectContext(), false))),
                 valClsLdrId);
 
             if (log.isDebugEnabled())
@@ -585,7 +588,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
             assert val != null;
 
             try {
-                byte[] bytes = val.valueBytes(cctx);
+                byte[] bytes = val.valueBytes(cctx.cacheObjectContext());
 
                 boolean plain = val.byteArray();
 
@@ -1030,7 +1033,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
             old = (retval || intercept) ? rawGetOrUnmarshalUnlocked(!retval) : this.val;
 
             if (intercept) {
-                key0 = key.value(cctx, false);
+                key0 = key.value(cctx.cacheObjectContext(), false);
                 val0 = CU.value(val, cctx, false);
 
                 Object interceptorVal = cctx.config().getInterceptor().onBeforePut(key0,
@@ -1181,7 +1184,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
             old = (retval || intercept) ? rawGetOrUnmarshalUnlocked(!retval) : val;
 
             if (intercept) {
-                key0 = key.value(cctx, false);
+                key0 = key.value(cctx.cacheObjectContext(), false);
                 old0 = CU.value(old, cctx, false);
 
                 interceptRes = cctx.config().getInterceptor().onBeforeRemove(key0, old0);
@@ -1422,7 +1425,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
 
                 assert entryProcessor != null;
 
-                key0 = key.value(cctx, false);
+                key0 = key.value(cctx.cacheObjectContext(), false);
                 old0 = value(old0, old, false);
 
                 CacheInvokeEntry<Object, Object> entry = new CacheInvokeEntry<>(cctx, key0, old0);
@@ -1876,7 +1879,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
 
                 EntryProcessor<Object, Object, ?> entryProcessor = (EntryProcessor<Object, Object, ?>)writeObj;
 
-                key0 = key.value(cctx, false);
+                key0 = key.value(cctx.cacheObjectContext(), false);
                 old0 = value(old0, oldVal, false);
 
                 CacheInvokeEntry<Object, Object> entry = new CacheInvokeEntry<>(cctx, key0, old0);
@@ -2214,7 +2217,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
         if (val != null)
             return val;
 
-        return cacheObj != null ? cacheObj.value(cctx, cpy) : null;
+        return cacheObj != null ? cacheObj.value(cctx.cacheObjectContext(), cpy) : null;
     }
 
     /**
@@ -3720,9 +3723,14 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
         try {
             GridCacheQueryManager qryMgr = cctx.queries();
 
-            // TODO IGNITE-51.
-            if (qryMgr != null)
-                qryMgr.store(key.value(cctx, false), null, CU.value(val, cctx, false), null, ver, expireTime);
+            if (qryMgr != null) {
+                qryMgr.store(key.value(cctx.cacheObjectContext(), false),
+                    null,
+                    CU.value(val, cctx, false),
+                    null,
+                    ver,
+                    expireTime);
+            }
         }
         catch (IgniteCheckedException e) {
             throw new GridCacheIndexUpdateException(e);
@@ -3741,9 +3749,8 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
         try {
             GridCacheQueryManager<?, ?> qryMgr = cctx.queries();
 
-            // TODO IGNITE-51.
             if (qryMgr != null)
-                qryMgr.remove(key().value(cctx, false));
+                qryMgr.remove(key().value(cctx.cacheObjectContext(), false));
         }
         catch (IgniteCheckedException e) {
             throw new GridCacheIndexUpdateException(e);
@@ -3782,7 +3789,8 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
             else
                 val = rawGetOrUnmarshal(false);
 
-            return new CacheEntryImpl<>(key.<K>value(cctx, false), val != null ? val.<V>value(cctx, false) : null);
+            return new CacheEntryImpl<>(key.<K>value(cctx.cacheObjectContext(), false),
+                CU.<V>value(val, cctx, false));
         }
         catch (GridCacheFilterFailedException ignored) {
             throw new IgniteException("Should never happen.");
@@ -3801,7 +3809,8 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
     @Override public <K, V> Cache.Entry<K, V> wrapFilterLocked() throws IgniteCheckedException {
         CacheObject val = rawGetOrUnmarshal(true);
 
-        return new CacheEntryImpl<>(key.<K>value(cctx, false), val != null ? val.<V>value(cctx, false) : null) ;
+        return new CacheEntryImpl<>(key.<K>value(cctx.cacheObjectContext(), false),
+            CU.<V>value(val, cctx, false));
     }
 
     /** {@inheritDoc} */
@@ -3811,7 +3820,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
 
     /** {@inheritDoc} */
     @Override public synchronized <K, V> CacheVersionedEntryImpl<K, V> wrapVersioned() {
-        return new CacheVersionedEntryImpl<>(key.<K>value(cctx, false), null, ver);
+        return new CacheVersionedEntryImpl<>(key.<K>value(cctx.cacheObjectContext(), false), null, ver);
     }
 
     /** {@inheritDoc} */
@@ -3923,7 +3932,8 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
                     IgniteUuid valClsLdrId = null;
 
                     if (val != null)
-                        valClsLdrId = cctx.deploy().getClassLoaderId(U.detectObjectClassLoader(val.value(cctx, false)));
+                        valClsLdrId = cctx.deploy().getClassLoaderId(
+                            U.detectObjectClassLoader(val.value(cctx.cacheObjectContext(), false)));
 
                     IgniteBiTuple<byte[], Boolean> valBytes = valueBytes0();
 
@@ -3934,7 +3944,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
                         ver,
                         ttlExtras(),
                         expireTimeExtras(),
-                        cctx.deploy().getClassLoaderId(U.detectObjectClassLoader(key.value(cctx, false))),
+                        cctx.deploy().getClassLoaderId(U.detectObjectClassLoader(key.value(cctx.cacheObjectContext(), false))),
                         valClsLdrId);
                 }
 
@@ -4339,7 +4349,7 @@ public abstract class GridCacheMapEntry implements GridCacheEntryEx {
 
         /** {@inheritDoc} */
         @Override public K getKey() {
-            return key.value(cctx, false);
+            return key.value(cctx.cacheObjectContext(), false);
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
index ec9ca1a..b67ccc6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
@@ -254,7 +254,7 @@ public abstract class GridCacheMessage implements Message {
             info.marshal(ctx);
 
             if (ctx.deploymentEnabled()) {
-                prepareObject(info.key().value(ctx, false), ctx.shared());
+                prepareObject(info.key().value(ctx.cacheObjectContext(), false), ctx.shared());
                 prepareObject(CU.value(info.value(), ctx, false), ctx.shared());
             }
         }
@@ -457,7 +457,7 @@ public abstract class GridCacheMessage implements Message {
                 obj.prepareMarshal(ctx.cacheObjectContext());
 
                 if (depEnabled)
-                    prepareObject(obj.value(ctx, false), ctx.shared());
+                    prepareObject(obj.value(ctx.cacheObjectContext(), false), ctx.shared());
             }
         }
     }
@@ -479,7 +479,7 @@ public abstract class GridCacheMessage implements Message {
                 obj.prepareMarshal(ctx.cacheObjectContext());
 
                 if (depEnabled)
-                    prepareObject(obj.value(ctx, false), ctx.shared());
+                    prepareObject(obj.value(ctx.cacheObjectContext(), false), ctx.shared());
             }
         }
     }
@@ -505,7 +505,7 @@ public abstract class GridCacheMessage implements Message {
             CacheObject obj = col.get(i);
 
             if (obj != null)
-                obj.finishUnmarshal(ctx, ldr);
+                obj.finishUnmarshal(ctx.cacheObjectContext(), ldr);
         }
     }
 
@@ -525,7 +525,7 @@ public abstract class GridCacheMessage implements Message {
 
         for (CacheObject obj : col) {
             if (obj != null)
-                obj.finishUnmarshal(ctx, ldr);
+                obj.finishUnmarshal(ctx.cacheObjectContext(), ldr);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index d88f83b..122281c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -122,7 +122,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
      * @throws IgniteCheckedException If configuration is not valid.
      */
     @SuppressWarnings("unchecked")
-    private void initialize(CacheConfiguration cfg) throws IgniteCheckedException {
+    private void initialize(CacheConfiguration cfg, CacheObjectContext cacheObjCtx) throws IgniteCheckedException {
         if (cfg.getCacheMode() == null)
             cfg.setCacheMode(DFLT_CACHE_MODE);
 
@@ -164,7 +164,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
             cfg.setBackups(Integer.MAX_VALUE);
 
         if (cfg.getAffinityMapper() == null)
-            cfg.setAffinityMapper(new GridCacheDefaultAffinityKeyMapper());
+            cfg.setAffinityMapper(cacheObjCtx.defaultAffMapper());
 
         ctx.igfsHelper().preProcessCacheConfiguration(cfg);
 
@@ -580,8 +580,10 @@ public class GridCacheProcessor extends GridProcessorAdapter {
         for (int i = 0; i < cfgs.length; i++) {
             CacheConfiguration<?, ?> cfg = new CacheConfiguration(cfgs[i]);
 
+            CacheObjectContext cacheObjCtx = ctx.portable().contextForCache(null, cfg.getName());
+
             // Initialize defaults.
-            initialize(cfg);
+            initialize(cfg, cacheObjCtx);
 
             CacheStore cfgStore = cfg.getCacheStoreFactory() != null ? cfg.getCacheStoreFactory().create() : null;
 
@@ -599,6 +601,10 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
             toPrepare.add(jta.tmLookup());
             toPrepare.add(cfgStore);
+            toPrepare.add(cfg.getAffinityMapper());
+
+            if (cfg.getAffinityMapper() != cacheObjCtx.defaultAffMapper())
+                toPrepare.add(cacheObjCtx.defaultAffMapper());
 
             if (cfgStore instanceof GridCacheLoaderWriterStore) {
                 toPrepare.add(((GridCacheLoaderWriterStore)cfgStore).loader());
@@ -609,17 +615,6 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
             U.startLifecycleAware(lifecycleAwares(cfg, jta.tmLookup(), cfgStore));
 
-            // Init default key mapper.
-            CacheAffinityKeyMapper dfltAffMapper;
-
-            if (cfg.getAffinityMapper().getClass().equals(GridCacheDefaultAffinityKeyMapper.class))
-                dfltAffMapper = cfg.getAffinityMapper();
-            else {
-                dfltAffMapper = new GridCacheDefaultAffinityKeyMapper();
-
-                prepare(cfg, dfltAffMapper, false);
-            }
-
             cfgs[i] = cfg; // Replace original configuration value.
 
             GridCacheAffinityManager affMgr = new GridCacheAffinityManager();
@@ -657,7 +652,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                 drMgr,
                 jta);
 
-            cacheCtx.defaultAffMapper(dfltAffMapper);
+            cacheCtx.cacheObjectContext(cacheObjCtx);
 
             GridCacheAdapter cache = null;
 
@@ -797,7 +792,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                     drMgr,
                     jta);
 
-                cacheCtx.defaultAffMapper(dfltAffMapper);
+                cacheCtx.cacheObjectContext(cacheObjCtx);
 
                 GridDhtCacheAdapter dht = null;
 
@@ -1492,7 +1487,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                 try {
                     KeyCacheObject key = cctx.toCacheKeyObject(null, keyBytes, false);
 
-                    qryMgr.remove(key.value(cctx, false));
+                    qryMgr.remove(key.value(cctx.cacheObjectContext(), false));
                 }
                 catch (IgniteCheckedException e) {
                     U.error(log, "Failed to unmarshal key evicted from swap [swapSpaceName=" + spaceName + ']', e);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManager.java
index 0933c48..a6dd765 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheStoreManager.java
@@ -266,7 +266,7 @@ public class GridCacheStoreManager extends GridCacheManagerAdapter {
                 // Never load internal keys from store as they are never persisted.
                 return null;
 
-            Object storeKey = key.value(cctx, false);
+            Object storeKey = key.value(cctx.cacheObjectContext(), false);
 
             if (convertPortable)
                 storeKey = cctx.unwrapPortableIfNeeded(storeKey, false);
@@ -411,14 +411,14 @@ public class GridCacheStoreManager extends GridCacheManagerAdapter {
             if (convertPortable) {
                 keys0 = F.viewReadOnly(keys, new C1<KeyCacheObject, Object>() {
                     @Override public Object apply(KeyCacheObject key) {
-                        return cctx.unwrapPortableIfNeeded(key.value(cctx, false), false);
+                        return cctx.unwrapPortableIfNeeded(key.value(cctx.cacheObjectContext(), false), false);
                     }
                 });
             }
             else {
                 keys0 = F.viewReadOnly(keys, new C1<KeyCacheObject, Object>() {
                     @Override public Object apply(KeyCacheObject key) {
-                        return key.value(cctx, false);
+                        return key.value(cctx.cacheObjectContext(), false);
                     }
                 });
             }
@@ -561,8 +561,8 @@ public class GridCacheStoreManager extends GridCacheManagerAdapter {
             if (key.internal())
                 return true;
 
-            Object storeKey = key.value(cctx, false);
-            Object storeVal = val.value(cctx, false);
+            Object storeKey = key.value(cctx.cacheObjectContext(), false);
+            Object storeVal = val.value(cctx.cacheObjectContext(), false);
 
             if (convertPortable) {
                 storeKey = cctx.unwrapPortableIfNeeded(storeKey, false);
@@ -677,7 +677,7 @@ public class GridCacheStoreManager extends GridCacheManagerAdapter {
             if (key.internal())
                 return false;
 
-            Object storeKey = key.value(cctx, false);
+            Object storeKey = key.value(cctx.cacheObjectContext(), false);
 
             if (convertPortable)
                 storeKey = cctx.unwrapPortableIfNeeded(storeKey, false);
@@ -737,14 +737,14 @@ public class GridCacheStoreManager extends GridCacheManagerAdapter {
             if (convertPortable) {
                 keys0 = F.viewReadOnly(keys, new C1<KeyCacheObject, Object>() {
                     @Override public Object apply(KeyCacheObject key) {
-                        return cctx.unwrapPortableIfNeeded(key.value(cctx, false), false);
+                        return cctx.unwrapPortableIfNeeded(key.value(cctx.cacheObjectContext(), false), false);
                     }
                 });
             }
             else {
                 keys0 = F.viewReadOnly(keys, new C1<KeyCacheObject, Object>() {
                     @Override public Object apply(KeyCacheObject key) {
-                        return key.value(cctx, false);
+                        return key.value(cctx.cacheObjectContext(), false);
                     }
                 });
             }
@@ -1053,8 +1053,8 @@ public class GridCacheStoreManager extends GridCacheManagerAdapter {
                         if (rmvd != null && rmvd.contains(k))
                             continue;
 
-                        Object storeKey = e.getKey().value(cctx, false);
-                        Object storeVal = e.getValue().get1().value(cctx, false);
+                        Object storeKey = e.getKey().value(cctx.cacheObjectContext(), false);
+                        Object storeVal = CU.value(e.getValue().get1(), cctx, false);
 
                         if (convertPortable) {
                             storeKey = cctx.unwrapPortableIfNeeded(storeKey, false);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
index 6d1ae6f..36d33ee 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
@@ -458,14 +458,14 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
         // First check off-heap store.
         if (offheapEnabled)
-            if (offheap.contains(spaceName, part, key, key.valueBytes(cctx)))
+            if (offheap.contains(spaceName, part, key, key.valueBytes(cctx.cacheObjectContext())))
                 return true;
 
         if (swapEnabled) {
             assert key != null;
 
             byte[] valBytes = swapMgr.read(spaceName,
-                new SwapKey(key.value(cctx, false), part, key.valueBytes(cctx)),
+                new SwapKey(key.value(cctx.cacheObjectContext(), false), part, key.valueBytes(cctx.cacheObjectContext())),
                 cctx.deploy().globalLoader());
 
             return valBytes != null;
@@ -523,7 +523,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
             assert key != null;
 
             byte[] bytes = swapMgr.read(spaceName,
-                new SwapKey(key.value(cctx, false), part, keyBytes),
+                new SwapKey(key.value(cctx.cacheObjectContext(), false), part, keyBytes),
                 cctx.deploy().globalLoader());
 
             if (bytes == null && lsnr != null)
@@ -554,7 +554,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
         // First try removing from offheap.
         if (offheapEnabled) {
-            byte[] entryBytes = offheap.remove(spaceName, part, key, key.valueBytes(cctx));
+            byte[] entryBytes = offheap.remove(spaceName, part, key, key.valueBytes(cctx.cacheObjectContext()));
 
             if (entryBytes != null) {
                 GridCacheSwapEntry entry = swapEntry(unmarshalSwapEntry(entryBytes));
@@ -608,7 +608,11 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
         final GridTuple<GridCacheSwapEntry> t = F.t1();
         final GridTuple<IgniteCheckedException> err = F.t1();
 
-        swapMgr.remove(spaceName, new SwapKey(key.value(cctx, false), part, key.valueBytes(cctx)), new CI1<byte[]>() {
+        SwapKey swapKey = new SwapKey(key.value(cctx.cacheObjectContext(), false),
+            part,
+            key.valueBytes(cctx.cacheObjectContext()));
+
+        swapMgr.remove(spaceName, swapKey, new CI1<byte[]>() {
             @Override public void apply(byte[] rmv) {
                 if (rmv != null) {
                     try {
@@ -678,7 +682,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
             return null;
 
         return read(entry.key(),
-            entry.key().valueBytes(cctx),
+            entry.key().valueBytes(cctx.cacheObjectContext()),
             entry.partition(),
             locked,
             readOffheap,
@@ -698,7 +702,8 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
         int part = cctx.affinity().partition(key);
 
-        IgniteBiTuple<Long, Integer> ptr = offheap.valuePointer(spaceName, part, key, key.valueBytes(cctx));
+        IgniteBiTuple<Long, Integer> ptr =
+            offheap.valuePointer(spaceName, part, key, key.valueBytes(cctx.cacheObjectContext()));
 
         if (ptr != null) {
             assert ptr.get1() != null;
@@ -727,7 +732,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
         int part = cctx.affinity().partition(key);
 
-        return read(key, key.valueBytes(cctx), part, false, readOffheap, readSwap);
+        return read(key, key.valueBytes(cctx.cacheObjectContext()), part, false, readOffheap, readSwap);
     }
 
     /**
@@ -764,7 +769,8 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
             for (KeyCacheObject key : keys) {
                 int part = cctx.affinity().partition(key);
 
-                byte[] entryBytes = offheap.remove(spaceName, part, key, key.valueBytes(cctx));
+                byte[] entryBytes =
+                    offheap.remove(spaceName, part, key, key.valueBytes(cctx.cacheObjectContext()));
 
                 if (entryBytes != null) {
                     GridCacheSwapEntry entry = swapEntry(unmarshalSwapEntry(entryBytes));
@@ -801,9 +807,9 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
                     if (unprocessedKeys == null)
                         unprocessedKeys = new ArrayList<>(keys.size());
 
-                    SwapKey swapKey = new SwapKey(key.value(cctx, false),
+                    SwapKey swapKey = new SwapKey(key.value(cctx.cacheObjectContext(), false),
                         cctx.affinity().partition(key),
-                        key.valueBytes(cctx));
+                        key.valueBytes(cctx.cacheObjectContext()));
 
                     unprocessedKeys.add(swapKey);
                 }
@@ -816,9 +822,9 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
             unprocessedKeys = new ArrayList<>(keys.size());
 
             for (KeyCacheObject key : keys) {
-                SwapKey swapKey = new SwapKey(key.value(cctx, false),
+                SwapKey swapKey = new SwapKey(key.value(cctx.cacheObjectContext(), false),
                     cctx.affinity().partition(key),
-                    key.valueBytes(cctx));
+                    key.valueBytes(cctx.cacheObjectContext()));
 
                 unprocessedKeys.add(swapKey);
             }
@@ -906,7 +912,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
         int part = cctx.affinity().partition(key);
 
-        return offheap.removex(spaceName, part, key, key.valueBytes(cctx));
+        return offheap.removex(spaceName, part, key, key.valueBytes(cctx.cacheObjectContext()));
     }
 
     /**
@@ -930,7 +936,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
         int part = cctx.affinity().partition(key);
 
-        offheap.enableEviction(spaceName, part, key, key.valueBytes(cctx));
+        offheap.enableEviction(spaceName, part, key, key.valueBytes(cctx.cacheObjectContext()));
     }
 
     /**
@@ -968,7 +974,10 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
         // First try offheap.
         if (offheapEnabled) {
-            byte[] val = offheap.remove(spaceName, part, key.value(cctx, false), key.valueBytes(cctx));
+            byte[] val = offheap.remove(spaceName,
+                part,
+                key.value(cctx.cacheObjectContext(), false),
+                key.valueBytes(cctx.cacheObjectContext()));
 
             if (val != null) {
                 if (c != null)
@@ -979,8 +988,12 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
         }
 
         if (swapEnabled) {
+            SwapKey swapKey = new SwapKey(key.value(cctx.cacheObjectContext(), false),
+                part,
+                key.valueBytes(cctx.cacheObjectContext()));
+
             swapMgr.remove(spaceName,
-                new SwapKey(key.value(cctx, false), part, key.valueBytes(cctx)),
+                swapKey,
                 c,
                 cctx.deploy().globalLoader());
         }
@@ -1024,7 +1037,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
             valClsLdrId);
 
         if (offheapEnabled) {
-            offheap.put(spaceName, part, key, key.valueBytes(cctx), entry.marshal());
+            offheap.put(spaceName, part, key, key.valueBytes(cctx.cacheObjectContext()), entry.marshal());
 
             if (cctx.events().isRecordable(EVT_CACHE_OBJECT_TO_OFFHEAP))
                 cctx.events().addEvent(part, key, cctx.nodeId(), (IgniteUuid)null, null,
@@ -1057,7 +1070,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
                 offheap.put(spaceName,
                     swapEntry.partition(),
                     swapEntry.key(),
-                    swapEntry.key().valueBytes(cctx),
+                    swapEntry.key().valueBytes(cctx.cacheObjectContext()),
                     swapEntry.marshal());
 
                 if (cctx.events().isRecordable(EVT_CACHE_OBJECT_TO_OFFHEAP))
@@ -1072,9 +1085,9 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
             Map<SwapKey, byte[]> batch = new LinkedHashMap<>();
 
             for (GridCacheBatchSwapEntry entry : swapped) {
-                SwapKey swapKey = new SwapKey(entry.key().value(cctx, false),
+                SwapKey swapKey = new SwapKey(entry.key().value(cctx.cacheObjectContext(), false),
                     entry.partition(),
-                    entry.key().valueBytes(cctx));
+                    entry.key().valueBytes(cctx.cacheObjectContext()));
 
                 batch.put(swapKey, entry.marshal());
             }
@@ -1109,7 +1122,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
         checkIteratorQueue();
 
         swapMgr.write(spaceName,
-            new SwapKey(key.value(cctx, false), part, key.valueBytes(cctx)),
+            new SwapKey(key.value(cctx.cacheObjectContext(), false), part, key.valueBytes(cctx.cacheObjectContext())),
             entry,
             cctx.deploy().globalLoader());
 
@@ -1295,7 +1308,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
                     int part = cctx.affinity().partition(key);
 
-                    offheap.removex(spaceName, part, key, key.valueBytes(cctx));
+                    offheap.removex(spaceName, part, key, key.valueBytes(cctx.cacheObjectContext()));
                 }
                 else
                     it.removeX();
@@ -1421,7 +1434,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
                         try {
                             KeyCacheObject key = cctx.toCacheKeyObject(null, cur0.getKey(), false);
 
-                            return key.value(cctx, false);
+                            return key.value(cctx.cacheObjectContext(), false);
                         }
                         catch (IgniteCheckedException e) {
                             throw new IgniteException(e);
@@ -1434,7 +1447,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
                             swapEntry(e);
 
-                            return e.value().value(cctx, false);
+                            return e.value().value(cctx.cacheObjectContext(), false);
                         }
                         catch (IgniteCheckedException ex) {
                             throw new IgniteException(ex);
@@ -1615,7 +1628,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
 
                 int part = cctx.affinity().partition(key);
 
-                offheap.removex(spaceName, part, key, key.valueBytes(cctx));
+                offheap.removex(spaceName, part, key, key.valueBytes(cctx.cacheObjectContext()));
             }
 
             @Override protected void onClose() throws IgniteCheckedException {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
index e4243ab..7700fa4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
@@ -906,7 +906,7 @@ public class GridCacheUtils {
 
                     return val != null &&
                         valType.isAssignableFrom(val.getClass()) &&
-                        keyType.isAssignableFrom(e.key().value(e.context(), false).getClass());
+                        keyType.isAssignableFrom(e.key().value(e.context().cacheObjectContext(), false).getClass());
                 }
                 catch (IgniteCheckedException err) {
                     throw new IgniteException(err);
@@ -1825,7 +1825,7 @@ public class GridCacheUtils {
     ) {
         return new CacheEntryPredicateAdapter() {
             @Override public boolean apply(GridCacheEntryEx e) {
-                return aff.isPrimary(n, e.key().value(e.context(), false));
+                return aff.isPrimary(n, e.key().value(e.context().cacheObjectContext(), false));
             }
         };
     }
@@ -1870,9 +1870,10 @@ public class GridCacheUtils {
     /**
      * @param cacheObj Cache object.
      * @param ctx Cache context.
+     * @param cpy Copy flag.
      * @return Cache object value.
      */
     @Nullable public static <T> T value(@Nullable CacheObject cacheObj, GridCacheContext ctx, boolean cpy) {
-        return cacheObj != null ? cacheObj.<T>value(ctx, cpy) : null;
+        return cacheObj != null ? cacheObj.<T>value(ctx.cacheObjectContext(), cpy) : null;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
index 981da1f..91958a3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectImpl.java
@@ -65,7 +65,7 @@ public class KeyCacheObjectImpl extends CacheObjectAdapter implements KeyCacheOb
     }
 
     /** {@inheritDoc} */
-    @Override public byte[] valueBytes(GridCacheContext ctx) throws IgniteCheckedException {
+    @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
         assert valBytes != null : this;
 
         return valBytes;
@@ -80,14 +80,14 @@ public class KeyCacheObjectImpl extends CacheObjectAdapter implements KeyCacheOb
 
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
-    @Nullable @Override public <T> T value(GridCacheContext ctx, boolean cpy) {
+    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
         cpy = cpy && needCopy(ctx);
 
         if (cpy) {
             try {
-                return (T)ctx.portable().unmarshal(ctx.cacheObjectContext(),
+                return (T)ctx.processor().unmarshal(ctx,
                     valBytes,
-                    ctx.deploy().globalLoader());
+                    ctx.kernalContext().config().getClassLoader());
             }
             catch (IgniteCheckedException e) {
                 throw new IgniteException("Failed to unmarshal object.", e);
@@ -98,7 +98,7 @@ public class KeyCacheObjectImpl extends CacheObjectAdapter implements KeyCacheOb
     }
 
     /** {@inheritDoc} */
-    @Override public CacheObject prepareForCache(GridCacheContext ctx) {
+    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
         return this;
     }
 
@@ -170,11 +170,11 @@ public class KeyCacheObjectImpl extends CacheObjectAdapter implements KeyCacheOb
     }
 
     /** {@inheritDoc} */
-    @Override public void finishUnmarshal(GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
         if (val == null) {
             assert valBytes != null;
 
-            val = ctx.kernalContext().portable().unmarshal(ctx.cacheObjectContext(), valBytes, ldr);
+            val = ctx.kernalContext().portable().unmarshal(ctx, valBytes, ldr);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectTransferImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectTransferImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectTransferImpl.java
index 267b957..b243e62 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectTransferImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/KeyCacheObjectTransferImpl.java
@@ -45,7 +45,7 @@ public class KeyCacheObjectTransferImpl implements KeyCacheObject {
     }
 
     /** {@inheritDoc} */
-    @Nullable @Override public <T> T value(GridCacheContext ctx, boolean cpy) {
+    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
         throw new IllegalStateException();
     }
 
@@ -65,17 +65,17 @@ public class KeyCacheObjectTransferImpl implements KeyCacheObject {
     }
 
     /** {@inheritDoc} */
-    @Override public byte[] valueBytes(GridCacheContext ctx) throws IgniteCheckedException {
+    @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
         throw new IllegalStateException();
     }
 
     /** {@inheritDoc} */
-    @Override public void finishUnmarshal(GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
         throw new IllegalStateException();
     }
 
     /** {@inheritDoc} */
-    @Override public CacheObject prepareForCache(GridCacheContext ctx) {
+    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
         throw new IllegalStateException();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/UserCacheObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/UserCacheObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/UserCacheObjectImpl.java
index 41d47db..4c38f18 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/UserCacheObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/UserCacheObjectImpl.java
@@ -41,7 +41,7 @@ public class UserCacheObjectImpl extends CacheObjectImpl {
     }
 
     /** {@inheritDoc} */
-    @Override public CacheObject prepareForCache(GridCacheContext ctx) {
+    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
         if (needCopy(ctx)) {
             if (val instanceof byte[]) {
                 byte[] byteArr = (byte[])val;
@@ -51,7 +51,7 @@ public class UserCacheObjectImpl extends CacheObjectImpl {
             else {
                 try {
                     if (valBytes == null)
-                        valBytes = ctx.portable().marshal(ctx.cacheObjectContext(), val);
+                        valBytes = ctx.processor().marshal(ctx, val);
 
                     return new CacheObjectImpl(null, valBytes);
                 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b876320e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/UserKeyCacheObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/UserKeyCacheObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/UserKeyCacheObjectImpl.java
index eb5d748..d052f94 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/UserKeyCacheObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/UserKeyCacheObjectImpl.java
@@ -40,23 +40,23 @@ public class UserKeyCacheObjectImpl extends KeyCacheObjectImpl {
     }
 
     /** {@inheritDoc} */
-    @Override public byte[] valueBytes(GridCacheContext ctx) throws IgniteCheckedException {
+    @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
         if (valBytes == null)
-            valBytes = ctx.portable().marshal(ctx.cacheObjectContext(), val);
+            valBytes = ctx.processor().marshal(ctx, val);
 
         return valBytes;
     }
 
     /** {@inheritDoc} */
-    @Override public CacheObject prepareForCache(GridCacheContext ctx) {
+    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
         try {
             if (valBytes == null)
-                valBytes = ctx.portable().marshal(ctx.cacheObjectContext(), val);
+                valBytes = ctx.processor().marshal(ctx, val);
 
             if (needCopy(ctx)) {
-                Object val = ctx.portable().unmarshal(ctx.cacheObjectContext(),
+                Object val = ctx.processor().unmarshal(ctx,
                     valBytes,
-                    ctx.deploy().globalLoader());
+                    ctx.kernalContext().config().getClassLoader());
 
                 return new KeyCacheObjectImpl(val, valBytes);
             }


Mime
View raw message