geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [13/20] incubator-geode git commit: move DataAsAddress from SimpleMemoryAllocatorImpl
Date Fri, 20 Nov 2015 01:07:48 GMT
move DataAsAddress from SimpleMemoryAllocatorImpl


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

Branch: refs/heads/feature/GEODE-580
Commit: ff64d0b0708c7b3ee38d60b3f82de595c6543c39
Parents: e7b29ce
Author: Darrel Schneider <dschneider@pivotal.io>
Authored: Thu Nov 19 16:00:09 2015 -0800
Committer: Darrel Schneider <dschneider@pivotal.io>
Committed: Thu Nov 19 16:00:09 2015 -0800

----------------------------------------------------------------------
 .../internal/cache/tier/sockets/Part.java       |   2 +-
 .../gemfire/internal/offheap/DataAsAddress.java | 205 +++++++++++++++++++
 .../offheap/OffHeapRegionEntryHelper.java       |   1 -
 .../offheap/SimpleMemoryAllocatorImpl.java      | 185 -----------------
 .../cache/OldValueImporterTestBase.java         |   2 +-
 .../OffHeapWriteObjectAsByteArrayJUnitTest.java |   1 -
 6 files changed, 207 insertions(+), 189 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ff64d0b0/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/Part.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/Part.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/Part.java
index 0bbcc6b..5418c68 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/Part.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/tier/sockets/Part.java
@@ -19,7 +19,7 @@ package com.gemstone.gemfire.internal.cache.tier.sockets;
 import com.gemstone.gemfire.internal.*;
 import com.gemstone.gemfire.internal.cache.CachedDeserializable;
 import com.gemstone.gemfire.internal.offheap.Chunk;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.DataAsAddress;
+import com.gemstone.gemfire.internal.offheap.DataAsAddress;
 import com.gemstone.gemfire.internal.offheap.StoredObject;
 import com.gemstone.gemfire.internal.offheap.UnsafeMemoryChunk;
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ff64d0b0/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/DataAsAddress.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/DataAsAddress.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/DataAsAddress.java
new file mode 100644
index 0000000..61204ba
--- /dev/null
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/DataAsAddress.java
@@ -0,0 +1,205 @@
+/*
+ * 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 com.gemstone.gemfire.internal.offheap;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import com.gemstone.gemfire.DataSerializer;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.internal.DataSerializableFixedID;
+import com.gemstone.gemfire.internal.InternalDataSerializer;
+import com.gemstone.gemfire.internal.cache.BytesAndBitsForCompactor;
+import com.gemstone.gemfire.internal.cache.EntryBits;
+import com.gemstone.gemfire.internal.cache.RegionEntry;
+import com.gemstone.gemfire.internal.cache.RegionEntryContext;
+import com.gemstone.gemfire.internal.lang.StringUtils;
+
+/**
+ * Used to represent offheap addresses whose
+ * value encodes actual data instead a memory
+ * location.
+ * Instances of this class have a very short lifetime.
+ */
+public class DataAsAddress implements StoredObject {
+  private final long address;
+  
+  public DataAsAddress(long addr) {
+    this.address = addr;
+  }
+  
+  public long getEncodedAddress() {
+    return this.address;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (o instanceof DataAsAddress) {
+      return getEncodedAddress() == ((DataAsAddress) o).getEncodedAddress();
+    }
+    return false;
+  }
+  
+  @Override
+  public int hashCode() {
+    long value = getEncodedAddress();
+    return (int)(value ^ (value >>> 32));
+  }
+
+  @Override
+  public int getSizeInBytes() {
+    return 0;
+  }
+
+  public byte[] getDecompressedBytes(RegionEntryContext r) {
+    return OffHeapRegionEntryHelper.encodedAddressToBytes(this.address, true, r);
+  }
+
+  /**
+   * If we contain a byte[] return it.
+   * Otherwise return the serialize bytes in us in a byte array.
+   */
+  public byte[] getRawBytes() {
+    return OffHeapRegionEntryHelper.encodedAddressToRawBytes(this.address);
+  }
+  
+  @Override
+  public byte[] getSerializedValue() {
+    return OffHeapRegionEntryHelper.encodedAddressToBytes(this.address);
+  }
+
+  @Override
+  public Object getDeserializedValue(Region r, RegionEntry re) {
+    return OffHeapRegionEntryHelper.encodedAddressToObject(this.address);
+  }
+
+  @Override
+  public Object getDeserializedForReading() {
+    return getDeserializedValue(null,null);
+  }
+  
+  @Override
+  public Object getValueAsDeserializedHeapObject() {
+    return getDeserializedValue(null,null);
+  }
+  
+  @Override
+  public byte[] getValueAsHeapByteArray() {
+    if (isSerialized()) {
+      return getSerializedValue();
+    } else {
+      return (byte[])getDeserializedForReading();
+    }
+  }
+
+  @Override
+  public String getStringForm() {
+    try {
+      return StringUtils.forceToString(getDeserializedForReading());
+    } catch (RuntimeException ex) {
+      return "Could not convert object to string because " + ex;
+    }
+  }
+
+  @Override
+  public Object getDeserializedWritableCopy(Region r, RegionEntry re) {
+    return getDeserializedValue(null,null);
+  }
+
+  @Override
+  public Object getValue() {
+    if (isSerialized()) {
+      return getSerializedValue();
+    } else {
+      throw new IllegalStateException("Can not call getValue on StoredObject that is not
serialized");
+    }
+  }
+
+  @Override
+  public void writeValueAsByteArray(DataOutput out) throws IOException {
+    DataSerializer.writeByteArray(getSerializedValue(), out);
+  }
+
+  @Override
+  public void fillSerializedValue(BytesAndBitsForCompactor wrapper,
+      byte userBits) {
+    byte[] value;
+    if (isSerialized()) {
+      value = getSerializedValue();
+      userBits = EntryBits.setSerialized(userBits, true);
+    } else {
+      value = (byte[]) getDeserializedForReading();
+    }
+    wrapper.setData(value, userBits, value.length, true);
+  }
+
+  @Override
+  public int getValueSizeInBytes() {
+    return 0;
+  }
+  
+  @Override
+  public void sendTo(DataOutput out) throws IOException {
+    if (isSerialized()) {
+      out.write(getSerializedValue());
+    } else {
+      Object objToSend = (byte[]) getDeserializedForReading(); // deserialized as a byte[]
+      DataSerializer.writeObject(objToSend, out);
+    }
+  }
+
+  @Override
+  public void sendAsByteArray(DataOutput out) throws IOException {
+    byte[] bytes;
+    if (isSerialized()) {
+      bytes = getSerializedValue();
+    } else {
+      bytes = (byte[]) getDeserializedForReading();
+    }
+    DataSerializer.writeByteArray(bytes, out);
+    
+  }
+  
+  @Override
+  public void sendAsCachedDeserializable(DataOutput out) throws IOException {
+    if (!isSerialized()) {
+      throw new IllegalStateException("sendAsCachedDeserializable can only be called on serialized
StoredObjects");
+    }
+    InternalDataSerializer.writeDSFIDHeader(DataSerializableFixedID.VM_CACHED_DESERIALIZABLE,
out);
+    sendAsByteArray(out);
+  }
+
+  @Override
+  public boolean isSerialized() {
+    return OffHeapRegionEntryHelper.isSerialized(this.address);
+  }
+
+  @Override
+  public boolean isCompressed() {
+    return OffHeapRegionEntryHelper.isCompressed(this.address);
+  }
+  
+  @Override
+  public boolean retain() {
+    // nothing needed
+    return true;
+  }
+  @Override
+  public void release() {
+    // nothing needed
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ff64d0b0/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
index 6cb43ad..34c3468 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/OffHeapRegionEntryHelper.java
@@ -24,7 +24,6 @@ import com.gemstone.gemfire.internal.cache.EntryEventImpl;
 import com.gemstone.gemfire.internal.cache.OffHeapRegionEntry;
 import com.gemstone.gemfire.internal.cache.RegionEntryContext;
 import com.gemstone.gemfire.internal.cache.Token;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.DataAsAddress;
 import com.gemstone.gemfire.internal.offheap.annotations.Released;
 import com.gemstone.gemfire.internal.offheap.annotations.Retained;
 import com.gemstone.gemfire.internal.offheap.annotations.Unretained;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ff64d0b0/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
index 98be355..40a01b5 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/offheap/SimpleMemoryAllocatorImpl.java
@@ -17,7 +17,6 @@
 package com.gemstone.gemfire.internal.offheap;
 
 import java.io.ByteArrayOutputStream;
-import java.io.DataOutput;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.util.ArrayList;
@@ -53,19 +52,13 @@ import com.gemstone.gemfire.OutOfOffHeapMemoryException;
 import com.gemstone.gemfire.cache.CacheClosedException;
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
-import com.gemstone.gemfire.internal.DataSerializableFixedID;
-import com.gemstone.gemfire.internal.InternalDataSerializer;
 import com.gemstone.gemfire.internal.cache.BucketRegion;
-import com.gemstone.gemfire.internal.cache.BytesAndBitsForCompactor;
 import com.gemstone.gemfire.internal.cache.CachedDeserializableFactory;
-import com.gemstone.gemfire.internal.cache.EntryBits;
 import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
 import com.gemstone.gemfire.internal.cache.LocalRegion;
 import com.gemstone.gemfire.internal.cache.PartitionedRegion;
 import com.gemstone.gemfire.internal.cache.PartitionedRegionDataStore;
 import com.gemstone.gemfire.internal.cache.RegionEntry;
-import com.gemstone.gemfire.internal.cache.RegionEntryContext;
-import com.gemstone.gemfire.internal.lang.StringUtils;
 import com.gemstone.gemfire.internal.logging.LogService;
 import com.gemstone.gemfire.internal.offheap.annotations.OffHeapIdentifier;
 import com.gemstone.gemfire.internal.offheap.annotations.Unretained;
@@ -398,184 +391,6 @@ public final class SimpleMemoryAllocatorImpl implements MemoryAllocator,
MemoryI
     return result;
   }
   
-  /**
-   * Used to represent offheap addresses whose
-   * value encodes actual data instead a memory
-   * location.
-   * Instances of this class have a very short lifetime.
-   * 
-   * @author darrel
-   *
-   */
-  public static class DataAsAddress implements StoredObject {
-    private final long address;
-    
-    public DataAsAddress(long addr) {
-      this.address = addr;
-    }
-    
-    public long getEncodedAddress() {
-      return this.address;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-      if (o instanceof DataAsAddress) {
-        return getEncodedAddress() == ((DataAsAddress) o).getEncodedAddress();
-      }
-      return false;
-    }
-    
-    @Override
-    public int hashCode() {
-      long value = getEncodedAddress();
-      return (int)(value ^ (value >>> 32));
-    }
-
-    @Override
-    public int getSizeInBytes() {
-      return 0;
-    }
-
-    public byte[] getDecompressedBytes(RegionEntryContext r) {
-      return OffHeapRegionEntryHelper.encodedAddressToBytes(this.address, true, r);
-    }
-
-    /**
-     * If we contain a byte[] return it.
-     * Otherwise return the serialize bytes in us in a byte array.
-     */
-    public byte[] getRawBytes() {
-      return OffHeapRegionEntryHelper.encodedAddressToRawBytes(this.address);
-    }
-    
-    @Override
-    public byte[] getSerializedValue() {
-      return OffHeapRegionEntryHelper.encodedAddressToBytes(this.address);
-    }
-
-    @Override
-    public Object getDeserializedValue(Region r, RegionEntry re) {
-      return OffHeapRegionEntryHelper.encodedAddressToObject(this.address);
-    }
-
-    @Override
-    public Object getDeserializedForReading() {
-      return getDeserializedValue(null,null);
-    }
-    
-    @Override
-    public Object getValueAsDeserializedHeapObject() {
-      return getDeserializedValue(null,null);
-    }
-    
-    @Override
-    public byte[] getValueAsHeapByteArray() {
-      if (isSerialized()) {
-        return getSerializedValue();
-      } else {
-        return (byte[])getDeserializedForReading();
-      }
-    }
-
-    @Override
-    public String getStringForm() {
-      try {
-        return StringUtils.forceToString(getDeserializedForReading());
-      } catch (RuntimeException ex) {
-        return "Could not convert object to string because " + ex;
-      }
-    }
-
-    @Override
-    public Object getDeserializedWritableCopy(Region r, RegionEntry re) {
-      return getDeserializedValue(null,null);
-    }
-
-    @Override
-    public Object getValue() {
-      if (isSerialized()) {
-        return getSerializedValue();
-      } else {
-        throw new IllegalStateException("Can not call getValue on StoredObject that is not
serialized");
-      }
-    }
-
-    @Override
-    public void writeValueAsByteArray(DataOutput out) throws IOException {
-      DataSerializer.writeByteArray(getSerializedValue(), out);
-    }
-
-    @Override
-    public void fillSerializedValue(BytesAndBitsForCompactor wrapper,
-        byte userBits) {
-      byte[] value;
-      if (isSerialized()) {
-        value = getSerializedValue();
-        userBits = EntryBits.setSerialized(userBits, true);
-      } else {
-        value = (byte[]) getDeserializedForReading();
-      }
-      wrapper.setData(value, userBits, value.length, true);
-    }
-
-    @Override
-    public int getValueSizeInBytes() {
-      return 0;
-    }
-    
-    @Override
-    public void sendTo(DataOutput out) throws IOException {
-      if (isSerialized()) {
-        out.write(getSerializedValue());
-      } else {
-        Object objToSend = (byte[]) getDeserializedForReading(); // deserialized as a byte[]
-        DataSerializer.writeObject(objToSend, out);
-      }
-    }
-
-    @Override
-    public void sendAsByteArray(DataOutput out) throws IOException {
-      byte[] bytes;
-      if (isSerialized()) {
-        bytes = getSerializedValue();
-      } else {
-        bytes = (byte[]) getDeserializedForReading();
-      }
-      DataSerializer.writeByteArray(bytes, out);
-      
-    }
-    
-    @Override
-    public void sendAsCachedDeserializable(DataOutput out) throws IOException {
-      if (!isSerialized()) {
-        throw new IllegalStateException("sendAsCachedDeserializable can only be called on
serialized StoredObjects");
-      }
-      InternalDataSerializer.writeDSFIDHeader(DataSerializableFixedID.VM_CACHED_DESERIALIZABLE,
out);
-      sendAsByteArray(out);
-    }
-
-    @Override
-    public boolean isSerialized() {
-      return OffHeapRegionEntryHelper.isSerialized(this.address);
-    }
-
-    @Override
-    public boolean isCompressed() {
-      return OffHeapRegionEntryHelper.isCompressed(this.address);
-    }
-    
-    @Override
-    public boolean retain() {
-      // nothing needed
-      return true;
-    }
-    @Override
-    public void release() {
-      // nothing needed
-    }
-  }
-
   @SuppressWarnings("unused")
   public static void debugLog(String msg, boolean logStack) {
     if (logStack) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ff64d0b0/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OldValueImporterTestBase.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OldValueImporterTestBase.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OldValueImporterTestBase.java
index 2889b0c..f7d0714 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OldValueImporterTestBase.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OldValueImporterTestBase.java
@@ -27,10 +27,10 @@ import org.junit.Test;
 import com.gemstone.gemfire.internal.HeapDataOutputStream;
 import com.gemstone.gemfire.internal.cache.EntryEventImpl.OldValueImporter;
 import com.gemstone.gemfire.internal.offheap.Chunk;
+import com.gemstone.gemfire.internal.offheap.DataAsAddress;
 import com.gemstone.gemfire.internal.offheap.NullOffHeapMemoryStats;
 import com.gemstone.gemfire.internal.offheap.NullOutOfOffHeapMemoryListener;
 import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.DataAsAddress;
 import com.gemstone.gemfire.internal.offheap.UnsafeMemoryChunk;
 import com.gemstone.gemfire.internal.util.BlobHelper;
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ff64d0b0/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
index e371231..daebefa 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/OffHeapWriteObjectAsByteArrayJUnitTest.java
@@ -34,7 +34,6 @@ import com.gemstone.gemfire.internal.cache.EntryEventImpl;
 import com.gemstone.gemfire.internal.offheap.NullOffHeapMemoryStats;
 import com.gemstone.gemfire.internal.offheap.NullOutOfOffHeapMemoryListener;
 import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl;
-import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl.DataAsAddress;
 import com.gemstone.gemfire.internal.offheap.StoredObject;
 import com.gemstone.gemfire.internal.offheap.UnsafeMemoryChunk;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;


Mime
View raw message