ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject [43/55] [abbrv] incubator-ignite git commit: IGNITE-61 - Direct marshalling
Date Sun, 08 Feb 2015 07:56:00 GMT
IGNITE-61 - Direct marshalling


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

Branch: refs/heads/ignite-61
Commit: 39fcfb630672dff86780d4c7826af6f27429990b
Parents: 43e19ee
Author: Valentin Kulichenko <vkulichenko@gridgain.com>
Authored: Sat Feb 7 21:52:24 2015 -0800
Committer: Valentin Kulichenko <vkulichenko@gridgain.com>
Committed: Sat Feb 7 21:52:24 2015 -0800

----------------------------------------------------------------------
 .../CommunicationMessageCodeGenerator.java      | 58 +++++++-------------
 .../internal/direct/DirectByteBufferStream.java | 11 ++++
 .../internal/direct/DirectMessageReader.java    |  9 +++
 .../internal/direct/DirectMessageWriter.java    |  7 +++
 .../communication/MessageAdapter.java           |  6 ++
 .../extensions/communication/MessageReader.java |  2 +
 .../extensions/communication/MessageWriter.java |  2 +
 7 files changed, 58 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/39fcfb63/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java
----------------------------------------------------------------------
diff --git a/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java
b/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java
index b828d73..b8c6aa9 100644
--- a/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java
+++ b/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java
@@ -34,6 +34,12 @@ public class CommunicationMessageCodeGenerator {
     };
 
     /** */
+    private static final String[] EXCLUDED_PACKAGES = new String[] {
+        "org.apache.ignite.internal.processors.rest.client.message",
+        "org.apache.ignite.internal.processors.rest.protocols.tcp"
+    };
+
+    /** */
     private static final String SRC_DIR = U.getIgniteHome() + "/modules/core/src/main/java";
 
     /** */
@@ -46,34 +52,13 @@ public class CommunicationMessageCodeGenerator {
     private static final String TAB = "    ";
 
     /** */
-    private static final String COMM_STATE_VAR = "commState";
-
-    /** */
     private static final String BUF_VAR = "buf";
 
     /** */
-    private static final String STATE_VAR = COMM_STATE_VAR + "." + "idx";
-
-    /** */
-    private static final String TYPE_WRITTEN_VAR = COMM_STATE_VAR + "." + "typeWritten";
-
-    /** */
-    private static final String IT_VAR = COMM_STATE_VAR + "." + "it";
-
-    /** */
-    private static final String CUR_VAR = COMM_STATE_VAR + "." + "cur";
+    private static final String STATE_VAR = "state";
 
     /** */
-    private static final String KEY_DONE_VAR = COMM_STATE_VAR + "." + "keyDone";
-
-    /** */
-    private static final String READ_SIZE_VAR = COMM_STATE_VAR + "." + "readSize";
-
-    /** */
-    private static final String READ_ITEMS_VAR = COMM_STATE_VAR + "." + "readItems";
-
-    /** */
-    private static final String DFLT_LOC_VAR = "_val";
+    private static final String TYPE_WRITTEN_VAR = "typeWritten";
 
     /** */
     private final Collection<String> write = new ArrayList<>();
@@ -297,14 +282,8 @@ public class CommunicationMessageCodeGenerator {
 
             for (Field field : cloningFields) {
                 String name = field.getName();
-                Class<?> type = field.getType();
-
-                String res = name;
-
-                if (BASE_CLS.isAssignableFrom(type))
-                    res = name + " != null ? (" + type.getSimpleName() + ")" + name + ".clone()
: null";
 
-                clone0.add(builder().a("_clone.").a(name).a(" = ").a(res).a(";").toString());
+                clone0.add(builder().a("_clone.").a(name).a(" = ").a(name).a(";").toString());
             }
         }
 
@@ -359,12 +338,12 @@ public class CommunicationMessageCodeGenerator {
     /**
      * @param code Code lines.
      * @param superMtd Super class method name.
-     * @param writeType Whether to write message type.
+     * @param write Whether write code is generated.
      */
-    private void start(Collection<String> code, @Nullable String superMtd, boolean
writeType) {
+    private void start(Collection<String> code, @Nullable String superMtd, boolean
write) {
         assert code != null;
 
-        code.add(builder().a(COMM_STATE_VAR).a(".setBuffer(").a(BUF_VAR).a(");").toString());
+        code.add(builder().a(write ? "writer" : "reader").a(".setBuffer(").a(BUF_VAR).a(");").toString());
         code.add(EMPTY);
 
         if (superMtd != null) {
@@ -373,12 +352,12 @@ public class CommunicationMessageCodeGenerator {
             code.add(EMPTY);
         }
 
-        if (writeType) {
+        if (write) {
             code.add(builder().a("if (!").a(TYPE_WRITTEN_VAR).a(") {").toString());
 
             indent++;
 
-            returnFalseIfFailed(code, COMM_STATE_VAR + ".putByte", "null", "directType()");
+            returnFalseIfFailed(code, "writer.writeByte", "null", "directType()");
 
             code.add(EMPTY);
             code.add(builder().a(TYPE_WRITTEN_VAR).a(" = true;").toString());
@@ -537,7 +516,7 @@ public class CommunicationMessageCodeGenerator {
         else if (type.isEnum())
             returnFalseIfFailed(write, "writer.writeEnum", field, name);
         else if (BASE_CLS.isAssignableFrom(type))
-            returnFalseIfFailed(write, "writer.writeMessage", field, name);
+            returnFalseIfFailed(write, "writer.writeMessage", field, name + " != null ? "
+ name + ".clone() : null");
         else if (type.isArray()) {
             returnFalseIfFailed(write, "writer.writeObjectArray", field, name,
                 type.getComponentType().getSimpleName() + ".class");
@@ -615,7 +594,7 @@ public class CommunicationMessageCodeGenerator {
         else if (type == IgniteUuid.class)
             returnFalseIfReadFailed(retType, name, "reader.readGridUuid", field);
         else if (type.isEnum())
-            returnFalseIfReadFailed(retType, name, "reader.readEnum", field);
+            returnFalseIfReadFailed(retType, name, "reader.readEnum", field, retType + ".class");
         else if (BASE_CLS.isAssignableFrom(type))
             returnFalseIfReadFailed(retType, name, "reader.readMessage", field);
         else if (type.isArray()) {
@@ -776,6 +755,11 @@ public class CommunicationMessageCodeGenerator {
             if (path.endsWith(".class")) {
                 String clsName = path.substring(prefixLen, path.length() - 6).replace(File.separatorChar,
'.');
 
+                for (String excluded : EXCLUDED_PACKAGES) {
+                    if (clsName.startsWith(excluded))
+                        return;
+                }
+
                 Class<?> cls = Class.forName(clsName, false, ldr);
 
                 if (cls.getDeclaringClass() == null && cls.getEnclosingClass() ==
null &&

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/39fcfb63/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
index cbb8d4c..e674861 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
@@ -524,6 +524,10 @@ public class DirectByteBufferStream {
         writeByteArray(val != null ? U.igniteUuidToBytes(val) : null);
     }
 
+    public void writeEnum(Enum<?> val) {
+        writeByte(val != null ? (byte)val.ordinal() : -1);
+    }
+
     /**
      * @param msg Message.
      */
@@ -840,6 +844,13 @@ public class DirectByteBufferStream {
         return arr != null ? U.bytesToIgniteUuid(arr, 0) : null;
     }
 
+    @SuppressWarnings("unchecked")
+    public <T extends Enum<T>> Enum<T> readEnum(Class<T> enumCls)
{
+        byte ord = readByte();
+
+        return ord >= 0 ? (Enum<T>)GridEnumCache.get(enumCls)[ord] : null;
+    }
+
     /**
      * @return Message.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/39fcfb63/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
index 547c71a..3875cfe 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
@@ -227,6 +227,15 @@ public class DirectMessageReader implements MessageReader {
     }
 
     /** {@inheritDoc} */
+    @Override public <T extends Enum<T>> Enum<T> readEnum(String name,
Class<T> enumCls) {
+        Enum<T> val = stream.readEnum(enumCls);
+
+        lastRead = stream.lastFinished();
+
+        return val;
+    }
+
+    /** {@inheritDoc} */
     @Nullable @Override public MessageAdapter readMessage(String name) {
         MessageAdapter msg = stream.readMessage();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/39fcfb63/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
index d7c679d..e5f005d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
@@ -177,6 +177,13 @@ public class DirectMessageWriter implements MessageWriter {
     }
 
     /** {@inheritDoc} */
+    @Override public boolean writeEnum(String name, Enum<?> val) {
+        stream.writeEnum(val);
+
+        return stream.lastFinished();
+    }
+
+    /** {@inheritDoc} */
     @Override public boolean writeMessage(String name, @Nullable MessageAdapter msg) {
         if (msg != null)
             msg.setWriter(this);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/39fcfb63/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageAdapter.java
b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageAdapter.java
index 89d26fc..2234698 100644
--- a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageAdapter.java
@@ -41,6 +41,12 @@ public abstract class MessageAdapter implements Serializable, Cloneable
{
     /** Reader. */
     protected MessageReader reader;
 
+    /** */
+    protected boolean typeWritten;
+
+    /** */
+    protected int state;
+
     /**
      * @param writer Writer.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/39fcfb63/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageReader.java
b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageReader.java
index aa1c09b..fa4ca66 100644
--- a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageReader.java
@@ -60,6 +60,8 @@ public interface MessageReader {
 
     public IgniteUuid readIgniteUuid(String name);
 
+    public <T extends Enum<T>> Enum<T> readEnum(String name, Class<T>
enumCls);
+
     public MessageAdapter readMessage(String name);
 
     public <T> T[] readObjectArray(String name, Class<T> itemCls);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/39fcfb63/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageWriter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageWriter.java
b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageWriter.java
index 19bb268..fc348ee 100644
--- a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageWriter.java
+++ b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageWriter.java
@@ -60,6 +60,8 @@ public interface MessageWriter {
 
     public boolean writeIgniteUuid(String name, IgniteUuid val);
 
+    public boolean writeEnum(String name, Enum<?> val);
+
     public boolean writeMessage(String name, MessageAdapter val);
 
     public <T> boolean writeObjectArray(String name, T[] arr, Class<T> itemCls);


Mime
View raw message