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/10/23 16:28:16 UTC
[1/8] ignite git commit: IGNITE-1770: Added 1 byte to flags.
Repository: ignite
Updated Branches:
refs/heads/ignite-1770 b9422dfa1 -> d53278369
IGNITE-1770: Added 1 byte to flags.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d2187140
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d2187140
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d2187140
Branch: refs/heads/ignite-1770
Commit: d218714087d64369bbe0f8c855d7c9cd3f2b8ef2
Parents: b9422df
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Fri Oct 23 15:36:49 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Fri Oct 23 15:36:49 2015 +0300
----------------------------------------------------------------------
.../portable/GridPortableMarshaller.java | 15 ++++----
.../portable/PortableClassDescriptor.java | 4 ++-
.../internal/portable/PortableReaderExImpl.java | 8 ++---
.../ignite/internal/portable/PortableUtils.java | 38 ++++++++++++++++++++
.../portable/builder/PortableBuilderImpl.java | 4 ++-
.../GridPortableMarshallerSelfTest.java | 14 ++++----
6 files changed, 64 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/d2187140/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 6f16755..14221e7 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
@@ -198,23 +198,26 @@ public class GridPortableMarshaller {
/** Protocol version position. */
public static final int PROTO_VER_POS = 1;
+ /** Flags position in header. */
+ public static final int FLAGS_POS = 2;
+
/** */
- public static final int TYPE_ID_POS = 3;
+ public static final int TYPE_ID_POS = 4;
/** */
- public static final int HASH_CODE_POS = 7;
+ public static final int HASH_CODE_POS = 8;
/** */
- public static final int TOTAL_LEN_POS = 11;
+ public static final int TOTAL_LEN_POS = 12;
/** */
- public static final byte RAW_DATA_OFF_POS = 15;
+ public static final byte RAW_DATA_OFF_POS = 16;
/** */
- public static final int CLS_NAME_POS = 19;
+ public static final int CLS_NAME_POS = 20;
/** */
- public static final byte DFLT_HDR_LEN = 19;
+ public static final byte DFLT_HDR_LEN = 20;
/** */
private final PortableContext ctx;
http://git-wip-us.apache.org/repos/asf/ignite/blob/d2187140/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 0a9974e..5f7ab08 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
@@ -650,7 +650,9 @@ public class PortableClassDescriptor {
writer.doWriteByte(GridPortableMarshaller.OBJ);
writer.doWriteByte(GridPortableMarshaller.PROTO_VER);
- writer.doWriteBoolean(userType);
+
+ PortableUtils.writeFlags(writer, userType);
+
writer.doWriteInt(registered ? typeId : GridPortableMarshaller.UNREGISTERED_TYPE_ID);
writer.doWriteInt(obj instanceof CacheObjectImpl ? 0 : obj.hashCode());
http://git-wip-us.apache.org/repos/asf/ignite/blob/d2187140/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
index c14aa1d..5af6059 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
@@ -203,8 +203,8 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
// Validate protocol version.
PortableUtils.checkProtocolVersion(doReadByte(true));
- // skip user flag
- rawOff += 1;
+ // Skip flags
+ rawOff += 2;
typeId = doReadInt(true);
@@ -1957,7 +1957,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
* @param raw Raw flag.
* @return Value.
*/
- private short doReadShort(boolean raw) {
+ public short doReadShort(boolean raw) {
in.position(raw ? rawOff : off);
short val = in.readShort();
@@ -2199,7 +2199,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
PortableUtils.checkProtocolVersion(doReadByte(true));
- boolean userType = doReadBoolean(true);
+ boolean userType = PortableUtils.isUserType(PortableUtils.readFlags(this));
// Skip typeId and hash code.
rawOff += 8;
http://git-wip-us.apache.org/repos/asf/ignite/blob/d2187140/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 2140bee..4a866fd 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
@@ -92,6 +92,44 @@ public class PortableUtils {
/** Portable classes. */
private static final Collection<Class<?>> PORTABLE_CLS = new HashSet<>();
+ /** Flag: user type. */
+ private static final short FLAG_USR_TYP = 0x1;
+
+ /**
+ * Write flags.
+ *
+ * @param writer Writer.
+ * @param userType User type flag.
+ */
+ public static void writeFlags(PortableWriterExImpl writer, boolean userType) {
+ short val = 0;
+
+ if (userType)
+ val |= FLAG_USR_TYP;
+
+ writer.doWriteShort(val);
+ }
+
+ /**
+ * Read flags.
+ *
+ * @param reader Reader.
+ * @return Flags.
+ */
+ public static short readFlags(PortableReaderExImpl reader) {
+ return reader.doReadShort(true);
+ }
+
+ /**
+ * Check if user type flag is set.
+ *
+ * @param flags Flags.
+ * @return {@code True} if set.
+ */
+ public static boolean isUserType(short flags) {
+ return (flags & FLAG_USR_TYP) == FLAG_USR_TYP;
+ }
+
/**
*
*/
http://git-wip-us.apache.org/repos/asf/ignite/blob/d2187140/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
index 00fc866..50c48a2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
@@ -201,7 +201,9 @@ public class PortableBuilderImpl implements PortableBuilder {
void serializeTo(PortableWriterExImpl writer, PortableBuilderSerializer serializer) {
writer.doWriteByte(GridPortableMarshaller.OBJ);
writer.doWriteByte(PROTO_VER);
- writer.doWriteBoolean(true);
+
+ PortableUtils.writeFlags(writer, true);
+
writer.doWriteInt(registeredType ? typeId : UNREGISTERED_TYPE_ID);
writer.doWriteInt(hashCode);
http://git-wip-us.apache.org/repos/asf/ignite/blob/d2187140/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
index 2b29e4d..b93e60e 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
@@ -720,7 +720,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
arr[0] = 103;
arr[1] = 1;
- U.intToBytes(Integer.reverseBytes(11111), arr, 3);
+ U.intToBytes(Integer.reverseBytes(11111), arr, 4);
final PortableObject po = new PortableObjectImpl(initPortableContext(new PortableMarshaller()), arr, 0);
@@ -849,8 +849,8 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableObject po1 = marshal(obj1, marsh);
assertEquals(11111, po1.typeId());
- assertEquals(22222, intFromPortable(po1, 19));
- assertEquals(33333, intFromPortable(po1, 32));
+ assertEquals(22222, intFromPortable(po1, 20));
+ assertEquals(33333, intFromPortable(po1, 33));
assertEquals(10, po1.<CustomMappedObject1>deserialize().val1);
assertEquals("str", po1.<CustomMappedObject1>deserialize().val2);
@@ -908,8 +908,8 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableObject po1 = marshal(obj1, marsh);
assertEquals(11111, po1.typeId());
- assertEquals(22222, intFromPortable(po1, 19));
- assertEquals(33333, intFromPortable(po1, 32));
+ assertEquals(22222, intFromPortable(po1, 20));
+ assertEquals(33333, intFromPortable(po1, 33));
assertEquals(10, po1.<CustomMappedObject1>deserialize().val1);
assertEquals("str1", po1.<CustomMappedObject1>deserialize().val2);
@@ -919,8 +919,8 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
PortableObject po2 = marshal(obj2, marsh);
assertEquals(44444, po2.typeId());
- assertEquals(55555, intFromPortable(po2, 19));
- assertEquals(66666, intFromPortable(po2, 32));
+ assertEquals(55555, intFromPortable(po2, 20));
+ assertEquals(66666, intFromPortable(po2, 33));
assertEquals(20, po2.<CustomMappedObject2>deserialize().val1);
assertEquals("str2", po2.<CustomMappedObject2>deserialize().val2);
[8/8] ignite git commit: IGNITE-1770: Better raw mode handling.
Posted by vo...@apache.org.
IGNITE-1770: Better raw mode handling.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d5327836
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d5327836
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d5327836
Branch: refs/heads/ignite-1770
Commit: d5327836941fd4805ca441de51a81e427484bfb6
Parents: 7cf2136
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Fri Oct 23 17:28:53 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Fri Oct 23 17:28:53 2015 +0300
----------------------------------------------------------------------
.../ignite/internal/portable/PortableWriterExImpl.java | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/d5327836/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
index fdff5ce..9fb5e56 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
@@ -328,11 +328,10 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
}
/**
- *
+ * Write length and raw offset.
*/
public void writeLengthAndRawOffset() {
- if (rawOffPos == 0)
- out.writeInt(start + RAW_DATA_OFF_POS, out.position() - start);
+ out.writeInt(start + RAW_DATA_OFF_POS, (rawOffPos == 0 ? out.position() : rawOffPos) - start);
out.writeInt(start + TOTAL_LEN_POS, out.position() - start);
}
@@ -1702,11 +1701,8 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
/** {@inheritDoc} */
@Override public PortableRawWriter rawWriter() {
- if (rawOffPos == 0) {
- out.writeInt(start + RAW_DATA_OFF_POS, out.position() - start);
-
+ if (rawOffPos == 0)
rawOffPos = out.position();
- }
return this;
}
[2/8] ignite git commit: IGNITE-1770: Simplifications on writer side.
Posted by vo...@apache.org.
IGNITE-1770: Simplifications on writer side.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1e62f467
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1e62f467
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1e62f467
Branch: refs/heads/ignite-1770
Commit: 1e62f46721edcf59671337df7a7df2180e470aa7
Parents: d218714
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Fri Oct 23 16:35:29 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Fri Oct 23 16:35:29 2015 +0300
----------------------------------------------------------------------
.../portable/GridPortableMarshaller.java | 9 +-
.../internal/portable/PortableWriterExImpl.java | 267 ++++++++-----------
.../portable/builder/PortableBuilderImpl.java | 2 +-
.../builder/PortableBuilderSerializer.java | 6 +-
.../CacheObjectPortableProcessorImpl.java | 6 +-
.../marshaller/portable/PortableMarshaller.java | 2 +-
.../GridPortableMarshallerSelfTest.java | 2 +-
7 files changed, 118 insertions(+), 176 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e62f467/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 14221e7..d3ddf17 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
@@ -231,16 +231,15 @@ public class GridPortableMarshaller {
/**
* @param obj Object to marshal.
- * @param off Offset.
* @return Byte array.
* @throws PortableException In case of error.
*/
- public byte[] marshal(@Nullable Object obj, int off) throws PortableException {
+ public byte[] marshal(@Nullable Object obj) throws PortableException {
if (obj == null)
return new byte[] { NULL };
- try (PortableWriterExImpl writer = new PortableWriterExImpl(ctx, off)) {
- writer.marshal(obj, false);
+ try (PortableWriterExImpl writer = new PortableWriterExImpl(ctx)) {
+ writer.marshal(obj);
return writer.array();
}
@@ -296,7 +295,7 @@ public class GridPortableMarshaller {
* @return Writer.
*/
public PortableWriterExImpl writer(PortableOutputStream out) {
- return new PortableWriterExImpl(ctx, out, 0);
+ return new PortableWriterExImpl(ctx, out);
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e62f467/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
index a8a4295..c3213a8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
@@ -94,9 +94,6 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
private final PortableContext ctx;
/** */
- private final WriterContext wCtx;
-
- /** */
private final int start;
/** */
@@ -117,64 +114,56 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
/** */
private int metaHashSum;
+ /** Handles. */
+ private Map<Object, Integer> handles;
+
+ /** Output stream. */
+ private PortableOutputStream out;
+
/**
* @param ctx Context.
- * @param off Start offset.
*/
- PortableWriterExImpl(PortableContext ctx, int off) {
- this.ctx = ctx;
-
- PortableOutputStream out = new PortableHeapOutputStream(off + INIT_CAP);
-
- out.position(off);
-
- wCtx = new WriterContext(out, null);
-
- start = off;
+ PortableWriterExImpl(PortableContext ctx) {
+ this(ctx, new PortableHeapOutputStream(INIT_CAP));
}
/**
* @param ctx Context.
* @param out Output stream.
- * @param off Start offset.
*/
- PortableWriterExImpl(PortableContext ctx, PortableOutputStream out, int off) {
- this.ctx = ctx;
+ PortableWriterExImpl(PortableContext ctx, PortableOutputStream out) {
+ this(ctx, out, new IdentityHashMap<Object, Integer>());
+ }
- wCtx = new WriterContext(out, null);
+ /**
+ * @param ctx Context.
+ * @param out Output stream.
+ * @param handles Handles.
+ */
+ private PortableWriterExImpl(PortableContext ctx, PortableOutputStream out, Map<Object, Integer> handles) {
+ this.ctx = ctx;
+ this.out = out;
+ this.handles = handles;
- start = off;
- }
+ start = out.position();
+ }
/**
* @param ctx Context.
- * @param off Start offset.
* @param typeId Type ID.
*/
- public PortableWriterExImpl(PortableContext ctx, int off, int typeId, boolean metaEnabled) {
- this(ctx, off);
+ public PortableWriterExImpl(PortableContext ctx, int typeId, boolean metaEnabled) {
+ this(ctx);
this.typeId = typeId;
-
this.metaEnabled = metaEnabled;
}
/**
- * @param ctx Context.
- * @param wCtx Writer context.
- */
- private PortableWriterExImpl(PortableContext ctx, WriterContext wCtx) {
- this.ctx = ctx;
- this.wCtx = wCtx;
-
- start = wCtx.out.position();
- }
-
- /**
* Close the writer releasing resources if necessary.
*/
@Override public void close() {
- wCtx.out.close();
+ out.close();
}
/**
@@ -186,10 +175,9 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
/**
* @param obj Object.
- * @param detached Detached or not.
* @throws PortableException In case of error.
*/
- void marshal(Object obj, boolean detached) throws PortableException {
+ void marshal(Object obj) throws PortableException {
assert obj != null;
cls = obj.getClass();
@@ -258,9 +246,6 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
metaEnabled = ctx.isMetaDataEnabled(typeId);
- if (detached)
- wCtx.resetHandles();
-
desc.write(obj, this);
}
@@ -271,28 +256,29 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
int handle(Object obj) {
assert obj != null;
- return wCtx.handle(obj);
+ Integer h = handles.get(obj);
+
+ if (h != null)
+ return out.position() - h;
+ else {
+ handles.put(obj, out.position());
+
+ return -1;
+ }
}
/**
* @return Array.
*/
public byte[] array() {
- return wCtx.out.arrayCopy();
- }
-
- /**
- * @return Output stream.
- */
- public PortableOutputStream outputStream() {
- return wCtx.out;
+ return out.arrayCopy();
}
/**
* @return Stream current position.
*/
int position() {
- return wCtx.out.position();
+ return out.position();
}
/**
@@ -301,7 +287,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
* @param pos Position.
*/
void position(int pos) {
- wCtx.out.position(pos);
+ out.position(pos);
}
/**
@@ -309,9 +295,9 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
* @return Offset.
*/
public int reserve(int bytes) {
- int pos = wCtx.out.position();
+ int pos = out.position();
- wCtx.out.position(pos + bytes);
+ out.position(pos + bytes);
return pos;
}
@@ -323,7 +309,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
public int reserveAndMark(int bytes) {
int off0 = reserve(bytes);
- mark = wCtx.out.position();
+ mark = out.position();
return off0;
}
@@ -332,14 +318,14 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
* @param off Offset.
*/
public void writeDelta(int off) {
- wCtx.out.writeInt(off, wCtx.out.position() - mark);
+ out.writeInt(off, out.position() - mark);
}
/**
*
*/
public void writeLength() {
- wCtx.out.writeInt(start + TOTAL_LEN_POS, wCtx.out.position() - start);
+ out.writeInt(start + TOTAL_LEN_POS, out.position() - start);
}
/**
@@ -347,7 +333,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
*/
public void writeRawOffsetIfNeeded() {
if (allowFields)
- wCtx.out.writeInt(start + RAW_DATA_OFF_POS, wCtx.out.position() - start);
+ out.writeInt(start + RAW_DATA_OFF_POS, out.position() - start);
}
/**
@@ -356,7 +342,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
public void write(byte[] val) {
assert val != null;
- wCtx.out.writeByteArray(val);
+ out.writeByteArray(val);
}
/**
@@ -367,63 +353,63 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
public void write(byte[] val, int off, int len) {
assert val != null;
- wCtx.out.write(val, off, len);
+ out.write(val, off, len);
}
/**
* @param val Value.
*/
public void doWriteByte(byte val) {
- wCtx.out.writeByte(val);
+ out.writeByte(val);
}
/**
* @param val Value.
*/
public void doWriteShort(short val) {
- wCtx.out.writeShort(val);
+ out.writeShort(val);
}
/**
* @param val Value.
*/
public void doWriteInt(int val) {
- wCtx.out.writeInt(val);
+ out.writeInt(val);
}
/**
* @param val Value.
*/
public void doWriteLong(long val) {
- wCtx.out.writeLong(val);
+ out.writeLong(val);
}
/**
* @param val Value.
*/
public void doWriteFloat(float val) {
- wCtx.out.writeFloat(val);
+ out.writeFloat(val);
}
/**
* @param val Value.
*/
public void doWriteDouble(double val) {
- wCtx.out.writeDouble(val);
+ out.writeDouble(val);
}
/**
* @param val Value.
*/
public void doWriteChar(char val) {
- wCtx.out.writeChar(val);
+ out.writeChar(val);
}
/**
* @param val Value.
*/
public void doWriteBoolean(boolean val) {
- wCtx.out.writeBoolean(val);
+ out.writeBoolean(val);
}
/**
@@ -440,15 +426,15 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
if (intVal.signum() == -1) {
intVal = intVal.negate();
- wCtx.out.writeInt(val.scale() | 0x80000000);
+ out.writeInt(val.scale() | 0x80000000);
}
else
- wCtx.out.writeInt(val.scale());
+ out.writeInt(val.scale());
byte[] vals = intVal.toByteArray();
- wCtx.out.writeInt(vals.length);
- wCtx.out.writeByteArray(vals);
+ out.writeInt(vals.length);
+ out.writeByteArray(vals);
}
}
@@ -468,7 +454,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
doWriteInt(strArr.length);
- wCtx.out.writeByteArray(strArr);
+ out.writeByteArray(strArr);
}
else {
doWriteBoolean(false);
@@ -477,7 +463,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
doWriteInt(strArr.length);
- wCtx.out.writeCharArray(strArr);
+ out.writeCharArray(strArr);
}
}
}
@@ -507,36 +493,32 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
}
}
- /**
- * @param ts Timestamp.
- */
- public void doWriteTimestamp(@Nullable Timestamp ts) {
- if (ts== null)
- doWriteByte(NULL);
- else {
- doWriteByte(TIMESTAMP);
- doWriteLong(ts.getTime());
- doWriteInt(ts.getNanos() % 1000000);
- }
- }
+ /**
+ * @param ts Timestamp.
+ */
+ public void doWriteTimestamp(@Nullable Timestamp ts) {
+ if (ts== null)
+ doWriteByte(NULL);
+ else {
+ doWriteByte(TIMESTAMP);
+ doWriteLong(ts.getTime());
+ doWriteInt(ts.getNanos() % 1000000);
+ }
+ }
/**
+ * Write object.
+ *
* @param obj Object.
- * @param detached Detached or not.
* @throws PortableException In case of error.
*/
- public void doWriteObject(@Nullable Object obj, boolean detached) throws PortableException {
+ public void doWriteObject(@Nullable Object obj) throws PortableException {
if (obj == null)
doWriteByte(NULL);
else {
- WriterContext wCtx = detached ? new WriterContext(this.wCtx.out, this.wCtx.handles) : this.wCtx;
-
- PortableWriterExImpl writer = new PortableWriterExImpl(ctx, wCtx);
+ PortableWriterExImpl writer = new PortableWriterExImpl(ctx, out, handles);
- writer.marshal(obj, detached);
-
- if (detached)
- this.wCtx.out = wCtx.out;
+ writer.marshal(obj);
}
}
@@ -553,7 +535,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
doWriteByte(BYTE_ARR);
doWriteInt(val.length);
- wCtx.out.writeByteArray(val);
+ out.writeByteArray(val);
}
}
@@ -570,7 +552,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
doWriteByte(SHORT_ARR);
doWriteInt(val.length);
- wCtx.out.writeShortArray(val);
+ out.writeShortArray(val);
}
}
@@ -587,7 +569,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
doWriteByte(INT_ARR);
doWriteInt(val.length);
- wCtx.out.writeIntArray(val);
+ out.writeIntArray(val);
}
}
@@ -604,7 +586,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
doWriteByte(LONG_ARR);
doWriteInt(val.length);
- wCtx.out.writeLongArray(val);
+ out.writeLongArray(val);
}
}
@@ -621,7 +603,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
doWriteByte(FLOAT_ARR);
doWriteInt(val.length);
- wCtx.out.writeFloatArray(val);
+ out.writeFloatArray(val);
}
}
@@ -638,7 +620,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
doWriteByte(DOUBLE_ARR);
doWriteInt(val.length);
- wCtx.out.writeDoubleArray(val);
+ out.writeDoubleArray(val);
}
}
@@ -655,7 +637,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
doWriteByte(CHAR_ARR);
doWriteInt(val.length);
- wCtx.out.writeCharArray(val);
+ out.writeCharArray(val);
}
}
@@ -672,7 +654,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
doWriteByte(BOOLEAN_ARR);
doWriteInt(val.length);
- wCtx.out.writeBooleanArray(val);
+ out.writeBooleanArray(val);
}
}
@@ -791,7 +773,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
doWriteInt(val.length);
for (Object obj : val)
- doWriteObject(obj, false);
+ doWriteObject(obj);
}
}
@@ -811,7 +793,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
doWriteByte(ctx.collectionType(col.getClass()));
for (Object obj : col)
- doWriteObject(obj, false);
+ doWriteObject(obj);
}
}
@@ -831,8 +813,8 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
doWriteByte(ctx.mapType(map.getClass()));
for (Map.Entry<?, ?> e : map.entrySet()) {
- doWriteObject(e.getKey(), false);
- doWriteObject(e.getValue(), false);
+ doWriteObject(e.getKey());
+ doWriteObject(e.getValue());
}
}
}
@@ -849,8 +831,8 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
return;
doWriteByte(MAP_ENTRY);
- doWriteObject(e.getKey(), false);
- doWriteObject(e.getValue(), false);
+ doWriteObject(e.getKey());
+ doWriteObject(e.getValue());
}
}
@@ -936,7 +918,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
doWriteInt(poArr.length);
- wCtx.out.writeByteArray(poArr);
+ out.writeByteArray(poArr);
doWriteInt(po.start());
}
@@ -1118,7 +1100,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
void writeObjectField(@Nullable Object obj) throws PortableException {
int lenPos = reserveAndMark(4);
- doWriteObject(obj, false);
+ doWriteObject(obj);
writeDelta(lenPos);
}
@@ -1499,12 +1481,18 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
/** {@inheritDoc} */
@Override public void writeObject(@Nullable Object obj) throws PortableException {
- doWriteObject(obj, false);
+ doWriteObject(obj);
}
/** {@inheritDoc} */
@Override public void writeObjectDetached(@Nullable Object obj) throws PortableException {
- doWriteObject(obj, true);
+ if (obj == null)
+ doWriteByte(NULL);
+ else {
+ PortableWriterExImpl writer = new PortableWriterExImpl(ctx, out, new IdentityHashMap<Object, Integer>());
+
+ writer.marshal(obj);
+ }
}
/** {@inheritDoc} */
@@ -1714,7 +1702,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
/** {@inheritDoc} */
@Override public PortableRawWriter rawWriter() {
if (allowFields) {
- wCtx.out.writeInt(start + RAW_DATA_OFF_POS, wCtx.out.position() - start);
+ out.writeInt(start + RAW_DATA_OFF_POS, out.position() - start);
allowFields = false;
}
@@ -1724,7 +1712,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
/** {@inheritDoc} */
@Override public PortableOutputStream out() {
- return wCtx.out;
+ return out;
}
/** {@inheritDoc} */
@@ -1784,7 +1772,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
/** {@inheritDoc} */
@Override public void writeInt(int pos, int val) throws PortableException {
- wCtx.out.writeInt(pos, val);
+ out.writeInt(pos, val);
}
/**
@@ -1831,7 +1819,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
* @return New writer.
*/
public PortableWriterExImpl newWriter(int typeId) {
- PortableWriterExImpl res = new PortableWriterExImpl(ctx, wCtx);
+ PortableWriterExImpl res = new PortableWriterExImpl(ctx, out, handles);
res.typeId = typeId;
@@ -1844,49 +1832,4 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
public PortableContext context() {
return ctx;
}
-
- /** */
- private static class WriterContext {
- /** */
- private Map<Object, Integer> handles = new IdentityHashMap<>();
-
- /** Output stream. */
- private PortableOutputStream out;
-
- /**
- * Constructor.
- *
- * @param out Output stream.
- * @param handles Handles.
- */
- private WriterContext(PortableOutputStream out, Map<Object, Integer> handles) {
- this.out = out;
- this.handles = handles == null ? new IdentityHashMap<Object, Integer>() : handles;
- }
-
- /**
- * @param obj Object.
- * @return Handle.
- */
- private int handle(Object obj) {
- assert obj != null;
-
- Integer h = handles.get(obj);
-
- if (h != null)
- return out.position() - h;
- else {
- handles.put(obj, out.position());
-
- return -1;
- }
- }
-
- /**
- *
- */
- private void resetHandles() {
- handles = new IdentityHashMap<>();
- }
- }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e62f467/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
index 50c48a2..8664e1f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
@@ -180,7 +180,7 @@ public class PortableBuilderImpl implements PortableBuilder {
/** {@inheritDoc} */
@Override public PortableObject build() {
- try (PortableWriterExImpl writer = new PortableWriterExImpl(ctx, 0, typeId, false)) {
+ try (PortableWriterExImpl writer = new PortableWriterExImpl(ctx, typeId, false)) {
PortableBuilderSerializer serializationCtx = new PortableBuilderSerializer();
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e62f467/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java
index 2d9c961..fa08d79 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java
@@ -82,12 +82,12 @@ class PortableBuilderSerializer {
Integer posInResArr = objToPos.get(obj);
if (posInResArr == null) {
- objToPos.put(obj, writer.outputStream().position());
+ objToPos.put(obj, writer.out().position());
obj.serializeTo(writer.newWriter(obj.typeId()), this);
}
else {
- int handle = writer.outputStream().position() - posInResArr;
+ int handle = writer.out().position() - posInResArr;
writer.writeByte(GridPortableMarshaller.HANDLE);
writer.writeInt(handle);
@@ -177,7 +177,7 @@ class PortableBuilderSerializer {
return;
}
- writer.doWriteObject(val, false);
+ writer.doWriteObject(val);
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e62f467/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessorImpl.java
index 7bf32cd..68951c6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessorImpl.java
@@ -430,7 +430,7 @@ public class CacheObjectPortableProcessorImpl extends IgniteCacheObjectProcessor
* @throws PortableException If failed.
*/
public byte[] marshal(@Nullable Object obj) throws PortableException {
- byte[] arr = portableMarsh.marshal(obj, 0);
+ byte[] arr = portableMarsh.marshal(obj);
assert arr.length > 0;
@@ -515,7 +515,7 @@ public class CacheObjectPortableProcessorImpl extends IgniteCacheObjectProcessor
return new GridMapEntry<>(marshalToPortable(e.getKey()), marshalToPortable(e.getValue()));
}
- byte[] arr = portableMarsh.marshal(obj, 0);
+ byte[] arr = portableMarsh.marshal(obj);
assert arr.length > 0;
@@ -720,7 +720,7 @@ public class CacheObjectPortableProcessorImpl extends IgniteCacheObjectProcessor
if (!((CacheObjectPortableContext)ctx).portableEnabled() || portableMarsh == null)
return super.marshal(ctx, val);
- byte[] arr = portableMarsh.marshal(val, 0);
+ byte[] arr = portableMarsh.marshal(val);
assert arr.length > 0;
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e62f467/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java b/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
index ea2e1cc..3c8fda9 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
@@ -260,7 +260,7 @@ public class PortableMarshaller extends AbstractMarshaller {
/** {@inheritDoc} */
@Override public byte[] marshal(@Nullable Object obj) throws IgniteCheckedException {
- return impl.marshal(obj, 0);
+ return impl.marshal(obj);
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/1e62f467/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
index b93e60e..accebe8 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
@@ -2100,7 +2100,7 @@ public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
// Checking the writer directly.
assertEquals(false, THREAD_LOCAL_ALLOC.isThreadLocalArrayAcquired());
- try (PortableWriterExImpl writer = new PortableWriterExImpl(initPortableContext(new PortableMarshaller()), 0)) {
+ try (PortableWriterExImpl writer = new PortableWriterExImpl(initPortableContext(new PortableMarshaller()))) {
assertEquals(true, THREAD_LOCAL_ALLOC.isThreadLocalArrayAcquired());
writer.writeString("Thread local test");
[7/8] ignite git commit: IGNITE-1770: Better raw mode handling.
Posted by vo...@apache.org.
IGNITE-1770: Better raw mode handling.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7cf21365
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7cf21365
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7cf21365
Branch: refs/heads/ignite-1770
Commit: 7cf21365f124c16560eba05d14507e7e124a838b
Parents: 2a8b75a
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Fri Oct 23 17:27:10 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Fri Oct 23 17:27:10 2015 +0300
----------------------------------------------------------------------
.../internal/portable/PortableClassDescriptor.java | 9 +++------
.../ignite/internal/portable/PortableWriterExImpl.java | 11 +++--------
.../internal/portable/builder/PortableBuilderImpl.java | 7 +------
3 files changed, 7 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/7cf21365/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 ee78fd0..3764c24 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
@@ -515,8 +515,7 @@ public class PortableClassDescriptor {
else
((PortableMarshalAware)obj).writePortable(writer);
- writer.writeRawOffsetIfNeeded();
- writer.writeLength();
+ writer.writeLengthAndRawOffset();
if (obj.getClass() != PortableMetaDataImpl.class
&& ctx.isMetaDataChanged(typeId, writer.metaDataHashSum())) {
@@ -544,8 +543,7 @@ public class PortableClassDescriptor {
throw new PortableException("Failed to write Externalizable object: " + obj, e);
}
- writer.writeRawOffsetIfNeeded();
- writer.writeLength();
+ writer.writeLengthAndRawOffset();
}
break;
@@ -555,8 +553,7 @@ public class PortableClassDescriptor {
for (FieldInfo info : fields)
info.write(obj, writer);
- writer.writeRawOffsetIfNeeded();
- writer.writeLength();
+ writer.writeLengthAndRawOffset();
}
break;
http://git-wip-us.apache.org/repos/asf/ignite/blob/7cf21365/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
index e671db1..fdff5ce 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
@@ -330,16 +330,11 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
/**
*
*/
- public void writeLength() {
- out.writeInt(start + TOTAL_LEN_POS, out.position() - start);
- }
-
- /**
- *
- */
- public void writeRawOffsetIfNeeded() {
+ public void writeLengthAndRawOffset() {
if (rawOffPos == 0)
out.writeInt(start + RAW_DATA_OFF_POS, out.position() - start);
+
+ out.writeInt(start + TOTAL_LEN_POS, out.position() - start);
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/7cf21365/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
index f905b26..4d52b27 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
@@ -32,10 +32,6 @@ import org.apache.ignite.portable.PortableMetadata;
import org.apache.ignite.portable.PortableObject;
import org.jetbrains.annotations.Nullable;
import org.apache.ignite.internal.portable.*;
-import org.apache.ignite.internal.processors.cache.portable.*;
-import org.apache.ignite.internal.util.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.portable.*;
import static org.apache.ignite.internal.portable.GridPortableMarshaller.CLS_NAME_POS;
import static org.apache.ignite.internal.portable.GridPortableMarshaller.DFLT_HDR_LEN;
@@ -399,8 +395,7 @@ public class PortableBuilderImpl implements PortableBuilder {
writer.write(reader.array(), rawOff, len - rawOff);
}
- writer.writeRawOffsetIfNeeded();
- writer.writeLength();
+ writer.writeLengthAndRawOffset();
}
/** {@inheritDoc} */
[5/8] ignite git commit: IGNITE-1770: Better raw mode handling.
Posted by vo...@apache.org.
IGNITE-1770: Better raw mode handling.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/03e1f8d2
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/03e1f8d2
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/03e1f8d2
Branch: refs/heads/ignite-1770
Commit: 03e1f8d25eb257e7cfcc3fd2c8d7f427b3a470c8
Parents: cd931d3
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Fri Oct 23 17:21:42 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Fri Oct 23 17:21:42 2015 +0300
----------------------------------------------------------------------
.../ignite/internal/portable/PortableWriterExImpl.java | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/03e1f8d2/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
index ef6470d..e671db1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
@@ -107,8 +107,8 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
/** */
private int typeId;
- /** */
- private boolean allowFields = true;
+ /** Raw offset position. */
+ private int rawOffPos;
/** */
private boolean metaEnabled;
@@ -338,7 +338,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
*
*/
public void writeRawOffsetIfNeeded() {
- if (allowFields)
+ if (rawOffPos == 0)
out.writeInt(start + RAW_DATA_OFF_POS, out.position() - start);
}
@@ -1707,10 +1707,10 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
/** {@inheritDoc} */
@Override public PortableRawWriter rawWriter() {
- if (allowFields) {
+ if (rawOffPos == 0) {
out.writeInt(start + RAW_DATA_OFF_POS, out.position() - start);
- allowFields = false;
+ rawOffPos = out.position();
}
return this;
@@ -1788,7 +1788,7 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
private void writeFieldId(String fieldName, byte fieldType) throws PortableException {
A.notNull(fieldName, "fieldName");
- if (!allowFields)
+ if (rawOffPos != 0)
throw new PortableException("Individual field can't be written after raw writer is acquired " +
"via rawWriter() method. Consider fixing serialization logic for class: " + cls.getName());
[4/8] ignite git commit: IGNITE-1770: Better raw mode handling.
Posted by vo...@apache.org.
IGNITE-1770: Better raw mode handling.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/cd931d3e
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/cd931d3e
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/cd931d3e
Branch: refs/heads/ignite-1770
Commit: cd931d3e2d67d527e8f493c86eaa8248b0356327
Parents: 844ff1e
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Fri Oct 23 17:20:16 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Fri Oct 23 17:20:16 2015 +0300
----------------------------------------------------------------------
.../ignite/internal/portable/builder/PortableBuilderImpl.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/cd931d3e/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
index 8664e1f..f905b26 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
@@ -389,7 +389,7 @@ public class PortableBuilderImpl implements PortableBuilder {
}
}
- writer.writeRawOffsetIfNeeded();
+ writer.rawWriter();
if (reader != null) {
int rawOff = reader.readIntAbsolute(start + RAW_DATA_OFF_POS);
@@ -399,6 +399,7 @@ public class PortableBuilderImpl implements PortableBuilder {
writer.write(reader.array(), rawOff, len - rawOff);
}
+ writer.writeRawOffsetIfNeeded();
writer.writeLength();
}
[3/8] ignite git commit: IGNITE-1770: Better raw mode handling.
Posted by vo...@apache.org.
IGNITE-1770: Better raw mode handling.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/844ff1e8
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/844ff1e8
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/844ff1e8
Branch: refs/heads/ignite-1770
Commit: 844ff1e829b0071d129b332d3a6748960dec66b4
Parents: 1e62f46
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Fri Oct 23 17:19:30 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Fri Oct 23 17:19:30 2015 +0300
----------------------------------------------------------------------
.../portable/GridPortableMarshaller.java | 5 ++++-
.../internal/portable/PortableWriterExImpl.java | 20 ++++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/844ff1e8/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 d3ddf17..119e80d 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
@@ -211,7 +211,10 @@ public class GridPortableMarshaller {
public static final int TOTAL_LEN_POS = 12;
/** */
- public static final byte RAW_DATA_OFF_POS = 16;
+ public static final int RAW_DATA_OFF_POS = 16;
+
+ /** Schema offset position. */
+ public static final int SCHEMA_OFF_POS = 20;
/** */
public static final int CLS_NAME_POS = 20;
http://git-wip-us.apache.org/repos/asf/ignite/blob/844ff1e8/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
index c3213a8..ef6470d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
@@ -32,9 +32,11 @@ import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Timestamp;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.IdentityHashMap;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -120,6 +122,10 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
/** Output stream. */
private PortableOutputStream out;
+ /** Field infos. */
+ // TODO: Optimize.
+ private List<Integer> fieldInfos = new ArrayList<>();
+
/**
* @param ctx Context.
*/
@@ -1787,6 +1793,9 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
"via rawWriter() method. Consider fixing serialization logic for class: " + cls.getName());
int id = ctx.fieldId(typeId, fieldName);
+ int off = out.position() - start;
+
+ saveFieldInfo(id, off);
if (metaEnabled)
metaHashSum = 31 * metaHashSum + (id + fieldType);
@@ -1795,6 +1804,17 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
}
/**
+ * Save field info.
+ *
+ * @param id Field ID.
+ * @param off Offset starting from object head.
+ */
+ private void saveFieldInfo(int id, int off) {
+ fieldInfos.add(id);
+ fieldInfos.add(off);
+ }
+
+ /**
* Attempts to write the object as a handle.
*
* @param obj Object to write.
[6/8] ignite git commit: IGNITE-1770: Better raw mode handling.
Posted by vo...@apache.org.
IGNITE-1770: Better raw mode handling.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/2a8b75a2
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/2a8b75a2
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/2a8b75a2
Branch: refs/heads/ignite-1770
Commit: 2a8b75a269f71f2487bd9eb24457df2e1c53d3c1
Parents: 03e1f8d
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Fri Oct 23 17:26:03 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Fri Oct 23 17:26:03 2015 +0300
----------------------------------------------------------------------
.../apache/ignite/internal/portable/PortableClassDescriptor.java | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/2a8b75a2/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 5f7ab08..ee78fd0 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
@@ -535,6 +535,8 @@ public class PortableClassDescriptor {
case EXTERNALIZABLE:
if (writeHeader(obj, writer)) {
+ writer.rawWriter();
+
try {
((Externalizable)obj).writeExternal(writer);
}
@@ -542,6 +544,7 @@ public class PortableClassDescriptor {
throw new PortableException("Failed to write Externalizable object: " + obj, e);
}
+ writer.writeRawOffsetIfNeeded();
writer.writeLength();
}