ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject incubator-ignite git commit: # IGNITE-141 - Marshallers refactoring
Date Thu, 05 Mar 2015 01:08:53 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-141 91740cc39 -> 423169168


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

Branch: refs/heads/ignite-141
Commit: 423169168a25e12a30b0f0a43658835739907c3c
Parents: 91740cc
Author: Valentin Kulichenko <vkulichenko@gridgain.com>
Authored: Wed Mar 4 17:09:41 2015 -0800
Committer: Valentin Kulichenko <vkulichenko@gridgain.com>
Committed: Wed Mar 4 17:09:41 2015 -0800

----------------------------------------------------------------------
 .../internal/MarshallerContextAdapter.java      | 60 ++++++++++++++++++++
 .../ignite/internal/MarshallerContextImpl.java  | 38 +------------
 .../ignite/internal/classnames.properties       |  1 +
 .../client/GridClientConfiguration.java         |  3 +-
 .../GridClientOptimizedMarshaller.java          | 23 ++++++++
 5 files changed, 86 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/42316916/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextAdapter.java
new file mode 100644
index 0000000..cb4847b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextAdapter.java
@@ -0,0 +1,60 @@
+/*
+ * 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.marshaller.*;
+import org.jdk8.backport.*;
+
+import java.io.*;
+import java.util.concurrent.*;
+
+/**
+ * Marshaller context adapter.
+ */
+public abstract class MarshallerContextAdapter implements MarshallerContext {
+    /** */
+    private static final String CLS_NAMES_FILE = "org/apache/ignite/internal/classnames.properties";
+
+    /** */
+    protected final ConcurrentMap<Integer, String> clsNameById = new ConcurrentHashMap8<>();
+
+    /**
+     * Initializes context.
+     */
+    public MarshallerContextAdapter() {
+        try {
+            ClassLoader ldr = getClass().getClassLoader();
+
+            BufferedReader rdr = new BufferedReader(new InputStreamReader(ldr.getResourceAsStream(CLS_NAMES_FILE)));
+
+            String line;
+
+            while ((line = rdr.readLine()) != null) {
+                if (line.isEmpty() || line.startsWith("#"))
+                    continue;
+
+                String clsName = line.trim();
+
+                clsNameById.put(clsName.hashCode(), clsName);
+            }
+        }
+        catch (IOException e) {
+            throw new IllegalStateException("Failed to initialize marshaller context.", e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/42316916/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
index 5b0cb38..4a254fb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
@@ -20,22 +20,13 @@ package org.apache.ignite.internal;
 import org.apache.ignite.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.marshaller.*;
-import org.jdk8.backport.*;
 
-import java.io.*;
 import java.util.concurrent.*;
 
 /**
  * Marshaller context implementation.
  */
-public class MarshallerContextImpl implements MarshallerContext {
-    /** */
-    private static final String CLS_NAMES_FILE = "org/apache/ignite/internal/classnames.properties";
-
-    /** */
-    private final ConcurrentMap<Integer, String> clsNameById = new ConcurrentHashMap8<>();
-
+public class MarshallerContextImpl extends MarshallerContextAdapter {
     /** */
     private final CountDownLatch latch = new CountDownLatch(1);
 
@@ -43,31 +34,6 @@ public class MarshallerContextImpl implements MarshallerContext {
     private volatile GridCacheAdapter<Integer, String> cache;
 
     /**
-     * Constructor.
-     */
-    MarshallerContextImpl() {
-        try {
-            ClassLoader ldr = getClass().getClassLoader();
-
-            BufferedReader rdr = new BufferedReader(new InputStreamReader(ldr.getResourceAsStream(CLS_NAMES_FILE)));
-
-            String line;
-
-            while ((line = rdr.readLine()) != null) {
-                if (line.isEmpty() || line.startsWith("#"))
-                    continue;
-
-                String clsName = line.trim();
-
-                clsNameById.put(clsName.hashCode(), clsName);
-            }
-        }
-        catch (IOException e) {
-            throw new IllegalStateException("Failed to initialize marshaller context.", e);
-        }
-    }
-
-    /**
      * @param ctx Kernal context.
      */
     public void onMarshallerCacheReady(GridKernalContext ctx) {
@@ -82,8 +48,6 @@ public class MarshallerContextImpl implements MarshallerContext {
     @Override public void registerClass(int id, Class cls) {
         if (!clsNameById.containsKey(id)) {
             try {
-                U.debug("REG: " + cls.getName());
-
                 if (cache == null)
                     U.awaitQuiet(latch);
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/42316916/modules/core/src/main/java/org/apache/ignite/internal/classnames.properties
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/classnames.properties b/modules/core/src/main/java/org/apache/ignite/internal/classnames.properties
index def4e59..a39bcf3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/classnames.properties
+++ b/modules/core/src/main/java/org/apache/ignite/internal/classnames.properties
@@ -28,6 +28,7 @@
 [Lorg.apache.ignite.lang.IgniteBiTuple;
 [Lorg.apache.ignite.lang.IgniteFuture;
 [Lorg.apache.ignite.lang.IgnitePredicate;
+[Ljava.io.Serializable;
 [S
 [Z
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/42316916/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientConfiguration.java
b/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientConfiguration.java
index 9aaad8e..cfd780c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/client/GridClientConfiguration.java
@@ -19,7 +19,6 @@ package org.apache.ignite.internal.client;
 
 import org.apache.ignite.internal.client.balancer.*;
 import org.apache.ignite.internal.client.marshaller.*;
-import org.apache.ignite.internal.client.marshaller.jdk.*;
 import org.apache.ignite.internal.client.marshaller.optimized.*;
 import org.apache.ignite.internal.client.ssl.*;
 import org.apache.ignite.internal.util.typedef.*;
@@ -111,7 +110,7 @@ public class GridClientConfiguration {
     private ExecutorService executor;
 
     /** Marshaller. */
-    private GridClientMarshaller marshaller = new GridClientJdkMarshaller();
+    private GridClientMarshaller marshaller = new GridClientOptimizedMarshaller();
 
     /** Daemon flag. */
     private boolean daemon;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/42316916/modules/core/src/main/java/org/apache/ignite/internal/client/marshaller/optimized/GridClientOptimizedMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/client/marshaller/optimized/GridClientOptimizedMarshaller.java
b/modules/core/src/main/java/org/apache/ignite/internal/client/marshaller/optimized/GridClientOptimizedMarshaller.java
index e8b0899..e630277 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/client/marshaller/optimized/GridClientOptimizedMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/client/marshaller/optimized/GridClientOptimizedMarshaller.java
@@ -18,8 +18,10 @@
 package org.apache.ignite.internal.client.marshaller.optimized;
 
 import org.apache.ignite.*;
+import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.client.marshaller.*;
 import org.apache.ignite.internal.processors.rest.client.message.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.marshaller.optimized.*;
 
 import java.io.*;
@@ -41,6 +43,8 @@ public class GridClientOptimizedMarshaller implements GridClientMarshaller
{
      */
     public GridClientOptimizedMarshaller() {
         opMarsh = new OptimizedMarshaller();
+
+        opMarsh.setContext(new ClientMarshallerContext());
     }
 
     /**
@@ -55,6 +59,7 @@ public class GridClientOptimizedMarshaller implements GridClientMarshaller
{
     public GridClientOptimizedMarshaller(boolean requireSer, int poolSize) throws IOException
{
         opMarsh = new OptimizedMarshaller();
 
+        opMarsh.setContext(new ClientMarshallerContext());
         opMarsh.setRequireSerializable(requireSer);
         opMarsh.setPoolSize(poolSize);
     }
@@ -92,4 +97,22 @@ public class GridClientOptimizedMarshaller implements GridClientMarshaller
{
             throw new IOException(e);
         }
     }
+
+    /**
+     */
+    private static class ClientMarshallerContext extends MarshallerContextAdapter {
+        /** {@inheritDoc} */
+        @Override public void registerClass(int id, Class cls) {
+            // No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public Class className(int id, ClassLoader ldr) throws ClassNotFoundException
{
+            String clsName = clsNameById.get(id);
+
+            assert clsName != null : id;
+
+            return U.forName(clsName, ldr);
+        }
+    }
 }


Mime
View raw message