ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject [53/55] [abbrv] incubator-ignite git commit: IGNITE-61 - Direct marshalling
Date Sun, 08 Feb 2015 07:56:10 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/01b20a69
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/01b20a69
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/01b20a69

Branch: refs/heads/ignite-61
Commit: 01b20a695ce7b5207888bf2dca998942d4224440
Parents: 159c1e8
Author: Valentin Kulichenko <vkulichenko@gridgain.com>
Authored: Sat Feb 7 23:07:34 2015 -0800
Committer: Valentin Kulichenko <vkulichenko@gridgain.com>
Committed: Sat Feb 7 23:07:34 2015 -0800

----------------------------------------------------------------------
 .../CommunicationMessageCodeGenerator.java      |  21 +-
 .../ignite/internal/direct/DirectUtils.java     | 346 -------------------
 .../managers/communication/GridIoMessage.java   |   4 +-
 3 files changed, 20 insertions(+), 351 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/01b20a69/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 45a383c..4a81a92 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
@@ -10,6 +10,7 @@
 package org.apache.ignite.codegen;
 
 import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.managers.communication.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.plugin.extensions.communication.*;
@@ -76,6 +77,9 @@ public class CommunicationMessageCodeGenerator {
     private final Map<Class<?>, Integer> fieldCnt = new HashMap<>();
 
     /** */
+    private Class<? extends MessageAdapter> curCls;
+
+    /** */
     private List<Field> fields;
 
     /** */
@@ -233,6 +237,8 @@ public class CommunicationMessageCodeGenerator {
     public void generate(Class<? extends MessageAdapter> cls) throws Exception {
         assert cls != null;
 
+        curCls = cls;
+
         write.clear();
         read.clear();
         clone.clear();
@@ -282,8 +288,14 @@ public class CommunicationMessageCodeGenerator {
 
             for (Field field : cloningFields) {
                 String name = field.getName();
+                Class<?> type = field.getType();
+
+                String res = name;
 
-                clone0.add(builder().a("_clone.").a(name).a(" = ").a(name).a(";").toString());
+                if (curCls.equals(GridIoMessage.class) && BASE_CLS.isAssignableFrom(type))
+                    res = name + " != null ? (" + type.getSimpleName() + ")" + name + ".clone()
: null";
+
+                clone0.add(builder().a("_clone.").a(name).a(" = ").a(res).a(";").toString());
             }
         }
 
@@ -515,8 +527,11 @@ public class CommunicationMessageCodeGenerator {
             returnFalseIfFailed(write, "writer.writeIgniteUuid", field, name);
         else if (type.isEnum())
             returnFalseIfFailed(write, "writer.writeEnum", field, name);
-        else if (BASE_CLS.isAssignableFrom(type))
-            returnFalseIfFailed(write, "writer.writeMessage", field, name + " != null ? "
+ name + ".clone() : null");
+        else if (BASE_CLS.isAssignableFrom(type)) {
+            String arg = curCls.equals(GridIoMessage.class) ? name : name + " != null ? "
+ name + ".clone() : null";
+
+            returnFalseIfFailed(write, "writer.writeMessage", field, arg);
+        }
         else if (type.isArray()) {
             returnFalseIfFailed(write, "writer.writeObjectArray", field, name,
                 type.getComponentType().getSimpleName() + ".class");

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/01b20a69/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectUtils.java
deleted file mode 100644
index d0d966f..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectUtils.java
+++ /dev/null
@@ -1,346 +0,0 @@
-/*
- * 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.direct;
-
-import org.apache.ignite.internal.processors.cache.*;
-import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.*;
-import org.apache.ignite.internal.processors.cache.version.*;
-import org.apache.ignite.internal.processors.clock.*;
-import org.apache.ignite.internal.util.*;
-import org.apache.ignite.lang.*;
-import sun.misc.*;
-
-import java.util.*;
-
-/**
- * Direct marshalling utility methods.
- */
-public class DirectUtils {
-    /** */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
-    private static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /**
-     * Do not instantiate.
-     */
-    private DirectUtils() {
-        // No-op.
-    }
-
-    /**
-     * @param uuid {@link UUID}.
-     * @return Array.
-     */
-    public static byte[] uuidToArray(UUID uuid) {
-        byte[] arr = null;
-
-        if (uuid != null) {
-            arr = new byte[16];
-
-            UNSAFE.putLong(arr, BYTE_ARR_OFF, uuid.getMostSignificantBits());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, uuid.getLeastSignificantBits());
-        }
-
-        return arr;
-    }
-
-    /**
-     * @param arr Array.
-     * @return {@link UUID}.
-     */
-    public static UUID arrayToUuid(byte[] arr) {
-        if (arr == null)
-            return null;
-        else {
-            long most = UNSAFE.getLong(arr, BYTE_ARR_OFF);
-            long least = UNSAFE.getLong(arr, BYTE_ARR_OFF + 8);
-
-            return new UUID(most, least);
-        }
-    }
-
-    /**
-     * @param uuid {@link IgniteUuid}.
-     * @return Array.
-     */
-    public static byte[] gridUuidToArray(IgniteUuid uuid) {
-        byte[] arr = null;
-
-        if (uuid != null) {
-            arr = new byte[24];
-
-            UNSAFE.putLong(arr, BYTE_ARR_OFF, uuid.globalId().getMostSignificantBits());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, uuid.globalId().getLeastSignificantBits());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 16, uuid.localId());
-        }
-
-        return arr;
-    }
-
-    /**
-     * @param arr Array.
-     * @return {@link IgniteUuid}.
-     */
-    public static IgniteUuid arrayToIgniteUuid(byte[] arr) {
-        if (arr == null)
-            return null;
-        else {
-            long most = UNSAFE.getLong(arr, BYTE_ARR_OFF);
-            long least = UNSAFE.getLong(arr, BYTE_ARR_OFF + 8);
-            long loc = UNSAFE.getLong(arr, BYTE_ARR_OFF + 16);
-
-            return new IgniteUuid(new UUID(most, least), loc);
-        }
-    }
-
-    /**
-     * @param ver {@link GridClockDeltaVersion}.
-     * @return Array.
-     */
-    public static byte[] clockDeltaVersionToArray(GridClockDeltaVersion ver) {
-        byte[] arr = null;
-
-        if (ver != null) {
-            arr = new byte[16];
-
-            UNSAFE.putLong(arr, BYTE_ARR_OFF, ver.version());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, ver.topologyVersion());
-        }
-
-        return arr;
-    }
-
-    /**
-     * @param arr Array.
-     * @return {@link GridClockDeltaVersion}.
-     */
-    public static GridClockDeltaVersion arrayToClockDeltaVersion(byte[] arr) {
-        if (arr == null)
-            return null;
-        else {
-            long ver = UNSAFE.getLong(arr, BYTE_ARR_OFF);
-            long topVer = UNSAFE.getLong(arr, BYTE_ARR_OFF + 8);
-
-            return new GridClockDeltaVersion(ver, topVer);
-        }
-    }
-
-    /**
-     * @param list {@link GridByteArrayList}.
-     * @return Array.
-     */
-    public static byte[] byteArrayListToArray(GridByteArrayList list) {
-        return list != null ? list.array() : null;
-    }
-
-    /**
-     * @param arr Array.
-     * @return {@link GridByteArrayList}.
-     */
-    public static GridByteArrayList arrayToByteArrayList(byte[] arr) {
-        return arr != null ? new GridByteArrayList(arr) : null;
-    }
-
-    /**
-     * @param list {@link GridLongList}.
-     * @return Array.
-     */
-    public static long[] longListToArray(GridLongList list) {
-        return list != null ? list.array() : null;
-    }
-
-    /**
-     * @param arr Array.
-     * @return {@link GridLongList}.
-     */
-    public static GridLongList arrayToLongList(long[] arr) {
-        return arr != null ? new GridLongList(arr) : null;
-    }
-
-    /**
-     * @param ver {@link GridCacheVersion}.
-     * @return Array.
-     */
-    public static byte[] cacheVersionToArray(GridCacheVersion ver) {
-        byte[] arr = null;
-
-        if (ver != null) {
-            arr = new byte[24];
-
-            UNSAFE.putInt(arr, BYTE_ARR_OFF, ver.topologyVersion());
-            UNSAFE.putInt(arr, BYTE_ARR_OFF + 4, ver.nodeOrderAndDrIdRaw());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, ver.globalTime());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 16, ver.order());
-        }
-
-        return arr;
-    }
-
-    /**
-     * @param arr Array.
-     * @return {@link GridCacheVersion}.
-     */
-    public static GridCacheVersion arrayToCacheVersion(byte[] arr) {
-        if (arr == null)
-            return null;
-        else {
-            int topVerDrId = UNSAFE.getInt(arr, BYTE_ARR_OFF);
-            int nodeOrder = UNSAFE.getInt(arr, BYTE_ARR_OFF + 4);
-            long globalTime = UNSAFE.getLong(arr, BYTE_ARR_OFF + 8);
-            long order = UNSAFE.getLong(arr, BYTE_ARR_OFF + 16);
-
-            return new GridCacheVersion(topVerDrId, nodeOrder, globalTime, order);
-        }
-    }
-
-    /**
-     * @param id {@link GridDhtPartitionExchangeId}.
-     * @return Array.
-     */
-    public static byte[] dhtPartitionExchangeIdToArray(GridDhtPartitionExchangeId id) {
-        byte[] arr = null;
-
-        if (id != null) {
-            arr = new byte[28];
-
-            UNSAFE.putLong(arr, BYTE_ARR_OFF, id.nodeId().getMostSignificantBits());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, id.nodeId().getLeastSignificantBits());
-            UNSAFE.putInt(arr, BYTE_ARR_OFF + 16, id.event());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 20, id.topologyVersion());
-        }
-
-        return arr;
-    }
-
-    /**
-     * @param arr Array.
-     * @return {@link GridDhtPartitionExchangeId}.
-     */
-    public static GridDhtPartitionExchangeId arrayToDhtPartitionExchangeId(byte[] arr) {
-        if (arr == null)
-            return null;
-        else {
-            long most = UNSAFE.getLong(arr, BYTE_ARR_OFF);
-            long least = UNSAFE.getLong(arr, BYTE_ARR_OFF + 8);
-            int evt = UNSAFE.getInt(arr, BYTE_ARR_OFF + 16);
-            long topVer = UNSAFE.getLong(arr, BYTE_ARR_OFF + 20);
-
-            return new GridDhtPartitionExchangeId(new UUID(most, least), evt, topVer);
-        }
-    }
-
-    /**
-     * @param bytes {@link GridCacheValueBytes}.
-     * @return Array.
-     */
-    public static byte[] valueBytesToArray(GridCacheValueBytes bytes) {
-        byte[] arr = null;
-
-        if (bytes != null) {
-            byte[] bytes0 = bytes.get();
-
-            if (bytes0 != null) {
-                int len = bytes0.length;
-
-                arr = new byte[len + 2];
-
-                UNSAFE.putBoolean(arr, BYTE_ARR_OFF, true);
-                UNSAFE.copyMemory(bytes0, BYTE_ARR_OFF, arr, BYTE_ARR_OFF + 1, len);
-                UNSAFE.putBoolean(arr, BYTE_ARR_OFF + 1 + len, bytes.isPlain());
-            }
-            else {
-                arr = new byte[1];
-
-                UNSAFE.putBoolean(arr, BYTE_ARR_OFF, false);
-            }
-        }
-
-        return arr;
-    }
-
-    /**
-     * @param arr Array.
-     * @return {@link GridCacheValueBytes}.
-     */
-    public static GridCacheValueBytes arrayToValueBytes(byte[] arr) {
-        if (arr == null)
-            return null;
-        else {
-            boolean notNull = UNSAFE.getBoolean(arr, BYTE_ARR_OFF);
-
-            if (notNull) {
-                int len = arr.length - 2;
-
-                assert len >= 0 : len;
-
-                byte[] bytesArr = new byte[len];
-
-                UNSAFE.copyMemory(arr, BYTE_ARR_OFF + 1, bytesArr, BYTE_ARR_OFF, len);
-
-                boolean isPlain = UNSAFE.getBoolean(arr, BYTE_ARR_OFF + 1 + len);
-
-                return new GridCacheValueBytes(bytesArr, isPlain);
-            }
-            else
-                return new GridCacheValueBytes();
-        }
-    }
-
-    /**
-     * @param str {@link String}.
-     * @return Array.
-     */
-    public static byte[] stringToArray(String str) {
-        return str != null ? str.getBytes() : null;
-    }
-
-    /**
-     * @param arr Array.
-     * @return {@link String}.
-     */
-    public static String arrayToString(byte[] arr) {
-        return arr != null ? new String(arr) : null;
-    }
-
-    /**
-     * @param bits {@link BitSet}.
-     * @return Array.
-     */
-    public static long[] bitSetToArray(BitSet bits) {
-        return bits != null ? bits.toLongArray() : null;
-    }
-
-    /**
-     * @param arr Array.
-     * @return {@link BitSet}.
-     */
-    public static BitSet arrayToBitSet(long[] arr) {
-        return arr != null ? BitSet.valueOf(arr) : null;
-    }
-
-//    /**
-//     * @param name Field name.
-//     * @param e Enum.
-//     * @return Whether value was fully written.
-//     */
-//    protected boolean putEnum(String name, @Nullable Enum<?> e) {
-//        return writer.writeByte(name, e != null ? (byte)e.ordinal() : -1);
-//    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/01b20a69/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessage.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessage.java
index 27d64be..c77f174 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessage.java
@@ -200,7 +200,7 @@ public class GridIoMessage extends MessageAdapter {
         _clone.ordered = ordered;
         _clone.timeout = timeout;
         _clone.skipOnTimeout = skipOnTimeout;
-        _clone.msg = msg;
+        _clone.msg = msg != null ? (MessageAdapter)msg.clone() : null;
     }
 
     /** {@inheritDoc} */
@@ -217,7 +217,7 @@ public class GridIoMessage extends MessageAdapter {
 
         switch (state) {
             case 0:
-                if (!writer.writeMessage("msg", msg != null ? msg.clone() : null))
+                if (!writer.writeMessage("msg", msg))
                     return false;
 
                 state++;


Mime
View raw message