ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [3/5] ignite git commit: IGNITE-4611 Write IgniteUuid with BinaryMarshaller
Date Mon, 20 Feb 2017 11:33:46 GMT
IGNITE-4611 Write IgniteUuid with BinaryMarshaller

This closes #1551


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

Branch: refs/heads/ignite-4705
Commit: 53802d8b46f8ee09d51ba84267f65dc6f7e73a2f
Parents: ab1b685
Author: Vyacheslav Daradur <daradurvs@gmail.com>
Authored: Mon Feb 20 11:22:49 2017 +0300
Committer: Pavel Tupitsyn <ptupitsyn@apache.org>
Committed: Mon Feb 20 11:22:49 2017 +0300

----------------------------------------------------------------------
 .../ignite/internal/binary/BinaryContext.java   |  3 +++
 .../java/org/apache/ignite/lang/IgniteUuid.java | 25 +++++++++++++++++++-
 .../binary/BinaryMarshallerSelfTest.java        | 10 ++++++++
 3 files changed, 37 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/53802d8b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
index ec2fc7b..4773e3b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
@@ -85,6 +85,7 @@ import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.T2;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.marshaller.MarshallerContext;
 import org.apache.ignite.marshaller.MarshallerUtils;
 import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
@@ -194,6 +195,8 @@ public class BinaryContext {
         sysClss.add(GridClosureProcessor.C4V2.class.getName());
         sysClss.add(GridClosureProcessor.C4MLAV2.class.getName());
 
+        sysClss.add(IgniteUuid.class.getName());
+
         if (BinaryUtils.wrapTrees()) {
             sysClss.add(TreeMap.class.getName());
             sysClss.add(TreeSet.class.getName());

http://git-wip-us.apache.org/repos/asf/ignite/blob/53802d8b/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java b/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
index 7de389e..4b93261 100644
--- a/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
+++ b/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
@@ -24,6 +24,12 @@ import java.io.ObjectOutput;
 import java.util.Collections;
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicLong;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryRawReader;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.binary.Binarylizable;
 import org.apache.ignite.internal.util.lang.GridIterator;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.A;
@@ -34,7 +40,7 @@ import org.apache.ignite.internal.util.typedef.internal.U;
  * 10x time faster for ID creation. It uses extra memory for 8-byte counter additionally
to
  * internal UUID.
  */
-public final class IgniteUuid implements Comparable<IgniteUuid>, Iterable<IgniteUuid>,
Cloneable, Externalizable {
+public final class IgniteUuid implements Comparable<IgniteUuid>, Iterable<IgniteUuid>,
Cloneable, Externalizable, Binarylizable {
     /** */
     private static final long serialVersionUID = 0L;
 
@@ -203,6 +209,23 @@ public final class IgniteUuid implements Comparable<IgniteUuid>,
Iterable<Ignite
     }
 
     /** {@inheritDoc} */
+    @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+        BinaryRawWriter out = writer.rawWriter();
+
+        out.writeLong(locId);
+        out.writeLong(gid.getMostSignificantBits());
+        out.writeLong(gid.getLeastSignificantBits());
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+        BinaryRawReader in = reader.rawReader();
+
+        locId = in.readLong();
+        gid = new UUID(in.readLong(), in.readLong());
+    }
+
+    /** {@inheritDoc} */
     @Override public int hashCode() {
         return 31 * gid.hashCode() + (int)(locId ^ (locId >>> 32));
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/53802d8b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
index 5bfc95c..1cac1a8 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
@@ -86,6 +86,7 @@ import org.apache.ignite.internal.util.lang.GridMapEntry;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.logger.NullLogger;
 import org.apache.ignite.marshaller.MarshallerContextTestImpl;
 import org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage;
@@ -294,6 +295,15 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest
{
     /**
      * @throws Exception If failed.
      */
+    public void testIgniteUuid() throws Exception {
+        IgniteUuid uuid = IgniteUuid.randomUuid();
+
+        assertEquals(uuid, marshalUnmarshal(uuid));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testDate() throws Exception {
         Date date = new Date();
 


Mime
View raw message