# 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/b7ea910f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/b7ea910f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/b7ea910f

Branch: refs/heads/ignite-51
Commit: b7ea910fe242177f7b30c663c652aebd8cdb0c26
Parents: add4ee4
Author: sboikov <sboi...@gridgain.com>
Authored: Fri Feb 20 13:38:34 2015 +0300
Committer: sboikov <sboi...@gridgain.com>
Committed: Fri Feb 20 19:03:58 2015 +0300

----------------------------------------------------------------------
 .../internal/processors/cache/CacheObject.java  |  37 ++
 .../processors/cache/EvictableEntryImpl.java    |  29 +-
 .../processors/cache/GridCacheAdapter.java      | 279 ++++++-----
 .../cache/GridCacheBatchSwapEntry.java          |   8 +-
 .../cache/GridCacheConcurrentMap.java           | 207 ++++----
 .../processors/cache/GridCacheContext.java      |  19 +-
 .../processors/cache/GridCacheEntryEx.java      | 116 +++--
 .../processors/cache/GridCacheEntryInfo.java    |  46 +-
 .../processors/cache/GridCacheEventManager.java | 121 ++++-
 .../cache/GridCacheEvictionRequest.java         |  12 +-
 .../cache/GridCacheEvictionResponse.java        |  12 +-
 .../processors/cache/GridCacheMapEntry.java     | 339 +++++++------
 .../cache/GridCacheMapEntryFactory.java         |   6 +-
 .../processors/cache/GridCacheMessage.java      |  75 +--
 .../processors/cache/GridCacheMvcc.java         | 214 ++++----
 .../cache/GridCacheMvccCandidate.java           |  50 +-
 .../cache/GridCacheSharedContext.java           |   8 +-
 .../processors/cache/GridCacheStoreManager.java | 305 ++++++++----
 .../processors/cache/GridCacheSwapEntry.java    |   6 +-
 .../cache/GridCacheSwapEntryImpl.java           |   2 +-
 .../processors/cache/GridCacheSwapManager.java  |  35 +-
 .../cache/GridCacheUpdateAtomicResult.java      |  20 +-
 .../processors/cache/KeyCacheObject.java        |  30 ++
 ...idCacheOptimisticCheckPreparedTxRequest.java |   4 +-
 ...dCacheOptimisticCheckPreparedTxResponse.java |   2 +-
 .../distributed/GridCacheTtlUpdateRequest.java  |  12 +-
 .../distributed/GridDistributedBaseMessage.java |  28 +-
 .../distributed/GridDistributedLockRequest.java |  16 +-
 .../GridDistributedLockResponse.java            |  59 +--
 .../GridDistributedTxFinishRequest.java         |   6 +-
 .../GridDistributedTxFinishResponse.java        |   2 +-
 .../GridDistributedTxPrepareRequest.java        |  46 +-
 .../GridDistributedTxPrepareResponse.java       |  14 +-
 .../GridDistributedTxRemoteAdapter.java         |  38 +-
 .../GridDistributedUnlockRequest.java           |  12 +-
 .../dht/GridDhtAffinityAssignmentRequest.java   |   2 +-
 .../dht/GridDhtAffinityAssignmentResponse.java  |   6 +-
 .../distributed/dht/GridDhtLockRequest.java     |  27 +-
 .../distributed/dht/GridDhtLockResponse.java    |  20 +-
 .../distributed/dht/GridDhtTxFinishRequest.java |   2 +-
 .../dht/GridDhtTxFinishResponse.java            |   2 +-
 .../dht/GridDhtTxPrepareRequest.java            |  30 +-
 .../dht/GridDhtTxPrepareResponse.java           |  20 +-
 .../distributed/dht/GridDhtUnlockRequest.java   |  11 +-
 .../dht/atomic/GridDhtAtomicCache.java          |   2 +-
 .../GridDhtAtomicDeferredUpdateResponse.java    |   2 +-
 .../dht/atomic/GridDhtAtomicUpdateRequest.java  |  74 +--
 .../dht/atomic/GridDhtAtomicUpdateResponse.java |  18 +-
 .../dht/atomic/GridNearAtomicUpdateRequest.java |  26 +-
 .../atomic/GridNearAtomicUpdateResponse.java    |   6 +-
 .../dht/preloader/GridDhtForceKeysRequest.java  |  14 +-
 .../dht/preloader/GridDhtForceKeysResponse.java |  22 +-
 .../GridDhtPartitionDemandMessage.java          |   8 +-
 .../GridDhtPartitionSupplyMessage.java          |  23 +-
 .../GridDhtPartitionsAbstractMessage.java       |   2 +-
 .../preloader/GridDhtPartitionsFullMessage.java |   6 +-
 .../GridDhtPartitionsSingleMessage.java         |   6 +-
 .../GridDhtPartitionsSingleRequest.java         |   2 +-
 .../distributed/near/GridNearGetRequest.java    |  12 +-
 .../distributed/near/GridNearGetResponse.java   |  12 +-
 .../distributed/near/GridNearLockRequest.java   |  18 +-
 .../distributed/near/GridNearLockResponse.java  |   6 +-
 .../near/GridNearTxFinishRequest.java           |   2 +-
 .../near/GridNearTxFinishResponse.java          |   6 +-
 .../near/GridNearTxPrepareRequest.java          |  16 +-
 .../near/GridNearTxPrepareResponse.java         |  92 ++--
 .../distributed/near/GridNearUnlockRequest.java |   2 +-
 .../extras/GridCacheAttributesEntryExtras.java  |  16 +-
 .../GridCacheAttributesMvccEntryExtras.java     |  18 +-
 ...dCacheAttributesMvccObsoleteEntryExtras.java |  24 +-
 ...cheAttributesMvccObsoleteTtlEntryExtras.java |  24 +-
 .../GridCacheAttributesMvccTtlEntryExtras.java  |  18 +-
 .../GridCacheAttributesObsoleteEntryExtras.java |  18 +-
 ...idCacheAttributesObsoleteTtlEntryExtras.java |  10 +-
 .../GridCacheAttributesTtlEntryExtras.java      |  16 +-
 .../cache/extras/GridCacheEntryExtras.java      |  12 +-
 .../extras/GridCacheEntryExtrasAdapter.java     |   4 +-
 .../cache/extras/GridCacheMvccEntryExtras.java  |  16 +-
 .../GridCacheMvccObsoleteEntryExtras.java       |  24 +-
 .../GridCacheMvccObsoleteTtlEntryExtras.java    |  18 +-
 .../extras/GridCacheMvccTtlEntryExtras.java     |  24 +-
 .../extras/GridCacheObsoleteEntryExtras.java    |  14 +-
 .../extras/GridCacheObsoleteTtlEntryExtras.java |  12 +-
 .../cache/extras/GridCacheTtlEntryExtras.java   |  14 +-
 .../cache/query/GridCacheQueryManager.java      |   2 +-
 .../cache/query/GridCacheQueryRequest.java      |   8 +-
 .../cache/query/GridCacheQueryResponse.java     |   6 +-
 .../continuous/CacheContinuousQueryManager.java |   4 +-
 .../cache/transactions/IgniteInternalTx.java    |  42 +-
 .../cache/transactions/IgniteTxAdapter.java     | 117 +++--
 .../cache/transactions/IgniteTxEntry.java       | 486 ++++++++-----------
 .../cache/transactions/IgniteTxHandler.java     |   6 +-
 .../cache/transactions/IgniteTxKey.java         |  11 +-
 .../portable/GridPortableProcessor.java         |  13 +
 94 files changed, 1953 insertions(+), 1736 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b7ea910f/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
new file mode 100644
index 0000000..6991d74
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObject.java
@@ -0,0 +1,37 @@
+/*
+ * 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.internal.processors.cache;
+
+import org.jetbrains.annotations.*;
+
+/**
+ *
+ */
+public interface CacheObject {
+    /**
+     * @param ctx Context.
+     * @return Value.
+     */
+    @Nullable public <T> T value(GridCacheContext ctx);
+
+    /**
+     * @param name Field name.
+     * @return Field value.
+     */
+    @Nullable public <T> T getField(String name);
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b7ea910f/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 9ca6c33..e72b9d0 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
@@ -34,19 +34,19 @@ public class EvictableEntryImpl<K, V> implements 
EvictableEntry<K, V> {
 
     /** Cached entry. */
     @GridToStringInclude
-    protected GridCacheEntryEx<K, V> cached;
+    protected GridCacheEntryEx cached;
 
     /**
      * @param cached Cached entry.
      */
     @SuppressWarnings({"TypeMayBeWeakened"})
-    protected EvictableEntryImpl(GridCacheEntryEx<K, V> cached) {
+    protected EvictableEntryImpl(GridCacheEntryEx cached) {
         this.cached = cached;
     }
 
     /** {@inheritDoc} */
     @Override public K getKey() throws IllegalStateException {
-        return cached.key();
+        return cached.key().value(cached.context());
     }
 
     /** {@inheritDoc} */
@@ -77,7 +77,9 @@ public class EvictableEntryImpl<K, V> implements 
EvictableEntry<K, V> {
     @SuppressWarnings("unchecked")
     @Nullable public V peek() {
         try {
-            return cached.peek(GridCachePeekMode.GLOBAL);
+            CacheObject val = cached.peek(GridCachePeekMode.GLOBAL);
+
+            return val != null ? val.<V>value(cached.context()) : null;
         }
         catch (GridCacheEntryRemovedException e) {
             return null;
@@ -88,26 +90,31 @@ public class EvictableEntryImpl<K, V> implements 
EvictableEntry<K, V> {
     @SuppressWarnings("unchecked")
     @Override public V getValue() {
         try {
-            IgniteInternalTx<K, V> tx = cached.context().tm().userTx();
+            IgniteInternalTx tx = cached.context().tm().userTx();
 
             if (tx != null) {
-                GridTuple<V> peek = tx.peek(cached.context(), false, 
cached.key(), null);
+                GridTuple<CacheObject> peek = tx.peek(cached.context(), false, 
cached.key(), null);
 
                 if (peek != null)
-                    return peek.get();
+                    return peek.get().value(cached.context());
             }
 
-            if (cached.detached())
-                return cached.rawGet();
+            if (cached.detached()) {
+                CacheObject val = cached.rawGet();
+
+                return val != null ? val.<V>value(cached.context()) : null;
+            }
 
             for (;;) {
-                GridCacheEntryEx<K, V> e = 
cached.context().cache().peekEx(cached.key());
+                GridCacheEntryEx e = 
cached.context().cache().peekEx(cached.key());
 
                 if (e == null)
                     return null;
 
                 try {
-                    return e.peek(GridCachePeekMode.GLOBAL, CU.<K, V>empty());
+                    CacheObject val = e.peek(GridCachePeekMode.GLOBAL, CU.<K, 
V>empty());
+
+                    return val != null ? val.<V>value(cached.context()) : null;
                 }
                 catch (GridCacheEntryRemovedException ignored) {
                     // No-op.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b7ea910f/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 f5927c9..0d283c9 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
@@ -138,7 +138,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
 
     /** Local map. */
     @GridToStringExclude
-    protected GridCacheConcurrentMap<K, V> map;
+    protected GridCacheConcurrentMap map;
 
     /** Local node ID. */
     @GridToStringExclude
@@ -210,7 +210,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
      */
     @SuppressWarnings("OverriddenMethodCallDuringObjectConstruction")
     protected GridCacheAdapter(GridCacheContext<K, V> ctx, int startSize) {
-        this(ctx, new GridCacheConcurrentMap<>(ctx, startSize, 0.75F));
+        this(ctx, new GridCacheConcurrentMap(ctx, startSize, 0.75F));
     }
 
     /**
@@ -218,7 +218,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
      * @param map Concurrent map.
      */
     @SuppressWarnings("OverriddenMethodCallDuringObjectConstruction")
-    protected GridCacheAdapter(GridCacheContext<K, V> ctx, 
GridCacheConcurrentMap<K, V> map) {
+    protected GridCacheAdapter(GridCacheContext<K, V> ctx, 
GridCacheConcurrentMap map) {
         assert ctx != null;
 
         this.ctx = ctx;
@@ -294,7 +294,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
     /**
      * @return Base map.
      */
-    public GridCacheConcurrentMap<K, V> map() {
+    public GridCacheConcurrentMap map() {
         return map;
     }
 
@@ -752,7 +752,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
         if (modes.primary || modes.backup) {
             long topVer = ctx.affinity().affinityTopologyVersion();
 
-            GridCacheSwapManager<K, V> swapMgr = ctx.isNear() ? 
ctx.near().dht().context().swap() : ctx.swap();
+            GridCacheSwapManager swapMgr = ctx.isNear() ? 
ctx.near().dht().context().swap() : ctx.swap();
 
             if (modes.swap)
                 its.add(swapMgr.swapIterator(modes.primary, modes.backup, 
topVer));
@@ -791,15 +791,14 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
         PeekModes modes = parsePeekModes(peekModes);
 
         try {
-            if (ctx.portableEnabled())
-                key = (K)ctx.marshalToPortable(key);
+            KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);
 
-            V val = null;
+            CacheObject cacheVal = null;
 
             if (!ctx.isLocal()) {
                 long topVer = ctx.affinity().affinityTopologyVersion();
 
-                int part = ctx.affinity().partition(key);
+                int part = ctx.affinity().partition(cacheKey);
 
                 boolean nearKey;
 
@@ -847,11 +846,11 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
                     return null;
 
                 if (modes.heap) {
-                    GridCacheEntryEx<K, V> e = nearKey ? peekEx(key) :
-                        (ctx.isNear() ? ctx.near().dht().peekEx(key) : 
peekEx(key));
+                    GridCacheEntryEx e = nearKey ? peekEx(cacheKey) :
+                        (ctx.isNear() ? ctx.near().dht().peekEx(cacheKey) : 
peekEx(cacheKey));
 
                     if (e != null) {
-                        val = e.peek(modes.heap, modes.offheap, modes.swap, 
topVer, plc);
+                        cacheVal = e.peek(modes.heap, modes.offheap, 
modes.swap, topVer, plc);
 
                         modes.offheap = false;
                         modes.swap = false;
@@ -859,20 +858,22 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
                 }
 
                 if (modes.offheap || modes.swap) {
-                    GridCacheSwapManager<K, V> swapMgr = ctx.isNear() ? 
ctx.near().dht().context().swap() : ctx.swap();
+                    GridCacheSwapManager swapMgr = ctx.isNear() ? 
ctx.near().dht().context().swap() : ctx.swap();
 
-                    GridCacheSwapEntry<V> swapEntry = swapMgr.read(key, 
modes.offheap, modes.swap);
+                    GridCacheSwapEntry swapEntry = swapMgr.read(cacheKey, 
modes.offheap, modes.swap);
 
-                    val = swapEntry != null ? swapEntry.value() : null;
+                    cacheVal = swapEntry != null ? swapEntry.value() : null;
                 }
             }
             else
-                val = localCachePeek0(key, modes.heap, modes.offheap, 
modes.swap, plc);
+                cacheVal = localCachePeek0(cacheKey, modes.heap, 
modes.offheap, modes.swap, plc);
+
+            Object val = cacheVal != null ? cacheVal.value(ctx) : null;
 
             if (ctx.portableEnabled())
-                val = (V)ctx.unwrapPortableIfNeeded(val, ctx.keepPortable());
+                val = ctx.unwrapPortableIfNeeded(val, ctx.keepPortable());
 
-            return val;
+            return (V)val;
         }
         catch (GridCacheEntryRemovedException ignore) {
             if (log.isDebugEnabled())
@@ -892,7 +893,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
      * @throws GridCacheEntryRemovedException If entry removed.
      * @throws IgniteCheckedException If failed.
      */
-    @Nullable private V localCachePeek0(K key,
+    @Nullable private CacheObject localCachePeek0(KeyCacheObject key,
         boolean heap,
         boolean offheap,
         boolean swap,
@@ -902,16 +903,16 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
         assert heap || offheap || swap;
 
         if (heap) {
-            GridCacheEntryEx<K, V> e = peekEx(key);
+            GridCacheEntryEx e = peekEx(key);
 
             if (e != null)
                 return e.peek(heap, offheap, swap, -1, plc);
         }
 
         if (offheap || swap) {
-            GridCacheSwapManager<K, V> swapMgr = ctx.isNear() ? 
ctx.near().dht().context().swap() : ctx.swap();
+            GridCacheSwapManager swapMgr = ctx.isNear() ? 
ctx.near().dht().context().swap() : ctx.swap();
 
-            GridCacheSwapEntry<V> swapEntry = swapMgr.read(key, offheap, swap);
+            GridCacheSwapEntry swapEntry = swapMgr.read(key, offheap, swap);
 
             return swapEntry != null ? swapEntry.value() : null;
         }
@@ -952,19 +953,18 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
 
         ctx.checkSecurity(GridSecurityPermission.CACHE_READ);
 
-        GridCacheEntryEx<K, V> e = null;
+        GridCacheEntryEx e = null;
 
         try {
-            if (ctx.portableEnabled())
-                key = (K)ctx.marshalToPortable(key);
+            KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);
 
-            e = peekEx(key);
+            e = peekEx(cacheKey);
 
             if (e != null) {
-                GridTuple<V> peek = e.peek0(failFast, mode, filter, 
ctx.tm().localTxx());
+                GridTuple<CacheObject> peek = e.peek0(failFast, mode, filter, 
ctx.tm().localTxx());
 
                 if (peek != null) {
-                    V v = peek.get();
+                    CacheObject v = peek.get();
 
                     if (ctx.portableEnabled())
                         v = (V)ctx.unwrapPortableIfNeeded(v, 
ctx.keepPortable());
@@ -973,13 +973,13 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
                 }
             }
 
-            IgniteInternalTx<K, V> tx = ctx.tm().localTx();
+            IgniteInternalTx tx = ctx.tm().localTx();
 
             if (tx != null) {
-                GridTuple<V> peek = tx.peek(ctx, failFast, key, filter);
+                GridTuple<CacheObject> peek = tx.peek(ctx, failFast, cacheKey, 
filter);
 
                 if (peek != null) {
-                    V v = peek.get();
+                    CacheObject v = peek.get();
 
                     if (ctx.portableEnabled())
                         v = (V)ctx.unwrapPortableIfNeeded(v, 
ctx.keepPortable());
@@ -1020,7 +1020,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
         Map<K, V> ret = new HashMap<>(keys.size(), 1.0f);
 
         for (K k : keys) {
-            GridCacheEntryEx<K, V> e = peekEx(k);
+            GridCacheEntryEx e = peekEx(k);
 
             if (e != null)
                 try {
@@ -1078,7 +1078,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
      * @throws GridCacheFilterFailedException If filer validation failed.
      */
     @Nullable protected GridTuple<V> peek0(boolean failFast, K key, @Nullable 
Collection<GridCachePeekMode> modes,
-        IgniteInternalTx<K, V> tx) throws IgniteCheckedException, 
GridCacheFilterFailedException {
+        IgniteInternalTx tx) throws IgniteCheckedException, 
GridCacheFilterFailedException {
         if (F.isEmpty(modes))
             return F.t(peek(key, (IgnitePredicate<Cache.Entry<K, V>>)null));
 
@@ -1091,7 +1091,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
 
         ctx.checkSecurity(GridSecurityPermission.CACHE_READ);
 
-        GridCacheEntryEx<K, V> e = peekEx(key);
+        GridCacheEntryEx e = peekEx(key);
 
         try {
             for (GridCachePeekMode m : modes) {
@@ -1186,7 +1186,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
      * @throws IgniteCheckedException If failed.
      */
     private boolean poke0(K key, @Nullable V newVal) throws 
IgniteCheckedException {
-        GridCacheEntryEx<K, V> entryEx = peekEx(key);
+        GridCacheEntryEx entryEx = peekEx(key);
 
         if (entryEx == null || entryEx.deleted())
             return newVal == null;
@@ -1239,7 +1239,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
         if (keyCheck)
             validateCacheKey(key);
 
-        return entryEx(key, true).wrap();
+        return entryEx(ctx.toCacheKeyObject(key), true).wrap();
     }
 
     /**
@@ -1247,7 +1247,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
      * @param key Entry key.
      * @return Entry or <tt>null</tt>.
      */
-    @Nullable public GridCacheEntryEx<K, V> peekEx(K key) {
+    @Nullable public GridCacheEntryEx peekEx(KeyCacheObject key) {
         return entry0(key, ctx.affinity().affinityTopologyVersion(), false, 
false);
     }
 
@@ -1255,7 +1255,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
      * @param key Entry key.
      * @return Entry (never {@code null}).
      */
-    public GridCacheEntryEx<K, V> entryEx(K key) {
+    public GridCacheEntryEx entryEx(KeyCacheObject key) {
         return entryEx(key, false);
     }
 
@@ -1264,8 +1264,8 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
      * @param touch Whether created entry should be touched.
      * @return Entry (never {@code null}).
      */
-    public GridCacheEntryEx<K, V> entryEx(K key, boolean touch) {
-        GridCacheEntryEx<K, V> e = entry0(key, 
ctx.affinity().affinityTopologyVersion(), true, touch);
+    public GridCacheEntryEx entryEx(KeyCacheObject key, boolean touch) {
+        GridCacheEntryEx e = entry0(key, 
ctx.affinity().affinityTopologyVersion(), true, touch);
 
         assert e != null;
 
@@ -1277,8 +1277,8 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
      * @param key Entry key.
      * @return Entry (never {@code null}).
      */
-    public GridCacheEntryEx<K, V> entryEx(K key, long topVer) {
-        GridCacheEntryEx<K, V> e = entry0(key, topVer, true, false);
+    public GridCacheEntryEx entryEx(KeyCacheObject key, long topVer) {
+        GridCacheEntryEx e = entry0(key, topVer, true, false);
 
         assert e != null;
 
@@ -1292,13 +1292,13 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
      * @param touch Flag to touch created entry (only if entry was actually 
created).
      * @return Entry or <tt>null</tt>.
      */
-    @Nullable private GridCacheEntryEx<K, V> entry0(K key, long topVer, 
boolean create, boolean touch) {
-        GridTriple<GridCacheMapEntry<K, V>> t = 
map.putEntryIfObsoleteOrAbsent(topVer, key, null,
+    @Nullable private GridCacheEntryEx entry0(KeyCacheObject key, long topVer, 
boolean create, boolean touch) {
+        GridTriple<GridCacheMapEntry> t = 
map.putEntryIfObsoleteOrAbsent(topVer, key, null,
             ctx.config().getDefaultTimeToLive(), create);
 
-        GridCacheEntryEx<K, V> cur = t.get1();
-        GridCacheEntryEx<K, V> created = t.get2();
-        GridCacheEntryEx<K, V> doomed = t.get3();
+        GridCacheEntryEx cur = t.get1();
+        GridCacheEntryEx created = t.get2();
+        GridCacheEntryEx doomed = t.get3();
 
         if (doomed != null && 
ctx.events().isRecordable(EVT_CACHE_ENTRY_DESTROYED))
             // Event notification.
@@ -1321,14 +1321,14 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
     /**
      * @return Set of internal cached entry representations, excluding {@link 
GridCacheInternal} keys.
      */
-    public Set<GridCacheEntryEx<K, V>> entries() {
+    public Set<GridCacheEntryEx> entries() {
         return map.entries0();
     }
 
     /**
      * @return Set of internal cached entry representations, including {@link 
GridCacheInternal} keys.
      */
-    public Set<GridCacheEntryEx<K, V>> allEntries() {
+    public Set<GridCacheEntryEx> allEntries() {
         return map.allEntries0();
     }
 
@@ -1393,7 +1393,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
     public void removeIfObsolete(K key) {
         assert key != null;
 
-        GridCacheEntryEx<K, V> entry = map.removeEntryIfObsolete(key);
+        GridCacheEntryEx entry = map.removeEntryIfObsolete(key);
 
         if (entry != null) {
             assert entry.obsolete() : "Removed non-obsolete entry: " + entry;
@@ -1494,7 +1494,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
         GridCacheVersion obsoleteVer = ctx.versions().next();
 
         for (K key : keys) {
-            GridCacheEntryEx<K, V> e = peekEx(key);
+            GridCacheEntryEx e = peekEx(key);
 
             try {
                 if (e != null)
@@ -1521,7 +1521,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
             if (ctx.portableEnabled())
                 key = (K)ctx.marshalToPortable(key);
 
-            GridCacheEntryEx<K, V> e = peekEx(key);
+            GridCacheEntryEx e = peekEx(key);
 
             return e != null && e.clear(obsoleteVer, false, filter);
         }
@@ -1608,7 +1608,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
     /**
      * @param entry Removes entry from cache if currently mapped value is the 
same as passed.
      */
-    public void removeEntry(GridCacheEntryEx<K, V> entry) {
+    public void removeEntry(GridCacheEntryEx entry) {
         map.removeEntry(entry);
     }
 
@@ -1631,7 +1631,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
             }
         }
 
-        GridCacheEntryEx<K, V> entry = peekEx(key);
+        GridCacheEntryEx entry = peekEx(key);
 
         if (entry == null)
             return true;
@@ -1647,7 +1647,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
     }
 
     /** {@inheritDoc} */
-    @Override public V get(K key, @Nullable GridCacheEntryEx<K, V> entry, 
boolean deserializePortable,
+    @Override public V get(K key, @Nullable GridCacheEntryEx entry, boolean 
deserializePortable,
         @Nullable IgnitePredicate<Cache.Entry<K, V>>... filter) throws 
IgniteCheckedException {
         String taskName = ctx.kernalContext().job().currentTaskName();
 
@@ -1787,7 +1787,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
 
                 while (true) {
                     try {
-                        GridCacheEntryEx<K, V> entry = entryExSafe(key, 
topVer);
+                        GridCacheEntryEx entry = entryExSafe(key, topVer);
 
                         if (entry == null)
                             break;
@@ -1828,7 +1828,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
                     @Override public void apply(K key, V val) {
                         loadedKeys.add(key);
 
-                        GridCacheEntryEx<K, V> entry = peekEx(key);
+                        GridCacheEntryEx entry = peekEx(key);
 
                         if (entry != null) {
                             try {
@@ -1893,7 +1893,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
                     // Touch all not loaded keys.
                     for (K key : absentKeys) {
                         if (!loadedKeys.contains(key)) {
-                            GridCacheEntryEx<K, V> entry = peekEx(key);
+                            GridCacheEntryEx entry = peekEx(key);
 
                             if (entry != null)
                                 ctx.evicts().touch(entry, topVer);
@@ -1915,7 +1915,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
      * @param key Key.
      * @return Entry.
      */
-    @Nullable protected GridCacheEntryEx<K, V> entryExSafe(K key, long topVer) 
{
+    @Nullable protected GridCacheEntryEx entryExSafe(K key, long topVer) {
         return entryEx(key);
     }
 
@@ -2064,7 +2064,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
         @Nullable Collection<? extends K> keys,
         boolean forcePrimary,
         boolean skipTx,
-        @Nullable GridCacheEntryEx<K, V> entry,
+        @Nullable GridCacheEntryEx entry,
         @Nullable UUID subjId,
         String taskName,
         boolean deserializePortable,
@@ -2089,7 +2089,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
     /** {@inheritDoc} */
     public IgniteInternalFuture<Map<K, V>> getAllAsync(@Nullable final 
Collection<? extends K> keys,
         boolean readThrough,
-        @Nullable GridCacheEntryEx<K, V> cached,
+        @Nullable GridCacheEntryEx cached,
         boolean checkTx,
         @Nullable final UUID subjId,
         final String taskName,
@@ -2140,7 +2140,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
                         throw new NullPointerException("Null key.");
 
                     while (true) {
-                        GridCacheEntryEx<K, V> entry;
+                        GridCacheEntryEx entry;
 
                         if (cached != null) {
                             entry = cached;
@@ -2243,7 +2243,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
                                         loaded.add(key);
 
                                         while (true) {
-                                            GridCacheEntryEx<K, V> entry = 
entryEx(key);
+                                            GridCacheEntryEx entry = 
entryEx(key);
 
                                             try {
                                                 boolean set = 
entry.versionedValue(val, ver, nextVer);
@@ -2283,7 +2283,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
 
                                         if (tx0 == null || (!tx0.implicit() &&
                                             tx0.isolation() == 
READ_COMMITTED)) {
-                                            GridCacheEntryEx<K, V> entry = 
peekEx(key);
+                                            GridCacheEntryEx entry = 
peekEx(key);
 
                                             if (entry != null)
                                                 ctx.evicts().touch(entry, 
topVer);
@@ -2306,7 +2306,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
 
                                     // Touch entries that were not found in 
store.
                                     for (K key : notFound) {
-                                        GridCacheEntryEx<K, V> entry = 
peekEx(key);
+                                        GridCacheEntryEx entry = peekEx(key);
 
                                         if (entry != null)
                                             ctx.evicts().touch(entry, topVer);
@@ -2332,7 +2332,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
                     // If misses is not empty and store is disabled, we should 
touch missed entries.
                     if (misses != null) {
                         for (K key : misses.keySet()) {
-                            GridCacheEntryEx<K, V> entry = peekEx(key);
+                            GridCacheEntryEx entry = peekEx(key);
 
                             if (entry != null)
                                 ctx.evicts().touch(entry, topVer);
@@ -2347,7 +2347,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
             }
         }
         else {
-            final GridCacheEntryEx<K, V> cached0 = cached;
+            final GridCacheEntryEx cached0 = cached;
 
             return asyncOp(tx, new AsyncOp<Map<K, V>>(keys) {
                 @Override public IgniteInternalFuture<Map<K, V>> 
op(IgniteTxLocalAdapter<K, V> tx) {
@@ -2364,7 +2364,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
     }
 
     /** {@inheritDoc} */
-    @Nullable @Override public V put(final K key, final V val, @Nullable final 
GridCacheEntryEx<K, V> cached,
+    @Nullable @Override public V put(final K key, final V val, @Nullable final 
GridCacheEntryEx cached,
         final long ttl, @Nullable final IgnitePredicate<Cache.Entry<K, V>>[] 
filter) throws IgniteCheckedException {
         boolean statsEnabled = ctx.config().isStatisticsEnabled();
 
@@ -2379,7 +2379,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
 
         ctx.denyOnLocalRead();
 
-        V prevValue = ctx.cloneOnFlag(syncOp(new SyncOp<V>(true) {
+        V prevVal = ctx.cloneOnFlag(syncOp(new SyncOp<V>(true) {
             @Override public V op(IgniteTxLocalAdapter<K, V> tx) throws 
IgniteCheckedException {
                 return tx.putAllAsync(ctx, F.t(key, val), true, cached, ttl, 
filter).get().value();
             }
@@ -2392,11 +2392,11 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
         if (statsEnabled)
             metrics0().addPutAndGetTimeNanos(System.nanoTime() - start);
 
-        return prevValue;
+        return prevVal;
     }
 
     /** {@inheritDoc} */
-    @Override public boolean putx(final K key, final V val, @Nullable final 
GridCacheEntryEx<K, V> cached,
+    @Override public boolean putx(final K key, final V val, @Nullable final 
GridCacheEntryEx cached,
         final long ttl, @Nullable final IgnitePredicate<Cache.Entry<K, V>>... 
filter) throws IgniteCheckedException {
         A.notNull(key, "key", val, "val");
 
@@ -2436,7 +2436,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<V> putAsync(final K key, final V 
val, @Nullable final GridCacheEntryEx<K, V> entry,
+    @Override public IgniteInternalFuture<V> putAsync(final K key, final V 
val, @Nullable final GridCacheEntryEx entry,
         final long ttl, @Nullable final IgnitePredicate<Cache.Entry<K, V>>... 
filter) {
         A.notNull(key, "key", val, "val");
 
@@ -2766,7 +2766,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
 
     /** {@inheritDoc} */
     @Override public IgniteInternalFuture<Boolean> putxAsync(final K key, 
final V val,
-        @Nullable final GridCacheEntryEx<K, V> entry, final long ttl,
+        @Nullable final GridCacheEntryEx entry, final long ttl,
         @Nullable final IgnitePredicate<Cache.Entry<K, V>>... filter) {
         A.notNull(key, "key", val, "val");
 
@@ -3150,7 +3150,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
     }
 
     /** {@inheritDoc} */
-    @Override public V remove(final K key, @Nullable final GridCacheEntryEx<K, 
V> entry,
+    @Override public V remove(final K key, @Nullable final GridCacheEntryEx 
entry,
         @Nullable final IgnitePredicate<Cache.Entry<K, V>>... filter) throws 
IgniteCheckedException {
         boolean statsEnabled = ctx.config().isStatisticsEnabled();
 
@@ -3199,7 +3199,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<V> removeAsync(final K key, 
@Nullable final GridCacheEntryEx<K, V> entry,
+    @Override public IgniteInternalFuture<V> removeAsync(final K key, 
@Nullable final GridCacheEntryEx entry,
         @Nullable final IgnitePredicate<Cache.Entry<K, V>>... filter) {
         final boolean statsEnabled = ctx.config().isStatisticsEnabled();
 
@@ -3319,7 +3319,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
     }
 
     /** {@inheritDoc} */
-    @Override public boolean removex(final K key, @Nullable final 
GridCacheEntryEx<K, V> entry,
+    @Override public boolean removex(final K key, @Nullable final 
GridCacheEntryEx entry,
         @Nullable final IgnitePredicate<Cache.Entry<K, V>>... filter) throws 
IgniteCheckedException {
         boolean statsEnabled = ctx.config().isStatisticsEnabled();
 
@@ -3356,7 +3356,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteInternalFuture<Boolean> removexAsync(final K key, 
@Nullable final GridCacheEntryEx<K, V> entry,
+    @Override public IgniteInternalFuture<Boolean> removexAsync(final K key, 
@Nullable final GridCacheEntryEx entry,
         @Nullable final IgnitePredicate<Cache.Entry<K, V>>... filter) {
         final boolean statsEnabled = ctx.config().isStatisticsEnabled();
 
@@ -3680,7 +3680,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
 
     /** {@inheritDoc} */
     @Nullable @Override public Transaction tx() {
-        IgniteTxAdapter<K, V> tx = ctx.tm().threadLocalTx();
+        IgniteTxAdapter tx = ctx.tm().threadLocalTx();
 
         return tx == null ? null : new TransactionProxyImpl<>(tx, 
ctx.shared(), false);
     }
@@ -3754,7 +3754,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
 
         while (true) {
             try {
-                GridCacheEntryEx<K, V> entry = peekEx(key);
+                GridCacheEntryEx entry = peekEx(key);
 
                 return entry != null && entry.lockedByAny();
             }
@@ -3772,7 +3772,9 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
             validateCacheKey(key);
 
         try {
-            GridCacheEntryEx<K, V> e = entry0(key, 
ctx.discovery().topologyVersion(), false, false);
+            KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);
+
+            GridCacheEntryEx e = entry0(cacheKey, 
ctx.discovery().topologyVersion(), false, false);
 
             if (e == null)
                 return false;
@@ -3896,8 +3898,8 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
             // Version for all loaded entries.
             final GridCacheVersion ver0 = ctx.versions().nextForLoad();
 
-            ctx.store().loadCache(new CIX3<K, V, GridCacheVersion>() {
-                @Override public void applyx(K key, V val, @Nullable 
GridCacheVersion ver)
+            ctx.store().loadCache(new CIX3<Object, Object, GridCacheVersion>() 
{
+                @Override public void applyx(Object key, Object val, @Nullable 
GridCacheVersion ver)
                     throws IgniteException {
                     assert ver == null;
 
@@ -3906,7 +3908,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
                     if (ttl == CU.TTL_ZERO)
                         return;
 
-                    loadEntry(key, val, ver0, p, topVer, replicate, ttl);
+                    loadEntry(key, val, ver0, (IgniteBiPredicate<Object, 
Object>)p, topVer, replicate, ttl);
                 }
             }, args);
         }
@@ -3921,25 +3923,29 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
      * @param replicate Replication flag.
      * @param ttl TTL.
      */
-    private void loadEntry(K key,
-        V val,
+    private void loadEntry(Object key,
+        Object val,
         GridCacheVersion ver,
-        @Nullable IgniteBiPredicate<K, V> p,
+        @Nullable IgniteBiPredicate<Object, Object> p,
         long topVer,
         boolean replicate,
         long ttl) {
         if (p != null && !p.apply(key, val))
             return;
 
-        if (ctx.portableEnabled()) {
-            key = (K)ctx.marshalToPortable(key);
-            val = (V)ctx.marshalToPortable(val);
-        }
+// TODO IGNITE-51.
+//        if (ctx.portableEnabled()) {
+//            key = (K)ctx.marshalToPortable(key);
+//            val = (V)ctx.marshalToPortable(val);
+//        }
+
+        KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);
+        CacheObject cacheVal = ctx.toCacheObject(val);
 
-        GridCacheEntryEx<K, V> entry = entryEx(key, false);
+        GridCacheEntryEx entry = entryEx(cacheKey, false);
 
         try {
-            entry.initialValue(val, null, ver, ttl, CU.EXPIRE_TIME_CALCULATE, 
false, topVer,
+            entry.initialValue(cacheVal, null, ver, ttl, 
CU.EXPIRE_TIME_CALCULATE, false, topVer,
                 replicate ? DR_LOAD : DR_NONE);
         }
         catch (IgniteCheckedException e) {
@@ -4150,9 +4156,9 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
 
     /** {@inheritDoc} */
     @Nullable @Override public Cache.Entry<K, V> randomEntry() {
-        GridCacheMapEntry<K, V> e = map.randomEntry();
+        GridCacheMapEntry e = map.randomEntry();
 
-        return e == null || e.obsolete() ? null : e.wrapLazyValue();
+        return e == null || e.obsolete() ? null : e.<K, V>wrapLazyValue();
     }
 
     /** {@inheritDoc} */
@@ -4233,7 +4239,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
         if (modes.primary || modes.backup) {
             long topVer = ctx.affinity().affinityTopologyVersion();
 
-            GridCacheSwapManager<K, V> swapMgr = ctx.isNear() ? 
ctx.near().dht().context().swap() : ctx.swap();
+            GridCacheSwapManager swapMgr = ctx.isNear() ? 
ctx.near().dht().context().swap() : ctx.swap();
 
             if (modes.swap)
                 size += swapMgr.swapEntriesCount(modes.primary, modes.backup, 
topVer);
@@ -4329,15 +4335,17 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
         if (keyCheck)
             validateCacheKey(key);
 
-        GridCacheSwapEntry<V> unswapped = ctx.swap().readAndRemove(key);
+        KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);
+
+        GridCacheSwapEntry unswapped = ctx.swap().readAndRemove(cacheKey);
 
         if (unswapped == null)
             return null;
 
-        GridCacheEntryEx<K, V> entry = entryEx(key);
+        GridCacheEntryEx entry = entryEx(cacheKey);
 
         try {
-            if (!entry.initialValue(key, unswapped))
+            if (!entry.initialValue(cacheKey, unswapped))
                 return null;
         }
         catch (GridCacheEntryRemovedException ignored) {
@@ -4347,12 +4355,14 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
             return null;
         }
 
-        V val = unswapped.value();
+        CacheObject val = unswapped.value();
+
+        Object val0 = val != null ? val.value(ctx) : null;
 
         if (ctx.portableEnabled())
-            return (V)ctx.unwrapPortableIfNeeded(val, !deserializePortable);
+            return (V)ctx.unwrapPortableIfNeeded(val0, !deserializePortable);
         else
-            return ctx.cloneOnFlag(val);
+            return (V)ctx.cloneOnFlag(val0);
     }
 
     /** {@inheritDoc} */
@@ -4365,27 +4375,29 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
         if (keyCheck)
             validateCacheKeys(keys);
 
-        Collection<K> unswap = new ArrayList<>(keys.size());
+        Collection<KeyCacheObject> unswap = new ArrayList<>(keys.size());
 
         for (K key : keys) {
+            KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);
+
             // Do not look up in swap for existing entries.
-            GridCacheEntryEx<K, V> entry = peekEx(key);
+            GridCacheEntryEx entry = peekEx(cacheKey);
 
             try {
                 if (entry == null || entry.obsolete() || entry.isNewLocked())
-                    unswap.add(key);
+                    unswap.add(cacheKey);
             }
             catch (GridCacheEntryRemovedException ignored) {
                 // No-op.
             }
         }
 
-        Collection<GridCacheBatchSwapEntry<K, V>> swapped = 
ctx.swap().readAndRemove(unswap);
+        Collection<GridCacheBatchSwapEntry> swapped = 
ctx.swap().readAndRemove(unswap);
 
-        for (GridCacheBatchSwapEntry<K, V> swapEntry : swapped) {
-            K key = swapEntry.key();
+        for (GridCacheBatchSwapEntry swapEntry : swapped) {
+            KeyCacheObject key = swapEntry.key();
 
-            GridCacheEntryEx<K, V> entry = entryEx(key);
+            GridCacheEntryEx entry = entryEx(key);
 
             try {
                 entry.initialValue(key, swapEntry);
@@ -4917,7 +4929,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
         if (keyCheck)
             validateCacheKey(key);
 
-        GridCacheEntryEx<K, V> entry = peekEx(key);
+        GridCacheEntryEx entry = peekEx(ctx.toCacheKeyObject(key));
 
         try {
             if (entry != null && entry.compact(filter)) {
@@ -5161,16 +5173,17 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
 
         long topVer = ctx.affinity().affinityTopologyVersion();
 
-        if (ctx.portableEnabled())
-            key = (K)ctx.marshalToPortable(key);
-
         while (true) {
             try {
+                KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);
+
                 // Do not reload near entries, they will be reloaded in DHT 
cache.
-                if (ctx.isNear() && ctx.affinity().localNode(key, topVer))
+                if (ctx.isNear() && ctx.affinity().localNode(cacheKey, topVer))
                     return null;
 
-                return ctx.cloneOnFlag(entryEx(key).innerReload());
+                CacheObject val = entryEx(cacheKey).innerReload();
+
+                return (V)(val != null ? val.value(ctx) : null);
             }
             catch (GridCacheEntryRemovedException ignored) {
                 if (log.isDebugEnabled())
@@ -5236,7 +5249,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
      * @param entry Entry.
      * @param ver Version.
      */
-    public abstract void onDeferredDelete(GridCacheEntryEx<K, V> entry, 
GridCacheVersion ver);
+    public abstract void onDeferredDelete(GridCacheEntryEx entry, 
GridCacheVersion ver);
 
     /**
      * Validates that given cache value implements {@link Externalizable}.
@@ -5312,7 +5325,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
      * @param deserializePortable Deserialize portable flag.
      * @return Public API iterator.
      */
-    protected Iterator<Cache.Entry<K, V>> iterator(final 
Iterator<GridCacheEntryEx<K, V>> it,
+    protected Iterator<Cache.Entry<K, V>> iterator(final 
Iterator<GridCacheEntryEx> it,
         final boolean deserializePortable) {
         return new Iterator<Cache.Entry<K, V>>() {
             {
@@ -5348,7 +5361,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
                 next = null;
 
                 while (it.hasNext()) {
-                    GridCacheEntryEx<K, V> entry = it.next();
+                    GridCacheEntryEx entry = it.next();
 
                     try {
                         next = toCacheEntry(entry, deserializePortable);
@@ -5376,12 +5389,12 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
      * @throws IgniteCheckedException If failed.
      * @throws GridCacheEntryRemovedException If entry removed.
      */
-    @Nullable private Cache.Entry<K, V> toCacheEntry(GridCacheEntryEx<K, V> 
entry,
+    @Nullable private Cache.Entry<K, V> toCacheEntry(GridCacheEntryEx entry,
         boolean deserializePortable)
         throws IgniteCheckedException, GridCacheEntryRemovedException
     {
         try {
-            V val = entry.innerGet(
+            CacheObject val = entry.innerGet(
                 null,
                 false,
                 false,
@@ -5398,14 +5411,17 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
             if (val == null)
                 return null;
 
-            K key = entry.key();
+            KeyCacheObject key = entry.key();
+
+            Object key0 = key.value(ctx);
+            Object val0 = val.value(ctx);
 
             if (deserializePortable && ctx.portableEnabled()) {
-                key = (K)ctx.unwrapPortableIfNeeded(key, true);
-                val = (V)ctx.unwrapPortableIfNeeded(val, true);
+                key0 = ctx.unwrapPortableIfNeeded(key0, true);
+                val0 = ctx.unwrapPortableIfNeeded(val0, true);
             }
 
-            return new CacheEntryImpl<>(key, val);
+            return new CacheEntryImpl<>((K)key0, (V)val0);
         }
         catch (GridCacheFilterFailedException ignore) {
             assert false;
@@ -6126,9 +6142,9 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
     /**
      *
      */
-    private class LocalStoreLoadClosure extends CIX3<K, V, GridCacheVersion> {
+    private class LocalStoreLoadClosure extends CIX3<Object, Object, 
GridCacheVersion> {
         /** */
-        final IgniteBiPredicate<K, V> p;
+        final IgniteBiPredicate<Object, Object> p;
 
         /** */
         final Collection<Map.Entry<K, V>> col;
@@ -6144,7 +6160,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
          * @param ldr Loader.
          * @param plc Optional expiry policy.
          */
-        private LocalStoreLoadClosure(@Nullable IgniteBiPredicate<K, V> p,
+        private LocalStoreLoadClosure(@Nullable IgniteBiPredicate<Object, 
Object> p,
             IgniteDataLoaderImpl<K, V> ldr,
             @Nullable ExpiryPolicy plc) {
             this.p = p;
@@ -6155,7 +6171,7 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
         }
 
         /** {@inheritDoc} */
-        @Override public void applyx(K key, V val, GridCacheVersion ver) 
throws IgniteCheckedException {
+        @Override public void applyx(Object key, Object val, GridCacheVersion 
ver) throws IgniteCheckedException {
             assert ver != null;
 
             if (p != null && !p.apply(key, val))
@@ -6172,14 +6188,9 @@ public abstract class GridCacheAdapter<K, V> implements 
GridCache<K, V>,
                     ttl = 0;
             }
 
-            if (ctx.portableEnabled()) {
-                key = (K)ctx.marshalToPortable(key);
-                val = (V)ctx.marshalToPortable(val);
-            }
-
-            GridCacheRawVersionedEntry<K,V> e = new 
GridCacheRawVersionedEntry<>(key,
+            GridCacheRawVersionedEntry e = new 
GridCacheRawVersionedEntry<>(ctx.toCacheKeyObject(key),
                 null,
-                val,
+                ctx.toCacheObject(val),
                 null,
                 ttl,
                 0,

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b7ea910f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheBatchSwapEntry.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheBatchSwapEntry.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheBatchSwapEntry.java
index 8dbc5f5..e29868e 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheBatchSwapEntry.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheBatchSwapEntry.java
@@ -26,9 +26,9 @@ import java.nio.*;
 /**
  * Entry for batch swap operations.
  */
-public class GridCacheBatchSwapEntry<K, V> extends GridCacheSwapEntryImpl<V> {
+public class GridCacheBatchSwapEntry extends GridCacheSwapEntryImpl {
     /** Key. */
-    private K key;
+    private KeyCacheObject key;
 
     /** Key bytes. */
     private byte[] keyBytes;
@@ -50,7 +50,7 @@ public class GridCacheBatchSwapEntry<K, V> extends 
GridCacheSwapEntryImpl<V> {
      * @param keyClsLdrId Key class loader ID.
      * @param valClsLdrId Optional value class loader ID.
      */
-    public GridCacheBatchSwapEntry(K key,
+    public GridCacheBatchSwapEntry(KeyCacheObject key,
         byte[] keyBytes,
         int part,
         ByteBuffer valBytes,
@@ -70,7 +70,7 @@ public class GridCacheBatchSwapEntry<K, V> extends 
GridCacheSwapEntryImpl<V> {
     /**
      * @return Key.
      */
-    public K key() {
+    public KeyCacheObject key() {
         return key;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b7ea910f/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 a169706..945a5bc 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
@@ -40,7 +40,7 @@ import static 
org.apache.ignite.internal.processors.cache.CacheFlag.*;
 /**
  * Concurrent implementation of cache map.
  */
-public class GridCacheConcurrentMap<K, V> {
+public class GridCacheConcurrentMap {
     /** Debug flag. */
     private static final boolean DEBUG = false;
 
@@ -76,10 +76,10 @@ public class GridCacheConcurrentMap<K, V> {
     private final Segment[] segs;
 
     /** */
-    private GridCacheMapEntryFactory<K, V> factory;
+    private GridCacheMapEntryFactory factory;
 
     /** Cache context. */
-    protected final GridCacheContext<K, V> ctx;
+    protected final GridCacheContext ctx;
 
     /** */
     private final LongAdder mapPubSize = new LongAdder();
@@ -99,18 +99,18 @@ public class GridCacheConcurrentMap<K, V> {
     public static final IgnitePredicate[] NON_INTERNAL_ARR = new P1[] 
{NON_INTERNAL};
 
     /** Filters obsolete cache map entry. */
-    private final IgnitePredicate<GridCacheMapEntry<K, V>> obsolete =
-        new P1<GridCacheMapEntry<K, V>>() {
-            @Override public boolean apply(GridCacheMapEntry<K, V> entry) {
+    private final IgnitePredicate<GridCacheMapEntry> obsolete =
+        new P1<GridCacheMapEntry>() {
+            @Override public boolean apply(GridCacheMapEntry entry) {
                 return entry.obsolete();
             }
         };
 
     /** Soft iterator queue. */
-    private final ReferenceQueue<Iterator0<K, V>> itQ = new ReferenceQueue<>();
+    private final ReferenceQueue<Iterator0<KeyCacheObject, CacheObject>> itQ = 
new ReferenceQueue<>();
 
     /** Soft iterator set. */
-    private final Map<WeakIterator<K, V>, SegmentHeader<K, V>> itMap =
+    private final Map<WeakIterator<KeyCacheObject, CacheObject>, 
SegmentHeader> itMap =
         new ConcurrentHashMap8<>();
 
     /**
@@ -119,13 +119,14 @@ public class GridCacheConcurrentMap<K, V> {
     private void checkWeakQueue() {
         // If queue is empty, then it is a lock-free volatile read which 
should happen
         // in most cases. Otherwise queue uses synchronization to poll 
elements.
-        for (Reference<? extends Iterator0<K, V>> itRef = itQ.poll(); itRef != 
null; itRef = itQ.poll()) {
+        for (Reference<? extends Iterator0<KeyCacheObject, CacheObject>> itRef 
= itQ.poll();
+             itRef != null; itRef = itQ.poll()) {
             assert itRef instanceof WeakIterator;
 
             if (DEBUG)
                 X.println("Checking weak queue [itSetSize=" + itMap.size() + 
']');
 
-            SegmentHeader<K, V> lastSeg = removeWeakIterator(itRef);
+            SegmentHeader lastSeg = removeWeakIterator(itRef);
 
             // Segment may be null if iterator is empty at creation time.
             if (lastSeg != null)
@@ -137,10 +138,11 @@ public class GridCacheConcurrentMap<K, V> {
      * @param itRef Iterator reference.
      * @return Last segment.
      */
-    private SegmentHeader<K, V> removeWeakIterator(Reference<? extends 
Iterator0<K, V>> itRef) {
+    private SegmentHeader removeWeakIterator(
+        Reference<? extends Iterator0<KeyCacheObject, CacheObject>> itRef) {
         assert itRef instanceof WeakIterator;
 
-        SegmentHeader<K, V> hdr = itMap.remove(itRef);
+        SegmentHeader hdr = itMap.remove(itRef);
 
         if (DEBUG) {
             if (hdr == null)
@@ -156,8 +158,8 @@ public class GridCacheConcurrentMap<K, V> {
      * @param itRef Iterator reference.
      * @param hdr Segment header.
      */
-    private void addWeakIterator(WeakIterator<K, V> itRef, SegmentHeader<K, V> 
hdr) {
-        SegmentHeader<K, V> prev = itMap.put(itRef, hdr);
+    private void addWeakIterator(WeakIterator<KeyCacheObject, CacheObject> 
itRef, SegmentHeader hdr) {
+        SegmentHeader prev = itMap.put(itRef, hdr);
 
         if (DEBUG)
             if (prev == null)
@@ -281,7 +283,7 @@ public class GridCacheConcurrentMap<K, V> {
      * @throws IllegalArgumentException if the initial capacity of
      *      elements is negative or the load factor is non-positive.
      */
-    public GridCacheConcurrentMap(GridCacheContext<K, V> ctx, int initCap, 
float loadFactor) {
+    public GridCacheConcurrentMap(GridCacheContext ctx, int initCap, float 
loadFactor) {
         this(ctx, initCap, loadFactor, DFLT_CONCUR_LEVEL);
     }
 
@@ -295,7 +297,7 @@ public class GridCacheConcurrentMap<K, V> {
      * @throws IllegalArgumentException if the initial capacity of
      *      elements is negative.
      */
-    public GridCacheConcurrentMap(GridCacheContext<K, V> ctx, int initCap) {
+    public GridCacheConcurrentMap(GridCacheContext ctx, int initCap) {
         this(ctx, initCap, DFLT_LOAD_FACTOR, DFLT_CONCUR_LEVEL);
     }
 
@@ -304,7 +306,7 @@ public class GridCacheConcurrentMap<K, V> {
      *
      * @param factory Entry factory.
      */
-    public void setEntryFactory(GridCacheMapEntryFactory<K, V> factory) {
+    public void setEntryFactory(GridCacheMapEntryFactory factory) {
         assert factory != null;
 
         this.factory = factory;
@@ -395,7 +397,7 @@ public class GridCacheConcurrentMap<K, V> {
      * @param filter Filter.
      * @return a collection view of the values contained in this map.
      */
-    public Collection<V> allValues(IgnitePredicate<Cache.Entry<K, V>>[] 
filter) {
+    public <K, V> Collection<V> allValues(IgnitePredicate<Cache.Entry<K, V>>[] 
filter) {
         checkWeakQueue();
 
         return new Values<>(this, filter);
@@ -482,8 +484,12 @@ public class GridCacheConcurrentMap<K, V> {
      * @return Triple where the first element is current entry associated with 
the key,
      *      the second is created entry and the third is doomed (all may be 
null).
      */
-    public GridTriple<GridCacheMapEntry<K, V>> putEntryIfObsoleteOrAbsent(long 
topVer, K key, @Nullable V val,
-        long ttl, boolean create) {
+    public GridTriple<GridCacheMapEntry> putEntryIfObsoleteOrAbsent(long 
topVer,
+        KeyCacheObject key,
+        @Nullable CacheObject val,
+        long ttl,
+        boolean create)
+    {
         assert key != null;
 
         checkWeakQueue();
@@ -561,7 +567,7 @@ public class GridCacheConcurrentMap<K, V> {
      * @return Set of the mappings contained in this map.
      */
     @SuppressWarnings({"unchecked"})
-    public Set<Cache.Entry<K, V>> entries(IgnitePredicate<Cache.Entry<K, 
V>>... filter) {
+    public <K, V> Set<Cache.Entry<K, V>> 
entries(IgnitePredicate<Cache.Entry<K, V>>... filter) {
         checkWeakQueue();
 
         return new EntrySet<>(this, filter);
@@ -574,7 +580,7 @@ public class GridCacheConcurrentMap<K, V> {
      * @return Set of the mappings contained in this map.
      */
     @SuppressWarnings({"unchecked"})
-    public Set<Cache.Entry<K, V>> entriesx(IgnitePredicate<Cache.Entry<K, 
V>>... filter) {
+    public <K, V> Set<Cache.Entry<K, V>> 
entriesx(IgnitePredicate<Cache.Entry<K, V>>... filter) {
         checkWeakQueue();
 
         return new EntrySet<>(this, filter, true);
@@ -585,10 +591,10 @@ public class GridCacheConcurrentMap<K, V> {
      *
      * @return Set of the mappings contained in this map.
      */
-    public Set<GridCacheEntryEx<K, V>> entries0() {
+    public Set<GridCacheEntryEx> entries0() {
         checkWeakQueue();
 
-        return new Set0<>(this, GridCacheConcurrentMap.<K, V>nonInternal());
+        return new Set0<>(this, GridCacheConcurrentMap.nonInternal());
     }
 
     /**
@@ -598,10 +604,10 @@ public class GridCacheConcurrentMap<K, V> {
      * @param totalCnt Maximum modulo.
      * @return Striped entry iterator.
      */
-    public Iterator<GridCacheEntryEx<K, V>> stripedEntryIterator(int id, int 
totalCnt) {
+    public Iterator<GridCacheEntryEx> stripedEntryIterator(int id, int 
totalCnt) {
         checkWeakQueue();
 
-        return new Iterator0<>(this, false, GridCacheConcurrentMap.<K, 
V>nonInternal(), id, totalCnt);
+        return new Iterator0<>(this, false, 
GridCacheConcurrentMap.nonInternal(), id, totalCnt);
     }
 
     /**
@@ -609,10 +615,10 @@ public class GridCacheConcurrentMap<K, V> {
      *
      * @return All internal entry set, including {@link GridCacheInternal} 
entries.
      */
-    public Set<GridCacheEntryEx<K, V>> allEntries0() {
+    public Set<GridCacheEntryEx> allEntries0() {
         checkWeakQueue();
 
-        return new Set0<>(this, CU.<K, V>empty());
+        return new Set0<>(this, CU.empty());
     }
 
     /**
@@ -621,7 +627,7 @@ public class GridCacheConcurrentMap<K, V> {
      * @param filter Filter.
      * @return Set of the keys contained in this map.
      */
-    public Set<K> keySet(IgnitePredicate<Cache.Entry<K, V>>... filter) {
+    public <K, V> Set<K> keySet(IgnitePredicate<Cache.Entry<K, V>>... filter) {
         checkWeakQueue();
 
         return new KeySet<>(this, filter);
@@ -633,7 +639,7 @@ public class GridCacheConcurrentMap<K, V> {
      * @param filter Filter.
      * @return Collection view of the values contained in this map.
      */
-    public Collection<V> values(IgnitePredicate<Cache.Entry<K, V>>... filter) {
+    public <K, V> Collection<V> values(IgnitePredicate<Cache.Entry<K, V>>... 
filter) {
         checkWeakQueue();
 
         return allValues(filter);
@@ -864,11 +870,11 @@ public class GridCacheConcurrentMap<K, V> {
          * @return {@code True} if segment contains value.
          */
         boolean containsKey(Object key, int hash) {
-            SegmentHeader<K, V> hdr = headerForRead();
+            SegmentHeader hdr = headerForRead();
 
             try {
                 if (hdr.size() != 0) {
-                    GridCacheMapEntry<K, V> e = getFirst(hdr.table(), hash);
+                    GridCacheMapEntry e = getFirst(hdr.table(), hash);
 
                     while (e != null) {
                         if (e.hash() == hash && key.equals(e.key))
@@ -894,7 +900,7 @@ public class GridCacheConcurrentMap<K, V> {
          * @return Associated value.
          */
         @SuppressWarnings({"unchecked"})
-        GridCacheMapEntry<K, V> put(K key, int hash, @Nullable V val, long 
topVer, long ttl) {
+        GridCacheMapEntry put(KeyCacheObject key, int hash, @Nullable 
CacheObject val, long topVer, long ttl) {
             lock();
 
             try {
@@ -914,9 +920,9 @@ public class GridCacheConcurrentMap<K, V> {
          * @return Associated value.
          */
         @SuppressWarnings({"unchecked", 
"SynchronizationOnLocalVariableOrMethodParameter"})
-        private GridCacheMapEntry<K, V> put0(K key, int hash, V val, long 
topVer, long ttl) {
+        private GridCacheMapEntry put0(KeyCacheObject key, int hash, 
CacheObject val, long topVer, long ttl) {
             try {
-                SegmentHeader<K, V> hdr = this.hdr;
+                SegmentHeader hdr = this.hdr;
 
                 int c = hdr.size();
 
@@ -928,18 +934,18 @@ public class GridCacheConcurrentMap<K, V> {
 
                 int hdrId = hdr.id();
 
-                GridCacheMapEntry<K, V>[] tab = hdr.table();
+                GridCacheMapEntry[] tab = hdr.table();
 
                 int idx = hash & (tab.length - 1);
 
-                GridCacheMapEntry<K, V> bin = tab[idx];
+                GridCacheMapEntry bin = tab[idx];
 
-                GridCacheMapEntry<K, V> e = bin;
+                GridCacheMapEntry e = bin;
 
                 while (e != null && (e.hash() != hash || !key.equals(e.key)))
                     e = e.next(hdrId);
 
-                GridCacheMapEntry<K, V> retVal;
+                GridCacheMapEntry retVal;
 
                 if (e != null) {
                     retVal = e;
@@ -989,24 +995,29 @@ public class GridCacheConcurrentMap<K, V> {
          *      the second is created entry and the third is doomed (all may 
be null).
          */
         @SuppressWarnings( {"unchecked"})
-        GridTriple<GridCacheMapEntry<K, V>> putIfObsolete(K key, int hash, 
@Nullable V val, long topVer, long ttl,
-            boolean create) {
+        GridTriple<GridCacheMapEntry> putIfObsolete(KeyCacheObject key,
+            int hash,
+            @Nullable CacheObject val,
+            long topVer,
+            long ttl,
+            boolean create)
+        {
             lock();
 
             try {
-                SegmentHeader<K, V> hdr = this.hdr;
+                SegmentHeader hdr = this.hdr;
 
                 int hdrId = hdr.id();
 
-                GridCacheMapEntry<K, V>[] tab = hdr.table();
+                GridCacheMapEntry[] tab = hdr.table();
 
                 int idx = hash & (tab.length - 1);
 
-                GridCacheMapEntry<K, V> bin = tab[idx];
+                GridCacheMapEntry bin = tab[idx];
 
-                GridCacheMapEntry<K, V> cur = null;
-                GridCacheMapEntry<K, V> created = null;
-                GridCacheMapEntry<K, V> doomed = null;
+                GridCacheMapEntry cur = null;
+                GridCacheMapEntry created = null;
+                GridCacheMapEntry doomed = null;
 
                 if (bin == null) {
                     if (create)
@@ -1015,7 +1026,7 @@ public class GridCacheConcurrentMap<K, V> {
                     return new GridTriple<>(cur, created, doomed);
                 }
 
-                GridCacheMapEntry<K, V> e = bin;
+                GridCacheMapEntry e = bin;
 
                 while (e != null && (e.hash() != hash || !key.equals(e.key)))
                     e = e.next(hdrId);
@@ -1045,14 +1056,14 @@ public class GridCacheConcurrentMap<K, V> {
          */
         @SuppressWarnings("unchecked")
         void rehash() {
-            SegmentHeader<K, V> oldHdr = hdr;
+            SegmentHeader oldHdr = hdr;
 
             if (oldHdr.previous() != null && oldHdr.previous().hasReads())
                 return; // Wait for previous header to free up.
 
             int oldId = hdr.id();
 
-            GridCacheMapEntry<K, V>[] oldTbl = oldHdr.table();
+            GridCacheMapEntry[] oldTbl = oldHdr.table();
 
             int oldCap = oldTbl.length;
 
@@ -1072,24 +1083,24 @@ public class GridCacheConcurrentMap<K, V> {
              * reader thread that may be in the midst of traversing table
              * right now.
              */
-            SegmentHeader<K, V> newHdr = new SegmentHeader<>(oldCap << 1, 
oldId + 1, oldHdr);
+            SegmentHeader newHdr = new SegmentHeader(oldCap << 1, oldId + 1, 
oldHdr);
 
             oldHdr.next(newHdr); // Link.
 
             newHdr.size(oldHdr.size());
 
-            GridCacheMapEntry<K, V>[] newTbl = newHdr.table();
+            GridCacheMapEntry[] newTbl = newHdr.table();
 
             threshold = (int)(newTbl.length * loadFactor);
 
             int sizeMask = newTbl.length - 1;
 
-            for (GridCacheMapEntry<K, V> bin1 : oldTbl) {
+            for (GridCacheMapEntry bin1 : oldTbl) {
                 // Relink all nodes.
-                for (GridCacheMapEntry<K, V> e = bin1; e != null; e = 
e.next(oldId)) {
+                for (GridCacheMapEntry e = bin1; e != null; e = e.next(oldId)) 
{
                     int idx = e.hash() & sizeMask;
 
-                    GridCacheMapEntry<K, V> bin2 = newTbl[idx];
+                    GridCacheMapEntry bin2 = newTbl[idx];
 
                     newTbl[idx] = e;
 
@@ -1112,24 +1123,24 @@ public class GridCacheConcurrentMap<K, V> {
          * @return Removed value.
          */
         @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
-        @Nullable GridCacheMapEntry<K, V> remove(Object key, int hash,
-            @Nullable IgnitePredicate<GridCacheMapEntry<K, V>> filter) {
+        @Nullable GridCacheMapEntry remove(Object key, int hash,
+            @Nullable IgnitePredicate<GridCacheMapEntry> filter) {
             lock();
 
             try {
-                SegmentHeader<K, V> hdr = this.hdr;
+                SegmentHeader hdr = this.hdr;
 
-                GridCacheMapEntry<K, V>[] tbl = hdr.table();
+                GridCacheMapEntry[] tbl = hdr.table();
 
                 int idx = hash & (tbl.length - 1);
 
-                GridCacheMapEntry<K, V> bin = tbl[idx];
+                GridCacheMapEntry bin = tbl[idx];
 
                 if (bin == null)
                     return null;
 
-                GridCacheMapEntry<K, V> prev = null;
-                GridCacheMapEntry<K, V> e = bin;
+                GridCacheMapEntry prev = null;
+                GridCacheMapEntry e = bin;
 
                 while (e != null && (e.hash() != hash || !key.equals(e.key))) {
                     prev = e;
@@ -1201,27 +1212,27 @@ public class GridCacheConcurrentMap<K, V> {
         /**
          * @return Random cache map entry from this segment.
          */
-        @Nullable GridCacheMapEntry<K, V> randomEntry() {
-            SegmentHeader<K, V> hdr = headerForRead();
+        @Nullable GridCacheMapEntry randomEntry() {
+            SegmentHeader hdr = headerForRead();
 
             try {
-                GridCacheMapEntry<K, V>[] tbl = hdr.table();
+                GridCacheMapEntry[] tbl = hdr.table();
 
-                Collection<GridCacheMapEntry<K, V>> entries = new 
ArrayList<>(3);
+                Collection<GridCacheMapEntry> entries = new ArrayList<>(3);
 
                 int pubCnt = 0;
 
                 int start = RAND.nextInt(tbl.length);
 
                 for (int i = start; i < start + tbl.length; i++) {
-                    GridCacheMapEntry<K, V> first = tbl[i % tbl.length];
+                    GridCacheMapEntry first = tbl[i % tbl.length];
 
                     if (first == null)
                         continue;
 
                     entries.add(first);
 
-                    for (GridCacheMapEntry<K, V> e = first; e != null; e = 
e.next(hdr.id()))
+                    for (GridCacheMapEntry e = first; e != null; e = 
e.next(hdr.id()))
                         if (!e.isInternal())
                             pubCnt++;
 
@@ -1240,9 +1251,9 @@ public class GridCacheConcurrentMap<K, V> {
 
                 int i = 0;
 
-                GridCacheMapEntry<K, V> retVal = null;
+                GridCacheMapEntry retVal = null;
 
-                for (GridCacheMapEntry<K, V> e : entries) {
+                for (GridCacheMapEntry e : entries) {
                     for (; e != null; e = e.next(hdr.id())) {
                         if (!(e.key instanceof GridCacheInternal)) {
                             // In case desired entry was deleted, we return 
the closest one from left.
@@ -1265,16 +1276,16 @@ public class GridCacheConcurrentMap<K, V> {
          *
          */
         void checkSegmentConsistency() {
-            SegmentHeader<K, V> hdr = this.hdr;
+            SegmentHeader hdr = this.hdr;
 
-            GridCacheMapEntry<K, V>[] tbl = hdr.table();
+            GridCacheMapEntry[] tbl = hdr.table();
 
             int cnt = 0;
             int pubCnt = 0;
 
-            for (GridCacheMapEntry<K, V> b : tbl) {
+            for (GridCacheMapEntry b : tbl) {
                 if (b != null) {
-                    GridCacheMapEntry<K, V> e = b;
+                    GridCacheMapEntry e = b;
 
                     assert e != null;
 
@@ -1298,9 +1309,9 @@ public class GridCacheConcurrentMap<K, V> {
     /**
      * Segment header.
      */
-    private static class SegmentHeader<K, V> {
+    private static class SegmentHeader {
         /** Entry table. */
-        private final GridCacheMapEntry<K, V>[] tbl;
+        private final GridCacheMapEntry[] tbl;
 
         /** Id for rehash. */
         private final int id;
@@ -1309,10 +1320,10 @@ public class GridCacheConcurrentMap<K, V> {
         private final LongAdder reads = new LongAdder();
 
         /** */
-        private volatile SegmentHeader<K, V> prev;
+        private volatile SegmentHeader prev;
 
         /** */
-        private volatile SegmentHeader<K, V> next;
+        private volatile SegmentHeader next;
 
         /** The number of elements in this segment's region. */
         private volatile int size;
@@ -1329,7 +1340,7 @@ public class GridCacheConcurrentMap<K, V> {
          * @param prev Previous header.
          */
         @SuppressWarnings("unchecked")
-        private SegmentHeader(int size, int id, @Nullable SegmentHeader<K, V> 
prev) {
+        private SegmentHeader(int size, int id, @Nullable SegmentHeader prev) {
             tbl = new GridCacheMapEntry[size];
 
             assert id >= 0;
@@ -1366,10 +1377,10 @@ public class GridCacheConcurrentMap<K, V> {
 
                 // Clean up.
                 if (leftReads == 0 && cleaned.compareAndSet(false, true)) {
-                    for (GridCacheMapEntry<K, V> bin : tbl) {
+                    for (GridCacheMapEntry bin : tbl) {
                         if (bin != null) {
-                            for (GridCacheMapEntry<K, V> e = bin; e != null; ) 
{
-                                GridCacheMapEntry<K, V> next = e.next(id);
+                            for (GridCacheMapEntry e = bin; e != null; ) {
+                                GridCacheMapEntry next = e.next(id);
 
                                 e.next(id, null); // Unlink.
 
@@ -1517,16 +1528,16 @@ public class GridCacheConcurrentMap<K, V> {
         private int nextTblIdx;
 
         /** Segment header. */
-        private SegmentHeader<K, V> curSegHdr;
+        private SegmentHeader curSegHdr;
 
         /** */
-        private GridCacheMapEntry<K,V>[] curTbl;
+        private GridCacheMapEntry[] curTbl;
 
         /** */
-        private GridCacheMapEntry<K, V> nextEntry;
+        private GridCacheMapEntry nextEntry;
 
         /** Next entry to return. */
-        private GridCacheMapEntry<K, V> next;
+        private GridCacheMapEntry next;
 
         /** Next value. */
         private V nextVal;
@@ -1538,13 +1549,13 @@ public class GridCacheConcurrentMap<K, V> {
         private boolean isVal;
 
         /** Current entry. */
-        private GridCacheMapEntry<K, V> cur;
+        private GridCacheMapEntry cur;
 
         /** Iterator filter. */
         private IgnitePredicate<Cache.Entry<K, V>>[] filter;
 
         /** Outer cache map. */
-        private GridCacheConcurrentMap<K, V> map;
+        private GridCacheConcurrentMap map;
 
         /** Cache context. */
         private GridCacheContext<K, V> ctx;
@@ -1573,7 +1584,7 @@ public class GridCacheConcurrentMap<K, V> {
          * @param totalCnt Total count of iterators.
          */
         @SuppressWarnings({"unchecked"})
-        Iterator0(GridCacheConcurrentMap<K, V> map, boolean isVal,
+        Iterator0(GridCacheConcurrentMap map, boolean isVal,
             IgnitePredicate<Cache.Entry<K, V>>[] filter, int id, int totalCnt) 
{
             this.filter = filter;
             this.isVal = isVal;
@@ -2078,9 +2089,9 @@ public class GridCacheConcurrentMap<K, V> {
          * @param clone Clone flag.
          */
         private ValueIterator(
-            GridCacheConcurrentMap<K, V> map,
+            GridCacheConcurrentMap map,
             IgnitePredicate<Cache.Entry<K, V>>[] filter,
-            GridCacheContext<K, V> ctx,
+            GridCacheContext ctx,
             boolean clone) {
             it = new Iterator0<>(map, true, filter, -1, -1);
 
@@ -2150,7 +2161,7 @@ public class GridCacheConcurrentMap<K, V> {
          * @param map Cache map.
          * @param filter Filter.
          */
-        private KeyIterator(GridCacheConcurrentMap<K, V> map, 
IgnitePredicate<Cache.Entry<K, V>>[] filter) {
+        private KeyIterator(GridCacheConcurrentMap map, 
IgnitePredicate<Cache.Entry<K, V>>[] filter) {
             it = new Iterator0<>(map, false, filter, -1, -1);
         }
 
@@ -2161,7 +2172,7 @@ public class GridCacheConcurrentMap<K, V> {
 
         /** {@inheritDoc} */
         @Override public K next() {
-            return it.next().key();
+            return it.next().key().value();
         }
 
         /** {@inheritDoc} */
@@ -2202,7 +2213,7 @@ public class GridCacheConcurrentMap<K, V> {
          * @param map Base map.
          * @param filter Key filter.
          */
-        private KeySet(GridCacheConcurrentMap<K, V> map, 
IgnitePredicate<Cache.Entry<K, V>>[] filter) {
+        private KeySet(GridCacheConcurrentMap map, 
IgnitePredicate<Cache.Entry<K, V>>[] filter) {
             assert map != null;
 
             set = new Set0<>(map, nonInternal(filter));
@@ -2270,7 +2281,7 @@ public class GridCacheConcurrentMap<K, V> {
          * @param map Base map.
          * @param filter Value filter.
          */
-        private Values(GridCacheConcurrentMap<K, V> map, 
IgnitePredicate<Cache.Entry<K, V>>[] filter) {
+        private Values(GridCacheConcurrentMap map, 
IgnitePredicate<Cache.Entry<K, V>>[] filter) {
             assert map != null;
 
             set = new Set0<>(map, nonInternal(filter));
@@ -2330,7 +2341,7 @@ public class GridCacheConcurrentMap<K, V> {
          * @param map Base map.
          * @param filter Key filter.
          */
-        private EntrySet(GridCacheConcurrentMap<K, V> map, 
IgnitePredicate<Cache.Entry<K, V>>[] filter) {
+        private EntrySet(GridCacheConcurrentMap map, 
IgnitePredicate<Cache.Entry<K, V>>[] filter) {
             this(map, filter, false);
         }
 
@@ -2339,7 +2350,7 @@ public class GridCacheConcurrentMap<K, V> {
          * @param filter Key filter.
          * @param internal Whether to allow internal entries.
          */
-        private EntrySet(GridCacheConcurrentMap<K, V> map, 
IgnitePredicate<Cache.Entry<K, V>>[] filter,
+        private EntrySet(GridCacheConcurrentMap map, 
IgnitePredicate<Cache.Entry<K, V>>[] filter,
             boolean internal) {
             assert map != null;
 
@@ -2365,7 +2376,7 @@ public class GridCacheConcurrentMap<K, V> {
         @SuppressWarnings({"unchecked"})
         @Override public boolean contains(Object o) {
             if (o instanceof CacheEntryImpl) {
-                GridCacheEntryEx<K, V> unwrapped = 
set.map.getEntry(((CacheEntryImpl)o).getKey());
+                GridCacheEntryEx unwrapped = 
set.map.getEntry(((CacheEntryImpl)o).getKey());
 
                 return unwrapped != null && set.contains(unwrapped);
             }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b7ea910f/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 3ec013c..27db18f 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
@@ -605,8 +605,8 @@ public class GridCacheContext<K, V> implements 
Externalizable {
      * @param key Key to construct tx key for.
      * @return Transaction key.
      */
-    public IgniteTxKey<K> txKey(K key) {
-        return new IgniteTxKey<>(key, cacheId);
+    public IgniteTxKey txKey(KeyCacheObject key) {
+        return new IgniteTxKey(key, cacheId);
     }
 
     /**
@@ -1760,6 +1760,21 @@ public class GridCacheContext<K, V> implements 
Externalizable {
     public Object unwrapPortableIfNeeded(Object o, boolean keepPortable) {
         return serMgr.unwrapPortableIfNeeded(o, keepPortable);
     }
+    /**
+     * @param obj Object.
+     * @return Cache object.
+     */
+    @Nullable public CacheObject toCacheObject(@Nullable Object obj) {
+        return portable().toCacheObject(obj);
+    }
+
+    /**
+     * @param obj Object.
+     * @return Cache object.
+     */
+    @Nullable public KeyCacheObject toCacheKeyObject(@Nullable Object obj) {
+        return portable().toCacheKeyObject(obj);
+    }
 
     /**
      * Nulling references to potentially leak-prone objects.

Reply via email to