ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject [1/7] incubator-ignite git commit: IGNITE-141 - Marshallers refactoring
Date Tue, 03 Mar 2015 01:15:14 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-141 fb13a9a0d -> 2f2122ba7


IGNITE-141 - Marshallers refactoring


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

Branch: refs/heads/ignite-141
Commit: 70d4b90753ec999ba73b3879433405e0d41b148c
Parents: f06aefc
Author: Valentin Kulichenko <vkulichenko@gridgain.com>
Authored: Mon Mar 2 15:44:01 2015 -0800
Committer: Valentin Kulichenko <vkulichenko@gridgain.com>
Committed: Mon Mar 2 15:44:01 2015 -0800

----------------------------------------------------------------------
 .../ignite/internal/GridKernalContext.java      |   7 +
 .../ignite/internal/GridKernalContextImpl.java  |   8 +
 .../apache/ignite/internal/IgniteKernal.java    |  96 +---------
 .../ignite/internal/MarshallerContextImpl.java  | 188 +++++++++++++++++++
 .../deployment/GridDeploymentLocalStore.java    |   1 +
 .../GridDeploymentPerLoaderStore.java           |   1 +
 .../GridDeploymentPerVersionStore.java          |   1 +
 .../processors/cache/GridCacheProcessor.java    |   6 +
 .../ignite/marshaller/MarshallerContext.java    |  14 +-
 .../optimized/OptimizedMarshallerUtils.java     |  62 +-----
 .../cache/GridCacheEntryMemorySizeSelfTest.java |   4 +-
 .../marshaller/MarshallerContextTestImpl.java   |   8 +-
 .../discovery/AbstractDiscoverySelfTest.java    |   1 -
 .../junits/IgniteTestResources.java             |  32 ++--
 14 files changed, 245 insertions(+), 184 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70d4b907/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
index cb9ffa1..f1a135f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
@@ -516,4 +516,11 @@ public interface GridKernalContext extends Iterable<GridComponent>
{
      * @return Cluster processor.
      */
     public ClusterProcessor cluster();
+
+    /**
+     * Gets marshaller context.
+     *
+     * @return Marshaller context.
+     */
+    public MarshallerContextImpl marshallerContext();
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70d4b907/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
index 756c16a..787fe11 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
@@ -305,6 +305,9 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable
     /** Exception registry. */
     private IgniteExceptionRegistry registry;
 
+    /** Marshaller context. */
+    private final MarshallerContextImpl marshCtx = new MarshallerContextImpl();
+
     /**
      * No-arg constructor is required by externalization.
      */
@@ -866,6 +869,11 @@ public class GridKernalContextImpl implements GridKernalContext, Externalizable
     }
 
     /** {@inheritDoc} */
+    @Override public MarshallerContextImpl marshallerContext() {
+        return marshCtx;
+    }
+
+    /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(GridKernalContextImpl.class, this);
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70d4b907/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index 90d283a..a6a5bde 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -675,7 +675,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable
{
                 igfsExecSvc,
                 restExecSvc);
 
-            cfg.getMarshaller().setContext(new MarshallerContextImpl(ctx));
+            cfg.getMarshaller().setContext(ctx.marshallerContext());
 
             startProcessor(ctx, new ClusterProcessor(ctx), attrs);
 
@@ -2716,98 +2716,4 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable
{
     @Override public String toString() {
         return S.toString(IgniteKernal.class, this);
     }
-
-    /**
-     */
-    private static class MarshallerContextImpl implements MarshallerContext {
-        /** */
-        private final GridKernalContext ctx;
-
-        /** */
-        private GridCacheAdapter<Integer, String> cache;
-
-        /**
-         * @param ctx Kernal context.
-         */
-        private MarshallerContextImpl(GridKernalContext ctx) {
-            this.ctx = ctx;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void registerClass(int id, String clsName) {
-            if (cache == null)
-                cache = ctx.cache().marshallerCache();
-
-            // TODO: IGNITE-141 - Do not create thread.
-            Thread t = new Thread(new MarshallerCacheUpdater(ctx.log(), cache, id, clsName));
-
-            t.start();
-
-            try {
-                t.join();
-            }
-            catch (InterruptedException e) {
-                throw new IgniteException(e);
-            }
-        }
-
-        /** {@inheritDoc} */
-        @Override public String className(int id) {
-            if (cache == null)
-                cache = ctx.cache().marshallerCache();
-
-            try {
-                return cache.get(id);
-            }
-            catch (IgniteCheckedException e) {
-                throw U.convertException(e);
-            }
-        }
-    }
-
-    /**
-     */
-    private static class MarshallerCacheUpdater implements Runnable {
-        /** */
-        private final IgniteLogger log;
-
-        /** */
-        private final GridCacheAdapter<Integer, String> cache;
-
-        /** */
-        private final int typeId;
-
-        /** */
-        private final String clsName;
-
-        /**
-         * @param cache Cache.
-         * @param typeId Type ID.
-         * @param clsName Class name.
-         */
-        private MarshallerCacheUpdater(IgniteLogger log, GridCacheAdapter<Integer, String>
cache, int typeId, String clsName) {
-            this.log = log;
-            this.cache = cache;
-            this.typeId = typeId;
-            this.clsName = clsName;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void run() {
-            try {
-                // TODO: IGNITE-141 - Remove debug
-                U.debug(log, ">>> REGISTER: " + clsName);
-
-                String old = cache.putIfAbsent(typeId, clsName);
-
-                if (old != null && !old.equals(clsName))
-                    throw new IgniteException("Type ID collision acquired in OptimizedMarshaller.
Use " +
-                        "OptimizedMarshallerIdMapper to resolve it [id=" + typeId + ", clsName1="
+ clsName +
-                        "clsName2=" + old + ']');
-            }
-            catch (IgniteCheckedException e) {
-                throw U.convertException(e);
-            }
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70d4b907/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
new file mode 100644
index 0000000..86ebfd1
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
@@ -0,0 +1,188 @@
+/*
+ * 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;
+
+import org.apache.ignite.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.marshaller.*;
+import org.jdk8.backport.*;
+
+import java.io.*;
+import java.util.*;
+import java.util.concurrent.*;
+
+/**
+ * Marshaller context implementation.
+ */
+public class MarshallerContextImpl implements MarshallerContext {
+    /** */
+    private static final String CLS_NAMES_FILE = "org/apache/ignite/marshaller/optimized/classnames.properties";
+
+    /** */
+    private final ConcurrentMap<Integer, IgniteBiTuple<Class, Boolean>> clsById
= new ConcurrentHashMap8<>(256);
+
+    /** */
+    private final CountDownLatch latch = new CountDownLatch(1);
+
+    /** */
+    private volatile GridCacheAdapter<Integer, String> cache;
+
+    MarshallerContextImpl() {
+        try {
+            ClassLoader ldr = getClass().getClassLoader();
+
+            BufferedReader rdr = new BufferedReader(new InputStreamReader(ldr.getResourceAsStream(CLS_NAMES_FILE)));
+
+            String clsName;
+
+            while ((clsName = rdr.readLine()) != null) {
+                Class cls = U.forName(clsName, ldr);
+
+                clsById.put(cls.getName().hashCode(), F.t(cls, true));
+            }
+        }
+        catch (IOException | ClassNotFoundException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    /**
+     * @param ctx Kernal context.
+     */
+    public void onMarshallerCacheReady(GridKernalContext ctx) {
+        assert ctx != null;
+
+        cache = ctx.cache().marshallerCache();
+
+        latch.countDown();
+    }
+
+    /**
+     * @param ldr Undeployed class loader.
+     */
+    public void onUndeployed(ClassLoader ldr) {
+        for (Map.Entry<Integer, IgniteBiTuple<Class, Boolean>> e : clsById.entrySet())
{
+            if (!e.getValue().get2() && ldr.equals(e.getValue().get1().getClassLoader()))
+                clsById.remove(e.getKey());
+        }
+    }
+
+    /**
+     * Clears cached classes.
+     */
+    public void clear() {
+        for (Map.Entry<Integer, IgniteBiTuple<Class, Boolean>> e : clsById.entrySet())
{
+            if (!e.getValue().get2())
+                clsById.remove(e.getKey());
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void registerClass(int id, Class cls) {
+        if (cache == null)
+            U.awaitQuiet(latch);
+
+        if (clsById.putIfAbsent(id, F.t(cls, false)) == null) {
+            // TODO: IGNITE-141 - Do not create thread.
+            Thread t = new Thread(new MarshallerCacheUpdater(cache, id, cls.getName()));
+
+            t.start();
+
+            try {
+                t.join();
+            }
+            catch (InterruptedException e) {
+                throw new IgniteException(e);
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public Class className(int id, ClassLoader ldr) throws ClassNotFoundException
{
+        if (cache == null)
+            U.awaitQuiet(latch);
+
+        IgniteBiTuple<Class, Boolean> t = clsById.get(id);
+
+        if (t == null) {
+            String clsName;
+
+            try {
+                clsName = cache.get(id);
+            }
+            catch (IgniteCheckedException e) {
+                throw U.convertException(e);
+            }
+
+            assert clsName != null : id;
+
+            Class cls = U.forName(clsName, ldr);
+
+            IgniteBiTuple<Class, Boolean> old = clsById.putIfAbsent(id, t = F.t(cls,
false));
+
+            if (old != null)
+                t = old;
+        }
+
+        return t.get1();
+    }
+
+    /**
+     */
+    private static class MarshallerCacheUpdater implements Runnable {
+        /** */
+        private final GridCacheAdapter<Integer, String> cache;
+
+        /** */
+        private final int typeId;
+
+        /** */
+        private final String clsName;
+
+        /**
+         * @param cache Cache.
+         * @param typeId Type ID.
+         * @param clsName Class name.
+         */
+        private MarshallerCacheUpdater(GridCacheAdapter<Integer, String> cache, int
typeId, String clsName) {
+            assert cache != null;
+
+            this.cache = cache;
+            this.typeId = typeId;
+            this.clsName = clsName;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void run() {
+            try {
+                String old = cache.putIfAbsent(typeId, clsName);
+
+                if (old != null && !old.equals(clsName))
+                    throw new IgniteException("Type ID collision acquired in OptimizedMarshaller.
Use " +
+                        "OptimizedMarshallerIdMapper to resolve it [id=" + typeId + ", clsName1="
+ clsName +
+                        "clsName2=" + old + ']');
+            }
+            catch (IgniteCheckedException e) {
+                throw U.convertException(e);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70d4b907/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentLocalStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentLocalStore.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentLocalStore.java
index 195621c..7657137 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentLocalStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentLocalStore.java
@@ -522,6 +522,7 @@ class GridDeploymentLocalStore extends GridDeploymentStoreAdapter {
             if (dep.obsolete()) {
                 // Resource cleanup.
                 ctx.resource().onUndeployed(dep);
+                ctx.marshallerContext().onUndeployed(ldr);
 
                 // Clear optimized marshaller's cache. If another marshaller is used, this
is no-op.
                 OptimizedMarshaller.onUndeploy(ldr);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70d4b907/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerLoaderStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerLoaderStore.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerLoaderStore.java
index 7a98cbc..0d09489 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerLoaderStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerLoaderStore.java
@@ -495,6 +495,7 @@ public class GridDeploymentPerLoaderStore extends GridDeploymentStoreAdapter
{
 
                 ctx.cache().onUndeployed(ldr);
                 ctx.stream().onUndeployed(ldr);
+                ctx.marshallerContext().onUndeployed(ldr);
 
                 // Clear optimized marshaller's cache. If another marshaller is used, this
is no-op.
                 OptimizedMarshaller.onUndeploy(ldr);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70d4b907/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerVersionStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerVersionStore.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerVersionStore.java
index dc72248..6eb41aa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerVersionStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerVersionStore.java
@@ -1258,6 +1258,7 @@ public class GridDeploymentPerVersionStore extends GridDeploymentStoreAdapter
{
 
                 ctx.cache().onUndeployed(ldr);
                 ctx.stream().onUndeployed(ldr);
+                ctx.marshallerContext().onUndeployed(ldr);
 
                 // Clear optimized marshaller's cache. If another marshaller is used, this
is no-op.
                 OptimizedMarshaller.onUndeploy(ldr);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70d4b907/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index bf5277e..e8db8a6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -911,6 +911,12 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
         transactions = new IgniteTransactionsImpl(sharedCtx);
 
+        marshallerCache().context().preloader().syncFuture().listenAsync(new CI1<IgniteInternalFuture<?>>()
{
+            @Override public void apply(IgniteInternalFuture<?> f) {
+                ctx.marshallerContext().onMarshallerCacheReady(ctx);
+            }
+        });
+
         if (log.isDebugEnabled())
             log.debug("Started cache processor.");
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70d4b907/modules/core/src/main/java/org/apache/ignite/marshaller/MarshallerContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/MarshallerContext.java
b/modules/core/src/main/java/org/apache/ignite/marshaller/MarshallerContext.java
index b499c05..6c6e398 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/MarshallerContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/MarshallerContext.java
@@ -22,18 +22,20 @@ package org.apache.ignite.marshaller;
  */
 public interface MarshallerContext {
     /**
-     * Registers class name for provided type ID.
+     * Registers class with provided type ID.
      *
      * @param id Type ID.
-     * @param clsName Class name.
+     * @param cls Class.
      */
-    public void registerClass(int id, String clsName);
+    public void registerClass(int id, Class cls);
 
     /**
-     * Gets class name for provided type ID.
+     * Gets class for provided type ID.
      *
      * @param id Type ID.
-     * @return Class name.
+     * @param ldr Class loader.
+     * @return Class.
+     * @throws ClassNotFoundException If class was not found.
      */
-    public String className(int id);
+    public Class className(int id, ClassLoader ldr) throws ClassNotFoundException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70d4b907/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
index 7820e0a..dd6f732 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedMarshallerUtils.java
@@ -19,8 +19,6 @@ package org.apache.ignite.marshaller.optimized;
 
 import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.typedef.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.lang.*;
 import org.apache.ignite.marshaller.*;
 import org.jdk8.backport.*;
 import sun.misc.*;
@@ -51,36 +49,9 @@ class OptimizedMarshallerUtils {
     /** UTF-8 character name. */
     static final Charset UTF_8 = Charset.forName("UTF-8");
 
-    /** Classnames file path. */
-    private static final String CLS_NAMES_FILE = "org/apache/ignite/marshaller/optimized/classnames.properties";
-
     /** Class descriptors by class. */
     private static final ConcurrentMap<Class, OptimizedClassDescriptor> DESC_BY_CLS
= new ConcurrentHashMap8<>(256);
 
-    /** Classes by ID. */
-    // TODO: IGNITE-141 - Move to marshaller context implementation.
-    private static final ConcurrentMap<Integer, IgniteBiTuple<Class, Boolean>>
CLS_BY_ID =
-        new ConcurrentHashMap8<>(256);
-
-    static {
-        try {
-            ClassLoader ldr = OptimizedMarshallerUtils.class.getClassLoader();
-
-            BufferedReader rdr = new BufferedReader(new InputStreamReader(ldr.getResourceAsStream(CLS_NAMES_FILE)));
-
-            String clsName;
-
-            while ((clsName = rdr.readLine()) != null) {
-                Class cls = U.forName(clsName, ldr);
-
-                CLS_BY_ID.put(cls.getName().hashCode(), F.t(cls, true));
-            }
-        }
-        catch (IOException | ClassNotFoundException e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
     /**
      */
     private OptimizedMarshallerUtils() {
@@ -103,8 +74,7 @@ class OptimizedMarshallerUtils {
         if (desc == null) {
             desc = new OptimizedClassDescriptor(cls, ctx, mapper);
 
-            if (CLS_BY_ID.putIfAbsent(desc.typeId(), F.t(cls, false)) == null)
-                ctx.registerClass(desc.typeId(), cls.getName());
+            ctx.registerClass(desc.typeId(), cls);
 
             OptimizedClassDescriptor old = DESC_BY_CLS.putIfAbsent(cls, desc);
 
@@ -127,24 +97,8 @@ class OptimizedMarshallerUtils {
      * @throws ClassNotFoundException If class was not found.
      */
     static OptimizedClassDescriptor classDescriptor(int id, ClassLoader ldr, MarshallerContext
ctx,
-        OptimizedMarshallerIdMapper mapper)
-        throws IOException, ClassNotFoundException {
-        IgniteBiTuple<Class, Boolean> t = CLS_BY_ID.get(id);
-
-        if (t == null) {
-            String clsName = ctx.className(id);
-
-            assert clsName != null : id;
-
-            Class cls = U.forName(clsName, ldr);
-
-            IgniteBiTuple<Class, Boolean> old = CLS_BY_ID.putIfAbsent(id, t = F.t(cls,
false));
-
-            if (old != null)
-                t = old;
-        }
-
-        return classDescriptor(t.get1(), ctx, mapper);
+        OptimizedMarshallerIdMapper mapper) throws IOException, ClassNotFoundException {
+        return classDescriptor(ctx.className(id, ldr), ctx, mapper);
     }
 
     /**
@@ -157,11 +111,6 @@ class OptimizedMarshallerUtils {
             if (ldr.equals(cls.getClassLoader()))
                 DESC_BY_CLS.remove(cls);
         }
-
-        for (Map.Entry<Integer, IgniteBiTuple<Class, Boolean>> e : CLS_BY_ID.entrySet())
{
-            if (!e.getValue().get2() && ldr.equals(e.getValue().get1().getClassLoader()))
-                CLS_BY_ID.remove(e.getKey());
-        }
     }
 
     /**
@@ -169,11 +118,6 @@ class OptimizedMarshallerUtils {
      */
     public static void clearCache() {
         DESC_BY_CLS.clear();
-
-        for (Map.Entry<Integer, IgniteBiTuple<Class, Boolean>> e : CLS_BY_ID.entrySet())
{
-            if (!e.getValue().get2())
-                CLS_BY_ID.remove(e.getKey());
-        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70d4b907/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheEntryMemorySizeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheEntryMemorySizeSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheEntryMemorySizeSelfTest.java
index 1f5e93d..6eb9086 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheEntryMemorySizeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheEntryMemorySizeSelfTest.java
@@ -85,11 +85,11 @@ public class GridCacheEntryMemorySizeSelfTest extends GridCommonAbstractTest
{
             Marshaller marsh = new OptimizedMarshaller();
 
             marsh.setContext(new MarshallerContext() {
-                @Override public void registerClass(int id, String clsName) {
+                @Override public void registerClass(int id, Class cls) {
                     // No-op.
                 }
 
-                @Override public String className(int id) {
+                @Override public Class className(int id, ClassLoader ldr) {
                     throw new UnsupportedOperationException();
                 }
             });

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70d4b907/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java
b/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java
index 21cd1b6..86cb63a 100644
--- a/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java
+++ b/modules/core/src/test/java/org/apache/ignite/marshaller/MarshallerContextTestImpl.java
@@ -24,15 +24,15 @@ import java.util.*;
  */
 public class MarshallerContextTestImpl implements MarshallerContext {
     /** */
-    private final Map<Integer, String> map = new HashMap<>();
+    private final Map<Integer, Class> map = new HashMap<>();
 
     /** {@inheritDoc} */
-    @Override public void registerClass(int id, String clsName) {
-        map.put(id, clsName);
+    @Override public void registerClass(int id, Class cls) {
+        map.put(id, cls);
     }
 
     /** {@inheritDoc} */
-    @Override public String className(int id) {
+    @Override public Class className(int id, ClassLoader ldr) throws ClassNotFoundException
{
         return map.get(id);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70d4b907/modules/core/src/test/java/org/apache/ignite/spi/discovery/AbstractDiscoverySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/AbstractDiscoverySelfTest.java
b/modules/core/src/test/java/org/apache/ignite/spi/discovery/AbstractDiscoverySelfTest.java
index 8474573..c568c50 100644
--- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/AbstractDiscoverySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/AbstractDiscoverySelfTest.java
@@ -454,7 +454,6 @@ public abstract class AbstractDiscoverySelfTest<T extends IgniteSpi>
extends Gri
      * @throws IOException If write failed.
      */
     private void writeObject(ClusterNode node) throws Exception {
-
         Marshaller marshaller = getTestResources().getMarshaller();
 
         OutputStream out = new NullOutputStream();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70d4b907/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
index acd8c40..7af1e72 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
@@ -51,9 +51,6 @@ public class IgniteTestResources {
     private final UUID nodeId;
 
     /** */
-    private Marshaller marshaller;
-
-    /** */
     private final MBeanServer jmx;
 
     /** */
@@ -233,20 +230,21 @@ public class IgniteTestResources {
      */
     @SuppressWarnings("unchecked")
     public synchronized Marshaller getMarshaller() throws IgniteCheckedException {
-        if (marshaller == null) {
-            String marshallerName = GridTestProperties.getProperty("marshaller.class");
-
-            if (marshallerName == null)
-                marshaller = new OptimizedMarshaller();
-            else {
-                try {
-                    Class<? extends Marshaller> cls = (Class<? extends Marshaller>)Class.forName(marshallerName);
-
-                    marshaller = cls.newInstance();
-                }
-                catch (ClassNotFoundException | IllegalAccessException | InstantiationException
e) {
-                    throw new IgniteCheckedException("Failed to create test marshaller [marshaller="
+ marshallerName + ']', e);
-                }
+        String marshallerName = GridTestProperties.getProperty("marshaller.class");
+
+        Marshaller marshaller;
+
+        if (marshallerName == null)
+            marshaller = new OptimizedMarshaller();
+        else {
+            try {
+                Class<? extends Marshaller> cls = (Class<? extends Marshaller>)Class.forName(marshallerName);
+
+                marshaller = cls.newInstance();
+            }
+            catch (ClassNotFoundException | IllegalAccessException | InstantiationException
e) {
+                throw new IgniteCheckedException("Failed to create test marshaller [marshaller="
+
+                    marshallerName + ']', e);
             }
         }
 


Mime
View raw message