You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/11/16 11:05:50 UTC

[1/4] ignite git commit: IGNITE-1917: Writer simplification.

Repository: ignite
Updated Branches:
  refs/heads/ignite-1917 417bd0975 -> 1c71f2257


IGNITE-1917: Writer simplification.


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

Branch: refs/heads/ignite-1917
Commit: 4d81895aebe7b31c23a823d7a08c05f66aa7c194
Parents: 417bd09
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Mon Nov 16 12:33:19 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Mon Nov 16 12:33:19 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/BinaryWriterExImpl.java   | 338 ++++++++-----------
 .../portable/PortableClassDescriptor.java       |  24 +-
 .../ignite/internal/portable/PortableUtils.java |  13 +-
 3 files changed, 154 insertions(+), 221 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4d81895a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
index c440024..c303813 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
@@ -97,6 +97,12 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     /** */
     private final int start;
 
+    /** Output stream. */
+    private final PortableOutputStream out;
+
+    /** Schema. */
+    private final BinaryWriterSchemaHolder schema;
+
     /** */
     private int typeId;
 
@@ -106,12 +112,6 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     /** Handles. */
     private BinaryWriterHandles handles;
 
-    /** Output stream. */
-    private PortableOutputStream out;
-
-    /** Schema. */
-    private BinaryWriterSchemaHolder schema;
-
     /** Schema ID. */
     private int schemaId = PortableUtils.schemaInitialId();
 
@@ -203,7 +203,8 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
             throw new BinaryObjectException("Object is not portable: [class=" + cls + ']');
 
         if (desc.excluded()) {
-            doWriteByte(NULL);
+            out.writeByte(NULL);
+
             return;
         }
 
@@ -241,7 +242,8 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
             }
 
             if (replacedObj == null) {
-                doWriteByte(NULL);
+                out.writeByte(NULL);
+
                 return;
             }
 
@@ -378,69 +380,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     }
 
     /**
-     * @param val Value.
-     */
-    public void doWriteByte(byte val) {
-        out.writeByte(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    public void doWriteShort(short val) {
-        out.writeShort(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    public void doWriteInt(int val) {
-        out.writeInt(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    public void doWriteLong(long val) {
-        out.writeLong(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    public void doWriteFloat(float val) {
-        out.writeFloat(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    public void doWriteDouble(double val) {
-        out.writeDouble(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    public void doWriteChar(char val) {
-        out.writeChar(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    public void doWriteBoolean(boolean val) {
-        out.writeBoolean(val);
-    }
-
-    /**
      * @param val String value.
      */
     public void doWriteDecimal(@Nullable BigDecimal val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
-            doWriteByte(DECIMAL);
+            out.writeByte(DECIMAL);
 
             BigInteger intVal = val.unscaledValue();
 
@@ -464,14 +410,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     public void doWriteString(@Nullable String val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
-            doWriteByte(STRING);
+            out.writeByte(STRING);
 
             byte[] strArr = val.getBytes(UTF_8);
 
-            doWriteInt(strArr.length);
-
+            out.writeInt(strArr.length);
             out.writeByteArray(strArr);
         }
     }
@@ -481,11 +426,11 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     public void doWriteUuid(@Nullable UUID uuid) {
         if (uuid == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
-            doWriteByte(UUID);
-            doWriteLong(uuid.getMostSignificantBits());
-            doWriteLong(uuid.getLeastSignificantBits());
+            out.writeByte(UUID);
+            out.writeLong(uuid.getMostSignificantBits());
+            out.writeLong(uuid.getLeastSignificantBits());
         }
     }
 
@@ -494,10 +439,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     public void doWriteDate(@Nullable Date date) {
         if (date == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
-            doWriteByte(DATE);
-            doWriteLong(date.getTime());
+            out.writeByte(DATE);
+            out.writeLong(date.getTime());
         }
     }
 
@@ -506,11 +451,11 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     public void doWriteTimestamp(@Nullable Timestamp ts) {
         if (ts== null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
-            doWriteByte(TIMESTAMP);
-            doWriteLong(ts.getTime());
-            doWriteInt(ts.getNanos() % 1000000);
+            out.writeByte(TIMESTAMP);
+            out.writeLong(ts.getTime());
+            out.writeInt(ts.getNanos() % 1000000);
         }
     }
 
@@ -522,7 +467,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     public void doWriteObject(@Nullable Object obj) throws BinaryObjectException {
         if (obj == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out, schema, handles());
 
@@ -535,14 +480,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteByteArray(@Nullable byte[] val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(val))
                 return;
 
-            doWriteByte(BYTE_ARR);
-            doWriteInt(val.length);
-
+            out.writeByte(BYTE_ARR);
+            out.writeInt(val.length);
             out.writeByteArray(val);
         }
     }
@@ -552,14 +496,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteShortArray(@Nullable short[] val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(val))
                 return;
 
-            doWriteByte(SHORT_ARR);
-            doWriteInt(val.length);
-
+            out.writeByte(SHORT_ARR);
+            out.writeInt(val.length);
             out.writeShortArray(val);
         }
     }
@@ -569,14 +512,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteIntArray(@Nullable int[] val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(val))
                 return;
 
-            doWriteByte(INT_ARR);
-            doWriteInt(val.length);
-
+            out.writeByte(INT_ARR);
+            out.writeInt(val.length);
             out.writeIntArray(val);
         }
     }
@@ -586,14 +528,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteLongArray(@Nullable long[] val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(val))
                 return;
 
-            doWriteByte(LONG_ARR);
-            doWriteInt(val.length);
-
+            out.writeByte(LONG_ARR);
+            out.writeInt(val.length);
             out.writeLongArray(val);
         }
     }
@@ -603,14 +544,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteFloatArray(@Nullable float[] val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(val))
                 return;
 
-            doWriteByte(FLOAT_ARR);
-            doWriteInt(val.length);
-
+            out.writeByte(FLOAT_ARR);
+            out.writeInt(val.length);
             out.writeFloatArray(val);
         }
     }
@@ -620,13 +560,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteDoubleArray(@Nullable double[] val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(val))
                 return;
 
-            doWriteByte(DOUBLE_ARR);
-            doWriteInt(val.length);
+            out.writeByte(DOUBLE_ARR);
+            out.writeInt(val.length);
 
             out.writeDoubleArray(val);
         }
@@ -637,13 +577,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteCharArray(@Nullable char[] val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(val))
                 return;
 
-            doWriteByte(CHAR_ARR);
-            doWriteInt(val.length);
+            out.writeByte(CHAR_ARR);
+            out.writeInt(val.length);
 
             out.writeCharArray(val);
         }
@@ -654,13 +594,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteBooleanArray(@Nullable boolean[] val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(val))
                 return;
 
-            doWriteByte(BOOLEAN_ARR);
-            doWriteInt(val.length);
+            out.writeByte(BOOLEAN_ARR);
+            out.writeInt(val.length);
 
             out.writeBooleanArray(val);
         }
@@ -671,13 +611,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteDecimalArray(@Nullable BigDecimal[] val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(val))
                 return;
 
-            doWriteByte(DECIMAL_ARR);
-            doWriteInt(val.length);
+            out.writeByte(DECIMAL_ARR);
+            out.writeInt(val.length);
 
             for (BigDecimal str : val)
                 doWriteDecimal(str);
@@ -689,13 +629,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteStringArray(@Nullable String[] val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(val))
                 return;
 
-            doWriteByte(STRING_ARR);
-            doWriteInt(val.length);
+            out.writeByte(STRING_ARR);
+            out.writeInt(val.length);
 
             for (String str : val)
                 doWriteString(str);
@@ -707,13 +647,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteUuidArray(@Nullable UUID[] val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(val))
                 return;
 
-            doWriteByte(UUID_ARR);
-            doWriteInt(val.length);
+            out.writeByte(UUID_ARR);
+            out.writeInt(val.length);
 
             for (UUID uuid : val)
                 doWriteUuid(uuid);
@@ -725,13 +665,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteDateArray(@Nullable Date[] val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(val))
                 return;
 
-            doWriteByte(DATE_ARR);
-            doWriteInt(val.length);
+            out.writeByte(DATE_ARR);
+            out.writeInt(val.length);
 
             for (Date date : val)
                 doWriteDate(date);
@@ -743,13 +683,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
       */
      void doWriteTimestampArray(@Nullable Timestamp[] val) {
          if (val == null)
-             doWriteByte(NULL);
+             out.writeByte(NULL);
          else {
              if (tryWriteAsHandle(val))
                  return;
 
-             doWriteByte(TIMESTAMP_ARR);
-             doWriteInt(val.length);
+             out.writeByte(TIMESTAMP_ARR);
+             out.writeInt(val.length);
 
              for (Timestamp ts : val)
                  doWriteTimestamp(ts);
@@ -762,23 +702,23 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteObjectArray(@Nullable Object[] val) throws BinaryObjectException {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(val))
                 return;
 
             PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType());
 
-            doWriteByte(OBJ_ARR);
+            out.writeByte(OBJ_ARR);
 
             if (desc.registered())
-                doWriteInt(desc.typeId());
+                out.writeInt(desc.typeId());
             else {
-                doWriteInt(UNREGISTERED_TYPE_ID);
+                out.writeInt(UNREGISTERED_TYPE_ID);
                 doWriteString(val.getClass().getComponentType().getName());
             }
 
-            doWriteInt(val.length);
+            out.writeInt(val.length);
 
             for (Object obj : val)
                 doWriteObject(obj);
@@ -791,14 +731,14 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteCollection(@Nullable Collection<?> col) throws BinaryObjectException {
         if (col == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(col))
                 return;
 
-            doWriteByte(COL);
-            doWriteInt(col.size());
-            doWriteByte(ctx.collectionType(col.getClass()));
+            out.writeByte(COL);
+            out.writeInt(col.size());
+            out.writeByte(ctx.collectionType(col.getClass()));
 
             for (Object obj : col)
                 doWriteObject(obj);
@@ -811,14 +751,14 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteMap(@Nullable Map<?, ?> map) throws BinaryObjectException {
         if (map == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(map))
                 return;
 
-            doWriteByte(MAP);
-            doWriteInt(map.size());
-            doWriteByte(ctx.mapType(map.getClass()));
+            out.writeByte(MAP);
+            out.writeInt(map.size());
+            out.writeByte(ctx.mapType(map.getClass()));
 
             for (Map.Entry<?, ?> e : map.entrySet()) {
                 doWriteObject(e.getKey());
@@ -833,12 +773,12 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteMapEntry(@Nullable Map.Entry<?, ?> e) throws BinaryObjectException {
         if (e == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             if (tryWriteAsHandle(e))
                 return;
 
-            doWriteByte(MAP_ENTRY);
+            out.writeByte(MAP_ENTRY);
             doWriteObject(e.getKey());
             doWriteObject(e.getValue());
         }
@@ -849,20 +789,20 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteEnum(@Nullable Enum<?> val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass());
 
-            doWriteByte(ENUM);
+            out.writeByte(ENUM);
 
             if (desc.registered())
-                doWriteInt(desc.typeId());
+                out.writeInt(desc.typeId());
             else {
-                doWriteInt(UNREGISTERED_TYPE_ID);
+                out.writeInt(UNREGISTERED_TYPE_ID);
                 doWriteString(val.getClass().getName());
             }
 
-            doWriteInt(val.ordinal());
+            out.writeInt(val.ordinal());
         }
     }
 
@@ -873,19 +813,19 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
         assert val == null || val.getClass().getComponentType().isEnum();
 
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType());
-            doWriteByte(ENUM_ARR);
+            out.writeByte(ENUM_ARR);
 
             if (desc.registered())
-                doWriteInt(desc.typeId());
+                out.writeInt(desc.typeId());
             else {
-                doWriteInt(UNREGISTERED_TYPE_ID);
+                out.writeInt(UNREGISTERED_TYPE_ID);
                 doWriteString(val.getClass().getComponentType().getName());
             }
 
-            doWriteInt(val.length);
+            out.writeInt(val.length);
 
             // TODO: Denis: Redundant data for each element of the array.
             for (Object o : val)
@@ -898,16 +838,16 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteClass(@Nullable Class val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             PortableClassDescriptor desc = ctx.descriptorForClass(val);
 
-            doWriteByte(CLASS);
+            out.writeByte(CLASS);
 
             if (desc.registered())
-                doWriteInt(desc.typeId());
+                out.writeInt(desc.typeId());
             else {
-                doWriteInt(UNREGISTERED_TYPE_ID);
+                out.writeInt(UNREGISTERED_TYPE_ID);
                 doWriteString(val.getClass().getName());
             }
         }
@@ -918,17 +858,15 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     public void doWritePortableObject(@Nullable BinaryObjectImpl po) {
         if (po == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
-            doWriteByte(PORTABLE_OBJ);
+            out.writeByte(PORTABLE_OBJ);
 
             byte[] poArr = po.array();
 
-            doWriteInt(poArr.length);
-
+            out.writeInt(poArr.length);
             out.writeByteArray(poArr);
-
-            doWriteInt(po.start());
+            out.writeInt(po.start());
         }
     }
 
@@ -936,8 +874,8 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      * @param val Value.
      */
     void writeByteFieldPrimitive(byte val) {
-        doWriteByte(BYTE);
-        doWriteByte(val);
+        out.writeByte(BYTE);
+        out.writeByte(val);
     }
 
     /**
@@ -945,7 +883,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeByteField(@Nullable Byte val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else
             writeByteFieldPrimitive(val);
     }
@@ -961,8 +899,8 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      * @param val Value.
      */
     void writeShortFieldPrimitive(short val) {
-        doWriteByte(SHORT);
-        doWriteShort(val);
+        out.writeByte(SHORT);
+        out.writeShort(val);
     }
 
     /**
@@ -970,7 +908,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeShortField(@Nullable Short val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else
             writeShortFieldPrimitive(val);
     }
@@ -979,8 +917,8 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      * @param val Value.
      */
     void writeIntFieldPrimitive(int val) {
-        doWriteByte(INT);
-        doWriteInt(val);
+        out.writeByte(INT);
+        out.writeInt(val);
     }
 
     /**
@@ -988,7 +926,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeIntField(@Nullable Integer val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else
             writeIntFieldPrimitive(val);
     }
@@ -997,8 +935,8 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      * @param val Value.
      */
     void writeLongFieldPrimitive(long val) {
-        doWriteByte(LONG);
-        doWriteLong(val);
+        out.writeByte(LONG);
+        out.writeLong(val);
     }
 
     /**
@@ -1006,7 +944,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeLongField(@Nullable Long val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else
             writeLongFieldPrimitive(val);
     }
@@ -1015,8 +953,8 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      * @param val Value.
      */
     void writeFloatFieldPrimitive(float val) {
-        doWriteByte(FLOAT);
-        doWriteFloat(val);
+        out.writeByte(FLOAT);
+        out.writeFloat(val);
     }
 
     /**
@@ -1024,7 +962,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeFloatField(@Nullable Float val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else
             writeFloatFieldPrimitive(val);
     }
@@ -1033,8 +971,8 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      * @param val Value.
      */
     void writeDoubleFieldPrimitive(double val) {
-        doWriteByte(DOUBLE);
-        doWriteDouble(val);
+        out.writeByte(DOUBLE);
+        out.writeDouble(val);
     }
 
     /**
@@ -1042,7 +980,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeDoubleField(@Nullable Double val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else
             writeDoubleFieldPrimitive(val);
     }
@@ -1051,8 +989,8 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      * @param val Value.
      */
     void writeCharFieldPrimitive(char val) {
-        doWriteByte(CHAR);
-        doWriteChar(val);
+        out.writeByte(CHAR);
+        out.writeChar(val);
     }
 
     /**
@@ -1060,7 +998,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeCharField(@Nullable Character val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else
             writeCharFieldPrimitive(val);
     }
@@ -1069,8 +1007,8 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      * @param val Value.
      */
     void writeBooleanFieldPrimitive(boolean val) {
-        doWriteByte(BOOLEAN);
-        doWriteBoolean(val);
+        out.writeByte(BOOLEAN);
+        out.writeBoolean(val);
     }
 
     /**
@@ -1078,7 +1016,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeBooleanField(@Nullable Boolean val) {
         if (val == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else
             writeBooleanFieldPrimitive(val);
     }
@@ -1279,7 +1217,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
     /** {@inheritDoc} */
     @Override public void writeByte(byte val) throws BinaryObjectException {
-        doWriteByte(val);
+        out.writeByte(val);
     }
 
     /** {@inheritDoc} */
@@ -1290,7 +1228,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
     /** {@inheritDoc} */
     @Override public void writeShort(short val) throws BinaryObjectException {
-        doWriteShort(val);
+        out.writeShort(val);
     }
 
     /** {@inheritDoc} */
@@ -1301,7 +1239,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
     /** {@inheritDoc} */
     @Override public void writeInt(int val) throws BinaryObjectException {
-        doWriteInt(val);
+        out.writeInt(val);
     }
 
     /** {@inheritDoc} */
@@ -1312,7 +1250,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
     /** {@inheritDoc} */
     @Override public void writeLong(long val) throws BinaryObjectException {
-        doWriteLong(val);
+        out.writeLong(val);
     }
 
     /** {@inheritDoc} */
@@ -1323,7 +1261,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
     /** {@inheritDoc} */
     @Override public void writeFloat(float val) throws BinaryObjectException {
-        doWriteFloat(val);
+        out.writeFloat(val);
     }
 
     /** {@inheritDoc} */
@@ -1334,7 +1272,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
     /** {@inheritDoc} */
     @Override public void writeDouble(double val) throws BinaryObjectException {
-        doWriteDouble(val);
+        out.writeDouble(val);
     }
 
     /** {@inheritDoc} */
@@ -1345,7 +1283,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
     /** {@inheritDoc} */
     @Override public void writeChar(char val) throws BinaryObjectException {
-        doWriteChar(val);
+        out.writeChar(val);
     }
 
     /** {@inheritDoc} */
@@ -1356,7 +1294,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
     /** {@inheritDoc} */
     @Override public void writeBoolean(boolean val) throws BinaryObjectException {
-        doWriteBoolean(val);
+        out.writeBoolean(val);
     }
 
     /** {@inheritDoc} */
@@ -1428,7 +1366,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     /** {@inheritDoc} */
     @Override public void writeObjectDetached(@Nullable Object obj) throws BinaryObjectException {
         if (obj == null)
-            doWriteByte(NULL);
+            out.writeByte(NULL);
         else {
             BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out, schema, null);
 
@@ -1683,22 +1621,22 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
     /** {@inheritDoc} */
     @Override public void writeByte(int v) throws IOException {
-        doWriteByte((byte) v);
+        out.writeByte((byte) v);
     }
 
     /** {@inheritDoc} */
     @Override public void writeShort(int v) throws IOException {
-        doWriteShort((short) v);
+        out.writeShort((short) v);
     }
 
     /** {@inheritDoc} */
     @Override public void writeChar(int v) throws IOException {
-        doWriteChar((char) v);
+        out.writeChar((char) v);
     }
 
     /** {@inheritDoc} */
     @Override public void write(int b) throws IOException {
-        doWriteByte((byte) b);
+        out.writeByte((byte) b);
     }
 
     /** {@inheritDoc} */
@@ -1799,8 +1737,8 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
         if (old == BinaryWriterHandles.POS_NULL)
             return false;
         else {
-            doWriteByte(GridPortableMarshaller.HANDLE);
-            doWriteInt(pos - old);
+            out.writeByte(GridPortableMarshaller.HANDLE);
+            out.writeInt(pos - old);
 
             return true;
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/4d81895a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
index 0946fa7..9502106 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
@@ -384,50 +384,42 @@ public class PortableClassDescriptor {
 
         switch (mode) {
             case BYTE:
-                writer.doWriteByte(GridPortableMarshaller.BYTE);
-                writer.doWriteByte((byte)obj);
+                writer.writeByteFieldPrimitive((byte) obj);
 
                 break;
 
             case SHORT:
-                writer.doWriteByte(GridPortableMarshaller.SHORT);
-                writer.doWriteShort((short)obj);
+                writer.writeShortFieldPrimitive((short)obj);
 
                 break;
 
             case INT:
-                writer.doWriteByte(GridPortableMarshaller.INT);
-                writer.doWriteInt((int)obj);
+                writer.writeIntFieldPrimitive((int) obj);
 
                 break;
 
             case LONG:
-                writer.doWriteByte(GridPortableMarshaller.LONG);
-                writer.doWriteLong((long)obj);
+                writer.writeLongFieldPrimitive((long) obj);
 
                 break;
 
             case FLOAT:
-                writer.doWriteByte(GridPortableMarshaller.FLOAT);
-                writer.doWriteFloat((float)obj);
+                writer.writeFloatFieldPrimitive((float) obj);
 
                 break;
 
             case DOUBLE:
-                writer.doWriteByte(GridPortableMarshaller.DOUBLE);
-                writer.doWriteDouble((double)obj);
+                writer.writeDoubleFieldPrimitive((double) obj);
 
                 break;
 
             case CHAR:
-                writer.doWriteByte(GridPortableMarshaller.CHAR);
-                writer.doWriteChar((char)obj);
+                writer.writeCharFieldPrimitive((char) obj);
 
                 break;
 
             case BOOLEAN:
-                writer.doWriteByte(GridPortableMarshaller.BOOLEAN);
-                writer.doWriteBoolean((boolean)obj);
+                writer.writeBooleanFieldPrimitive((boolean) obj);
 
                 break;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/4d81895a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
index 0e982ed..b0ffdbf 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
@@ -19,6 +19,7 @@ package org.apache.ignite.internal.portable;
 
 import org.apache.ignite.binary.Binarylizable;
 import org.apache.ignite.internal.portable.builder.PortableLazyValue;
+import org.apache.ignite.internal.portable.streams.PortableOutputStream;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
@@ -671,13 +672,15 @@ public class PortableUtils {
      * @return Position where length should be written.
      */
     public static int writeHeader(BinaryWriterExImpl writer, int typeId, int hashCode, @Nullable String clsName) {
-        writer.doWriteByte(GridPortableMarshaller.OBJ);
-        writer.doWriteByte(GridPortableMarshaller.PROTO_VER);
+        PortableOutputStream out = writer.out();
 
-        writer.doWriteShort((short) 0);
+        out.writeByte(GridPortableMarshaller.OBJ);
+        out.writeByte(GridPortableMarshaller.PROTO_VER);
 
-        writer.doWriteInt(typeId);
-        writer.doWriteInt(hashCode);
+        out.writeShort((short) 0);
+
+        out.writeInt(typeId);
+        out.writeInt(hashCode);
 
         int reserved = writer.reserve(12);
 


[4/4] ignite git commit: IGNITE-1917: Fixed NPE in metadata generation.

Posted by vo...@apache.org.
IGNITE-1917: Fixed NPE in metadata generation.


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

Branch: refs/heads/ignite-1917
Commit: 1c71f225761359e6fecd42d274543dadf554d6d3
Parents: 0b5fb1c
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Mon Nov 16 13:04:56 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Mon Nov 16 13:04:56 2015 +0300

----------------------------------------------------------------------
 .../ignite/internal/portable/BinaryWriterExImpl.java  | 14 ++++++++------
 .../ignite/internal/portable/PortableContext.java     |  7 ++++---
 2 files changed, 12 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/1c71f225/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
index 277bdb9..fa258d9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
@@ -125,13 +125,15 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      * @param ctx Context.
      */
     public BinaryWriterExImpl(PortableContext ctx) {
-        BinaryThreadLocalContext tlsCtx = BinaryThreadLocalContext.get();
-
-        this.ctx = ctx;
-        this.out = new PortableHeapOutputStream(INIT_CAP, tlsCtx.chunk());
-        this.schema = tlsCtx.schemaHolder();
+        this(ctx, BinaryThreadLocalContext.get());
+    }
 
-        start = out.position();
+    /**
+     * @param ctx Context.
+     * @param tlsCtx TLS context.
+     */
+    public BinaryWriterExImpl(PortableContext ctx, BinaryThreadLocalContext tlsCtx) {
+        this(ctx, new PortableHeapOutputStream(INIT_CAP, tlsCtx.chunk()), tlsCtx.schemaHolder(), null);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/1c71f225/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
index 193e368..e3caba4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
@@ -574,8 +574,9 @@ public class PortableContext implements Externalizable {
 
         mappers.putIfAbsent(typeId, idMapper);
 
-        metaHnd.addMeta(typeId, new BinaryMetadata(typeId, typeName, desc.fieldsMeta(), null,
-            Collections.singleton(desc.schema())).wrap(this));
+        Collection<PortableSchema> schemas = desc.schema() != null ? Collections.singleton(desc.schema()) : null;
+
+        metaHnd.addMeta(typeId, new BinaryMetadata(typeId, typeName, desc.fieldsMeta(), null, schemas).wrap(this));
 
         return desc;
     }
@@ -783,7 +784,7 @@ public class PortableContext implements Externalizable {
             );
 
             fieldsMeta = desc.fieldsMeta();
-            schemas = Collections.singleton(desc.schema());
+            schemas = desc.schema() != null ? Collections.singleton(desc.schema()) : null;
 
             if (IgniteUtils.detectClassLoader(cls).equals(dfltLdr))
                 userTypes.put(id, desc);


[2/4] ignite git commit: IGNITE-1917: Minors.

Posted by vo...@apache.org.
IGNITE-1917: Minors.


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

Branch: refs/heads/ignite-1917
Commit: ccb7748cdcab92016972e42c222fc22f2ab79ccc
Parents: 4d81895
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Mon Nov 16 12:35:53 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Mon Nov 16 12:35:53 2015 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/internal/portable/BinaryWriterExImpl.java   | 3 ---
 1 file changed, 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ccb7748c/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
index c303813..3e5f608 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
@@ -567,7 +567,6 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
             out.writeByte(DOUBLE_ARR);
             out.writeInt(val.length);
-
             out.writeDoubleArray(val);
         }
     }
@@ -584,7 +583,6 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
             out.writeByte(CHAR_ARR);
             out.writeInt(val.length);
-
             out.writeCharArray(val);
         }
     }
@@ -601,7 +599,6 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
             out.writeByte(BOOLEAN_ARR);
             out.writeInt(val.length);
-
             out.writeBooleanArray(val);
         }
     }


[3/4] ignite git commit: IGNITE-1917: Minor refactoring.

Posted by vo...@apache.org.
IGNITE-1917: Minor refactoring.


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

Branch: refs/heads/ignite-1917
Commit: 0b5fb1c6011e77608972be775a19c2ec7600642b
Parents: ccb7748
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Mon Nov 16 12:46:36 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Mon Nov 16 12:46:36 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/BinaryWriterExImpl.java   | 42 ++++++--------------
 .../portable/GridPortableMarshaller.java        |  2 +-
 .../builder/BinaryObjectBuilderImpl.java        |  4 +-
 3 files changed, 17 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/0b5fb1c6/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
index 3e5f608..277bdb9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
@@ -124,53 +124,37 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     /**
      * @param ctx Context.
      */
-    BinaryWriterExImpl(PortableContext ctx) {
+    public BinaryWriterExImpl(PortableContext ctx) {
         BinaryThreadLocalContext tlsCtx = BinaryThreadLocalContext.get();
 
         this.ctx = ctx;
         this.out = new PortableHeapOutputStream(INIT_CAP, tlsCtx.chunk());
+        this.schema = tlsCtx.schemaHolder();
 
         start = out.position();
-        schema = tlsCtx.schemaHolder();
-    }
-
-    /**
-     * @param ctx Context.
-     * @param typeId Type ID.
-     */
-    public BinaryWriterExImpl(PortableContext ctx, int typeId) {
-        this(ctx);
-
-        this.typeId = typeId;
     }
 
     /**
      * @param ctx Context.
      * @param out Output stream.
+     * @param handles Handles.
      */
-    BinaryWriterExImpl(PortableContext ctx, PortableOutputStream out) {
+    public BinaryWriterExImpl(PortableContext ctx, PortableOutputStream out, BinaryWriterSchemaHolder schema,
+        BinaryWriterHandles handles) {
         this.ctx = ctx;
         this.out = out;
+        this.schema = schema;
+        this.handles = handles;
 
         start = out.position();
-
-        schema = BinaryThreadLocalContext.get().schemaHolder();
     }
 
-     /**
-      * @param ctx Context.
-      * @param out Output stream.
-      * @param handles Handles.
-      */
-     private BinaryWriterExImpl(PortableContext ctx, PortableOutputStream out, BinaryWriterSchemaHolder schema,
-         BinaryWriterHandles handles) {
-         this.ctx = ctx;
-         this.out = out;
-         this.schema = schema;
-         this.handles = handles;
-
-         start = out.position();
-     }
+    /**
+     * @param typeId Type ID.
+     */
+    public void typeId(int typeId) {
+        this.typeId = typeId;
+    }
 
     /**
      * Close the writer releasing resources if necessary.

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b5fb1c6/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java
index 056a7c7..989f16d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java
@@ -295,7 +295,7 @@ public class GridPortableMarshaller {
      * @return Writer.
      */
     public BinaryWriterExImpl writer(PortableOutputStream out) {
-        return new BinaryWriterExImpl(ctx, out);
+        return new BinaryWriterExImpl(ctx, out, BinaryThreadLocalContext.get().schemaHolder(), null);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/0b5fb1c6/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
index 51eddcc..509bd6f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
@@ -178,7 +178,9 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
 
     /** {@inheritDoc} */
     @Override public BinaryObject build() {
-        try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, typeId)) {
+        try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) {
+            writer.typeId(typeId);
+
             PortableBuilderSerializer serializationCtx = new PortableBuilderSerializer();
 
             serializationCtx.registerObjectWriting(this, 0);