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 10:13:55 UTC
[3/3] ignite git commit: IGNITE-1917: Moved marshalling context to a
separate class.
IGNITE-1917: Moved marshalling context to a separate class.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/417bd097
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/417bd097
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/417bd097
Branch: refs/heads/ignite-1917
Commit: 417bd09750d44d9347baa78add48fb836b2b695b
Parents: a409163
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Mon Nov 16 12:14:37 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Mon Nov 16 12:14:37 2015 +0300
----------------------------------------------------------------------
.../portable/BinaryThreadLocalContext.java | 69 ++++++++++++++++++++
.../internal/portable/BinaryWriterExImpl.java | 22 ++-----
2 files changed, 73 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/417bd097/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryThreadLocalContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryThreadLocalContext.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryThreadLocalContext.java
new file mode 100644
index 0000000..c6a7fc3
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryThreadLocalContext.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.portable;
+
+import org.apache.ignite.internal.portable.streams.PortableMemoryAllocator;
+import org.apache.ignite.internal.portable.streams.PortableMemoryAllocatorChunk;
+
+/**
+ * Contains thread-local data for binary marshalling.
+ */
+public class BinaryThreadLocalContext {
+ /** Thread-local instance. */
+ private static final ThreadLocal<BinaryThreadLocalContext> CTX = new ThreadLocal<BinaryThreadLocalContext>() {
+ @Override protected BinaryThreadLocalContext initialValue() {
+ return new BinaryThreadLocalContext();
+ }
+ };
+
+ /** Memory chunk. */
+ private final PortableMemoryAllocatorChunk chunk = PortableMemoryAllocator.INSTANCE.chunk();
+
+ /** Schema holder. */
+ private final BinaryWriterSchemaHolder schema = new BinaryWriterSchemaHolder();
+
+ /**
+ * Get current context.
+ *
+ * @return Context.
+ */
+ public static BinaryThreadLocalContext get() {
+ return CTX.get();
+ }
+
+ /**
+ * Private constructor.
+ */
+ private BinaryThreadLocalContext() {
+ // No-op.
+ }
+
+ /**
+ * @return Memory chunk.
+ */
+ public PortableMemoryAllocatorChunk chunk() {
+ return chunk;
+ }
+
+ /**
+ * @return Schema holder.
+ */
+ public BinaryWriterSchemaHolder schemaHolder() {
+ return schema;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/417bd097/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 0e8c855..c440024 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
@@ -23,8 +23,6 @@ import org.apache.ignite.binary.BinaryObjectException;
import org.apache.ignite.binary.BinaryRawWriter;
import org.apache.ignite.binary.BinaryWriter;
import org.apache.ignite.internal.portable.streams.PortableHeapOutputStream;
-import org.apache.ignite.internal.portable.streams.PortableMemoryAllocator;
-import org.apache.ignite.internal.portable.streams.PortableMemoryAllocatorChunk;
import org.apache.ignite.internal.portable.streams.PortableOutputStream;
import org.apache.ignite.internal.util.typedef.internal.A;
import org.jetbrains.annotations.Nullable;
@@ -123,29 +121,17 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
/** ID mapper. */
private BinaryIdMapper idMapper;
- private static final ThreadLocal<TLSContext> TLS_CTX = new ThreadLocal<TLSContext>() {
- @Override protected TLSContext initialValue() {
- return new TLSContext();
- }
- };
-
- private static class TLSContext {
-
- public PortableMemoryAllocatorChunk chunk = PortableMemoryAllocator.INSTANCE.chunk();
- public BinaryWriterSchemaHolder schema = new BinaryWriterSchemaHolder();
- }
-
/**
* @param ctx Context.
*/
BinaryWriterExImpl(PortableContext ctx) {
- TLSContext tlsCtx = TLS_CTX.get();
+ BinaryThreadLocalContext tlsCtx = BinaryThreadLocalContext.get();
this.ctx = ctx;
- this.out = new PortableHeapOutputStream(INIT_CAP, tlsCtx.chunk);
+ this.out = new PortableHeapOutputStream(INIT_CAP, tlsCtx.chunk());
start = out.position();
- schema = tlsCtx.schema;
+ schema = tlsCtx.schemaHolder();
}
/**
@@ -168,7 +154,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
start = out.position();
- schema = TLS_CTX.get().schema;
+ schema = BinaryThreadLocalContext.get().schemaHolder();
}
/**