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/12/24 10:36:07 UTC
[2/2] ignite git commit: IGNITE-2257: Fixed.
IGNITE-2257: Fixed.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/0009b134
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/0009b134
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/0009b134
Branch: refs/heads/ignite-2257
Commit: 0009b1345a5b25210bccc7acfed337a48b4e7531
Parents: e67eb6d
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Thu Dec 24 12:37:02 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Thu Dec 24 12:37:02 2015 +0300
----------------------------------------------------------------------
.../internal/binary/GridBinaryMarshaller.java | 44 ++++++++++++++------
1 file changed, 32 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/0009b134/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
index 95fbc0c..93f3a40 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
@@ -240,15 +240,13 @@ public class GridBinaryMarshaller {
@Nullable public <T> T unmarshal(byte[] bytes, @Nullable ClassLoader clsLdr) throws BinaryObjectException {
assert bytes != null;
- assert BINARY_CTX.get() == null;
-
- BINARY_CTX.set(ctx);
+ BinaryContext oldCtx = pushContext(ctx);
try {
return (T) BinaryUtils.unmarshal(BinaryHeapInputStream.create(bytes, 0), ctx, clsLdr);
}
finally {
- BINARY_CTX.remove();
+ popContext(oldCtx);
}
}
@@ -259,15 +257,13 @@ public class GridBinaryMarshaller {
*/
@SuppressWarnings("unchecked")
@Nullable public <T> T unmarshal(BinaryInputStream in) throws BinaryObjectException {
- assert BINARY_CTX.get() == null;
-
- BINARY_CTX.set(ctx);
+ BinaryContext oldCtx = pushContext(ctx);
try {
return (T)BinaryUtils.unmarshal(in, ctx, null);
}
finally {
- BINARY_CTX.remove();
+ popContext(oldCtx);
}
}
@@ -285,19 +281,43 @@ public class GridBinaryMarshaller {
if (arr[0] == NULL)
return null;
- assert BINARY_CTX.get() == null;
-
- BINARY_CTX.set(ctx);
+ BinaryContext oldCtx = pushContext(ctx);
try {
return (T)new BinaryReaderExImpl(ctx, BinaryHeapInputStream.create(arr, 0), ldr).deserialize();
}
finally {
- BINARY_CTX.remove();
+ popContext(oldCtx);
}
}
/**
+ * Push binary context and return the old one.
+ *
+ * @param ctx Binary context.
+ * @return Old binary context.
+ */
+ @Nullable private static BinaryContext pushContext(BinaryContext ctx) {
+ BinaryContext old = BINARY_CTX.get();
+
+ BINARY_CTX.set(ctx);
+
+ return old;
+ }
+
+ /**
+ * Pop binary context and restore the old one.
+ *
+ * @param oldCtx Old binary context.
+ */
+ private static void popContext(@Nullable BinaryContext oldCtx) {
+ if (oldCtx == null)
+ BINARY_CTX.remove();
+ else
+ BINARY_CTX.set(oldCtx);
+ }
+
+ /**
* Whether object must be deserialized anyway. I.e. it cannot be converted to BinaryObject.
*
* @param obj Object.