ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [28/50] [abbrv] ignite git commit: IGNITE-2649 - Ignition.localIgnite() unreliable under Gateways and cause wrong components deserialization.
Date Wed, 24 Aug 2016 14:04:51 GMT
http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java
index 0c3cf0e..b8ab83c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java
@@ -71,6 +71,7 @@ import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteFuture;
 import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.MarshallerUtils;
 import org.apache.ignite.plugin.security.SecurityPermission;
 import org.jetbrains.annotations.Nullable;
 import org.jsr166.LongAdder8;
@@ -913,7 +914,7 @@ public class GridTaskProcessor extends GridProcessorAdapter {
                     GridTaskSessionRequest req = new GridTaskSessionRequest(
                         ses.getId(),
                         null,
-                        loc ? null : marsh.marshal(attrs),
+                        loc ? null : MarshallerUtils.marshal(marsh, attrs, ctx.gridName()),
                         attrs);
 
                     // Make sure to go through IO manager always, since order
@@ -1029,8 +1030,8 @@ public class GridTaskProcessor extends GridProcessorAdapter {
             boolean loc = ctx.localNodeId().equals(nodeId) && !ctx.config().isMarshalLocalJobs();
 
             Map<?, ?> attrs = loc ? msg.getAttributes() :
-                marsh.<Map<?, ?>>unmarshal(msg.getAttributesBytes(),
-                    U.resolveClassLoader(task.getTask().getClass().getClassLoader(), ctx.config()));
+                MarshallerUtils.<Map<?, ?>>unmarshal(marsh, msg.getAttributesBytes(),
+                    U.resolveClassLoader(task.getTask().getClass().getClassLoader(), ctx.config()), ctx.gridName());
 
             GridTaskSessionImpl ses = task.getSession();
 
@@ -1305,7 +1306,8 @@ public class GridTaskProcessor extends GridProcessorAdapter {
                     if (topic == null) {
                         assert req.topicBytes() != null;
 
-                        topic = marsh.unmarshal(req.topicBytes(), U.resolveClassLoader(ctx.config()));
+                        topic = MarshallerUtils.unmarshal(marsh, req.topicBytes(),
+                            U.resolveClassLoader(ctx.config()), ctx.gridName());
                     }
 
                     boolean loc = ctx.localNodeId().equals(nodeId);
@@ -1313,7 +1315,7 @@ public class GridTaskProcessor extends GridProcessorAdapter {
                     ctx.io().send(nodeId, topic,
                         new GridJobSiblingsResponse(
                             loc ? siblings : null,
-                            loc ? null : marsh.marshal(siblings)),
+                            loc ? null : MarshallerUtils.marshal(marsh, siblings, ctx.gridName())),
                         SYSTEM_POOL);
                 }
                 catch (IgniteCheckedException e) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java
index 8ce005a..fd0881d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java
@@ -81,6 +81,7 @@ import org.apache.ignite.internal.visor.util.VisorClusterGroupEmptyException;
 import org.apache.ignite.lang.IgniteInClosure;
 import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.MarshallerUtils;
 import org.apache.ignite.resources.TaskContinuousMapperResource;
 import org.jetbrains.annotations.Nullable;
 import org.jsr166.ConcurrentLinkedDeque8;
@@ -774,16 +775,16 @@ class GridTaskWorker<T, R> extends GridWorker implements GridTimeoutObject {
                     try {
                         boolean loc = ctx.localNodeId().equals(res.getNodeId()) && !ctx.config().isMarshalLocalJobs();
 
-                        Object res0 = loc ? res.getJobResult() : marsh.unmarshal(res.getJobResultBytes(),
-                            U.resolveClassLoader(clsLdr, ctx.config()));
+                        Object res0 = loc ? res.getJobResult() : MarshallerUtils.unmarshal(marsh,
+                            res.getJobResultBytes(), U.resolveClassLoader(clsLdr, ctx.config()), ctx.gridName());
 
                         IgniteException ex = loc ? res.getException() :
-                            marsh.<IgniteException>unmarshal(res.getExceptionBytes(),
-                                U.resolveClassLoader(clsLdr, ctx.config()));
+                            MarshallerUtils.<IgniteException>unmarshal(marsh, res.getExceptionBytes(),
+                                U.resolveClassLoader(clsLdr, ctx.config()), ctx.gridName());
 
                         Map<Object, Object> attrs = loc ? res.getJobAttributes() :
-                            marsh.<Map<Object, Object>>unmarshal(res.getJobAttributesBytes(),
-                                U.resolveClassLoader(clsLdr, ctx.config()));
+                            MarshallerUtils.<Map<Object, Object>>unmarshal(marsh, res.getJobAttributesBytes(),
+                                U.resolveClassLoader(clsLdr, ctx.config()), ctx.gridName());
 
                         jobRes.onResponse(res0, ex, attrs, res.isCancelled());
 
@@ -1253,16 +1254,16 @@ class GridTaskWorker<T, R> extends GridWorker implements GridTimeoutObject {
                         ses.getTaskName(),
                         ses.getUserVersion(),
                         ses.getTaskClassName(),
-                        loc ? null : marsh.marshal(res.getJob()),
+                        loc ? null : MarshallerUtils.marshal(marsh, res.getJob(), ctx.gridName()),
                         loc ? res.getJob() : null,
                         ses.getStartTime(),
                         timeout,
                         ses.getTopology(),
-                        loc ? null : marsh.marshal(ses.getJobSiblings()),
+                        loc ? null : MarshallerUtils.marshal(marsh, ses.getJobSiblings(), ctx.gridName()),
                         loc ? ses.getJobSiblings() : null,
-                        loc ? null : marsh.marshal(sesAttrs),
+                        loc ? null : MarshallerUtils.marshal(marsh, sesAttrs, ctx.gridName()),
                         loc ? sesAttrs : null,
-                        loc ? null : marsh.marshal(jobAttrs),
+                        loc ? null : MarshallerUtils.marshal(marsh, jobAttrs, ctx.gridName()),
                         loc ? jobAttrs : null,
                         ses.getCheckpointSpi(),
                         dep.classLoaderId(),

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/IpcToNioAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/IpcToNioAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/IpcToNioAdapter.java
index 6820dc7..56d0c30 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/IpcToNioAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/IpcToNioAdapter.java
@@ -25,6 +25,7 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicReference;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.util.nio.GridNioFilter;
 import org.apache.ignite.internal.util.nio.GridNioFilterAdapter;
 import org.apache.ignite.internal.util.nio.GridNioFilterChain;
@@ -73,10 +74,12 @@ public class IpcToNioAdapter<T> {
      * @param endp Endpoint.
      * @param lsnr Listener.
      * @param writerFactory Writer factory.
+     * @param igniteCfg Ignite config.
      * @param filters Filters.
      */
     public IpcToNioAdapter(GridNioMetricsListener metricsLsnr, IgniteLogger log, IpcEndpoint endp,
-        GridNioServerListener<T> lsnr, GridNioMessageWriterFactory writerFactory, GridNioFilter... filters) {
+                           GridNioServerListener<T> lsnr, GridNioMessageWriterFactory writerFactory,
+                           IgniteConfiguration igniteCfg, GridNioFilter... filters) {
         assert metricsLsnr != null;
 
         this.metricsLsnr = metricsLsnr;
@@ -84,7 +87,7 @@ public class IpcToNioAdapter<T> {
         this.writerFactory = writerFactory;
 
         chain = new GridNioFilterChain<>(log, lsnr, new HeadFilter(), filters);
-        ses = new GridNioSessionImpl(chain, null, null, true);
+        ses = new GridNioSessionImpl(chain, null, null, true, igniteCfg);
 
         writeBuf = ByteBuffer.allocate(8 << 10);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java
index ac55a14..3a2a98f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioServer.java
@@ -47,6 +47,7 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.configuration.ConnectorConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.util.GridConcurrentHashSet;
@@ -196,6 +197,9 @@ public class GridNioServer<T> {
         }
     }
 
+    /** Grid name */
+    private String gridName;
+
     /**
      * @param addr Address.
      * @param port Port.
@@ -260,6 +264,7 @@ public class GridNioServer<T> {
         this.sockSndBuf = sockSndBuf;
         this.sndQueueLimit = sndQueueLimit;
         this.msgQueueLsnr = msgQueueLsnr;
+        this.gridName = gridName;
 
         filterChain = new GridNioFilterChain<>(log, lsnr, new HeadFilter(), filters);
 
@@ -1630,6 +1635,10 @@ public class GridNioServer<T> {
                     readBuf.order(order);
                 }
 
+                final IgniteConfiguration cfg = new IgniteConfiguration(); // TODO provide real config
+
+                cfg.setGridName(gridName);
+
                 final GridSelectorNioSessionImpl ses = new GridSelectorNioSessionImpl(
                     log,
                     idx,
@@ -1639,7 +1648,8 @@ public class GridNioServer<T> {
                     req.accepted(),
                     sndQueueLimit,
                     writeBuf,
-                    readBuf);
+                    readBuf,
+                    cfg);
 
                 Map<Integer, ?> meta = req.meta();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioSession.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioSession.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioSession.java
index e4a7225..edc9aa6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioSession.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioSession.java
@@ -18,6 +18,8 @@
 package org.apache.ignite.internal.util.nio;
 
 import java.net.InetSocketAddress;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -164,4 +166,9 @@ public interface GridNioSession {
      * @return Recovery descriptor if recovery is supported, {@code null otherwise.}
      */
     @Nullable public GridNioRecoveryDescriptor recoveryDescriptor();
+
+    /**
+     * @return Ignite configuration.
+     */
+    public IgniteConfiguration igniteConfiguration();
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioSessionImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioSessionImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioSessionImpl.java
index 0bcfe64..b1465c6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioSessionImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridNioSessionImpl.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.util.nio;
 import java.net.InetSocketAddress;
 import java.util.concurrent.atomic.AtomicLong;
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.jetbrains.annotations.Nullable;
@@ -69,22 +70,28 @@ public class GridNioSessionImpl implements GridNioSession {
     /** Accepted flag. */
     private final boolean accepted;
 
+    /** Ignite configuration. */
+    private IgniteConfiguration igniteCfg;
+
     /**
      * @param filterChain Chain.
      * @param locAddr Local address.
      * @param rmtAddr Remote address.
+     * @param igniteCfg Ignite config.
      * @param accepted {@code True} if this session was initiated from remote host.
      */
     public GridNioSessionImpl(
         GridNioFilterChain filterChain,
         @Nullable InetSocketAddress locAddr,
         @Nullable InetSocketAddress rmtAddr,
-        boolean accepted
+        boolean accepted,
+        IgniteConfiguration igniteCfg
     ) {
         this.filterChain = filterChain;
         this.locAddr = locAddr;
         this.rmtAddr = rmtAddr;
         this.accepted = accepted;
+        this.igniteCfg = igniteCfg;
 
         long now = U.currentTimeMillis();
 
@@ -309,4 +316,9 @@ public class GridNioSessionImpl implements GridNioSession {
     @Override public String toString() {
         return S.toString(GridNioSessionImpl.class, this);
     }
+
+    /** {@inheritDoc} */
+    @Override public IgniteConfiguration igniteConfiguration() {
+        return igniteCfg;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridSelectorNioSessionImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridSelectorNioSessionImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridSelectorNioSessionImpl.java
index 360b3d4..042eaee 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridSelectorNioSessionImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridSelectorNioSessionImpl.java
@@ -24,6 +24,7 @@ import java.util.Collection;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.atomic.AtomicInteger;
 import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.internal.LT;
 import org.apache.ignite.internal.util.typedef.internal.S;
@@ -77,6 +78,7 @@ class GridSelectorNioSessionImpl extends GridNioSessionImpl {
      * @param sndQueueLimit Send queue limit.
      * @param writeBuf Write buffer.
      * @param readBuf Read buffer.
+     * @param igniteCfg Ignite config.
      */
     GridSelectorNioSessionImpl(
         IgniteLogger log,
@@ -87,9 +89,10 @@ class GridSelectorNioSessionImpl extends GridNioSessionImpl {
         boolean accepted,
         int sndQueueLimit,
         @Nullable ByteBuffer writeBuf,
-        @Nullable ByteBuffer readBuf
+        @Nullable ByteBuffer readBuf,
+        IgniteConfiguration igniteCfg
     ) {
-        super(filterChain, locAddr, rmtAddr, accepted);
+        super(filterChain, locAddr, rmtAddr, accepted, igniteCfg);
 
         assert selectorIdx >= 0;
         assert sndQueueLimit >= 0;

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/marshaller/MarshallerUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/MarshallerUtils.java b/modules/core/src/main/java/org/apache/ignite/marshaller/MarshallerUtils.java
new file mode 100644
index 0000000..b6808e9
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/MarshallerUtils.java
@@ -0,0 +1,241 @@
+/*
+ * 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.marshaller;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgnitionEx;
+import org.apache.ignite.internal.client.marshaller.GridClientMarshaller;
+import org.apache.ignite.internal.util.typedef.F;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+
+/**
+ * Util class that sets and discards thread local
+ * ignite configuration in {@link IgnitionEx} class.
+ */
+public final class MarshallerUtils {
+    /**
+     *
+     */
+    private MarshallerUtils() {
+    }
+
+    /**
+     *
+     * @param marshaller marshaller.
+     * @param obj object.
+     * @param out output stream.
+     * @param gridName Grid name.
+     * @throws IgniteCheckedException
+     */
+    public static void marshal(final Marshaller marshaller, final @Nullable Object obj,
+        final OutputStream out, final String gridName) throws IgniteCheckedException {
+        final String name = setGridName(gridName);
+
+        try {
+            marshaller.marshal(obj, out);
+        } finally {
+            restoreGridName(name);
+        }
+    }
+
+    /**
+     *
+     * @param marshaller marshaller.
+     * @param obj object.
+     * @param igniteCfg ignite config.
+     * @return serialized.
+     * @throws IgniteCheckedException
+     */
+    public static byte[] marshal(final Marshaller marshaller, @Nullable Object obj,
+        final IgniteConfiguration igniteCfg) throws IgniteCheckedException {
+        return marshal(marshaller, obj, igniteCfg.getGridName());
+    }
+
+    /**
+     *
+     * @param marshaller marshaller.
+     * @param obj object.
+     * @param gridName Grid name.
+     * @return serialized.
+     * @throws IgniteCheckedException
+     */
+    public static byte[] marshal(final Marshaller marshaller, @Nullable Object obj,
+        final String gridName) throws IgniteCheckedException {
+        final String name = setGridName(gridName);
+
+        try {
+            return marshaller.marshal(obj);
+        } finally {
+            restoreGridName(name);
+        }
+    }
+
+    /**
+     *
+     * @param marshaller marshaller.
+     * @param in input stream.
+     * @param clsLdr class loader.
+     * @param gridName Grid name.
+     * @param <T> target type.
+     * @return deserialized object.
+     * @throws IgniteCheckedException
+     */
+    public static <T> T unmarshal(final Marshaller marshaller, InputStream in, @Nullable ClassLoader clsLdr,
+        final String gridName) throws IgniteCheckedException {
+        final String name = setGridName(gridName);
+
+        try {
+            return marshaller.unmarshal(in, clsLdr);
+        } finally {
+            restoreGridName(name);
+        }
+    }
+
+    /**
+     *
+     * @param marshaller marshaller.
+     * @param arr byte array.
+     * @param clsLdr class loader.
+     * @param gridName Grid name.
+     * @param <T> target type
+     * @return deserialized object.
+     * @throws IgniteCheckedException
+     */
+    public static <T> T unmarshal(final Marshaller marshaller, byte[] arr, @Nullable ClassLoader clsLdr,
+        final String gridName) throws IgniteCheckedException {
+        final String name = setGridName(gridName);
+
+        try {
+            return marshaller.unmarshal(arr, clsLdr);
+        } finally {
+            restoreGridName(name);
+        }
+    }
+
+    /**
+     *
+     * @param marshaller marshaller.
+     * @param arr byte array.
+     * @param clsLdr class loader.
+     * @param igniteCfg ignite config.
+     * @param <T> target type
+     * @return deserialized object.
+     * @throws IgniteCheckedException
+     */
+    public static <T> T unmarshal(final Marshaller marshaller, byte[] arr, @Nullable ClassLoader clsLdr,
+        final IgniteConfiguration igniteCfg) throws IgniteCheckedException {
+        return unmarshal(marshaller, arr, clsLdr, igniteCfg.getGridName());
+    }
+
+    /**
+     *
+     * @param marshaller marshaller.
+     * @param obj object
+     * @param clsLdr class loader.
+     * @param gridName Grid name.
+     * @param <T> target type.
+     * @return deserialized value.
+     * @throws IgniteCheckedException
+     */
+    public static <T> T clone(final Marshaller marshaller, T obj, @Nullable ClassLoader clsLdr,
+        final String gridName) throws IgniteCheckedException {
+        final String name = setGridName(gridName);
+
+        try {
+            return marshaller.unmarshal(marshaller.marshal(obj), clsLdr);
+        } finally {
+            restoreGridName(name);
+        }
+    }
+
+    /**
+     *
+     * @param gridMarshaller grid marshaller.
+     * @param obj object.
+     * @param off offset.
+     * @param gridName ignite config.
+     * @return serialized data.
+     * @throws IOException
+     */
+    public static ByteBuffer marshal(GridClientMarshaller gridMarshaller, Object obj, int off,
+        String gridName) throws IOException {
+        final String name = setGridName(gridName);
+
+        try {
+            return gridMarshaller.marshal(obj, off);
+        } finally {
+            restoreGridName(name);
+        }
+    }
+
+    /**
+     *
+     * @param gridMarshaller grid marshaller.
+     * @param bytes byte array.
+     * @param gridName ignite config.
+     * @param <T> target type.
+     * @return deserialized value.
+     * @throws IOException
+     */
+    public static <T> T unmarshal(GridClientMarshaller gridMarshaller, byte[] bytes,
+        String gridName) throws IOException {
+        final String name = setGridName(gridName);
+
+        try {
+            return gridMarshaller.unmarshal(bytes);
+        } finally {
+            restoreGridName(name);
+        }
+    }
+
+    /**
+     * @param name Grid name.
+     * @return Old grid name.
+     */
+    private static String setGridName(final String name) {
+        final String gridName = IgnitionEx.getGridNameThreadLocal();
+
+        if (!F.eq(name, gridName))
+            IgnitionEx.setGridNameThreadLocal(name);
+
+        return gridName;
+    }
+
+    /**
+     * @param name Grid name.
+     */
+    private static void restoreGridName(final String name) {
+        IgnitionEx.setGridNameThreadLocal(name);
+    }
+
+    /**
+     *
+     * @param kernalCtx kernal context.
+     * @return ignite config or null.
+     */
+    private static IgniteConfiguration getConfig(final @Nullable GridKernalContext kernalCtx) {
+        return kernalCtx == null ? null : kernalCtx.config();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsCheckpointSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsCheckpointSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsCheckpointSpi.java
index 36a4ea6..7a12582 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsCheckpointSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsCheckpointSpi.java
@@ -323,7 +323,7 @@ public class SharedFsCheckpointSpi extends IgniteSpiAdapter implements Checkpoin
                         log.debug("Checking checkpoint file: " + file.getAbsolutePath());
 
                     try {
-                        SharedFsCheckpointData data = SharedFsUtils.read(file, marsh, log);
+                        SharedFsCheckpointData data = SharedFsUtils.read(file, marsh, log, ignite.configuration());
 
                         if (data.getHost().equals(host)) {
                             files.put(file, new SharedFsTimeData(data.getExpireTime(), file.lastModified(),
@@ -386,7 +386,7 @@ public class SharedFsCheckpointSpi extends IgniteSpiAdapter implements Checkpoin
 
         if (file.exists())
             try {
-                SharedFsCheckpointData data = SharedFsUtils.read(file, marsh, log);
+                SharedFsCheckpointData data = SharedFsUtils.read(file, marsh, log, ignite.configuration());
 
                 return data != null ?
                     data.getExpireTime() == 0 || data.getExpireTime() > U.currentTimeMillis() ?
@@ -434,7 +434,7 @@ public class SharedFsCheckpointSpi extends IgniteSpiAdapter implements Checkpoin
 
             try {
                 SharedFsUtils.write(file, new SharedFsCheckpointData(state, expireTime, host, key),
-                    marsh, log);
+                    marsh, log, ignite.configuration());
             }
             catch (IOException e) {
                 // Select next shared directory if exists, otherwise throw exception

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsTimeoutTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsTimeoutTask.java b/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsTimeoutTask.java
index 3cf11f8..07619c0 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsTimeoutTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsTimeoutTask.java
@@ -25,6 +25,7 @@ import java.util.HashSet;
 import java.util.Map;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.marshaller.Marshaller;
@@ -116,8 +117,13 @@ class SharedFsTimeoutTask extends IgniteSpiThread {
                     SharedFsTimeData timeData = entry.getValue();
 
                     try {
-                        if (timeData.getLastAccessTime() != file.lastModified())
-                            timeData.setExpireTime(SharedFsUtils.read(file, marshaller, log).getExpireTime());
+                        if (timeData.getLastAccessTime() != file.lastModified()) {
+                            final IgniteConfiguration igniteCfg = new IgniteConfiguration();
+
+                            igniteCfg.setGridName(getGridName());
+
+                            timeData.setExpireTime(SharedFsUtils.read(file, marshaller, log, igniteCfg).getExpireTime());
+                        }
                     }
                     catch (IgniteCheckedException e) {
                         U.error(log, "Failed to marshal/unmarshal in checkpoint file: " + file.getAbsolutePath(), e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsUtils.java b/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsUtils.java
index b1698fa..da55499 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsUtils.java
@@ -25,8 +25,10 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.MarshallerUtils;
 
 /**
  * Utility class that helps to manage files. It provides read/write
@@ -52,7 +54,7 @@ final class SharedFsUtils {
      *    to {@link SharedFsCheckpointData} object.
      * @throws IOException Thrown if file read error occurred.
      */
-    static SharedFsCheckpointData read(File file, Marshaller m, IgniteLogger log)
+    static SharedFsCheckpointData read(File file, Marshaller m, IgniteLogger log, final IgniteConfiguration igniteCfg)
         throws IOException, IgniteCheckedException {
         assert file != null;
         assert m != null;
@@ -61,7 +63,7 @@ final class SharedFsUtils {
         InputStream in = new FileInputStream(file);
 
         try {
-            return (SharedFsCheckpointData)m.unmarshal(in, U.gridClassLoader());
+            return (SharedFsCheckpointData) MarshallerUtils.unmarshal(m, in, U.gridClassLoader(), igniteCfg.getGridName());
         }
         finally {
             U.close(in, log);
@@ -76,11 +78,12 @@ final class SharedFsUtils {
      * @param data Checkpoint data.
      * @param m Grid marshaller.
      * @param log Messages logger.
+     * @param igniteCfg Ignite config.
      * @throws IgniteCheckedException Thrown if data could not be marshalled.
      * @throws IOException Thrown if file write operation failed.
      */
-    static void write(File file, SharedFsCheckpointData data, Marshaller m, IgniteLogger log)
-        throws IOException, IgniteCheckedException {
+    static void write(File file, SharedFsCheckpointData data, Marshaller m, IgniteLogger log,
+        final IgniteConfiguration igniteCfg) throws IOException, IgniteCheckedException {
         assert file != null;
         assert m != null;
         assert data != null;
@@ -91,7 +94,7 @@ final class SharedFsUtils {
         try {
             out = new FileOutputStream(file);
 
-            m.marshal(data, out);
+            MarshallerUtils.marshal(m, data, out, igniteCfg.getGridName());
         }
         finally {
             U.close(out, log);

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
index ed29b59..8e78352 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
@@ -3013,6 +3013,7 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter
                     endpoint,
                     srvLsnr,
                     writerFactory,
+                    ignite.configuration(),
                     new GridNioCodecFilter(new GridDirectParser(msgFactory, readerFactory), log, true),
                     new GridConnectionBytesVerifyFilter(log)
                 );

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ClientImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ClientImpl.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ClientImpl.java
index 79e58b1..f383fe7 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ClientImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ClientImpl.java
@@ -64,6 +64,7 @@ import org.apache.ignite.internal.util.typedef.internal.LT;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteInClosure;
 import org.apache.ignite.lang.IgniteUuid;
+import org.apache.ignite.marshaller.MarshallerUtils;
 import org.apache.ignite.spi.IgniteSpiContext;
 import org.apache.ignite.spi.IgniteSpiException;
 import org.apache.ignite.spi.IgniteSpiOperationTimeoutHelper;
@@ -430,7 +431,7 @@ class ClientImpl extends TcpDiscoveryImpl {
 
         try {
             sockWriter.sendMessage(new TcpDiscoveryCustomEventMessage(getLocalNodeId(), evt,
-                spi.marsh.marshal(evt)));
+                MarshallerUtils.marshal(spi.marsh, evt, spi.ignite().configuration())));
         }
         catch (IgniteCheckedException e) {
             throw new IgniteSpiException("Failed to marshal custom event: " + evt, e);
@@ -684,7 +685,8 @@ class ClientImpl extends TcpDiscoveryImpl {
             Map<String, Object> attrs = new HashMap<>(node.getAttributes());
 
             attrs.put(IgniteNodeAttributes.ATTR_SECURITY_CREDENTIALS,
-                spi.marsh.marshal(attrs.get(IgniteNodeAttributes.ATTR_SECURITY_CREDENTIALS)));
+                    MarshallerUtils.marshal(spi.marsh, attrs.get(IgniteNodeAttributes.ATTR_SECURITY_CREDENTIALS),
+                        spi.ignite().configuration()));
 
             node.setAttributes(attrs);
         }
@@ -885,7 +887,8 @@ class ClientImpl extends TcpDiscoveryImpl {
                         TcpDiscoveryAbstractMessage msg;
 
                         try {
-                            msg = spi.marsh.unmarshal(in, U.resolveClassLoader(spi.ignite().configuration()));
+                            msg = MarshallerUtils.unmarshal(spi.marsh, in,
+                                U.resolveClassLoader(spi.ignite().configuration()), spi.ignite().configuration().getGridName());
                         }
                         catch (IgniteCheckedException e) {
                             if (log.isDebugEnabled())
@@ -1210,8 +1213,8 @@ class ClientImpl extends TcpDiscoveryImpl {
                         List<TcpDiscoveryAbstractMessage> msgs = null;
 
                         while (!isInterrupted()) {
-                            TcpDiscoveryAbstractMessage msg = spi.marsh.unmarshal(in,
-                                U.resolveClassLoader(spi.ignite().configuration()));
+                            TcpDiscoveryAbstractMessage msg = MarshallerUtils.unmarshal(spi.marsh, in,
+                                U.resolveClassLoader(spi.ignite().configuration()), spi.ignite().configuration().getGridName());
 
                             if (msg instanceof TcpDiscoveryClientReconnectMessage) {
                                 TcpDiscoveryClientReconnectMessage res = (TcpDiscoveryClientReconnectMessage)msg;
@@ -1965,7 +1968,7 @@ class ClientImpl extends TcpDiscoveryImpl {
                     if (node != null && node.visible()) {
                         try {
                             DiscoverySpiCustomMessage msgObj = msg.message(spi.marsh,
-                                U.resolveClassLoader(spi.ignite().configuration()));
+                                U.resolveClassLoader(spi.ignite().configuration()), spi.ignite().configuration());
 
                             notifyDiscovery(EVT_DISCOVERY_CUSTOM_EVT, topVer, node, allVisibleNodes(), msgObj);
                         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
index 7f689c5..3244182 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ServerImpl.java
@@ -65,6 +65,7 @@ import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.cache.CacheMetrics;
 import org.apache.ignite.cluster.ClusterMetrics;
 import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException;
 import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.IgniteNodeAttributes;
@@ -90,6 +91,7 @@ import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.lang.IgniteInClosure;
 import org.apache.ignite.lang.IgniteProductVersion;
 import org.apache.ignite.lang.IgniteUuid;
+import org.apache.ignite.marshaller.MarshallerUtils;
 import org.apache.ignite.plugin.security.SecurityCredentials;
 import org.apache.ignite.plugin.security.SecurityPermissionSet;
 import org.apache.ignite.spi.IgniteNodeValidationResult;
@@ -740,7 +742,8 @@ class ServerImpl extends TcpDiscoveryImpl {
     /** {@inheritDoc} */
     @Override public void sendCustomEvent(DiscoverySpiCustomMessage evt) {
         try {
-            msgWorker.addMessage(new TcpDiscoveryCustomEventMessage(getLocalNodeId(), evt, spi.marsh.marshal(evt)));
+            msgWorker.addMessage(new TcpDiscoveryCustomEventMessage(getLocalNodeId(), evt,
+                    MarshallerUtils.marshal(spi.marsh, evt, spi.ignite().configuration())));
         }
         catch (IgniteCheckedException e) {
             throw new IgniteSpiException("Failed to marshal custom event: " + evt, e);
@@ -823,7 +826,8 @@ class ServerImpl extends TcpDiscoveryImpl {
 
                         Map<String, Object> attrs = new HashMap<>(locNode.attributes());
 
-                        attrs.put(IgniteNodeAttributes.ATTR_SECURITY_SUBJECT, spi.marsh.marshal(subj));
+                        attrs.put(IgniteNodeAttributes.ATTR_SECURITY_SUBJECT,
+                            MarshallerUtils.marshal(spi.marsh, subj, spi.ignite().configuration()));
                         attrs.remove(IgniteNodeAttributes.ATTR_SECURITY_CREDENTIALS);
 
                         locNode.setAttributes(attrs);
@@ -1239,7 +1243,8 @@ class ServerImpl extends TcpDiscoveryImpl {
             Map<String, Object> attrs = new HashMap<>(node.getAttributes());
 
             attrs.put(IgniteNodeAttributes.ATTR_SECURITY_CREDENTIALS,
-                spi.marsh.marshal(attrs.get(IgniteNodeAttributes.ATTR_SECURITY_CREDENTIALS)));
+                MarshallerUtils.marshal(spi.marsh,
+                        attrs.get(IgniteNodeAttributes.ATTR_SECURITY_CREDENTIALS), spi.ignite().configuration()));
 
             node.setAttributes(attrs);
         }
@@ -1262,7 +1267,7 @@ class ServerImpl extends TcpDiscoveryImpl {
             if (credBytes == null)
                 return null;
 
-            return spi.marsh.unmarshal(credBytes, null);
+            return MarshallerUtils.unmarshal(spi.marsh, credBytes, null, spi.ignite().configuration());
         }
         catch (IgniteCheckedException e) {
             throw new IgniteSpiException("Failed to unmarshal node security credentials: " + node.id(), e);
@@ -2356,7 +2361,7 @@ class ServerImpl extends TcpDiscoveryImpl {
                 for (ClientMessageWorker clientMsgWorker : clientMsgWorkers.values()) {
                     if (msgBytes == null) {
                         try {
-                            msgBytes = spi.marsh.marshal(msg);
+                            msgBytes = MarshallerUtils.marshal(spi.marsh, msg, spi.ignite().configuration());
                         }
                         catch (IgniteCheckedException e) {
                             U.error(log, "Failed to marshal message: " + msg, e);
@@ -2375,8 +2380,8 @@ class ServerImpl extends TcpDiscoveryImpl {
 
                         if (clientMsgWorker.clientNodeId.equals(node.id())) {
                             try {
-                                msg0 = spi.marsh.unmarshal(msgBytes,
-                                    U.resolveClassLoader(spi.ignite().configuration()));
+                                msg0 = MarshallerUtils.unmarshal(spi.marsh, msgBytes,
+                                    U.resolveClassLoader(spi.ignite().configuration()), spi.ignite().configuration());
 
                                 prepareNodeAddedMessage(msg0, clientMsgWorker.clientNodeId, null, null, null);
 
@@ -3134,7 +3139,8 @@ class ServerImpl extends TcpDiscoveryImpl {
                             // Stick in authentication subject to node (use security-safe attributes for copy).
                             Map<String, Object> attrs = new HashMap<>(node.getAttributes());
 
-                            attrs.put(IgniteNodeAttributes.ATTR_SECURITY_SUBJECT, spi.marsh.marshal(subj));
+                            attrs.put(IgniteNodeAttributes.ATTR_SECURITY_SUBJECT,
+                                    MarshallerUtils.marshal(spi.marsh, subj, spi.ignite().configuration()));
 
                             node.setAttributes(attrs);
                         }
@@ -3785,9 +3791,11 @@ class ServerImpl extends TcpDiscoveryImpl {
                         else {
                             SecurityContext subj = spi.nodeAuth.authenticateNode(node, cred);
 
-                            SecurityContext coordSubj = spi.marsh.unmarshal(
+                            final IgniteConfiguration cfg = spi.ignite().configuration();
+
+                            SecurityContext coordSubj = MarshallerUtils.unmarshal(spi.marsh,
                                 node.<byte[]>attribute(IgniteNodeAttributes.ATTR_SECURITY_SUBJECT),
-                                U.resolveClassLoader(spi.ignite().configuration()));
+                                U.resolveClassLoader(cfg), cfg);
 
                             if (!permissionsEqual(coordSubj.subject().permissions(), subj.subject().permissions())) {
                                 // Node has not pass authentication.
@@ -4838,7 +4846,8 @@ class ServerImpl extends TcpDiscoveryImpl {
                     DiscoverySpiCustomMessage msgObj = null;
 
                     try {
-                        msgObj = msg.message(spi.marsh, U.resolveClassLoader(spi.ignite().configuration()));
+                        msgObj = msg.message(spi.marsh, U.resolveClassLoader(spi.ignite().configuration()),
+                                spi.ignite().configuration());
                     }
                     catch (Throwable e) {
                         U.error(log, "Failed to unmarshal discovery custom message.", e);
@@ -4850,7 +4859,8 @@ class ServerImpl extends TcpDiscoveryImpl {
                         if (nextMsg != null) {
                             try {
                                 TcpDiscoveryCustomEventMessage ackMsg = new TcpDiscoveryCustomEventMessage(
-                                    getLocalNodeId(), nextMsg, spi.marsh.marshal(nextMsg));
+                                    getLocalNodeId(), nextMsg,
+                                        MarshallerUtils.marshal(spi.marsh, nextMsg, spi.ignite().configuration()));
 
                                 ackMsg.topologyVersion(msg.topologyVersion());
 
@@ -4981,8 +4991,10 @@ class ServerImpl extends TcpDiscoveryImpl {
 
                 if (node != null) {
                     try {
+                        final IgniteConfiguration cfg = spi.ignite().configuration();
+
                         DiscoverySpiCustomMessage msgObj = msg.message(spi.marsh,
-                            U.resolveClassLoader(spi.ignite().configuration()));
+                            U.resolveClassLoader(cfg), cfg);
 
                         lsnr.onDiscovery(DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT,
                             msg.topologyVersion(),
@@ -4992,7 +5004,8 @@ class ServerImpl extends TcpDiscoveryImpl {
                             msgObj);
 
                         if (msgObj.isMutable())
-                            msg.message(msgObj, spi.marsh.marshal(msgObj));
+                            msg.message(msgObj,
+                                    MarshallerUtils.marshal(spi.marsh, msgObj, spi.ignite().configuration()));
                     }
                     catch (Throwable e) {
                         U.error(log, "Failed to unmarshal discovery custom message.", e);
@@ -5428,8 +5441,8 @@ class ServerImpl extends TcpDiscoveryImpl {
 
                 while (!isInterrupted()) {
                     try {
-                        TcpDiscoveryAbstractMessage msg = spi.marsh.unmarshal(in,
-                            U.resolveClassLoader(spi.ignite().configuration()));
+                        TcpDiscoveryAbstractMessage msg = MarshallerUtils.unmarshal(spi.marsh, in,
+                            U.resolveClassLoader(spi.ignite().configuration()), spi.ignite().configuration().getGridName());
 
                         msg.senderNodeId(nodeId);
 
@@ -5919,7 +5932,7 @@ class ServerImpl extends TcpDiscoveryImpl {
                 byte[] msgBytes = msgT.get2();
 
                 if (msgBytes == null)
-                    msgBytes = spi.marsh.marshal(msg);
+                    msgBytes = MarshallerUtils.marshal(spi.marsh, msg, spi.ignite().configuration());
 
                 if (msg instanceof TcpDiscoveryClientAckResponse) {
                     if (clientVer == null) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
index 308830e..bb01f74 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
@@ -64,6 +64,7 @@ import org.apache.ignite.lang.IgniteInClosure;
 import org.apache.ignite.lang.IgniteProductVersion;
 import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.MarshallerUtils;
 import org.apache.ignite.marshaller.jdk.JdkMarshaller;
 import org.apache.ignite.resources.IgniteInstanceResource;
 import org.apache.ignite.resources.LoggerResource;
@@ -1377,7 +1378,7 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements DiscoverySpi, T
         IgniteCheckedException err = null;
 
         try {
-            marsh.marshal(msg, out);
+            MarshallerUtils.marshal(marsh, msg, out, ignite.configuration().getGridName());
         }
         catch (IgniteCheckedException e) {
             err = e;
@@ -1461,10 +1462,8 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements DiscoverySpi, T
         try {
             sock.setSoTimeout((int)timeout);
 
-            T res = marsh.unmarshal(in == null ? sock.getInputStream() : in,
-                U.resolveClassLoader(ignite.configuration()));
-
-            return res;
+            return MarshallerUtils.unmarshal(marsh, in == null ? sock.getInputStream() : in,
+                U.resolveClassLoader(ignite.configuration()), ignite.configuration().getGridName());
         }
         catch (IOException | IgniteCheckedException e) {
             if (X.hasCause(e, SocketTimeoutException.class))
@@ -1679,7 +1678,7 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements DiscoverySpi, T
 
         for (Map.Entry<Integer, Serializable> entry : data.entrySet()) {
             try {
-                byte[] bytes = marsh.marshal(entry.getValue());
+                byte[] bytes = MarshallerUtils.marshal(marsh, entry.getValue(), ignite.configuration());
 
                 data0.put(entry.getKey(), bytes);
             }
@@ -1709,7 +1708,8 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter implements DiscoverySpi, T
 
         for (Map.Entry<Integer, byte[]> entry : data.entrySet()) {
             try {
-                Serializable compData = marsh.unmarshal(entry.getValue(), clsLdr);
+                Serializable compData = MarshallerUtils.unmarshal(marsh, entry.getValue(), clsLdr,
+                        ignite.configuration());
 
                 data0.put(entry.getKey(), compData);
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/multicast/TcpDiscoveryMulticastIpFinder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/multicast/TcpDiscoveryMulticastIpFinder.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/multicast/TcpDiscoveryMulticastIpFinder.java
index 8b29efd..d213eaa 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/multicast/TcpDiscoveryMulticastIpFinder.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/ipfinder/multicast/TcpDiscoveryMulticastIpFinder.java
@@ -32,6 +32,7 @@ import java.util.HashSet;
 import java.util.Set;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.F;
@@ -40,6 +41,7 @@ import org.apache.ignite.internal.util.typedef.internal.LT;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.MarshallerUtils;
 import org.apache.ignite.marshaller.jdk.JdkMarshaller;
 import org.apache.ignite.resources.LoggerResource;
 import org.apache.ignite.spi.IgniteSpiConfiguration;
@@ -359,7 +361,7 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder {
             if (!addr.isLoopbackAddress()) {
                 try {
                     if (!clientMode)
-                        addrSnds.add(new AddressSender(mcastAddr, addr, addrs));
+                        addrSnds.add(new AddressSender(mcastAddr, addr, addrs, getIgniteConfiguration()));
 
                     reqItfs.add(addr);
                 }
@@ -379,7 +381,7 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder {
                 try {
                     // Create non-bound socket if local host is loopback or failed to create sockets explicitly
                     // bound to interfaces.
-                    addrSnds.add(new AddressSender(mcastAddr, null, addrs));
+                    addrSnds.add(new AddressSender(mcastAddr, null, addrs, getIgniteConfiguration()));
                 }
                 catch (IOException e) {
                     if (log.isDebugEnabled())
@@ -389,7 +391,7 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder {
 
                 if (addrSnds.isEmpty()) {
                     try {
-                        addrSnds.add(new AddressSender(mcastAddr, mcastAddr, addrs));
+                        addrSnds.add(new AddressSender(mcastAddr, mcastAddr, addrs, getIgniteConfiguration()));
 
                         reqItfs.add(mcastAddr);
                     }
@@ -593,7 +595,7 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder {
                             AddressResponse addrRes;
 
                             try {
-                                addrRes = new AddressResponse(data);
+                                addrRes = new AddressResponse(data, getIgniteConfiguration());
                             }
                             catch (IgniteCheckedException e) {
                                 LT.warn(log, e, "Failed to deserialize multicast response.");
@@ -640,6 +642,15 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder {
         }
     }
 
+    /**
+     * get Ignite configuration if possible.
+     *
+     * @return Ignite config or {@code null}.
+     */
+    @Nullable private IgniteConfiguration getIgniteConfiguration() {
+        return ignite == null ? null : ignite.configuration();
+    }
+
     /** {@inheritDoc} */
     @Override public void close() {
         if (addrSnds != null) {
@@ -688,10 +699,10 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder {
          * @param addrs Addresses discovery SPI binds to.
          * @throws IgniteCheckedException If marshalling failed.
          */
-        private AddressResponse(Collection<InetSocketAddress> addrs) throws IgniteCheckedException {
+        private AddressResponse(Collection<InetSocketAddress> addrs, final IgniteConfiguration igniteCfg) throws IgniteCheckedException {
             this.addrs = addrs;
 
-            byte[] addrsData = marsh.marshal(addrs);
+            byte[] addrsData = MarshallerUtils.marshal(marsh, addrs, igniteCfg);
             data = new byte[U.IGNITE_HEADER.length + addrsData.length];
 
             if (data.length > MAX_DATA_LENGTH)
@@ -705,12 +716,13 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder {
          * @param data Message data.
          * @throws IgniteCheckedException If unmarshalling failed.
          */
-        private AddressResponse(byte[] data) throws IgniteCheckedException {
+        private AddressResponse(byte[] data, final IgniteConfiguration igniteCfg) throws IgniteCheckedException {
             assert U.bytesEqual(U.IGNITE_HEADER, 0, data, 0, U.IGNITE_HEADER.length);
 
             this.data = data;
 
-            addrs = marsh.unmarshal(Arrays.copyOfRange(data, U.IGNITE_HEADER.length, data.length), null);
+            addrs = MarshallerUtils.unmarshal(marsh,
+                    Arrays.copyOfRange(data, U.IGNITE_HEADER.length, data.length), null, igniteCfg);
         }
 
         /**
@@ -782,18 +794,24 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder {
         /** */
         private final InetAddress sockItf;
 
+        /** */
+        private final IgniteConfiguration igniteCfg;
+
         /**
          * @param mcastGrp Multicast address.
          * @param sockItf Optional interface multicast socket should be bound to.
          * @param addrs Local node addresses.
+         * @param igniteCfg Ignite configuration.
          * @throws IOException If fails to create multicast socket.
          */
-        private AddressSender(InetAddress mcastGrp, @Nullable InetAddress sockItf, Collection<InetSocketAddress> addrs)
+        private AddressSender(InetAddress mcastGrp, @Nullable InetAddress sockItf, Collection<InetSocketAddress> addrs,
+            final IgniteConfiguration igniteCfg)
             throws IOException {
             super(ignite == null ? null : ignite.name(), "tcp-disco-multicast-addr-sender", log);
             this.mcastGrp = mcastGrp;
             this.addrs = addrs;
             this.sockItf = sockItf;
+            this.igniteCfg = igniteCfg;
 
             sock = createSocket();
         }
@@ -829,7 +847,7 @@ public class TcpDiscoveryMulticastIpFinder extends TcpDiscoveryVmIpFinder {
             AddressResponse res;
 
             try {
-                res = new AddressResponse(addrs);
+                res = new AddressResponse(addrs, igniteCfg);
             }
             catch (IgniteCheckedException e) {
                 U.error(log, "Failed to prepare multicast message.", e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryCustomEventMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryCustomEventMessage.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryCustomEventMessage.java
index ca5dd56..1555718 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryCustomEventMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryCustomEventMessage.java
@@ -18,9 +18,12 @@
 package org.apache.ignite.spi.discovery.tcp.messages;
 
 import java.util.UUID;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.MarshallerUtils;
 import org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -70,20 +73,26 @@ public class TcpDiscoveryCustomEventMessage extends TcpDiscoveryAbstractMessage
     }
 
     /**
-     * @return Deserialized message,
+     * @param marsh Marshaller.
+     * @param igniteCfg Ignite configuration.
+     * @return Deserialized message.
      * @throws java.lang.Throwable if unmarshal failed.
      */
-    @Nullable public DiscoverySpiCustomMessage message(@NotNull Marshaller marsh) throws Throwable {
-        return message(marsh, null);
+    @Nullable public DiscoverySpiCustomMessage message(@NotNull Marshaller marsh, IgniteConfiguration igniteCfg) throws Throwable {
+        return message(marsh, null, igniteCfg);
     }
 
     /**
-     * @return Deserialized message,
+     * @param marsh Marshaller.
+     * @param ldr Class loader.
+     * @param igniteCfg Ignite configuration.
+     * @return Deserialized message.
      * @throws java.lang.Throwable if unmarshal failed.
      */
-    @Nullable public DiscoverySpiCustomMessage message(@NotNull Marshaller marsh, ClassLoader ldr) throws Throwable {
+    @Nullable public DiscoverySpiCustomMessage message(@NotNull Marshaller marsh, ClassLoader ldr,
+        final IgniteConfiguration igniteCfg) throws Throwable {
         if (msg == null) {
-            msg = marsh.unmarshal(msgBytes, ldr);
+            msg = MarshallerUtils.unmarshal(marsh, msgBytes, ldr, igniteCfg);
 
             assert msg != null;
         }
@@ -104,4 +113,4 @@ public class TcpDiscoveryCustomEventMessage extends TcpDiscoveryAbstractMessage
     @Override public String toString() {
         return S.toString(TcpDiscoveryCustomEventMessage.class, this, "super", super.toString());
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java
index df35ed3..a9e19b5 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/swapspace/file/FileSwapSpaceSpi.java
@@ -57,6 +57,7 @@ import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiInClosure;
 import org.apache.ignite.lang.IgniteInClosure;
+import org.apache.ignite.marshaller.MarshallerUtils;
 import org.apache.ignite.resources.LoggerResource;
 import org.apache.ignite.spi.IgniteSpiAdapter;
 import org.apache.ignite.spi.IgniteSpiCloseableIterator;
@@ -594,7 +595,7 @@ public class FileSwapSpaceSpi extends IgniteSpiAdapter implements SwapSpaceSpi,
 
         if (keyBytes == null) {
             try {
-                keyBytes = ignite.configuration().getMarshaller().marshal(key.key());
+                keyBytes = MarshallerUtils.marshal(ignite.configuration().getMarshaller(), key.key(), ignite.configuration());
             }
             catch (IgniteCheckedException e) {
                 throw new IgniteSpiException("Failed to marshal key: " + key.key(), e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketMessageConverter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketMessageConverter.java b/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketMessageConverter.java
index 03e82e3..d1372ee 100644
--- a/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketMessageConverter.java
+++ b/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketMessageConverter.java
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.stream.socket;
 
+import org.apache.ignite.configuration.IgniteConfiguration;
+
 /**
  * Socket message converter.
  */
@@ -25,7 +27,8 @@ public interface SocketMessageConverter<T> {
      * Converter message represented by array of bytes to object.
      *
      * @param msg Message.
+     * @param igniteCfg Ignite config.
      * @return Converted object.
      */
-    public T convert(byte[] msg);
+    public T convert(byte[] msg, IgniteConfiguration igniteCfg);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketStreamer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketStreamer.java b/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketStreamer.java
index 066a5fd..24580e7 100644
--- a/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketStreamer.java
+++ b/modules/core/src/main/java/org/apache/ignite/stream/socket/SocketStreamer.java
@@ -24,6 +24,7 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteDataStreamer;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.util.nio.GridBufferedParser;
 import org.apache.ignite.internal.util.nio.GridDelimitedParser;
 import org.apache.ignite.internal.util.nio.GridNioCodecFilter;
@@ -35,6 +36,7 @@ import org.apache.ignite.internal.util.nio.GridNioServerListenerAdapter;
 import org.apache.ignite.internal.util.nio.GridNioSession;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.marshaller.MarshallerUtils;
 import org.apache.ignite.marshaller.jdk.JdkMarshaller;
 import org.apache.ignite.stream.StreamAdapter;
 import org.apache.ignite.stream.StreamTupleExtractor;
@@ -163,7 +165,7 @@ public class SocketStreamer<T, K, V> extends StreamAdapter<T, K, V> {
             }
 
             @Override public void onMessage(GridNioSession ses, byte[] msg) {
-                addMessage(converter.convert(msg));
+                addMessage(converter.convert(msg, ses.igniteConfiguration()));
             }
         };
 
@@ -218,9 +220,9 @@ public class SocketStreamer<T, K, V> extends StreamAdapter<T, K, V> {
         private static final JdkMarshaller MARSH = new JdkMarshaller();
 
         /** {@inheritDoc} */
-        @Override public T convert(byte[] msg) {
+        @Override public T convert(byte[] msg, final IgniteConfiguration igniteCfg) {
             try {
-                return MARSH.unmarshal(msg, null);
+                return MarshallerUtils.unmarshal(MARSH, msg, null, igniteCfg);
             }
             catch (IgniteCheckedException e) {
                 throw new IgniteException(e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridBinaryCacheSerializationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridBinaryCacheSerializationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridBinaryCacheSerializationTest.java
new file mode 100644
index 0000000..0308ab6
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridBinaryCacheSerializationTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.testframework.junits.GridAbstractTest;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.lang.reflect.Method;
+
+/**
+ *
+ */
+public class GridBinaryCacheSerializationTest extends GridCommonAbstractTest {
+    /** */
+    private static final String CACHE_NAME = "cache_name";
+
+    /**
+     * Emulate user thread.
+     *
+     * @throws Throwable
+     */
+    @Override protected void runTest() throws Throwable {
+        Class<?> cls = getClass();
+
+        while (!cls.equals(GridAbstractTest.class))
+            cls = cls.getSuperclass();
+
+        final Method runTest = cls.getDeclaredMethod("runTestInternal");
+
+        runTest.setAccessible(true);
+
+        runTest.invoke(this);
+    }
+
+    /**
+     * Test that calling {@link Ignition#localIgnite()}
+     * is safe for binary marshaller.
+     *
+     * @throws Exception
+     */
+    public void testPutGet() throws Exception {
+        final IgniteCache<Integer, MyObj> cache = startGrid().getOrCreateCache(CACHE_NAME);
+
+        final MyObj one = new MyObj("one");
+        final MyObj two = new MyObj("two");
+        final MyObj three = new MyObj("three");
+
+        cache.put(1, one);
+        cache.put(2, two);
+        cache.put(3, three);
+
+        final MyObj loadedOne = cache.get(1);
+        final MyObj loadedTwo = cache.get(2);
+        final MyObj loadedThree = cache.get(3);
+
+        assert one.equals(loadedOne);
+        assert two.equals(loadedTwo);
+        assert three.equals(loadedThree);
+
+    }
+
+    /**
+     * Test obj.
+     */
+    private static class MyObj {
+
+        /** */
+        final String val;
+
+        /** */
+        private MyObj(final String val) {
+            this.val = val;
+        }
+
+        private Object readResolve() {
+            Ignition.localIgnite();
+            return this;
+        }
+
+        /** */
+        @Override public boolean equals(final Object o) {
+            if (this == o) return true;
+            if (o == null || getClass() != o.getClass()) return false;
+
+            final MyObj myObj = (MyObj) o;
+
+            return val != null ? val.equals(myObj.val) : myObj.val == null;
+
+        }
+
+        /** */
+        @Override public int hashCode() {
+            return val != null ? val.hashCode() : 0;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/test/java/org/apache/ignite/internal/util/nio/impl/GridNioFilterChainSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/nio/impl/GridNioFilterChainSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/nio/impl/GridNioFilterChainSelfTest.java
index 201fd27..043ec02 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/util/nio/impl/GridNioFilterChainSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/util/nio/impl/GridNioFilterChainSelfTest.java
@@ -21,6 +21,7 @@ import java.net.InetSocketAddress;
 import java.nio.ByteBuffer;
 import java.util.concurrent.atomic.AtomicReference;
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.util.lang.GridMetadataAwareAdapter;
 import org.apache.ignite.internal.util.nio.GridNioFilterAdapter;
 import org.apache.ignite.internal.util.nio.GridNioFilterChain;
@@ -377,5 +378,10 @@ public class GridNioFilterChainSelfTest extends GridCommonAbstractTest {
         @Nullable @Override public GridNioRecoveryDescriptor recoveryDescriptor() {
             return null;
         }
+
+        /** {@inheritDoc} */
+        @Override public IgniteConfiguration igniteConfiguration() {
+            return null;
+        }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
index 32d9072..7014608 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java
@@ -1964,7 +1964,7 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
                 if (msg instanceof TcpDiscoveryCustomEventMessage) {
                     try {
                         DiscoveryCustomMessage custMsg = GridTestUtils.getFieldValue(
-                            ((TcpDiscoveryCustomEventMessage)msg).message(marsh), "delegate");
+                            ((TcpDiscoveryCustomEventMessage)msg).message(marsh, null), "delegate");
 
                         if (custMsg instanceof StartRoutineAckDiscoveryMessage) {
                             log.info("Skip message send and stop node: " + msg);

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/core/src/test/java/org/apache/ignite/stream/socket/SocketStreamerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/stream/socket/SocketStreamerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/stream/socket/SocketStreamerSelfTest.java
index 1056990..a76a1fa 100644
--- a/modules/core/src/test/java/org/apache/ignite/stream/socket/SocketStreamerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/stream/socket/SocketStreamerSelfTest.java
@@ -169,7 +169,7 @@ public class SocketStreamerSelfTest extends GridCommonAbstractTest {
      */
     public void testSizeBasedCustomConverter() throws Exception {
         SocketMessageConverter<Message> converter = new SocketMessageConverter<Message>() {
-            @Override public Message convert(byte[] msg) {
+            @Override public Message convert(byte[] msg, IgniteConfiguration cfg) {
                 int i = (msg[0] & 0xFF) << 24;
                 i |= (msg[1] & 0xFF) << 16;
                 i |= (msg[2] & 0xFF) << 8;
@@ -233,7 +233,7 @@ public class SocketStreamerSelfTest extends GridCommonAbstractTest {
      */
     public void testDelimiterBasedCustomConverter() throws Exception {
         SocketMessageConverter<Message> converter = new SocketMessageConverter<Message>() {
-            @Override public Message convert(byte[] msg) {
+            @Override public Message convert(byte[] msg, IgniteConfiguration cfg) {
                 int i = (msg[0] & 0xFF) << 24;
                 i |= (msg[1] & 0xFF) << 16;
                 i |= (msg[2] & 0xFF) << 8;

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/taskexecutor/external/communication/HadoopExternalCommunication.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/taskexecutor/external/communication/HadoopExternalCommunication.java b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/taskexecutor/external/communication/HadoopExternalCommunication.java
index 1d59a95..736c69f 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/taskexecutor/external/communication/HadoopExternalCommunication.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/taskexecutor/external/communication/HadoopExternalCommunication.java
@@ -35,6 +35,7 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.processors.hadoop.message.HadoopMessage;
 import org.apache.ignite.internal.processors.hadoop.taskexecutor.external.HadoopProcessDescriptor;
@@ -1174,11 +1175,15 @@ public class HadoopExternalCommunication {
 
             this.endpoint = endpoint;
 
+            final IgniteConfiguration cfg = new IgniteConfiguration(); // TODO provide real config
+            cfg.setGridName(gridName);
+
             adapter = new HadoopIpcToNioAdapter<>(
                 HadoopExternalCommunication.this.log,
                 endpoint,
                 accepted,
                 srvLsnr,
+                cfg,
                 filters());
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/taskexecutor/external/communication/HadoopIpcToNioAdapter.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/taskexecutor/external/communication/HadoopIpcToNioAdapter.java b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/taskexecutor/external/communication/HadoopIpcToNioAdapter.java
index a8de999..1000b8a 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/taskexecutor/external/communication/HadoopIpcToNioAdapter.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/taskexecutor/external/communication/HadoopIpcToNioAdapter.java
@@ -25,6 +25,7 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicReference;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.util.ipc.IpcEndpoint;
 import org.apache.ignite.internal.util.nio.GridNioFilter;
 import org.apache.ignite.internal.util.nio.GridNioFilterAdapter;
@@ -62,14 +63,15 @@ public class HadoopIpcToNioAdapter<T> {
      * @param log Log.
      * @param endp Endpoint.
      * @param lsnr Listener.
+     * @param igniteCfg Ignite config.
      * @param filters Filters.
      */
     public HadoopIpcToNioAdapter(IgniteLogger log, IpcEndpoint endp, boolean accepted,
-        GridNioServerListener<T> lsnr, GridNioFilter... filters) {
+        GridNioServerListener<T> lsnr, IgniteConfiguration igniteCfg, GridNioFilter... filters) {
         this.endp = endp;
 
         chain = new GridNioFilterChain<>(log, lsnr, new HeadFilter(), filters);
-        ses = new GridNioSessionImpl(chain, null, null, accepted);
+        ses = new GridNioSessionImpl(chain, null, null, accepted, igniteCfg);
 
         writeBuf = ByteBuffer.allocate(8 << 10);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/taskexecutor/external/communication/HadoopMarshallerFilter.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/taskexecutor/external/communication/HadoopMarshallerFilter.java b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/taskexecutor/external/communication/HadoopMarshallerFilter.java
index 3f79469..d0cbecc 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/taskexecutor/external/communication/HadoopMarshallerFilter.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/internal/processors/hadoop/taskexecutor/external/communication/HadoopMarshallerFilter.java
@@ -23,6 +23,7 @@ import org.apache.ignite.internal.util.nio.GridNioFilterAdapter;
 import org.apache.ignite.internal.util.nio.GridNioFuture;
 import org.apache.ignite.internal.util.nio.GridNioSession;
 import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.MarshallerUtils;
 
 /**
  * Serialization filter.
@@ -59,14 +60,15 @@ public class HadoopMarshallerFilter extends GridNioFilterAdapter {
     @Override public GridNioFuture<?> onSessionWrite(GridNioSession ses, Object msg) throws IgniteCheckedException {
         assert msg instanceof HadoopMessage : "Invalid message type: " + msg;
 
-        return proceedSessionWrite(ses, marshaller.marshal(msg));
+        return proceedSessionWrite(ses, MarshallerUtils.marshal(marshaller, msg, ses.igniteConfiguration()));
     }
 
+    /** {@inheritDoc} */
     @Override public void onMessageReceived(GridNioSession ses, Object msg) throws IgniteCheckedException {
         assert msg instanceof byte[];
 
         // Always unmarshal with system classloader.
-        proceedMessageReceived(ses, marshaller.unmarshal((byte[])msg, null));
+        proceedMessageReceived(ses, MarshallerUtils.unmarshal(marshaller, (byte[])msg, null, ses.igniteConfiguration()));
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index 7f0e230..a00795f 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -76,6 +76,7 @@ import org.apache.ignite.lang.IgniteBiPredicate;
 import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.lang.IgniteFuture;
 import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.MarshallerUtils;
 import org.apache.ignite.marshaller.jdk.JdkMarshaller;
 import org.apache.ignite.resources.LoggerResource;
 import org.apache.ignite.spi.IgniteSpiCloseableIterator;
@@ -1535,13 +1536,13 @@ public class IgniteH2Indexing implements GridQueryIndexing {
     protected JavaObjectSerializer h2Serializer() {
         return new JavaObjectSerializer() {
                 @Override public byte[] serialize(Object obj) throws Exception {
-                    return marshaller.marshal(obj);
+                    return MarshallerUtils.marshal(marshaller, obj, ctx.gridName());
                 }
 
                 @Override public Object deserialize(byte[] bytes) throws Exception {
                     ClassLoader clsLdr = ctx != null ? U.resolveClassLoader(ctx.config()) : null;
 
-                    return marshaller.unmarshal(bytes, clsLdr);
+                    return MarshallerUtils.unmarshal(marshaller, bytes, clsLdr, ctx.gridName());
                 }
             };
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
index 47ab083..1fa3368 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/GridReduceQueryExecutor.java
@@ -564,7 +564,7 @@ public class GridReduceQueryExecutor {
                     Marshaller m = ctx.config().getMarshaller();
 
                     for (GridCacheSqlQuery mapQry : mapQrys)
-                        mapQry.marshallParams(m);
+                        mapQry.marshallParams(m, ctx);
                 }
 
                 boolean retry = false;

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java
----------------------------------------------------------------------
diff --git a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java
index 2b7442f..414fef1 100644
--- a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java
+++ b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionFilter.java
@@ -514,8 +514,10 @@ public class WebSessionFilter implements Filter {
                 try {
                     final WebSessionEntity entity = binaryCache.get(sesId);
 
-                    if (entity != null)
-                        cached = new WebSessionV2(sesId, httpReq.getSession(false), false, ctx, entity, marshaller);
+                    if (entity != null) {
+                        cached = new WebSessionV2(sesId, httpReq.getSession(false), false, ctx, entity, marshaller,
+                            webSesIgnite.configuration());
+                    }
 
                     break;
                 }
@@ -698,7 +700,7 @@ public class WebSessionFilter implements Filter {
         if (log.isDebugEnabled())
             log.debug("Session created: " + sesId);
 
-        WebSessionV2 cached = new WebSessionV2(sesId, ses, true, ctx, null, marshaller);
+        WebSessionV2 cached = new WebSessionV2(sesId, ses, true, ctx, null, marshaller, webSesIgnite.configuration());
 
         final WebSessionEntity marshaledEntity = cached.marshalAttributes();
 
@@ -710,9 +712,9 @@ public class WebSessionFilter implements Filter {
                 final WebSessionEntity old = cache0.getAndPutIfAbsent(sesId, marshaledEntity);
 
                 if (old != null)
-                    cached = new WebSessionV2(sesId, ses, false, ctx, old, marshaller);
+                    cached = new WebSessionV2(sesId, ses, false, ctx, old, marshaller, webSesIgnite.configuration());
                 else
-                    cached = new WebSessionV2(sesId, ses, false, ctx, marshaledEntity, marshaller);
+                    cached = new WebSessionV2(sesId, ses, false, ctx, marshaledEntity, marshaller, webSesIgnite.configuration());
 
                 break;
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/97ce8fbb/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionV2.java
----------------------------------------------------------------------
diff --git a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionV2.java b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionV2.java
index b6540b2..28d16b1 100644
--- a/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionV2.java
+++ b/modules/web/src/main/java/org/apache/ignite/cache/websession/WebSessionV2.java
@@ -19,10 +19,12 @@ package org.apache.ignite.cache.websession;
 
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.websession.WebSessionEntity;
 import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.MarshallerUtils;
 import org.jetbrains.annotations.Nullable;
 
 import javax.servlet.ServletContext;
@@ -87,22 +89,27 @@ class WebSessionV2 implements HttpSession {
     /** Original session to delegate invalidation. */
     private final HttpSession genuineSes;
 
+    /** Ignite config. */
+    private final IgniteConfiguration cfg;
+
     /**
      * @param id Session ID.
      * @param ses Session.
      * @param isNew Is new flag.
      */
     WebSessionV2(final String id, final @Nullable HttpSession ses, final boolean isNew, final ServletContext ctx,
-        @Nullable WebSessionEntity entity, final Marshaller marshaller) {
+        @Nullable WebSessionEntity entity, final Marshaller marshaller, final IgniteConfiguration cfg) {
         assert id != null;
         assert marshaller != null;
         assert ctx != null;
         assert ses != null || entity != null;
+        assert cfg != null;
 
         this.marshaller = marshaller;
         this.ctx = ctx;
         this.isNew = isNew;
         this.genuineSes = ses;
+        this.cfg = cfg;
 
         accessTime = System.currentTimeMillis();
 
@@ -333,7 +340,7 @@ class WebSessionV2 implements HttpSession {
     @Nullable private <T> T unmarshal(final byte[] bytes) throws IOException {
         if (marshaller != null) {
             try {
-                return marshaller.unmarshal(bytes, getClass().getClassLoader());
+                return MarshallerUtils.unmarshal(marshaller, bytes, getClass().getClassLoader(), cfg);
             }
             catch (IgniteCheckedException e) {
                 throw new IOException(e);
@@ -353,7 +360,7 @@ class WebSessionV2 implements HttpSession {
     @Nullable private byte[] marshal(final Object obj) throws IOException {
         if (marshaller != null) {
             try {
-                return marshaller.marshal(obj);
+                return MarshallerUtils.marshal(marshaller, obj, cfg);
             }
             catch (IgniteCheckedException e) {
                 throw new IOException(e);


Mime
View raw message