You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mnemonic.apache.org by ga...@apache.org on 2016/04/09 00:00:03 UTC
[1/7] incubator-mnemonic git commit: format codestyle & add Apache
License
Repository: incubator-mnemonic
Updated Branches:
refs/heads/master af3bb7019 -> 551c8247d
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/test/java/org/apache/mnemonic/MemBufferHolderCachePoolNGTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/mnemonic/MemBufferHolderCachePoolNGTest.java b/core/src/test/java/org/apache/mnemonic/MemBufferHolderCachePoolNGTest.java
index b58c3c8..86f9936 100644
--- a/core/src/test/java/org/apache/mnemonic/MemBufferHolderCachePoolNGTest.java
+++ b/core/src/test/java/org/apache/mnemonic/MemBufferHolderCachePoolNGTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import static org.testng.Assert.*;
@@ -18,133 +35,123 @@ import java.util.Random;
/**
* test the functionalities of MemBufferHolderCachePool class
*
- * @author Wang, Gang(Gary) {@literal <ga...@intel.com>}
*/
public class MemBufferHolderCachePoolNGTest {
- /**
- * test to aggressively allow any MemBufferHolder objects in pool to be able
- * to drop at will that prevents this cache pool from overflowing.
- */
- @Test
- public void testMemBufferHolderCachePoolWithoutOverflow() {
-
- MemBufferHolderCachePool<Integer> mbhcpool = new MemBufferHolderCachePool<Integer>(
- 1024 * 1024 * 10);
- Random randomGenerator = new Random();
- MemClustering.NodeConfig<?> ncs[] = new MemClustering.NodeConfig<?>[] {
- new MemClustering.NodeConfig<BigDataMemAllocator>(
- new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 200, ".", true)
- .disableActiveGC(),
- MemClustering.PerformanceLevel.FAST),
- // new MemClustering.NodeConfig(new BigMemAllocator(1024*1024*20, ".",
- // true).disableActiveGC(), MemClustering.PerformanceLevel.NORMAL),
- // new MemClustering.NodeConfig(new BigMemAllocator(1024*1024*20, ".",
- // true).disableActiveGC(), MemClustering.PerformanceLevel.SLOW),
- };
- MemClustering mclst = new MemClustering(ncs);
- MemBufferHolder<?> mbh;
-
- DropEvent<Integer, MemBufferHolder<?>> dropevt =
- new DropEvent<Integer, MemBufferHolder<?>>() {
- @Override
- public void drop(CachePool<Integer, MemBufferHolder<?>> pool,
- Integer k, MemBufferHolder<?> v) {
- System.out.println(String.format("dropping idx: %d", k));
- v.destroy();
- }
- };
-
- EvictFilter<Integer, MemBufferHolder<?>> dfilter = new EvictFilter<Integer, MemBufferHolder<?>>() {
- @Override
- public boolean validate(CachePool<Integer, MemBufferHolder<?>> pool,
- Integer k, MemBufferHolder<?> v) {
- System.out.println(String.format("validating idx: %d", k));
- return true;
- }
- };
-
- for (int idx = 1; idx <= 100; ++idx) {
- int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
- mbh = mclst.createBuffer(size);
- System.out.println(String.format(
- "\nallocating idx: %d - size: %d, FreeCap: %d", idx, size,
- mbhcpool.freeCapacity()));
- assertNotNull(mbh);
- assertNotNull(mbh.get());
- for (int i = 0; i < size; i++) {
- mbh.get().put((byte) randomGenerator.nextInt(255));
- }
-
- mbh.get().flip();
-
- assertEquals(size, mbh.get().capacity());
-
- mbhcpool.put(idx, mbh, dropevt, dfilter);
-
- }
- }
-
- /**
- * test to overflow a cache pool of MemBufferHolder objects that is caused
- * by preventing any objected in pool from dropping.
- */
- @Test(expectedExceptions = ContainerOverflowException.class)
- public void testMemBufferHolderCachePoolWithOverflow() {
-
- MemBufferHolderCachePool<Integer> mbhcpool = new MemBufferHolderCachePool<Integer>(
- 1024 * 1024 * 10);
- Random randomGenerator = new Random();
- MemClustering.NodeConfig<?> ncs[] = new MemClustering.NodeConfig<?>[] {
- new MemClustering.NodeConfig<BigDataMemAllocator>(
- new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 200, ".", true)
- .disableActiveGC(),
- MemClustering.PerformanceLevel.FAST),
- // new MemClustering.NodeConfig(new BigMemAllocator(1024*1024*20, ".",
- // true).disableActiveGC(), MemClustering.PerformanceLevel.NORMAL),
- // new MemClustering.NodeConfig(new BigMemAllocator(1024*1024*20, ".",
- // true).disableActiveGC(), MemClustering.PerformanceLevel.SLOW),
- };
- MemClustering mclst = new MemClustering(ncs);
- MemBufferHolder<?> mbh;
-
- DropEvent<Integer, MemBufferHolder<?>> dropevt = new DropEvent<Integer, MemBufferHolder<?>>() {
- @Override
- public void drop(CachePool<Integer, MemBufferHolder<?>> pool,
- Integer k, MemBufferHolder<?> v) {
- System.out.println(String.format("dropping idx: %d", k));
- v.destroy();
- }
- };
-
- EvictFilter<Integer, MemBufferHolder<?>> dfilter = new EvictFilter<Integer, MemBufferHolder<?>>() {
- @Override
- public boolean validate(CachePool<Integer, MemBufferHolder<?>> pool,
- Integer k, MemBufferHolder<?> v) {
- System.out.println(String.format("validating idx: %d", k));
- return false;
- }
- };
-
- for (int idx = 1; idx <= 100; ++idx) {
- int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
- mbh = mclst.createBuffer(size);
- System.out.println(String.format(
- "\nallocating idx: %d - size: %d, FreeCap: %d", idx, size,
- mbhcpool.freeCapacity()));
- assertNotNull(mbh);
- assertNotNull(mbh.get());
- for (int i = 0; i < size; i++) {
- mbh.get().put((byte) randomGenerator.nextInt(255));
- }
-
- mbh.get().flip();
-
- assertEquals(size, mbh.get().capacity());
-
- mbhcpool.put(idx, mbh, dropevt, dfilter);
-
- }
- }
+ /**
+ * test to aggressively allow any MemBufferHolder objects in pool to be able
+ * to drop at will that prevents this cache pool from overflowing.
+ */
+ @Test
+ public void testMemBufferHolderCachePoolWithoutOverflow() {
+
+ MemBufferHolderCachePool<Integer> mbhcpool = new MemBufferHolderCachePool<Integer>(1024 * 1024 * 10);
+ Random randomGenerator = new Random();
+ MemClustering.NodeConfig<?> ncs[] = new MemClustering.NodeConfig<?>[] {
+ new MemClustering.NodeConfig<BigDataMemAllocator>(
+ new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 200, ".", true)
+ .disableActiveGC(),
+ MemClustering.PerformanceLevel.FAST),
+ // new MemClustering.NodeConfig(new BigMemAllocator(1024*1024*20, ".",
+ // true).disableActiveGC(), MemClustering.PerformanceLevel.NORMAL),
+ // new MemClustering.NodeConfig(new BigMemAllocator(1024*1024*20, ".",
+ // true).disableActiveGC(), MemClustering.PerformanceLevel.SLOW),
+ };
+ MemClustering mclst = new MemClustering(ncs);
+ MemBufferHolder<?> mbh;
+
+ DropEvent<Integer, MemBufferHolder<?>> dropevt = new DropEvent<Integer, MemBufferHolder<?>>() {
+ @Override
+ public void drop(CachePool<Integer, MemBufferHolder<?>> pool, Integer k, MemBufferHolder<?> v) {
+ System.out.println(String.format("dropping idx: %d", k));
+ v.destroy();
+ }
+ };
+
+ EvictFilter<Integer, MemBufferHolder<?>> dfilter = new EvictFilter<Integer, MemBufferHolder<?>>() {
+ @Override
+ public boolean validate(CachePool<Integer, MemBufferHolder<?>> pool, Integer k, MemBufferHolder<?> v) {
+ System.out.println(String.format("validating idx: %d", k));
+ return true;
+ }
+ };
+
+ for (int idx = 1; idx <= 100; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mbh = mclst.createBuffer(size);
+ System.out
+ .println(String.format("\nallocating idx: %d - size: %d, FreeCap: %d", idx, size, mbhcpool.freeCapacity()));
+ assertNotNull(mbh);
+ assertNotNull(mbh.get());
+ for (int i = 0; i < size; i++) {
+ mbh.get().put((byte) randomGenerator.nextInt(255));
+ }
+
+ mbh.get().flip();
+
+ assertEquals(size, mbh.get().capacity());
+
+ mbhcpool.put(idx, mbh, dropevt, dfilter);
+
+ }
+ }
+
+ /**
+ * test to overflow a cache pool of MemBufferHolder objects that is caused by
+ * preventing any objected in pool from dropping.
+ */
+ @Test(expectedExceptions = ContainerOverflowException.class)
+ public void testMemBufferHolderCachePoolWithOverflow() {
+
+ MemBufferHolderCachePool<Integer> mbhcpool = new MemBufferHolderCachePool<Integer>(1024 * 1024 * 10);
+ Random randomGenerator = new Random();
+ MemClustering.NodeConfig<?> ncs[] = new MemClustering.NodeConfig<?>[] {
+ new MemClustering.NodeConfig<BigDataMemAllocator>(
+ new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 200, ".", true)
+ .disableActiveGC(),
+ MemClustering.PerformanceLevel.FAST),
+ // new MemClustering.NodeConfig(new BigMemAllocator(1024*1024*20, ".",
+ // true).disableActiveGC(), MemClustering.PerformanceLevel.NORMAL),
+ // new MemClustering.NodeConfig(new BigMemAllocator(1024*1024*20, ".",
+ // true).disableActiveGC(), MemClustering.PerformanceLevel.SLOW),
+ };
+ MemClustering mclst = new MemClustering(ncs);
+ MemBufferHolder<?> mbh;
+
+ DropEvent<Integer, MemBufferHolder<?>> dropevt = new DropEvent<Integer, MemBufferHolder<?>>() {
+ @Override
+ public void drop(CachePool<Integer, MemBufferHolder<?>> pool, Integer k, MemBufferHolder<?> v) {
+ System.out.println(String.format("dropping idx: %d", k));
+ v.destroy();
+ }
+ };
+
+ EvictFilter<Integer, MemBufferHolder<?>> dfilter = new EvictFilter<Integer, MemBufferHolder<?>>() {
+ @Override
+ public boolean validate(CachePool<Integer, MemBufferHolder<?>> pool, Integer k, MemBufferHolder<?> v) {
+ System.out.println(String.format("validating idx: %d", k));
+ return false;
+ }
+ };
+
+ for (int idx = 1; idx <= 100; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mbh = mclst.createBuffer(size);
+ System.out
+ .println(String.format("\nallocating idx: %d - size: %d, FreeCap: %d", idx, size, mbhcpool.freeCapacity()));
+ assertNotNull(mbh);
+ assertNotNull(mbh.get());
+ for (int i = 0; i < size; i++) {
+ mbh.get().put((byte) randomGenerator.nextInt(255));
+ }
+
+ mbh.get().flip();
+
+ assertEquals(size, mbh.get().capacity());
+
+ mbhcpool.put(idx, mbh, dropevt, dfilter);
+
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/test/java/org/apache/mnemonic/MemClusteringNGTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/mnemonic/MemClusteringNGTest.java b/core/src/test/java/org/apache/mnemonic/MemClusteringNGTest.java
index 9e88979..010ab53 100644
--- a/core/src/test/java/org/apache/mnemonic/MemClusteringNGTest.java
+++ b/core/src/test/java/org/apache/mnemonic/MemClusteringNGTest.java
@@ -1,3 +1,19 @@
+/*
+ * 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.mnemonic;
@@ -15,175 +31,168 @@ import java.util.Random;
/**
* test the functionalities of MemClustering class
- *
- * @author Wang, Gang(Gary) {@literal <ga...@intel.com>}
*/
public class MemClusteringNGTest {
- /**
- * test to fill up memory pool without reclaim unused memory blocks that
- * will cause additional operations of allocation will be failed.
- *
- * @throws Exception
- */
- @Test(expectedExceptions = NullPointerException.class)
- public void testMemByteBufferWithoutActiveGC() throws Exception {
- Random randomGenerator = new Random();
- MemClustering.NodeConfig<?> ncs[] = new MemClustering.NodeConfig<?>[] {
- new MemClustering.NodeConfig<SysMemAllocator>(new SysMemAllocator(
- 1024 * 1024 * 20, true).disableActiveGC(),
- MemClustering.PerformanceLevel.FASTEST),
- new MemClustering.NodeConfig<BigDataMemAllocator>(new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"),
- 1024 * 1024 * 20, ".", true).disableActiveGC(),
- MemClustering.PerformanceLevel.FAST),
- // new MemClustering.NodeConfig(new
- // BigMemAllocator(1024*1024*20, ".", true).disableActiveGC(),
- // MemClustering.PerformanceLevel.NORMAL),
- new MemClustering.NodeConfig<BigDataMemAllocator>(new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"),
- 1024 * 1024 * 20, ".", true).disableActiveGC(),
- MemClustering.PerformanceLevel.SLOW), };
- MemClustering mclst = new MemClustering(ncs);
- MemBufferHolder<?> mbh;
- for (int idx = 1; idx <= 200; ++idx) {
- int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
- mbh = mclst.createBuffer(size);
- for (int i = 0; i < size; i++) {
- mbh.get().put((byte) randomGenerator.nextInt(255));
- }
- assertEquals(size, mbh.get().capacity());
- }
- }
+ /**
+ * test to fill up memory pool without reclaim unused memory blocks that will
+ * cause additional operations of allocation will be failed.
+ *
+ * @throws Exception
+ */
+ @Test(expectedExceptions = NullPointerException.class)
+ public void testMemByteBufferWithoutActiveGC() throws Exception {
+ Random randomGenerator = new Random();
+ MemClustering.NodeConfig<?> ncs[] = new MemClustering.NodeConfig<?>[] {
+ new MemClustering.NodeConfig<SysMemAllocator>(new SysMemAllocator(1024 * 1024 * 20, true).disableActiveGC(),
+ MemClustering.PerformanceLevel.FASTEST),
+ new MemClustering.NodeConfig<BigDataMemAllocator>(
+ new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 20, ".", true)
+ .disableActiveGC(),
+ MemClustering.PerformanceLevel.FAST),
+ // new MemClustering.NodeConfig(new
+ // BigMemAllocator(1024*1024*20, ".", true).disableActiveGC(),
+ // MemClustering.PerformanceLevel.NORMAL),
+ new MemClustering.NodeConfig<BigDataMemAllocator>(
+ new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 20, ".", true)
+ .disableActiveGC(),
+ MemClustering.PerformanceLevel.SLOW), };
+ MemClustering mclst = new MemClustering(ncs);
+ MemBufferHolder<?> mbh;
+ for (int idx = 1; idx <= 200; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mbh = mclst.createBuffer(size);
+ for (int i = 0; i < size; i++) {
+ mbh.get().put((byte) randomGenerator.nextInt(255));
+ }
+ assertEquals(size, mbh.get().capacity());
+ }
+ }
- /**
- * test to try to fill up memory pool and reclaim unused memory block as
- * required.
- */
- @Test
- public void testMemByteBufferWithActiveGC() {
- Random randomGenerator = new Random();
- MemClustering.NodeConfig<?> ncs[] = new MemClustering.NodeConfig<?>[] { new MemClustering.NodeConfig<BigDataMemAllocator>(
- new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 20, ".", true),
- MemClustering.PerformanceLevel.NORMAL),
- // new MemClustering.NodeConfig(new BigMemAllocator(1024*1024*20, ".",
- // true), MemClustering.PerformanceLevel.SLOW),
- };
- MemClustering mclst = new MemClustering(ncs);
- MemBufferHolder<?> mbh;
- for (int idx = 1; idx <= 200; ++idx) {
- int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
- mbh = mclst.createBuffer(size);
- for (int i = 0; i < size; i++) {
- mbh.get().put((byte) randomGenerator.nextInt(255));
- }
- assertEquals(size, mbh.get().capacity());
- }
- }
+ /**
+ * test to try to fill up memory pool and reclaim unused memory block as
+ * required.
+ */
+ @Test
+ public void testMemByteBufferWithActiveGC() {
+ Random randomGenerator = new Random();
+ MemClustering.NodeConfig<?> ncs[] = new MemClustering.NodeConfig<?>[] {
+ new MemClustering.NodeConfig<BigDataMemAllocator>(
+ new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 20, ".", true),
+ MemClustering.PerformanceLevel.NORMAL),
+ // new MemClustering.NodeConfig(new BigMemAllocator(1024*1024*20, ".",
+ // true), MemClustering.PerformanceLevel.SLOW),
+ };
+ MemClustering mclst = new MemClustering(ncs);
+ MemBufferHolder<?> mbh;
+ for (int idx = 1; idx <= 200; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mbh = mclst.createBuffer(size);
+ for (int i = 0; i < size; i++) {
+ mbh.get().put((byte) randomGenerator.nextInt(255));
+ }
+ assertEquals(size, mbh.get().capacity());
+ }
+ }
- /**
- * test to manually release memory resource once that is intended to be
- * unused.
- */
- @Test
- public void testMemByteBufferManualRelease() {
- Random randomGenerator = new Random();
- MemClustering.NodeConfig<?> ncs[] = new MemClustering.NodeConfig<?>[] {
- new MemClustering.NodeConfig<BigDataMemAllocator>(new BigDataMemAllocator(
- Utils.getVolatileMemoryAllocatorService("vmem"),
- 1024 * 1024 * 20, ".", true).disableActiveGC(),
- MemClustering.PerformanceLevel.FAST),
- // new MemClustering.NodeConfig(new
- // BigMemAllocator(1024*1024*20, ".", true).disableActiveGC(),
- // MemClustering.PerformanceLevel.NORMAL),
- new MemClustering.NodeConfig<BigDataMemAllocator>(new BigDataMemAllocator(
- Utils.getVolatileMemoryAllocatorService("vmem"),
- 1024 * 1024 * 20, ".", true),
- MemClustering.PerformanceLevel.SLOW), };
- MemClustering mclst = new MemClustering(ncs);
- MemBufferHolder<?> mbh;
- for (int idx = 1; idx <= 200; ++idx) {
- int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
- mbh = mclst.createBuffer(size);
- for (int i = 0; i < size; i++) {
- mbh.get().put((byte) randomGenerator.nextInt(255));
- }
- assertEquals(size, mbh.get().capacity());
- // System.out.println("testMemByteBufferManualRelease");
- mbh.destroy();
- }
- }
+ /**
+ * test to manually release memory resource once that is intended to be
+ * unused.
+ */
+ @Test
+ public void testMemByteBufferManualRelease() {
+ Random randomGenerator = new Random();
+ MemClustering.NodeConfig<?> ncs[] = new MemClustering.NodeConfig<?>[] {
+ new MemClustering.NodeConfig<BigDataMemAllocator>(
+ new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 20, ".", true)
+ .disableActiveGC(),
+ MemClustering.PerformanceLevel.FAST),
+ // new MemClustering.NodeConfig(new
+ // BigMemAllocator(1024*1024*20, ".", true).disableActiveGC(),
+ // MemClustering.PerformanceLevel.NORMAL),
+ new MemClustering.NodeConfig<BigDataMemAllocator>(
+ new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 20, ".", true),
+ MemClustering.PerformanceLevel.SLOW), };
+ MemClustering mclst = new MemClustering(ncs);
+ MemBufferHolder<?> mbh;
+ for (int idx = 1; idx <= 200; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mbh = mclst.createBuffer(size);
+ for (int i = 0; i < size; i++) {
+ mbh.get().put((byte) randomGenerator.nextInt(255));
+ }
+ assertEquals(size, mbh.get().capacity());
+ // System.out.println("testMemByteBufferManualRelease");
+ mbh.destroy();
+ }
+ }
- public boolean actriggered = false, pctriggered = false;
+ public boolean actriggered = false, pctriggered = false;
- /**
- * test change events that will be triggered by memory pool downgrading or
- * memory pool switching caused by fill up.
- *
- * @throws Exception
- */
- @Test
- public void testMemByteBufferWithChange() throws Exception {
- Random randomGenerator = new Random();
- MemClustering.NodeConfig<?> ncs[] = new MemClustering.NodeConfig<?>[] {
- new MemClustering.NodeConfig<SysMemAllocator>(new SysMemAllocator(
- 1024 * 1024 * 20, true).disableActiveGC(),
- MemClustering.PerformanceLevel.FASTEST),
- new MemClustering.NodeConfig<BigDataMemAllocator>(new BigDataMemAllocator(
- Utils.getVolatileMemoryAllocatorService("vmem"),
- 1024 * 1024 * 20, ".", true).disableActiveGC(),
- MemClustering.PerformanceLevel.FAST),
- // new MemClustering.NodeConfig(new
- // BigMemAllocator(1024*1024*20, ".", true).disableActiveGC(),
- // MemClustering.PerformanceLevel.NORMAL),
- new MemClustering.NodeConfig<BigDataMemAllocator>(new BigDataMemAllocator(
- Utils.getVolatileMemoryAllocatorService("vmem"),
- 1024 * 1024 * 20, ".", true),
- MemClustering.PerformanceLevel.SLOW), };
- MemClustering mclst = new MemClustering(ncs){};
+ /**
+ * test change events that will be triggered by memory pool downgrading or
+ * memory pool switching caused by fill up.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testMemByteBufferWithChange() throws Exception {
+ Random randomGenerator = new Random();
+ MemClustering.NodeConfig<?> ncs[] = new MemClustering.NodeConfig<?>[] {
+ new MemClustering.NodeConfig<SysMemAllocator>(new SysMemAllocator(1024 * 1024 * 20, true).disableActiveGC(),
+ MemClustering.PerformanceLevel.FASTEST),
+ new MemClustering.NodeConfig<BigDataMemAllocator>(
+ new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 20, ".", true)
+ .disableActiveGC(),
+ MemClustering.PerformanceLevel.FAST),
+ // new MemClustering.NodeConfig(new
+ // BigMemAllocator(1024*1024*20, ".", true).disableActiveGC(),
+ // MemClustering.PerformanceLevel.NORMAL),
+ new MemClustering.NodeConfig<BigDataMemAllocator>(
+ new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 20, ".", true),
+ MemClustering.PerformanceLevel.SLOW), };
+ MemClustering mclst = new MemClustering(ncs) {
+ };
- actriggered = false;
- pctriggered = false;
- mclst.setAllocatorChange(new MemClustering.AllocatorChange() {
- @Override
- public void changed(MemClustering.PerformanceLevel lvl,
- CommonAllocator<?> prevallocator, CommonAllocator<?> tgtallocator) {
- System.out.println(String.format(
- "Allocator Changed: %s, %X -> %X", lvl.name(),
- System.identityHashCode(prevallocator),
- System.identityHashCode(tgtallocator)));
- actriggered = true;
- }
- });
- mclst.setPerformanceLevelChange(new MemClustering.PerformanceLevelChange() {
- @Override
- public void changed(MemClustering.PerformanceLevel prevlvl,
- MemClustering.PerformanceLevel lvl) {
- System.out.println(String.format(
- "Perf.Level Changed: %s -> %s",
- null == prevlvl ? "NULL" : prevlvl.name(), lvl.name()));
- pctriggered = true;
- }
- });
+ actriggered = false;
+ pctriggered = false;
+ mclst.setAllocatorChange(new MemClustering.AllocatorChange() {
+ @Override
+ public void changed(MemClustering.PerformanceLevel lvl, CommonAllocator<?> prevallocator,
+ CommonAllocator<?> tgtallocator) {
+ System.out.println(String.format("Allocator Changed: %s, %X -> %X", lvl.name(),
+ System.identityHashCode(prevallocator), System.identityHashCode(tgtallocator)));
+ actriggered = true;
+ }
+ });
+ mclst.setPerformanceLevelChange(new MemClustering.PerformanceLevelChange() {
+ @Override
+ public void changed(MemClustering.PerformanceLevel prevlvl, MemClustering.PerformanceLevel lvl) {
+ System.out.println(
+ String.format("Perf.Level Changed: %s -> %s", null == prevlvl ? "NULL" : prevlvl.name(), lvl.name()));
+ pctriggered = true;
+ }
+ });
- MemBufferHolder<?> mbh;
- for (int idx = 1; idx <= 100; ++idx) {
- int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
- mbh = mclst.createBuffer(size);
- for (int i = 0; i < size; i++) {
- mbh.get().put((byte) randomGenerator.nextInt(255));
- }
- //mbh.destroy();
- }
- assertTrue(actriggered && pctriggered);
+ MemBufferHolder<?> mbh;
+ for (int idx = 1; idx <= 100; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mbh = mclst.createBuffer(size);
+ for (int i = 0; i < size; i++) {
+ mbh.get().put((byte) randomGenerator.nextInt(255));
+ }
+ // mbh.destroy();
+ }
+ assertTrue(actriggered && pctriggered);
- }
+ }
- /*
- * @Test public void testMemChunk() { Random randomGenerator = new Random();
- * Allocator act = new BigMemAllocator(1024*1024*1024, "/home/wg/bm", true);
- * MemChunkHolder mch; for (int idx = 1; idx <= 50000; ++idx){ int size =
- * randomGenerator.nextInt(1024*1024) + 1024*1024; mch =
- * act.createChunk(size);
- * System.out.println(String.format("[Seq.%d] addr : %X", idx, size,
- * mch.get())); mch.destroy(); } }
- */
+ /*
+ * @Test public void testMemChunk() { Random randomGenerator = new Random();
+ * Allocator act = new BigMemAllocator(1024*1024*1024, "/home/wg/bm", true);
+ * MemChunkHolder mch; for (int idx = 1; idx <= 50000; ++idx){ int size =
+ * randomGenerator.nextInt(1024*1024) + 1024*1024; mch =
+ * act.createChunk(size); System.out.println(String.format(
+ * "[Seq.%d] addr : %X", idx, size, mch.get())); mch.destroy(); } }
+ */
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/test/java/org/apache/mnemonic/NonVolatilePersonNGTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/mnemonic/NonVolatilePersonNGTest.java b/core/src/test/java/org/apache/mnemonic/NonVolatilePersonNGTest.java
index 2edf6ff..f407402 100644
--- a/core/src/test/java/org/apache/mnemonic/NonVolatilePersonNGTest.java
+++ b/core/src/test/java/org/apache/mnemonic/NonVolatilePersonNGTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -5,7 +22,6 @@ package org.apache.mnemonic;
*
*/
-
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Random;
@@ -19,118 +35,112 @@ public class NonVolatilePersonNGTest {
@Test(expectedExceptions = { OutOfPersistentMemory.class })
public void testGenPeople() throws OutOfPersistentMemory, RetrieveNonVolatileEntityError {
- Random rand = Utils.createRandom();
- BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 8, "./pobj_person.dat", true);
- KEYCAPACITY = act.handlerCapacity();
- act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
- @Override
- public boolean reclaim(ByteBuffer mres, Long sz) {
- System.out.println(String.format(
- "Reclaim Memory Buffer: %X Size: %s", System
- .identityHashCode(mres),
- null == sz ? "NULL" : sz.toString()));
- return false;
- }
- });
- act.setChunkReclaimer(new Reclaim<Long>() {
- @Override
- public boolean reclaim(Long mres, Long sz) {
- System.out.println(String.format(
- "Reclaim Memory Chunk: %X Size: %s", System
- .identityHashCode(mres),
- null == sz ? "NULL" : sz.toString()));
- return false;
- }
- });
-
- for (long i = 0; i < KEYCAPACITY; ++i) {
- act.setHandler(i, 0L);
- }
-
- Person<Integer> mother;
- Person<Integer> person;
-
- long keyidx = 0;
- long val;
-
- try {
- while(true) {
- //if (keyidx >= KEYCAPACITY) break;
-
- keyidx %= KEYCAPACITY;
-
- System.out.printf("************ Generating People on Key %d ***********\n", keyidx);
-
- val = act.getHandler(keyidx);
- if (0L != val) {
- PersonFactory.restore(act, val, true);
- }
-
- person = PersonFactory.create(act);
- person.setAge((short)rand.nextInt(50));
- person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
- person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
- person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
- person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
-
- act.setHandler(keyidx, person.getNonVolatileHandler());
-
- for (int deep = 0; deep < rand.nextInt(100); ++deep) {
-
- mother = PersonFactory.create(act);
- mother.setAge((short)(50 + rand.nextInt(50)));
- mother.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
-
- person.setMother(mother, true);
-
- person = mother;
-
- }
- ++keyidx;
- }
- }finally {
- act.close();
- }
+ Random rand = Utils.createRandom();
+ BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
+ 1024 * 1024 * 8, "./pobj_person.dat", true);
+ KEYCAPACITY = act.handlerCapacity();
+ act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
+ @Override
+ public boolean reclaim(ByteBuffer mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Buffer: %X Size: %s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+ act.setChunkReclaimer(new Reclaim<Long>() {
+ @Override
+ public boolean reclaim(Long mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Chunk: %X Size: %s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+
+ for (long i = 0; i < KEYCAPACITY; ++i) {
+ act.setHandler(i, 0L);
+ }
+
+ Person<Integer> mother;
+ Person<Integer> person;
+
+ long keyidx = 0;
+ long val;
+
+ try {
+ while (true) {
+ // if (keyidx >= KEYCAPACITY) break;
+
+ keyidx %= KEYCAPACITY;
+
+ System.out.printf("************ Generating People on Key %d ***********\n", keyidx);
+
+ val = act.getHandler(keyidx);
+ if (0L != val) {
+ PersonFactory.restore(act, val, true);
+ }
+
+ person = PersonFactory.create(act);
+ person.setAge((short) rand.nextInt(50));
+ person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
+ person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
+ person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
+ person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
+
+ act.setHandler(keyidx, person.getNonVolatileHandler());
+
+ for (int deep = 0; deep < rand.nextInt(100); ++deep) {
+
+ mother = PersonFactory.create(act);
+ mother.setAge((short) (50 + rand.nextInt(50)));
+ mother.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
+
+ person.setMother(mother, true);
+
+ person = mother;
+
+ }
+ ++keyidx;
+ }
+ } finally {
+ act.close();
+ }
}
- @Test(dependsOnMethods = {"testGenPeople"})
+ @Test(dependsOnMethods = { "testGenPeople" })
public void testCheckPeople() throws RetrieveNonVolatileEntityError {
- BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 8, "./pobj_person.dat", true);
- act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
- @Override
- public boolean reclaim(ByteBuffer mres, Long sz) {
- System.out.println(String.format(
- "Reclaim Memory Buffer: %X Size: %s", System
- .identityHashCode(mres),
- null == sz ? "NULL" : sz.toString()));
- return false;
- }
- });
- act.setChunkReclaimer(new Reclaim<Long>() {
- @Override
- public boolean reclaim(Long mres, Long sz) {
- System.out.println(String.format(
- "Reclaim Memory Chunk: %X Size: %s", System
- .identityHashCode(mres),
- null == sz ? "NULL" : sz.toString()));
- return false;
- }
- });
-
- long val;
- for (long i = 0; i < KEYCAPACITY; ++i) {
- System.out.printf("----------Key %d--------------\n", i);
- val = act.getHandler(i);
- if (0L == val) {
- break;
- }
- Person<Integer> person = PersonFactory.restore(act, val, true);
- while (null != person) {
- person.testOutput();
- person = person.getMother();
- }
- }
-
- act.close();
- }
+ BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
+ 1024 * 1024 * 8, "./pobj_person.dat", true);
+ act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
+ @Override
+ public boolean reclaim(ByteBuffer mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Buffer: %X Size: %s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+ act.setChunkReclaimer(new Reclaim<Long>() {
+ @Override
+ public boolean reclaim(Long mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Chunk: %X Size: %s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+
+ long val;
+ for (long i = 0; i < KEYCAPACITY; ++i) {
+ System.out.printf("----------Key %d--------------\n", i);
+ val = act.getHandler(i);
+ if (0L == val) {
+ break;
+ }
+ Person<Integer> person = PersonFactory.restore(act, val, true);
+ while (null != person) {
+ person.testOutput();
+ person = person.getMother();
+ }
+ }
+
+ act.close();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/test/java/org/apache/mnemonic/Payload.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/mnemonic/Payload.java b/core/src/test/java/org/apache/mnemonic/Payload.java
index 9f9468a..6a23707 100644
--- a/core/src/test/java/org/apache/mnemonic/Payload.java
+++ b/core/src/test/java/org/apache/mnemonic/Payload.java
@@ -1,3 +1,19 @@
+/*
+ * 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.mnemonic;
@@ -8,22 +24,21 @@ package org.apache.mnemonic;
*
*/
public class Payload implements java.io.Serializable, Comparable<Payload> {
-
- private static final long serialVersionUID = 187397440699436500L;
- public Payload(int iv, String strv, double dv) {
- ival = iv;
- strval = strv;
- dval = dv;
- }
+ private static final long serialVersionUID = 187397440699436500L;
+
+ public Payload(int iv, String strv, double dv) {
+ ival = iv;
+ strval = strv;
+ dval = dv;
+ }
- public int ival;
- public String strval;
- public double dval;
+ public int ival;
+ public String strval;
+ public double dval;
- @Override
- public int compareTo(Payload pl) {
- return ival == pl.ival && strval.equals(pl.strval) && dval == pl.dval ? 0
- : 1;
- }
+ @Override
+ public int compareTo(Payload pl) {
+ return ival == pl.ival && strval.equals(pl.strval) && dval == pl.dval ? 0 : 1;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/test/java/org/apache/mnemonic/Person.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/mnemonic/Person.java b/core/src/test/java/org/apache/mnemonic/Person.java
index f43001f..5e8775e 100644
--- a/core/src/test/java/org/apache/mnemonic/Person.java
+++ b/core/src/test/java/org/apache/mnemonic/Person.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import java.util.List;
@@ -9,53 +26,59 @@ import java.util.List;
@NonVolatileEntity
public abstract class Person<E> implements Durable, Comparable<Person<E>> {
- E element;
-
- @Override
- public void initializeAfterCreate() {
- System.out.println("Initializing After Created");
- }
-
- @Override
- public void initializeAfterRestore() {
- System.out.println("Initializing After Restored");
- }
-
- @Override
- public void setupGenericInfo(EntityFactoryProxy[] efproxies, GenericField.GType[] gftypes) {
-
- }
-
- public void testOutput() throws RetrieveNonVolatileEntityError {
- System.out.printf("Person %s, Age: %d ( %s ) \n", getName(), getAge(),
- null == getMother()? "No Recorded Mother" : "Has Recorded Mother");
- }
-
- public int compareTo(Person<E> anotherPerson) {
- int ret = 0;
- if (0 == ret) ret = getAge().compareTo(anotherPerson.getAge());
- if (0 == ret) ret = getName().compareTo(anotherPerson.getName());
- return ret;
- }
-
- @NonVolatileGetter
- abstract public Short getAge();
- @NonVolatileSetter
- abstract public void setAge(Short age);
-
- @NonVolatileGetter
- abstract public String getName() throws RetrieveNonVolatileEntityError;
- @NonVolatileSetter
- abstract public void setName(String name, boolean destroy) throws OutOfPersistentMemory, RetrieveNonVolatileEntityError;
-
- @NonVolatileGetter
- abstract public Person<E> getMother() throws RetrieveNonVolatileEntityError;
- @NonVolatileSetter
- abstract public void setMother(Person<E> mother, boolean destroy) throws RetrieveNonVolatileEntityError;
-
- @NonVolatileGetter
- abstract public Person<E> getFather() throws RetrieveNonVolatileEntityError;
- @NonVolatileSetter
- abstract public void setFather(Person<E> mother, boolean destroy) throws RetrieveNonVolatileEntityError;
-}
+ E element;
+
+ @Override
+ public void initializeAfterCreate() {
+ System.out.println("Initializing After Created");
+ }
+
+ @Override
+ public void initializeAfterRestore() {
+ System.out.println("Initializing After Restored");
+ }
+
+ @Override
+ public void setupGenericInfo(EntityFactoryProxy[] efproxies, GenericField.GType[] gftypes) {
+
+ }
+
+ public void testOutput() throws RetrieveNonVolatileEntityError {
+ System.out.printf("Person %s, Age: %d ( %s ) \n", getName(), getAge(),
+ null == getMother() ? "No Recorded Mother" : "Has Recorded Mother");
+ }
+ public int compareTo(Person<E> anotherPerson) {
+ int ret = 0;
+ if (0 == ret)
+ ret = getAge().compareTo(anotherPerson.getAge());
+ if (0 == ret)
+ ret = getName().compareTo(anotherPerson.getName());
+ return ret;
+ }
+
+ @NonVolatileGetter
+ abstract public Short getAge();
+
+ @NonVolatileSetter
+ abstract public void setAge(Short age);
+
+ @NonVolatileGetter
+ abstract public String getName() throws RetrieveNonVolatileEntityError;
+
+ @NonVolatileSetter
+ abstract public void setName(String name, boolean destroy)
+ throws OutOfPersistentMemory, RetrieveNonVolatileEntityError;
+
+ @NonVolatileGetter
+ abstract public Person<E> getMother() throws RetrieveNonVolatileEntityError;
+
+ @NonVolatileSetter
+ abstract public void setMother(Person<E> mother, boolean destroy) throws RetrieveNonVolatileEntityError;
+
+ @NonVolatileGetter
+ abstract public Person<E> getFather() throws RetrieveNonVolatileEntityError;
+
+ @NonVolatileSetter
+ abstract public void setFather(Person<E> mother, boolean destroy) throws RetrieveNonVolatileEntityError;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/examples/src/main/java/org/apache/mnemonic/example/Main.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/mnemonic/example/Main.java b/examples/src/main/java/org/apache/mnemonic/example/Main.java
index 39dba17..4546f0b 100644
--- a/examples/src/main/java/org/apache/mnemonic/example/Main.java
+++ b/examples/src/main/java/org/apache/mnemonic/example/Main.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic.example;
import java.nio.ByteBuffer;
@@ -14,178 +31,163 @@ import sun.misc.Unsafe;
@SuppressWarnings("restriction")
public class Main {
- /**
- * Run a example code to demonstrate some basic functionalities.
- *
- * @param argv
- * array of commandline parameters
- */
- public static void main(String[] argv) throws Exception {
- Random randomGenerator = new Random();
+ /**
+ * Run a example code to demonstrate some basic functionalities.
+ *
+ * @param argv
+ * array of commandline parameters
+ */
+ public static void main(String[] argv) throws Exception {
+ Random randomGenerator = new Random();
- /* Generate configuration for each node */
- /*
- * Currently only one node is supported due to the external native code 'vmem'
- * returns null for multiple 'vmem' allocator instantialization
- */
- MemClustering.NodeConfig ncs[] = new MemClustering.NodeConfig[] {
- new MemClustering.NodeConfig(new SysMemAllocator(
- 1024 * 1024 * 20, true).disableActiveGC(),
- MemClustering.PerformanceLevel.FASTEST),
+ /* Generate configuration for each node */
+ /*
+ * Currently only one node is supported due to the external native code
+ * 'vmem' returns null for multiple 'vmem' allocator instantialization
+ */
+ MemClustering.NodeConfig ncs[] = new MemClustering.NodeConfig[] {
+ new MemClustering.NodeConfig(new SysMemAllocator(1024 * 1024 * 20, true).disableActiveGC(),
+ MemClustering.PerformanceLevel.FASTEST),
- // new MemClustering.NodeConfig(new
- // BigDataMemAllocator(1024*1024*20, ".",
- // true).disableActiveGC(),
- // MemClustering.PerformanceLevel.FAST),
- // new MemClustering.NodeConfig(new
- // BigDataMemAllocator(1024*1024*20, ".",
- // true).disableActiveGC(),
- // MemClustering.PerformanceLevel.NORMAL),
- new MemClustering.NodeConfig(new BigDataMemAllocator(
- Utils.getVolatileMemoryAllocatorService("vmem"),
- 1024 * 1024 * 20, ".", true),
- //Utils.getVolatileMemoryAllocatorService("pmalloc"),
- //1024 * 1024 * 20, "./example.dat", true),
- MemClustering.PerformanceLevel.SLOW),
- };
+ // new MemClustering.NodeConfig(new
+ // BigDataMemAllocator(1024*1024*20, ".",
+ // true).disableActiveGC(),
+ // MemClustering.PerformanceLevel.FAST),
+ // new MemClustering.NodeConfig(new
+ // BigDataMemAllocator(1024*1024*20, ".",
+ // true).disableActiveGC(),
+ // MemClustering.PerformanceLevel.NORMAL),
+ new MemClustering.NodeConfig(
+ new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 20, ".", true),
+ // Utils.getVolatileMemoryAllocatorService("pmalloc"),
+ // 1024 * 1024 * 20, "./example.dat", true),
+ MemClustering.PerformanceLevel.SLOW), };
- for (MemClustering.NodeConfig nc : ncs) {
- /**
- * set a reclaimer for memory buffers
- */
- nc.getAllocator().setBufferReclaimer(new Reclaim<ByteBuffer>() {
- @Override
- public boolean reclaim(ByteBuffer mres, Long sz) {
- System.out.println(String.format(
- "Reclaim Memory Buffer: %X Size: %s", System
- .identityHashCode(mres),
- null == sz ? "NULL" : sz.toString()));
- return false;
- }
- });
- /**
- * set a reclaimer for memory chunks
- */
- nc.getAllocator().setChunkReclaimer(new Reclaim<Long>() {
- @Override
- public boolean reclaim(Long mres, Long sz) {
- System.out.println(String.format(
- "Reclaim Memory Chunk: %X Size: %s", mres,
- null == sz ? "NULL" : sz.toString()));
- return false;
- }
- });
+ for (MemClustering.NodeConfig nc : ncs) {
+ /**
+ * set a reclaimer for memory buffers
+ */
+ nc.getAllocator().setBufferReclaimer(new Reclaim<ByteBuffer>() {
+ @Override
+ public boolean reclaim(ByteBuffer mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Buffer: %X Size: %s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
}
+ });
+ /**
+ * set a reclaimer for memory chunks
+ */
+ nc.getAllocator().setChunkReclaimer(new Reclaim<Long>() {
+ @Override
+ public boolean reclaim(Long mres, Long sz) {
+ System.out
+ .println(String.format("Reclaim Memory Chunk: %X Size: %s", mres, null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+ }
+
+ /* Deploy Memory Clustering */
+ MemClustering mclst = new MemClustering(ncs);
- /* Deploy Memory Clustering */
- MemClustering mclst = new MemClustering(ncs);
+ /**
+ * Set event callback for allocator changing. this callback is used to trace
+ * the event of spilling out of allocation when previous allocator is unable
+ * to meet the allocation requirement so trying to switch to next allocator.
+ */
+ mclst.setAllocatorChange(new MemClustering.AllocatorChange() {
+ @Override
+ public void changed(MemClustering.PerformanceLevel lvl, CommonAllocator prevallocator,
+ CommonAllocator tgtallocator) {
+ System.out.println(String.format("AllocatorChanged: %s, %X -> %X", lvl.name(),
+ System.identityHashCode(prevallocator), System.identityHashCode(tgtallocator)));
+ }
+ });
+ /**
+ * Set event callback for performance level changing. this callback is used
+ * to trace the event of downgrading to low level performance allocation.
+ */
+ mclst.setPerformanceLevelChange(new MemClustering.PerformanceLevelChange() {
+ @Override
+ public void changed(MemClustering.PerformanceLevel prevlvl, MemClustering.PerformanceLevel lvl) {
+ System.out.println(
+ String.format("PerfLevelChanged: %s -> %s", null == prevlvl ? "NULL" : prevlvl.name(), lvl.name()));
+ }
+ });
+
+ /**
+ * Start to create a piece of memory resource backed ByteBuffer and then
+ * automatically release it or manually release it every six objects.
+ */
+ System.out.println(Utils.ANSI_GREEN + "[[Demo Allocation, Auto Destruction "
+ + "and Manual Destruction of Big Memory ByteBuffer.]]" + Utils.ANSI_RESET);
+ MemBufferHolder<?> mbh;
+ for (int idx = 1; idx <= 50; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mbh = mclst.createBuffer(size);
+ if (null == mbh) {
+ throw new OutOfMemoryError("Memory Cluster out of memory!");
+ }
+ for (int i = 0; i < size; i++) {
/**
- * Set event callback for allocator changing. this callback is used to
- * trace the event of spilling out of allocation when previous allocator
- * is unable to meet the allocation requirement so trying to switch to
- * next allocator.
+ * Manipulate the ByteBuffer backed by external memory resource. Note:
+ * Do not assigned internal ByteBuffer object to any variable, only use
+ * function get() to access it all time.
*/
- mclst.setAllocatorChange(new MemClustering.AllocatorChange() {
- @Override
- public void changed(MemClustering.PerformanceLevel lvl,
- CommonAllocator prevallocator, CommonAllocator tgtallocator) {
- System.out.println(String.format(
- "AllocatorChanged: %s, %X -> %X", lvl.name(),
- System.identityHashCode(prevallocator),
- System.identityHashCode(tgtallocator)));
- }
- });
-
+ mbh.get().put((byte) randomGenerator.nextInt(255));
+ }
+ System.out.println(String.format("[Seq.%d] size %d - %d, (%s)", idx, size, mbh.get().capacity(),
+ size == mbh.get().capacity() ? "Correct" : "Failed!!!"));
+ if (idx % 6 == 0) {
/**
- * Set event callback for performance level changing. this callback is
- * used to trace the event of downgrading to low level performance allocation.
+ * Force to release memory resource of specified ByteBuffer object
+ * immediately.
*/
- mclst.setPerformanceLevelChange(new MemClustering.PerformanceLevelChange() {
- @Override
- public void changed(MemClustering.PerformanceLevel prevlvl,
- MemClustering.PerformanceLevel lvl) {
- System.out.println(String.format("PerfLevelChanged: %s -> %s",
- null == prevlvl ? "NULL" : prevlvl.name(), lvl.name()));
- }
- });
+ System.out.println(String.format("Manually destroy Buffer at %X.", System.identityHashCode(mbh.get())));
+ mbh.destroy();
+ }
+ System.out.println("-------------------");
+ }
+ // Utils.collectGarbage();
+ /**
+ * Start to create a piece of memory resource backed chunk and then
+ * automatically release it or manually release it every six chunks.
+ */
+ System.out.println(Utils.ANSI_GREEN + "[[Demo Allocation, Auto Destruction "
+ + "and Manual Destruction of Big Memory Chunk.]]" + Utils.ANSI_RESET);
+ Unsafe unsafe = Utils.getUnsafe();
+ MemChunkHolder<?> mch;
+ for (int idx = 1; idx <= 50; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mch = mclst.createChunk(size);
+ if (null == mch) {
+ throw new OutOfMemoryError("Memory Cluster out of memory!");
+ }
+ // mch.cancelAutoReclaim();
+ mch.resize(size - 10);
+ System.out.printf("chunk size is %d \n", mch.getSize());
+ for (int i = 0; i < mch.getSize(); i++) {
/**
- * Start to create a piece of memory resource backed ByteBuffer and then automatically
- * release it or manually release it every six objects.
+ * Manipulate the chunk data. Note: Do not assigned the internal memory
+ * space to any variable, please always use function get() to access it
+ * at all time.
*/
- System.out.println(Utils.ANSI_GREEN + "[[Demo Allocation, Auto Destruction "
- + "and Manual Destruction of Big Memory ByteBuffer.]]" + Utils.ANSI_RESET);
- MemBufferHolder<?> mbh;
- for (int idx = 1; idx <= 50; ++idx) {
- int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
- mbh = mclst.createBuffer(size);
- if (null == mbh) {
- throw new OutOfMemoryError("Memory Cluster out of memory!");
- }
- for (int i = 0; i < size; i++) {
- /**
- * Manipulate the ByteBuffer backed by external memory resource.
- * Note: Do not assigned internal ByteBuffer object to any
- * variable, only use function get() to access it all time.
- */
- mbh.get().put((byte) randomGenerator.nextInt(255));
- }
- System.out.println(String.format("[Seq.%d] size %d - %d, (%s)",
- idx, size, mbh.get().capacity(), size == mbh.get()
- .capacity() ? "Correct" : "Failed!!!"));
- if (idx % 6 == 0) {
- /**
- * Force to release memory resource of specified ByteBuffer
- * object immediately.
- */
- System.out.println(String.format("Manually destroy Buffer at %X.",
- System.identityHashCode(mbh.get())));
- mbh.destroy();
- }
- System.out.println("-------------------");
- }
- //Utils.collectGarbage();
-
+ unsafe.putByte(mch.get() + i, (byte) randomGenerator.nextInt(255));
+ }
+ System.out.println(String.format("[Seq.%d] size %d - %d at %X.", idx, size, mch.getSize(), mch.get()));
+ if (idx % 6 == 0) {
/**
- * Start to create a piece of memory resource backed chunk and then automatically
- * release it or manually release it every six chunks.
+ * Force to release memory resource of specified Chunk object
+ * Immediately.
*/
- System.out.println(Utils.ANSI_GREEN + "[[Demo Allocation, Auto Destruction "
- + "and Manual Destruction of Big Memory Chunk.]]" + Utils.ANSI_RESET);
- Unsafe unsafe = Utils.getUnsafe();
- MemChunkHolder<?> mch;
- for (int idx = 1; idx <= 50; ++idx) {
- int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
- mch = mclst.createChunk(size);
- if (null == mch) {
- throw new OutOfMemoryError("Memory Cluster out of memory!");
- }
- //mch.cancelAutoReclaim();
- mch.resize(size - 10);
- System.out.printf("chunk size is %d \n", mch.getSize());
- for (int i = 0; i < mch.getSize(); i++) {
- /**
- * Manipulate the chunk data. Note: Do not
- * assigned the internal memory space to any variable, please always
- * use function get() to access it at all time.
- */
- unsafe.putByte(mch.get() + i,
- (byte) randomGenerator.nextInt(255));
- }
- System.out.println(String.format("[Seq.%d] size %d - %d at %X.",
- idx, size, mch.getSize(), mch.get()));
- if (idx % 6 == 0) {
- /**
- * Force to release memory resource of specified Chunk object
- * Immediately.
- */
- System.out.println(String.format("Manually destroy Chunk at %X.",
- mch.get()));
- mch.destroy();
- }
- System.out.println("-------------------");
- }
+ System.out.println(String.format("Manually destroy Chunk at %X.", mch.get()));
+ mch.destroy();
+ }
+ System.out.println("-------------------");
}
+ }
}
[5/7] incubator-mnemonic git commit: format codestyle & add Apache
License
Posted by ga...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/AnnotatedNonVolatileEntityClass.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/AnnotatedNonVolatileEntityClass.java b/core/src/main/java/org/apache/mnemonic/AnnotatedNonVolatileEntityClass.java
index 68a7a3d..1854bea 100644
--- a/core/src/main/java/org/apache/mnemonic/AnnotatedNonVolatileEntityClass.java
+++ b/core/src/main/java/org/apache/mnemonic/AnnotatedNonVolatileEntityClass.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import java.io.IOException;
@@ -30,948 +47,916 @@ import com.squareup.javapoet.*;
import com.squareup.javapoet.MethodSpec.Builder;
/**
- * this class managed to generate generic non-volatile concrete object and their corresponding factory.
+ * this class managed to generate generic non-volatile concrete object and their
+ * corresponding factory.
*
*/
public class AnnotatedNonVolatileEntityClass {
- protected class MethodInfo {
- public ExecutableElement elem;
- public MethodSpec.Builder specbuilder;
- public TypeName rettype;
- }
- protected class FieldInfo {
- public FieldSpec.Builder specbuilder;
- public TypeName type;
+ protected class MethodInfo {
+ public ExecutableElement elem;
+ public MethodSpec.Builder specbuilder;
+ public TypeName rettype;
+ }
+
+ protected class FieldInfo {
+ public FieldSpec.Builder specbuilder;
+ public TypeName type;
public long id;
- public String name;
- public String efproxiesname;
- public String gftypesname;
- public long fieldoff;
- public long fieldsize;
+ public String name;
+ public String efproxiesname;
+ public String gftypesname;
+ public long fieldoff;
+ public long fieldsize;
+ }
+
+ protected final String FACTORYNAMESUFFIX = "Factory";
+ protected final String PMEMNAMEPREFIX = "NonVolatile_";
+ protected final String FIELDNAMESUFFIX = String.format("_field_%s", Utils.genRandomString());
+ protected final String ALLOCATORFIELDNAME = String.format("alloc_%s", Utils.genRandomString());
+ protected final String AUTORECLAIMFIELDNAME = String.format("autoreclaim_%s", Utils.genRandomString());
+ protected final String UNSAFEFIELDNAME = String.format("unsafe_%s", Utils.genRandomString());
+ protected final String HOLDERFIELDNAME = String.format("holder_%s", Utils.genRandomString());
+ protected final String ALLOCTYPENAME = String.format("ALLOC_PMem3C93D24F59");
+
+ private Types m_typeutils;
+ private Elements m_elemutils;
+ private Messager m_msgr;
+ private TypeElement m_elem;
+
+ private String m_factoryname;
+ private String m_entityname;
+
+ private long m_holdersize;
+
+ private String m_packagename;
+
+ private TypeName m_alloctypename = TypeVariableName.get(ALLOCTYPENAME);
+ private TypeName m_factoryproxystypename = TypeName.get(EntityFactoryProxy[].class);
+ private TypeName m_gfieldstypename = TypeName.get(GenericField.GType[].class);
+ private TypeVariableName m_alloctypevarname = TypeVariableName.get(ALLOCTYPENAME,
+ ParameterizedTypeName.get(ClassName.get(CommonPersistAllocator.class), TypeVariableName.get(ALLOCTYPENAME)));
+
+ private Map<String, MethodInfo> m_gettersinfo = new HashMap<String, MethodInfo>();
+ private Map<String, MethodInfo> m_settersinfo = new HashMap<String, MethodInfo>();
+ private Map<String, FieldInfo> m_dynfieldsinfo = new HashMap<String, FieldInfo>();
+ private Map<String, FieldInfo> m_fieldsinfo = new HashMap<String, FieldInfo>();
+
+ private Map<String, MethodInfo> m_durablemtdinfo = new HashMap<String, MethodInfo>();
+ private Map<String, MethodInfo> m_entitymtdinfo = new HashMap<String, MethodInfo>();
+
+ private long computeTypeSize(TypeMirror type) {
+ long ret;
+ switch (type.getKind()) {
+ case BYTE:
+ ret = 1L;
+ break;
+ case BOOLEAN:
+ ret = 1L;
+ break;
+ case CHAR:
+ ret = 2L;
+ break;
+ case DOUBLE:
+ ret = 8L;
+ break;
+ case FLOAT:
+ ret = 4L;
+ break;
+ case SHORT:
+ ret = 2L;
+ break;
+ case INT:
+ ret = 4L;
+ break;
+ case LONG:
+ ret = 8L;
+ break;
+ default:
+ ret = 8L;
}
-
- protected final String FACTORYNAMESUFFIX = "Factory";
- protected final String PMEMNAMEPREFIX = "NonVolatile_";
- protected final String FIELDNAMESUFFIX = String.format("_field_%s", Utils.genRandomString());
- protected final String ALLOCATORFIELDNAME = String.format("alloc_%s", Utils.genRandomString());
- protected final String AUTORECLAIMFIELDNAME = String.format("autoreclaim_%s", Utils.genRandomString());
- protected final String UNSAFEFIELDNAME = String.format("unsafe_%s", Utils.genRandomString());
- protected final String HOLDERFIELDNAME = String.format("holder_%s", Utils.genRandomString());
- protected final String ALLOCTYPENAME = String.format("ALLOC_PMem3C93D24F59");
-
- private Types m_typeutils;
- private Elements m_elemutils;
- private Messager m_msgr;
- private TypeElement m_elem;
-
- private String m_factoryname;
- private String m_entityname;
-
- private long m_holdersize;
-
- private String m_packagename;
-
- private TypeName m_alloctypename = TypeVariableName.get(ALLOCTYPENAME);
- private TypeName m_factoryproxystypename = TypeName.get(EntityFactoryProxy[].class);
- private TypeName m_gfieldstypename = TypeName.get(GenericField.GType[].class);
- private TypeVariableName m_alloctypevarname = TypeVariableName.get(ALLOCTYPENAME,
- ParameterizedTypeName.get(ClassName.get(CommonPersistAllocator.class), TypeVariableName.get(ALLOCTYPENAME)));
-
- private Map<String, MethodInfo> m_gettersinfo = new HashMap<String, MethodInfo>();
- private Map<String, MethodInfo> m_settersinfo = new HashMap<String, MethodInfo>();
- private Map<String, FieldInfo> m_dynfieldsinfo = new HashMap<String, FieldInfo>();
- private Map<String, FieldInfo> m_fieldsinfo = new HashMap<String, FieldInfo>();
-
- private Map<String, MethodInfo> m_durablemtdinfo = new HashMap<String, MethodInfo>();
- private Map<String, MethodInfo> m_entitymtdinfo = new HashMap<String, MethodInfo>();
-
- private long computeTypeSize(TypeMirror type) {
- long ret;
- switch (type.getKind()) {
- case BYTE:
- ret = 1L;
- break;
- case BOOLEAN:
- ret = 1L;
- break;
- case CHAR:
- ret = 2L;
- break;
- case DOUBLE:
- ret = 8L;
- break;
- case FLOAT:
- ret = 4L;
- break;
- case SHORT:
- ret = 2L;
- break;
- case INT:
- ret = 4L;
- break;
- case LONG:
- ret = 8L;
- break;
- default:
- ret = 8L;
- }
- return ret;
+ return ret;
+ }
+
+ private boolean isUnboxPrimitive(TypeName tn) {
+ TypeName n = tn;
+ try {
+ n = tn.unbox();
+ } catch (UnsupportedOperationException ex) {
+ }
+ return n.isPrimitive();
+ }
+
+ private TypeName unboxTypeName(TypeName tn) {
+ TypeName n = tn;
+ try {
+ n = tn.unbox();
+ } catch (UnsupportedOperationException ex) {
+ }
+ return n;
+ }
+
+ public AnnotatedNonVolatileEntityClass(TypeElement classElement, Types typeUtils, Elements elementUtils,
+ Messager messager) {
+ m_elem = classElement;
+ m_typeutils = typeUtils;
+ m_elemutils = elementUtils;
+ m_msgr = messager;
+
+ m_packagename = m_elemutils.getPackageOf(m_elem).getQualifiedName().toString();
+
+ m_factoryname = String.format("%s%s", m_elem.getSimpleName(), FACTORYNAMESUFFIX);
+ m_entityname = String.format("%s%s_%s", PMEMNAMEPREFIX, m_elem.getSimpleName(), Utils.genRandomString());
+
+ m_durablemtdinfo.put("cancelAutoReclaim", new MethodInfo());
+ m_durablemtdinfo.put("registerAutoReclaim", new MethodInfo());
+ m_durablemtdinfo.put("getNonVolatileHandler", new MethodInfo());
+ m_durablemtdinfo.put("autoReclaim", new MethodInfo());
+ m_durablemtdinfo.put("destroy", new MethodInfo());
+ m_durablemtdinfo.put("getNativeFieldInfo", new MethodInfo());
+
+ m_entitymtdinfo.put("initializeNonVolatileEntity", new MethodInfo());
+ m_entitymtdinfo.put("createNonVolatileEntity", new MethodInfo());
+ m_entitymtdinfo.put("restoreNonVolatileEntity", new MethodInfo());
+
+ }
+
+ public void prepareProcessing() throws AnnotationProcessingException {
+ MethodInfo methodinfo = null;
+ FieldInfo fieldinfo;
+ String methodname;
+ long fieldoff = 0;
+ TypeElement intf_durable = m_elemutils.getTypeElement(Durable.class.getCanonicalName());
+ TypeElement intf_entity = m_elemutils.getTypeElement(MemoryNonVolatileEntity.class.getCanonicalName());
+ // System.err.printf("<><><><><> %s ======\n", intf_entity.toString());
+
+ boolean valid = false;
+ for (TypeMirror tm : m_elem.getInterfaces()) {
+ if (tm.toString().equals(Durable.class.getCanonicalName())) {
+ valid = true;
+ break;
+ }
+ }
+ if (!valid) {
+ throw new AnnotationProcessingException(m_elem, "Not implemented Durable Interface by %s.",
+ m_elem.getSimpleName().toString());
}
- private boolean isUnboxPrimitive(TypeName tn) {
- TypeName n = tn;
- try {
- n = tn.unbox();
- } catch(UnsupportedOperationException ex) {}
- return n.isPrimitive();
+ fieldinfo = new FieldInfo();
+ fieldinfo.name = String.format("m_unsafe_%s", Utils.genRandomString());
+ fieldinfo.type = TypeName.get(m_elemutils.getTypeElement(Unsafe.class.getCanonicalName()).asType());
+ fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type, fieldinfo.name, Modifier.PRIVATE);
+ m_fieldsinfo.put("unsafe", fieldinfo);
+
+ fieldinfo = new FieldInfo();
+ fieldinfo.name = String.format("m_holder_%s", Utils.genRandomString());
+ fieldinfo.type = ParameterizedTypeName.get(ClassName.get(MemChunkHolder.class), m_alloctypename);
+ fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type, fieldinfo.name, Modifier.PRIVATE);
+ m_fieldsinfo.put("holder", fieldinfo);
+
+ fieldinfo = new FieldInfo();
+ fieldinfo.name = String.format("m_autoreclaim_%s", Utils.genRandomString());
+ fieldinfo.type = TypeName.get(m_typeutils.getPrimitiveType(TypeKind.BOOLEAN));
+ fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type, fieldinfo.name, Modifier.PRIVATE, Modifier.VOLATILE);
+ m_fieldsinfo.put("autoreclaim", fieldinfo);
+
+ fieldinfo = new FieldInfo();
+ fieldinfo.name = String.format("m_allocator_%s", Utils.genRandomString());
+ fieldinfo.type = m_alloctypename;
+ fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type, fieldinfo.name, Modifier.PRIVATE);
+ m_fieldsinfo.put("allocator", fieldinfo);
+
+ fieldinfo = new FieldInfo();
+ fieldinfo.name = String.format("m_factoryproxy_%s", Utils.genRandomString());
+ fieldinfo.type = m_factoryproxystypename;
+ fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type, fieldinfo.name, Modifier.PRIVATE);
+ m_fieldsinfo.put("factoryproxy", fieldinfo);
+
+ fieldinfo = new FieldInfo();
+ fieldinfo.name = String.format("m_genericfield_%s", Utils.genRandomString());
+ fieldinfo.type = m_gfieldstypename;
+ fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type, fieldinfo.name, Modifier.PRIVATE);
+ m_fieldsinfo.put("genericfield", fieldinfo);
+
+ for (Element elem : m_elem.getEnclosedElements()) {
+ if (elem.getKind() == ElementKind.METHOD) {
+ methodname = elem.getSimpleName().toString();
+ // System.err.printf("=========== %s ======\n", methodname);
+ NonVolatileGetter pgetter = elem.getAnnotation(NonVolatileGetter.class);
+ if (pgetter != null) {
+ if (!elem.getModifiers().contains(Modifier.ABSTRACT)) {
+ throw new AnnotationProcessingException(elem, "%s annotated with NonVolatileGetter is not abstract.",
+ methodname);
+ }
+ if (null != elem.getAnnotation(NonVolatileSetter.class)) {
+ throw new AnnotationProcessingException(elem, "%s is annotated with NonVolatileSetter as well.",
+ methodname);
+ }
+ if (!methodname.startsWith("get")) {
+ throw new AnnotationProcessingException(elem, "%s does not comply name convention of getter.", methodname);
+ }
+ methodinfo = new MethodInfo();
+ methodinfo.elem = (ExecutableElement) elem;
+ methodinfo.specbuilder = MethodSpec.overriding(methodinfo.elem);
+ methodinfo.rettype = TypeName.get(methodinfo.elem.getReturnType());
+ m_gettersinfo.put(methodname.substring(3), methodinfo);
+ fieldinfo = new FieldInfo();
+ fieldinfo.type = methodinfo.rettype;
+ if (fieldinfo.type.toString().equals(String.class.getCanonicalName())) {
+ fieldinfo.type = ParameterizedTypeName.get(ClassName.get(MemBufferHolder.class), m_alloctypename);
+ }
+ if (fieldinfo.type instanceof TypeVariableName) {
+ fieldinfo.type = ParameterizedTypeName.get(ClassName.get(GenericField.class), m_alloctypename,
+ fieldinfo.type);
+ }
+ fieldinfo.name = String.format("m_%s_%s", methodname.substring(3).toLowerCase(), Utils.genRandomString());
+ fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type, fieldinfo.name, Modifier.PRIVATE);
+ fieldinfo.fieldsize = computeTypeSize(methodinfo.elem.getReturnType());
+ fieldinfo.fieldoff = fieldoff;
+ fieldoff += fieldinfo.fieldsize;
+ fieldinfo.efproxiesname = pgetter.EntityFactoryProxies();
+ fieldinfo.gftypesname = pgetter.GenericFieldTypes();
+ fieldinfo.id = pgetter.Id();
+ m_dynfieldsinfo.put(methodname.substring(3), fieldinfo);
+
+ }
+ if (null != elem.getAnnotation(NonVolatileSetter.class)) {
+ if (!elem.getModifiers().contains(Modifier.ABSTRACT)) {
+ throw new AnnotationProcessingException(elem, "%s annotated with NonVolatileSetter is not abstract.",
+ methodname);
+ }
+ if (!methodname.startsWith("set")) {
+ throw new AnnotationProcessingException(elem, "%s does not comply name convention of setter.", methodname);
+ }
+ methodinfo = new MethodInfo();
+ methodinfo.elem = (ExecutableElement) elem;
+ methodinfo.specbuilder = MethodSpec.overriding(methodinfo.elem);
+ m_settersinfo.put(methodname.substring(3), methodinfo);
+ }
+ // if
+ // (!methodinfo.elem.getThrownTypes().contains(m_elemutils.getTypeElement(RetrieveNonVolatileEntityError.class.getCanonicalName()).asType()))
+ // {
+ // throw new AnnotationProcessingException(methodinfo.elem, "%s must
+ // throw out %s.",
+ // methodname, RetrieveNonVolatileEntityError.class.getName());
+ // }
+ }
}
-
- private TypeName unboxTypeName(TypeName tn) {
- TypeName n = tn;
- try {
- n = tn.unbox();
- } catch(UnsupportedOperationException ex) {}
- return n;
- }
-
- public AnnotatedNonVolatileEntityClass(TypeElement classElement, Types typeUtils, Elements elementUtils,
- Messager messager) {
- m_elem = classElement;
- m_typeutils = typeUtils;
- m_elemutils = elementUtils;
- m_msgr = messager;
-
- m_packagename = m_elemutils.getPackageOf(m_elem).getQualifiedName().toString();
-
- m_factoryname = String.format("%s%s", m_elem.getSimpleName(), FACTORYNAMESUFFIX);
- m_entityname = String.format("%s%s_%s", PMEMNAMEPREFIX, m_elem.getSimpleName(), Utils.genRandomString());
-
- m_durablemtdinfo.put("cancelAutoReclaim", new MethodInfo());
- m_durablemtdinfo.put("registerAutoReclaim", new MethodInfo());
- m_durablemtdinfo.put("getNonVolatileHandler", new MethodInfo());
- m_durablemtdinfo.put("autoReclaim", new MethodInfo());
- m_durablemtdinfo.put("destroy", new MethodInfo());
- m_durablemtdinfo.put("getNativeFieldInfo", new MethodInfo());
-
- m_entitymtdinfo.put("initializeNonVolatileEntity", new MethodInfo());
- m_entitymtdinfo.put("createNonVolatileEntity", new MethodInfo());
- m_entitymtdinfo.put("restoreNonVolatileEntity", new MethodInfo());
+ m_holdersize = fieldoff;
+
+ // MethodInfo minfo = null;
+ for (String name : m_settersinfo.keySet()) {
+ if (!m_gettersinfo.containsKey(name)) {
+ throw new AnnotationProcessingException(null, "%s has no getter.", name);
+ }
+ // if
+ // (m_dynfieldsinfo.get(name).type.toString().equals(String.class.getCanonicalName()))
+ // {
+ // minfo = m_settersinfo.get(name);
+ // if
+ // (!minfo.elem.getThrownTypes().contains(m_elemutils.getTypeElement(OutOfPersistentMemory.class.getCanonicalName()).asType()))
+ // {
+ // throw new AnnotationProcessingException(minfo.elem, "%s must throw out
+ // %s.",
+ // gsetterName(name, false), OutOfPersistentMemory.class.getName());
+ // }
+ // }
}
- public void prepareProcessing() throws AnnotationProcessingException {
- MethodInfo methodinfo = null;
- FieldInfo fieldinfo;
- String methodname;
- long fieldoff = 0;
- TypeElement intf_durable = m_elemutils.getTypeElement(Durable.class.getCanonicalName());
- TypeElement intf_entity = m_elemutils.getTypeElement(MemoryNonVolatileEntity.class.getCanonicalName());
- // System.err.printf("<><><><><> %s ======\n", intf_entity.toString());
-
- boolean valid = false;
- for (TypeMirror tm : m_elem.getInterfaces()) {
- if (tm.toString().equals(Durable.class.getCanonicalName())) {
- valid = true;
- break;
- }
- }
- if (!valid) {
- throw new AnnotationProcessingException(m_elem, "Not implemented Durable Interface by %s.",
- m_elem.getSimpleName().toString());
- }
-
- fieldinfo = new FieldInfo();
- fieldinfo.name = String.format("m_unsafe_%s",
- Utils.genRandomString());
- fieldinfo.type = TypeName.get(m_elemutils.getTypeElement(Unsafe.class.getCanonicalName()).asType());
- fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type,
- fieldinfo.name, Modifier.PRIVATE);
- m_fieldsinfo.put("unsafe", fieldinfo);
-
- fieldinfo = new FieldInfo();
- fieldinfo.name = String.format("m_holder_%s",
- Utils.genRandomString());
- fieldinfo.type = ParameterizedTypeName.get(ClassName.get(MemChunkHolder.class), m_alloctypename);
- fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type,
- fieldinfo.name, Modifier.PRIVATE);
- m_fieldsinfo.put("holder", fieldinfo);
-
- fieldinfo = new FieldInfo();
- fieldinfo.name = String.format("m_autoreclaim_%s",
- Utils.genRandomString());
- fieldinfo.type = TypeName.get(m_typeutils.getPrimitiveType(TypeKind.BOOLEAN));
- fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type,
- fieldinfo.name, Modifier.PRIVATE, Modifier.VOLATILE);
- m_fieldsinfo.put("autoreclaim", fieldinfo);
-
- fieldinfo = new FieldInfo();
- fieldinfo.name = String.format("m_allocator_%s",
- Utils.genRandomString());
- fieldinfo.type = m_alloctypename;
- fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type,
- fieldinfo.name, Modifier.PRIVATE);
- m_fieldsinfo.put("allocator", fieldinfo);
-
- fieldinfo = new FieldInfo();
- fieldinfo.name = String.format("m_factoryproxy_%s",
- Utils.genRandomString());
- fieldinfo.type = m_factoryproxystypename;
- fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type,
- fieldinfo.name, Modifier.PRIVATE);
- m_fieldsinfo.put("factoryproxy", fieldinfo);
-
- fieldinfo = new FieldInfo();
- fieldinfo.name = String.format("m_genericfield_%s",
- Utils.genRandomString());
- fieldinfo.type = m_gfieldstypename;
- fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type,
- fieldinfo.name, Modifier.PRIVATE);
- m_fieldsinfo.put("genericfield", fieldinfo);
-
- for (Element elem : m_elem.getEnclosedElements()) {
- if (elem.getKind() == ElementKind.METHOD) {
- methodname = elem.getSimpleName().toString();
- // System.err.printf("=========== %s ======\n", methodname);
- NonVolatileGetter pgetter = elem.getAnnotation(NonVolatileGetter.class);
- if (pgetter != null) {
- if (!elem.getModifiers().contains(Modifier.ABSTRACT)) {
- throw new AnnotationProcessingException(elem,
- "%s annotated with NonVolatileGetter is not abstract.", methodname);
- }
- if (null != elem.getAnnotation(NonVolatileSetter.class)) {
- throw new AnnotationProcessingException(elem, "%s is annotated with NonVolatileSetter as well.",
- methodname);
- }
- if (!methodname.startsWith("get")) {
- throw new AnnotationProcessingException(elem, "%s does not comply name convention of getter.",
- methodname);
- }
- methodinfo = new MethodInfo();
- methodinfo.elem = (ExecutableElement) elem;
- methodinfo.specbuilder = MethodSpec.overriding(methodinfo.elem);
- methodinfo.rettype = TypeName.get(methodinfo.elem.getReturnType());
- m_gettersinfo.put(methodname.substring(3), methodinfo);
- fieldinfo = new FieldInfo();
- fieldinfo.type = methodinfo.rettype;
- if (fieldinfo.type.toString().equals(String.class.getCanonicalName())) {
- fieldinfo.type = ParameterizedTypeName.get(ClassName.get(MemBufferHolder.class), m_alloctypename);
- }
- if (fieldinfo.type instanceof TypeVariableName) {
- fieldinfo.type = ParameterizedTypeName.get(ClassName.get(GenericField.class), m_alloctypename, fieldinfo.type);
- }
- fieldinfo.name = String.format("m_%s_%s",
- methodname.substring(3).toLowerCase(),
- Utils.genRandomString());
- fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type,
- fieldinfo.name, Modifier.PRIVATE);
- fieldinfo.fieldsize = computeTypeSize(methodinfo.elem.getReturnType());
- fieldinfo.fieldoff = fieldoff;
- fieldoff += fieldinfo.fieldsize;
- fieldinfo.efproxiesname = pgetter.EntityFactoryProxies();
- fieldinfo.gftypesname = pgetter.GenericFieldTypes();
- fieldinfo.id = pgetter.Id();
- m_dynfieldsinfo.put(methodname.substring(3), fieldinfo);
-
- }
- if (null != elem.getAnnotation(NonVolatileSetter.class)) {
- if (!elem.getModifiers().contains(Modifier.ABSTRACT)) {
- throw new AnnotationProcessingException(elem,
- "%s annotated with NonVolatileSetter is not abstract.", methodname);
- }
- if (!methodname.startsWith("set")) {
- throw new AnnotationProcessingException(elem, "%s does not comply name convention of setter.",
- methodname);
- }
- methodinfo = new MethodInfo();
- methodinfo.elem = (ExecutableElement) elem;
- methodinfo.specbuilder = MethodSpec.overriding(methodinfo.elem);
- m_settersinfo.put(methodname.substring(3), methodinfo);
- }
- // if (!methodinfo.elem.getThrownTypes().contains(m_elemutils.getTypeElement(RetrieveNonVolatileEntityError.class.getCanonicalName()).asType())) {
- // throw new AnnotationProcessingException(methodinfo.elem, "%s must throw out %s.",
- // methodname, RetrieveNonVolatileEntityError.class.getName());
- // }
- }
- }
-
- m_holdersize = fieldoff;
-
- // MethodInfo minfo = null;
- for (String name : m_settersinfo.keySet()) {
- if (!m_gettersinfo.containsKey(name)) {
- throw new AnnotationProcessingException(null, "%s has no getter.", name);
- }
- // if (m_dynfieldsinfo.get(name).type.toString().equals(String.class.getCanonicalName())) {
- // minfo = m_settersinfo.get(name);
- // if (!minfo.elem.getThrownTypes().contains(m_elemutils.getTypeElement(OutOfPersistentMemory.class.getCanonicalName()).asType())) {
- // throw new AnnotationProcessingException(minfo.elem, "%s must throw out %s.",
- // gsetterName(name, false), OutOfPersistentMemory.class.getName());
- // }
- // }
- }
-
- // for (String name : m_dynfieldsinfo.keySet()) {
- // if (!isUnboxPrimitive(m_dynfieldsinfo.get(name).type)) {
- // if (m_gettersinfo.containsKey(name)) {
- // minfo = m_gettersinfo.get(name);
- // if (!minfo.elem.getThrownTypes().contains(m_elemutils.getTypeElement(RetrieveNonVolatileEntityError.class.getCanonicalName()).asType())) {
- // throw new AnnotationProcessingException(minfo.elem, "%s must throw out %s.",
- // gsetterName(name, true), RetrieveNonVolatileEntityError.class.getName());
- // }
- // }
- // if (m_settersinfo.containsKey(name)) {
- // minfo = m_settersinfo.get(name);
- // if (!minfo.elem.getThrownTypes().contains(m_elemutils.getTypeElement(RetrieveNonVolatileEntityError.class.getCanonicalName()).asType())) {
- // throw new AnnotationProcessingException(minfo.elem, "%s must throw out %s.",
- // gsetterName(name, false), RetrieveNonVolatileEntityError.class.getName());
- // }
- // }
- // }
- // }
-
- for (Element elem : intf_durable.getEnclosedElements()) {
- if (elem.getKind() == ElementKind.METHOD) {
- methodname = elem.getSimpleName().toString();
- if (m_durablemtdinfo.containsKey(methodname)) {
- // System.err.printf("**++++++++++ %s ======\n", methodname);
- methodinfo = m_durablemtdinfo.get(methodname);
- methodinfo.elem = (ExecutableElement) elem;
- methodinfo.specbuilder = MethodSpec.overriding(methodinfo.elem);
- }
- }
- }
-
- for (Element elem : intf_entity.getEnclosedElements()) {
- if (elem.getKind() == ElementKind.METHOD) {
- methodname = elem.getSimpleName().toString();
- if (m_entitymtdinfo.containsKey(methodname)) {
- // System.err.printf("**------- %s ======\n", elem.toString());
- methodinfo = m_entitymtdinfo.get(methodname);
- methodinfo.elem = (ExecutableElement) elem;
- methodinfo.specbuilder = overriding(methodinfo.elem, ALLOCTYPENAME);
-
- }
- }
- }
- genNFieldInfo();
+ // for (String name : m_dynfieldsinfo.keySet()) {
+ // if (!isUnboxPrimitive(m_dynfieldsinfo.get(name).type)) {
+ // if (m_gettersinfo.containsKey(name)) {
+ // minfo = m_gettersinfo.get(name);
+ // if
+ // (!minfo.elem.getThrownTypes().contains(m_elemutils.getTypeElement(RetrieveNonVolatileEntityError.class.getCanonicalName()).asType()))
+ // {
+ // throw new AnnotationProcessingException(minfo.elem, "%s must throw out
+ // %s.",
+ // gsetterName(name, true), RetrieveNonVolatileEntityError.class.getName());
+ // }
+ // }
+ // if (m_settersinfo.containsKey(name)) {
+ // minfo = m_settersinfo.get(name);
+ // if
+ // (!minfo.elem.getThrownTypes().contains(m_elemutils.getTypeElement(RetrieveNonVolatileEntityError.class.getCanonicalName()).asType()))
+ // {
+ // throw new AnnotationProcessingException(minfo.elem, "%s must throw out
+ // %s.",
+ // gsetterName(name, false),
+ // RetrieveNonVolatileEntityError.class.getName());
+ // }
+ // }
+ // }
+ // }
+
+ for (Element elem : intf_durable.getEnclosedElements()) {
+ if (elem.getKind() == ElementKind.METHOD) {
+ methodname = elem.getSimpleName().toString();
+ if (m_durablemtdinfo.containsKey(methodname)) {
+ // System.err.printf("**++++++++++ %s ======\n", methodname);
+ methodinfo = m_durablemtdinfo.get(methodname);
+ methodinfo.elem = (ExecutableElement) elem;
+ methodinfo.specbuilder = MethodSpec.overriding(methodinfo.elem);
+ }
+ }
}
- protected String transTypeToUnsafeMethod(TypeName tname, boolean isget) throws AnnotationProcessingException {
- String ret = null;
- if (isUnboxPrimitive(tname)) {
- TypeName tn = unboxTypeName(tname);
- if (tn.equals(TypeName.BOOLEAN)) ret = isget ? "getByte" : "putByte";
- if (tn.equals(TypeName.BYTE)) ret = isget ? "getByte" : "putByte";
- if (tn.equals(TypeName.CHAR)) ret = isget ? "getChar" : "putChar";
- if (tn.equals(TypeName.DOUBLE)) ret = isget ? "getDouble" : "putDouble";
- if (tn.equals(TypeName.FLOAT)) ret = isget ? "getFloat" : "putFloat";
- if (tn.equals(TypeName.INT)) ret = isget ? "getInt" : "putInt";
- if (tn.equals(TypeName.LONG)) ret = isget ? "getLong" : "putLong";
- if (tn.equals(TypeName.SHORT)) ret = isget ? "getShort" : "putShort";
- } else {
- ret = isget ? "getAddress" : "putAddress";
- }
- if (null == ret) {
- throw new AnnotationProcessingException(null, "%s is not supported by getters or setters.",
- tname.toString());
- }
- return ret;
+ for (Element elem : intf_entity.getEnclosedElements()) {
+ if (elem.getKind() == ElementKind.METHOD) {
+ methodname = elem.getSimpleName().toString();
+ if (m_entitymtdinfo.containsKey(methodname)) {
+ // System.err.printf("**------- %s ======\n", elem.toString());
+ methodinfo = m_entitymtdinfo.get(methodname);
+ methodinfo.elem = (ExecutableElement) elem;
+ methodinfo.specbuilder = overriding(methodinfo.elem, ALLOCTYPENAME);
+
+ }
+ }
+ }
+ genNFieldInfo();
+ }
+
+ protected String transTypeToUnsafeMethod(TypeName tname, boolean isget) throws AnnotationProcessingException {
+ String ret = null;
+ if (isUnboxPrimitive(tname)) {
+ TypeName tn = unboxTypeName(tname);
+ if (tn.equals(TypeName.BOOLEAN))
+ ret = isget ? "getByte" : "putByte";
+ if (tn.equals(TypeName.BYTE))
+ ret = isget ? "getByte" : "putByte";
+ if (tn.equals(TypeName.CHAR))
+ ret = isget ? "getChar" : "putChar";
+ if (tn.equals(TypeName.DOUBLE))
+ ret = isget ? "getDouble" : "putDouble";
+ if (tn.equals(TypeName.FLOAT))
+ ret = isget ? "getFloat" : "putFloat";
+ if (tn.equals(TypeName.INT))
+ ret = isget ? "getInt" : "putInt";
+ if (tn.equals(TypeName.LONG))
+ ret = isget ? "getLong" : "putLong";
+ if (tn.equals(TypeName.SHORT))
+ ret = isget ? "getShort" : "putShort";
+ } else {
+ ret = isget ? "getAddress" : "putAddress";
}
-
- protected String getIntialValueLiteral(TypeName tname) throws AnnotationProcessingException {
- String ret = null;
- if (isUnboxPrimitive(tname)) {
- TypeName tn = unboxTypeName(tname);
- if (tn.equals(TypeName.BOOLEAN)) ret = "false";
- if (tn.equals(TypeName.BYTE)) ret = "(byte)0";
- if (tn.equals(TypeName.CHAR)) ret = "(char)0";
- if (tn.equals(TypeName.DOUBLE)) ret = "(double)0.0";
- if (tn.equals(TypeName.FLOAT)) ret = "(float)0.0";
- if (tn.equals(TypeName.INT)) ret = "(int)0";
- if (tn.equals(TypeName.LONG)) ret = "(long)0";
- if (tn.equals(TypeName.SHORT)) ret = "(short)0";
- } else {
- ret = null;
- }
- if (null == ret) {
- throw new AnnotationProcessingException(null, "%s is not supported to determine the inital value.",
- tname.toString());
- }
- return ret;
+ if (null == ret) {
+ throw new AnnotationProcessingException(null, "%s is not supported by getters or setters.", tname.toString());
}
-
- private int getFactoryProxyIndex(TypeName gtname) throws AnnotationProcessingException {
- int ret = -1;
- boolean found = false;
- if (gtname instanceof TypeVariableName) {
- for (TypeParameterElement tpe : m_elem.getTypeParameters()) {
- ++ret;
- if (tpe.toString().equals(gtname.toString())) {
- found = true;
- break;
- }
- }
- if (!found) {
- throw new AnnotationProcessingException(null, "%s type is not found during factory proxy query.",
- gtname.toString());
- }
- } else {
- throw new AnnotationProcessingException(null, "%s type is not generic type for factory proxy query.",
- gtname.toString());
- }
- return ret;
+ return ret;
+ }
+
+ protected String getIntialValueLiteral(TypeName tname) throws AnnotationProcessingException {
+ String ret = null;
+ if (isUnboxPrimitive(tname)) {
+ TypeName tn = unboxTypeName(tname);
+ if (tn.equals(TypeName.BOOLEAN))
+ ret = "false";
+ if (tn.equals(TypeName.BYTE))
+ ret = "(byte)0";
+ if (tn.equals(TypeName.CHAR))
+ ret = "(char)0";
+ if (tn.equals(TypeName.DOUBLE))
+ ret = "(double)0.0";
+ if (tn.equals(TypeName.FLOAT))
+ ret = "(float)0.0";
+ if (tn.equals(TypeName.INT))
+ ret = "(int)0";
+ if (tn.equals(TypeName.LONG))
+ ret = "(long)0";
+ if (tn.equals(TypeName.SHORT))
+ ret = "(short)0";
+ } else {
+ ret = null;
}
-
- protected void genNFieldInfo() {
- FieldInfo dynfieldinfo, fieldinfo;
- List<long[]> finfo = new ArrayList<long[]>();
- for (String name : m_gettersinfo.keySet()) {
- dynfieldinfo = m_dynfieldsinfo.get(name);
- if (dynfieldinfo.id > 0) {
- finfo.add(new long[]{dynfieldinfo.id, dynfieldinfo.fieldoff, dynfieldinfo.fieldsize});
- }
+ if (null == ret) {
+ throw new AnnotationProcessingException(null, "%s is not supported to determine the inital value.",
+ tname.toString());
+ }
+ return ret;
+ }
+
+ private int getFactoryProxyIndex(TypeName gtname) throws AnnotationProcessingException {
+ int ret = -1;
+ boolean found = false;
+ if (gtname instanceof TypeVariableName) {
+ for (TypeParameterElement tpe : m_elem.getTypeParameters()) {
+ ++ret;
+ if (tpe.toString().equals(gtname.toString())) {
+ found = true;
+ break;
}
-
- fieldinfo = new FieldInfo();
- fieldinfo.name = String.format("m_nfieldinfo_%s",
- Utils.genRandomString());
- fieldinfo.type = ArrayTypeName.of(ArrayTypeName.of(TypeName.LONG));
- String initlstr = Utils.toInitLiteral(finfo);
- fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type,
- fieldinfo.name, Modifier.PRIVATE, Modifier.STATIC).initializer("$1L", initlstr);
- m_fieldsinfo.put("nfieldinfo", fieldinfo);
+ }
+ if (!found) {
+ throw new AnnotationProcessingException(null, "%s type is not found during factory proxy query.",
+ gtname.toString());
+ }
+ } else {
+ throw new AnnotationProcessingException(null, "%s type is not generic type for factory proxy query.",
+ gtname.toString());
}
-
- protected void buildGettersSpecs(TypeSpec.Builder typespecbuilder) throws AnnotationProcessingException {
- MethodInfo methodinfo;
- TypeName ftname;
- String unsafename = m_fieldsinfo.get("unsafe").name;
- String holdername = m_fieldsinfo.get("holder").name;
- String allocname = m_fieldsinfo.get("allocator").name;
- String autoreclaimname = m_fieldsinfo.get("autoreclaim").name;
- String factoryproxyname = m_fieldsinfo.get("factoryproxy").name;
- String genericfieldname = m_fieldsinfo.get("genericfield").name;
- FieldInfo dynfieldinfo;
- CodeBlock.Builder code;
- String codefmt;
- for (String name : m_gettersinfo.keySet()) {
- code = CodeBlock.builder();
- methodinfo = m_gettersinfo.get(name);
- dynfieldinfo = m_dynfieldsinfo.get(name);
- ftname = m_dynfieldsinfo.get(name).type;
- if (isUnboxPrimitive(ftname)) {
- if (unboxTypeName(ftname).equals(TypeName.BOOLEAN)) {
- codefmt = "return 1 == $1N.$4L($2N.get() + $3L)";
- } else {
- codefmt = "return $1N.$4L($2N.get() + $3L)";
- }
- code.addStatement(codefmt, unsafename, holdername, dynfieldinfo.fieldoff, transTypeToUnsafeMethod(ftname, true));
- } else {
- if(methodinfo.rettype.toString().equals(String.class.getCanonicalName())) {
- code.beginControlFlow("if (null == $1N)", dynfieldinfo.name);
- code.addStatement("long phandler = $1N.getAddress($2N.get() + $3L)",
- unsafename, holdername, dynfieldinfo.fieldoff);
- code.beginControlFlow("if (0L != phandler)");
- code.addStatement("$1N = $2N.retrieveBuffer(phandler, $3N)",
- dynfieldinfo.name, allocname, autoreclaimname);
- code.beginControlFlow("if (null == $1N)", dynfieldinfo.name);
- code.addStatement("throw new RetrieveNonVolatileEntityError(\"Retrieve String Buffer Failure.\")");
- code.endControlFlow();
- code.endControlFlow();
- code.endControlFlow();
- code.addStatement("return null == $1N ? null : $1N.get().asCharBuffer().toString()",
- dynfieldinfo.name);
- } else if (dynfieldinfo.type.toString().startsWith(GenericField.class.getCanonicalName())) {
- code.beginControlFlow("if (null == $1N)", dynfieldinfo.name);
- code.addStatement("$1T proxy = null", TypeName.get(EntityFactoryProxy.class));
- code.addStatement("$1T gftype = null", TypeName.get(GenericField.GType.class));
- code.addStatement("int gfpidx = $1L", getFactoryProxyIndex(methodinfo.rettype));
- code.beginControlFlow("if (null != $1N && $1N.length > gfpidx)", factoryproxyname);
- code.addStatement("proxy = $1L[gfpidx]", factoryproxyname);
- code.endControlFlow();
- code.beginControlFlow("if (null != $1N && $1N.length > gfpidx)", genericfieldname);
- code.addStatement("gftype = $1L[gfpidx]", genericfieldname);
- code.nextControlFlow("else");
- code.addStatement("throw new RetrieveNonVolatileEntityError(\"No Generic Field Type Info.\")");
- code.endControlFlow();
- code.addStatement("$1N = new $2T(proxy, gftype, $8L, $9L, $3N, $4N, $5N, $6N.get() + $7L)",
- dynfieldinfo.name, dynfieldinfo.type,
- allocname, unsafename, autoreclaimname, holdername, dynfieldinfo.fieldoff,
- dynfieldinfo.efproxiesname, dynfieldinfo.gftypesname);
- code.endControlFlow();
- code.addStatement("return $1N.get()", dynfieldinfo.name);
- } else {
- code.beginControlFlow("if (null == $1N)", dynfieldinfo.name);
- code.addStatement("long phandler = $1N.getAddress($2N.get() + $3L)",
- unsafename, holdername, dynfieldinfo.fieldoff);
- code.beginControlFlow("if (0L != phandler)");
- code.addStatement("$1N = $4N.restore($2N, $5L, $6L, phandler, $3N)",
- dynfieldinfo.name, allocname, autoreclaimname,
- String.format("%s%s", m_typeutils.asElement(methodinfo.elem.getReturnType()).getSimpleName(), FACTORYNAMESUFFIX),
- dynfieldinfo.efproxiesname, dynfieldinfo.gftypesname);
- code.endControlFlow();
- code.endControlFlow();
- code.addStatement("return $1N", dynfieldinfo.name);
- }
- }
- typespecbuilder.addMethod(methodinfo.specbuilder.addCode(code.build()).build());
- }
+ return ret;
+ }
+
+ protected void genNFieldInfo() {
+ FieldInfo dynfieldinfo, fieldinfo;
+ List<long[]> finfo = new ArrayList<long[]>();
+ for (String name : m_gettersinfo.keySet()) {
+ dynfieldinfo = m_dynfieldsinfo.get(name);
+ if (dynfieldinfo.id > 0) {
+ finfo.add(new long[] { dynfieldinfo.id, dynfieldinfo.fieldoff, dynfieldinfo.fieldsize });
+ }
}
-
- protected String gsetterName(String name, boolean isget) {
- return String.format("%s%s", isget ? "get" : "set", name); //Character.toUpperCase(name.charAt(0)) + name.substring(1));
+
+ fieldinfo = new FieldInfo();
+ fieldinfo.name = String.format("m_nfieldinfo_%s", Utils.genRandomString());
+ fieldinfo.type = ArrayTypeName.of(ArrayTypeName.of(TypeName.LONG));
+ String initlstr = Utils.toInitLiteral(finfo);
+ fieldinfo.specbuilder = FieldSpec.builder(fieldinfo.type, fieldinfo.name, Modifier.PRIVATE, Modifier.STATIC)
+ .initializer("$1L", initlstr);
+ m_fieldsinfo.put("nfieldinfo", fieldinfo);
+ }
+
+ protected void buildGettersSpecs(TypeSpec.Builder typespecbuilder) throws AnnotationProcessingException {
+ MethodInfo methodinfo;
+ TypeName ftname;
+ String unsafename = m_fieldsinfo.get("unsafe").name;
+ String holdername = m_fieldsinfo.get("holder").name;
+ String allocname = m_fieldsinfo.get("allocator").name;
+ String autoreclaimname = m_fieldsinfo.get("autoreclaim").name;
+ String factoryproxyname = m_fieldsinfo.get("factoryproxy").name;
+ String genericfieldname = m_fieldsinfo.get("genericfield").name;
+ FieldInfo dynfieldinfo;
+ CodeBlock.Builder code;
+ String codefmt;
+ for (String name : m_gettersinfo.keySet()) {
+ code = CodeBlock.builder();
+ methodinfo = m_gettersinfo.get(name);
+ dynfieldinfo = m_dynfieldsinfo.get(name);
+ ftname = m_dynfieldsinfo.get(name).type;
+ if (isUnboxPrimitive(ftname)) {
+ if (unboxTypeName(ftname).equals(TypeName.BOOLEAN)) {
+ codefmt = "return 1 == $1N.$4L($2N.get() + $3L)";
+ } else {
+ codefmt = "return $1N.$4L($2N.get() + $3L)";
+ }
+ code.addStatement(codefmt, unsafename, holdername, dynfieldinfo.fieldoff,
+ transTypeToUnsafeMethod(ftname, true));
+ } else {
+ if (methodinfo.rettype.toString().equals(String.class.getCanonicalName())) {
+ code.beginControlFlow("if (null == $1N)", dynfieldinfo.name);
+ code.addStatement("long phandler = $1N.getAddress($2N.get() + $3L)", unsafename, holdername,
+ dynfieldinfo.fieldoff);
+ code.beginControlFlow("if (0L != phandler)");
+ code.addStatement("$1N = $2N.retrieveBuffer(phandler, $3N)", dynfieldinfo.name, allocname, autoreclaimname);
+ code.beginControlFlow("if (null == $1N)", dynfieldinfo.name);
+ code.addStatement("throw new RetrieveNonVolatileEntityError(\"Retrieve String Buffer Failure.\")");
+ code.endControlFlow();
+ code.endControlFlow();
+ code.endControlFlow();
+ code.addStatement("return null == $1N ? null : $1N.get().asCharBuffer().toString()", dynfieldinfo.name);
+ } else if (dynfieldinfo.type.toString().startsWith(GenericField.class.getCanonicalName())) {
+ code.beginControlFlow("if (null == $1N)", dynfieldinfo.name);
+ code.addStatement("$1T proxy = null", TypeName.get(EntityFactoryProxy.class));
+ code.addStatement("$1T gftype = null", TypeName.get(GenericField.GType.class));
+ code.addStatement("int gfpidx = $1L", getFactoryProxyIndex(methodinfo.rettype));
+ code.beginControlFlow("if (null != $1N && $1N.length > gfpidx)", factoryproxyname);
+ code.addStatement("proxy = $1L[gfpidx]", factoryproxyname);
+ code.endControlFlow();
+ code.beginControlFlow("if (null != $1N && $1N.length > gfpidx)", genericfieldname);
+ code.addStatement("gftype = $1L[gfpidx]", genericfieldname);
+ code.nextControlFlow("else");
+ code.addStatement("throw new RetrieveNonVolatileEntityError(\"No Generic Field Type Info.\")");
+ code.endControlFlow();
+ code.addStatement("$1N = new $2T(proxy, gftype, $8L, $9L, $3N, $4N, $5N, $6N.get() + $7L)", dynfieldinfo.name,
+ dynfieldinfo.type, allocname, unsafename, autoreclaimname, holdername, dynfieldinfo.fieldoff,
+ dynfieldinfo.efproxiesname, dynfieldinfo.gftypesname);
+ code.endControlFlow();
+ code.addStatement("return $1N.get()", dynfieldinfo.name);
+ } else {
+ code.beginControlFlow("if (null == $1N)", dynfieldinfo.name);
+ code.addStatement("long phandler = $1N.getAddress($2N.get() + $3L)", unsafename, holdername,
+ dynfieldinfo.fieldoff);
+ code.beginControlFlow("if (0L != phandler)");
+ code.addStatement("$1N = $4N.restore($2N, $5L, $6L, phandler, $3N)", dynfieldinfo.name, allocname,
+ autoreclaimname, String.format("%s%s",
+ m_typeutils.asElement(methodinfo.elem.getReturnType()).getSimpleName(), FACTORYNAMESUFFIX),
+ dynfieldinfo.efproxiesname, dynfieldinfo.gftypesname);
+ code.endControlFlow();
+ code.endControlFlow();
+ code.addStatement("return $1N", dynfieldinfo.name);
+ }
+ }
+ typespecbuilder.addMethod(methodinfo.specbuilder.addCode(code.build()).build());
}
-
- protected void buildSettersSpecs(TypeSpec.Builder typespecbuilder) throws AnnotationProcessingException {
- MethodInfo methodinfo;
- TypeName ftname, valtname;
- String unsafename = m_fieldsinfo.get("unsafe").name;
- String holdername = m_fieldsinfo.get("holder").name;
- String allocname = m_fieldsinfo.get("allocator").name;
- String autoreclaimname = m_fieldsinfo.get("autoreclaim").name;
- String factoryproxyname = m_fieldsinfo.get("factoryproxy").name;
- String genericfieldname = m_fieldsinfo.get("genericfield").name;
- FieldInfo dynfieldinfo;
- CodeBlock.Builder code;
- VariableElement arg0;
- VariableElement arg1;
- String codefmt;
- for (String name : m_settersinfo.keySet()) {
- code = CodeBlock.builder();
- methodinfo = m_settersinfo.get(name);
- dynfieldinfo = m_dynfieldsinfo.get(name);
- ftname = m_dynfieldsinfo.get(name).type;
- valtname = m_gettersinfo.get(name).rettype;
- arg0 = methodinfo.elem.getParameters().get(0);
- if (!TypeName.get(arg0.asType()).equals(valtname)) {
- throw new AnnotationProcessingException(null, "%s has inconsistent value type with its getter/setter.",
- name);
- }
- if (isUnboxPrimitive(ftname)) {
- if (unboxTypeName(ftname).equals(TypeName.BOOLEAN)) {
- codefmt = "$1N.$4L($2N.get() + $3L, $5L?1:0)";
- } else {
- codefmt = "$1N.$4L($2N.get() + $3L, $5L)";
- }
- code.addStatement(codefmt, unsafename, holdername, dynfieldinfo.fieldoff, transTypeToUnsafeMethod(ftname, false), arg0);
- } else {
- try {
- arg1 = methodinfo.elem.getParameters().get(1);
- if (!TypeName.BOOLEAN.equals(TypeName.get(arg1.asType()))) {
- throw new AnnotationProcessingException(null, "the second parameter of %s's setter is not boolean type.",
- name);
- }
- } catch (IndexOutOfBoundsException ex) {
- throw new AnnotationProcessingException(null, "%s's setter has no second parameters for non primitive type.",
- name);
- }
- if(valtname.toString().equals(String.class.getCanonicalName())) {
- code.beginControlFlow("if ($1L && null != $2L())", arg1, gsetterName(name, true));
- code.addStatement("$1N.destroy()", dynfieldinfo.name);
- code.addStatement("$1N = null", dynfieldinfo.name);
- code.addStatement("$1N.putAddress($2N.get() + $3L, 0L)",
- unsafename, holdername, dynfieldinfo.fieldoff);
- code.endControlFlow();
- code.beginControlFlow("if (null == $1L)", arg0);
- code.addStatement("$1N.putLong($2N.get() + $3L, 0L)",
- unsafename, holdername, dynfieldinfo.fieldoff);
- code.nextControlFlow("else");
- code.addStatement("$1N = $2N.createBuffer($3L.length() * 2, $4N)",
- dynfieldinfo.name, allocname, arg0, autoreclaimname);
- code.beginControlFlow("if (null == $1N)", dynfieldinfo.name);
- code.addStatement("throw new OutOfPersistentMemory(\"Create Non-Volatile String Error!\")");
- code.endControlFlow();
- code.addStatement("$1N.get().asCharBuffer().put($2L)", dynfieldinfo.name, arg0);
- code.addStatement("$1N.putLong($2N.get() + $3L, $4N.getBufferHandler($5N))",
- unsafename, holdername, dynfieldinfo.fieldoff, allocname, dynfieldinfo.name);
- code.endControlFlow();
- } else if (dynfieldinfo.type.toString().startsWith(GenericField.class.getCanonicalName())) {
- code.beginControlFlow("if (null == $1N)", dynfieldinfo.name);
- code.addStatement("$1T proxy = null", TypeName.get(EntityFactoryProxy.class));
- code.addStatement("$1T gftype = null", TypeName.get(GenericField.GType.class));
- code.addStatement("int gfpidx = $1L", getFactoryProxyIndex(valtname));
- code.beginControlFlow("if (null != $1N && $1N.length > gfpidx)", factoryproxyname);
- code.addStatement("proxy = $1L[gfpidx]", factoryproxyname);
- code.endControlFlow();
- code.beginControlFlow("if (null != $1N && $1N.length > gfpidx)", genericfieldname);
- code.addStatement("gftype = $1L[gfpidx]", genericfieldname);
- code.nextControlFlow("else");
- code.addStatement("throw new RetrieveNonVolatileEntityError(\"No Generic Field Type Info.\")");
- code.endControlFlow();
- code.addStatement("$1N = new $2T(proxy, gftype, $8L, $9L, $3N, $4N, $5N, $6N.get() + $7L)",
- dynfieldinfo.name, dynfieldinfo.type,
- allocname, unsafename, autoreclaimname, holdername, dynfieldinfo.fieldoff,
- dynfieldinfo.efproxiesname, dynfieldinfo.gftypesname);
- code.endControlFlow();
- code.beginControlFlow("if (null != $1L)", dynfieldinfo.name);
- code.addStatement("$1N.set($2L, $3L)", dynfieldinfo.name, arg0, arg1);
- code.nextControlFlow("else");
- code.addStatement("throw new RetrieveNonVolatileEntityError(\"GenericField is null!\")");
- code.endControlFlow();
- } else {
- code.beginControlFlow("if ($1L && null != $2L())", arg1, gsetterName(name, true));
- code.addStatement("$1N.destroy()", dynfieldinfo.name);
- code.addStatement("$1N = null", dynfieldinfo.name);
- code.addStatement("$1N.putAddress($2N.get() + $3L, 0L)",
- unsafename, holdername, dynfieldinfo.fieldoff);
- code.endControlFlow();
- code.addStatement("$1N = $2L", dynfieldinfo.name, arg0);
- code.addStatement("$1N.putLong($2N.get() + $3L, null == $4N ? 0L : $4N.getNonVolatileHandler())",
- unsafename, holdername, dynfieldinfo.fieldoff, dynfieldinfo.name);
- }
- }
- typespecbuilder.addMethod(methodinfo.specbuilder.addCode(code.build()).build());
- }
+ }
+
+ protected String gsetterName(String name, boolean isget) {
+ return String.format("%s%s", isget ? "get" : "set", name); // Character.toUpperCase(name.charAt(0))
+ // +
+ // name.substring(1));
+ }
+
+ protected void buildSettersSpecs(TypeSpec.Builder typespecbuilder) throws AnnotationProcessingException {
+ MethodInfo methodinfo;
+ TypeName ftname, valtname;
+ String unsafename = m_fieldsinfo.get("unsafe").name;
+ String holdername = m_fieldsinfo.get("holder").name;
+ String allocname = m_fieldsinfo.get("allocator").name;
+ String autoreclaimname = m_fieldsinfo.get("autoreclaim").name;
+ String factoryproxyname = m_fieldsinfo.get("factoryproxy").name;
+ String genericfieldname = m_fieldsinfo.get("genericfield").name;
+ FieldInfo dynfieldinfo;
+ CodeBlock.Builder code;
+ VariableElement arg0;
+ VariableElement arg1;
+ String codefmt;
+ for (String name : m_settersinfo.keySet()) {
+ code = CodeBlock.builder();
+ methodinfo = m_settersinfo.get(name);
+ dynfieldinfo = m_dynfieldsinfo.get(name);
+ ftname = m_dynfieldsinfo.get(name).type;
+ valtname = m_gettersinfo.get(name).rettype;
+ arg0 = methodinfo.elem.getParameters().get(0);
+ if (!TypeName.get(arg0.asType()).equals(valtname)) {
+ throw new AnnotationProcessingException(null, "%s has inconsistent value type with its getter/setter.", name);
+ }
+ if (isUnboxPrimitive(ftname)) {
+ if (unboxTypeName(ftname).equals(TypeName.BOOLEAN)) {
+ codefmt = "$1N.$4L($2N.get() + $3L, $5L?1:0)";
+ } else {
+ codefmt = "$1N.$4L($2N.get() + $3L, $5L)";
+ }
+ code.addStatement(codefmt, unsafename, holdername, dynfieldinfo.fieldoff,
+ transTypeToUnsafeMethod(ftname, false), arg0);
+ } else {
+ try {
+ arg1 = methodinfo.elem.getParameters().get(1);
+ if (!TypeName.BOOLEAN.equals(TypeName.get(arg1.asType()))) {
+ throw new AnnotationProcessingException(null, "the second parameter of %s's setter is not boolean type.",
+ name);
+ }
+ } catch (IndexOutOfBoundsException ex) {
+ throw new AnnotationProcessingException(null, "%s's setter has no second parameters for non primitive type.",
+ name);
+ }
+ if (valtname.toString().equals(String.class.getCanonicalName())) {
+ code.beginControlFlow("if ($1L && null != $2L())", arg1, gsetterName(name, true));
+ code.addStatement("$1N.destroy()", dynfieldinfo.name);
+ code.addStatement("$1N = null", dynfieldinfo.name);
+ code.addStatement("$1N.putAddress($2N.get() + $3L, 0L)", unsafename, holdername, dynfieldinfo.fieldoff);
+ code.endControlFlow();
+ code.beginControlFlow("if (null == $1L)", arg0);
+ code.addStatement("$1N.putLong($2N.get() + $3L, 0L)", unsafename, holdername, dynfieldinfo.fieldoff);
+ code.nextControlFlow("else");
+ code.addStatement("$1N = $2N.createBuffer($3L.length() * 2, $4N)", dynfieldinfo.name, allocname, arg0,
+ autoreclaimname);
+ code.beginControlFlow("if (null == $1N)", dynfieldinfo.name);
+ code.addStatement("throw new OutOfPersistentMemory(\"Create Non-Volatile String Error!\")");
+ code.endControlFlow();
+ code.addStatement("$1N.get().asCharBuffer().put($2L)", dynfieldinfo.name, arg0);
+ code.addStatement("$1N.putLong($2N.get() + $3L, $4N.getBufferHandler($5N))", unsafename, holdername,
+ dynfieldinfo.fieldoff, allocname, dynfieldinfo.name);
+ code.endControlFlow();
+ } else if (dynfieldinfo.type.toString().startsWith(GenericField.class.getCanonicalName())) {
+ code.beginControlFlow("if (null == $1N)", dynfieldinfo.name);
+ code.addStatement("$1T proxy = null", TypeName.get(EntityFactoryProxy.class));
+ code.addStatement("$1T gftype = null", TypeName.get(GenericField.GType.class));
+ code.addStatement("int gfpidx = $1L", getFactoryProxyIndex(valtname));
+ code.beginControlFlow("if (null != $1N && $1N.length > gfpidx)", factoryproxyname);
+ code.addStatement("proxy = $1L[gfpidx]", factoryproxyname);
+ code.endControlFlow();
+ code.beginControlFlow("if (null != $1N && $1N.length > gfpidx)", genericfieldname);
+ code.addStatement("gftype = $1L[gfpidx]", genericfieldname);
+ code.nextControlFlow("else");
+ code.addStatement("throw new RetrieveNonVolatileEntityError(\"No Generic Field Type Info.\")");
+ code.endControlFlow();
+ code.addStatement("$1N = new $2T(proxy, gftype, $8L, $9L, $3N, $4N, $5N, $6N.get() + $7L)", dynfieldinfo.name,
+ dynfieldinfo.type, allocname, unsafename, autoreclaimname, holdername, dynfieldinfo.fieldoff,
+ dynfieldinfo.efproxiesname, dynfieldinfo.gftypesname);
+ code.endControlFlow();
+ code.beginControlFlow("if (null != $1L)", dynfieldinfo.name);
+ code.addStatement("$1N.set($2L, $3L)", dynfieldinfo.name, arg0, arg1);
+ code.nextControlFlow("else");
+ code.addStatement("throw new RetrieveNonVolatileEntityError(\"GenericField is null!\")");
+ code.endControlFlow();
+ } else {
+ code.beginControlFlow("if ($1L && null != $2L())", arg1, gsetterName(name, true));
+ code.addStatement("$1N.destroy()", dynfieldinfo.name);
+ code.addStatement("$1N = null", dynfieldinfo.name);
+ code.addStatement("$1N.putAddress($2N.get() + $3L, 0L)", unsafename, holdername, dynfieldinfo.fieldoff);
+ code.endControlFlow();
+ code.addStatement("$1N = $2L", dynfieldinfo.name, arg0);
+ code.addStatement("$1N.putLong($2N.get() + $3L, null == $4N ? 0L : $4N.getNonVolatileHandler())", unsafename,
+ holdername, dynfieldinfo.fieldoff, dynfieldinfo.name);
+ }
+ }
+ typespecbuilder.addMethod(methodinfo.specbuilder.addCode(code.build()).build());
}
-
- protected void buildDurableMethodSpecs(TypeSpec.Builder typespecbuilder) throws AnnotationProcessingException {
- MethodInfo methodinfo;
- CodeBlock.Builder code;
- FieldInfo dynfieldinfo;
- String holdername = m_fieldsinfo.get("holder").name;
- String allocname = m_fieldsinfo.get("allocator").name;
- String autoreclaimname = m_fieldsinfo.get("autoreclaim").name;
- for (String name : m_durablemtdinfo.keySet()) {
- methodinfo = m_durablemtdinfo.get(name);
- code = CodeBlock.builder();
- switch(name) {
- case "cancelAutoReclaim" :
- code.addStatement("$1N.cancelAutoReclaim()", holdername);
- for (String fname : m_dynfieldsinfo.keySet()) {
- dynfieldinfo = m_dynfieldsinfo.get(fname);
- if (!isUnboxPrimitive(dynfieldinfo.type)) {
- code.beginControlFlow("if (null != $1N)", dynfieldinfo.name);
- code.addStatement("$1N.cancelAutoReclaim()", dynfieldinfo.name);
- code.endControlFlow();
- }
- }
- code.addStatement("$1N = false", autoreclaimname);
- break;
- case "registerAutoReclaim" :
- code.addStatement("$1N.registerAutoReclaim()", holdername);
- for (String fname : m_dynfieldsinfo.keySet()) {
- dynfieldinfo = m_dynfieldsinfo.get(fname);
- if (!isUnboxPrimitive(dynfieldinfo.type)) {
- code.beginControlFlow("if (null != $1N)", dynfieldinfo.name);
- code.addStatement("$1N.registerAutoReclaim()", dynfieldinfo.name);
- code.endControlFlow();
- }
- }
- code.addStatement("$1N = true", autoreclaimname);
- break;
- case "getNonVolatileHandler" :
- code.addStatement("return $1N.getChunkHandler($2N)", allocname, holdername);
- break;
- case "autoReclaim" :
- code.addStatement("return $1N", autoreclaimname);
- break;
- case "destroy" :
- code.addStatement("$1N.destroy()", holdername);
- for (String fname : m_dynfieldsinfo.keySet()) {
- dynfieldinfo = m_dynfieldsinfo.get(fname);
- if (!isUnboxPrimitive(dynfieldinfo.type)) {
- code.beginControlFlow("if (null != $1N)", dynfieldinfo.name);
- code.addStatement("$1N.destroy()", dynfieldinfo.name);
- code.addStatement("$1N = null", dynfieldinfo.name);
- code.endControlFlow();
- }
- }
- break;
- case "getNativeFieldInfo" :
+ }
+
+ protected void buildDurableMethodSpecs(TypeSpec.Builder typespecbuilder) throws AnnotationProcessingException {
+ MethodInfo methodinfo;
+ CodeBlock.Builder code;
+ FieldInfo dynfieldinfo;
+ String holdername = m_fieldsinfo.get("holder").name;
+ String allocname = m_fieldsinfo.get("allocator").name;
+ String autoreclaimname = m_fieldsinfo.get("autoreclaim").name;
+ for (String name : m_durablemtdinfo.keySet()) {
+ methodinfo = m_durablemtdinfo.get(name);
+ code = CodeBlock.builder();
+ switch (name) {
+ case "cancelAutoReclaim":
+ code.addStatement("$1N.cancelAutoReclaim()", holdername);
+ for (String fname : m_dynfieldsinfo.keySet()) {
+ dynfieldinfo = m_dynfieldsinfo.get(fname);
+ if (!isUnboxPrimitive(dynfieldinfo.type)) {
+ code.beginControlFlow("if (null != $1N)", dynfieldinfo.name);
+ code.addStatement("$1N.cancelAutoReclaim()", dynfieldinfo.name);
+ code.endControlFlow();
+ }
+ }
+ code.addStatement("$1N = false", autoreclaimname);
+ break;
+ case "registerAutoReclaim":
+ code.addStatement("$1N.registerAutoReclaim()", holdername);
+ for (String fname : m_dynfieldsinfo.keySet()) {
+ dynfieldinfo = m_dynfieldsinfo.get(fname);
+ if (!isUnboxPrimitive(dynfieldinfo.type)) {
+ code.beginControlFlow("if (null != $1N)", dynfieldinfo.name);
+ code.addStatement("$1N.registerAutoReclaim()", dynfieldinfo.name);
+ code.endControlFlow();
+ }
+ }
+ code.addStatement("$1N = true", autoreclaimname);
+ break;
+ case "getNonVolatileHandler":
+ code.addStatement("return $1N.getChunkHandler($2N)", allocname, holdername);
+ break;
+ case "autoReclaim":
+ code.addStatement("return $1N", autoreclaimname);
+ break;
+ case "destroy":
+ code.addStatement("$1N.destroy()", holdername);
+ for (String fname : m_dynfieldsinfo.keySet()) {
+ dynfieldinfo = m_dynfieldsinfo.get(fname);
+ if (!isUnboxPrimitive(dynfieldinfo.type)) {
+ code.beginControlFlow("if (null != $1N)", dynfieldinfo.name);
+ code.addStatement("$1N.destroy()", dynfieldinfo.name);
+ code.addStatement("$1N = null", dynfieldinfo.name);
+ code.endControlFlow();
+ }
+ }
+ break;
+ case "getNativeFieldInfo":
code.addStatement("return $1N", m_fieldsinfo.get("nfieldinfo").name);
break;
- default:
- throw new AnnotationProcessingException(null, "Method %s is not supported.",
- name);
- }
- typespecbuilder.addMethod(methodinfo.specbuilder.addCode(code.build()).build());
- }
+ default:
+ throw new AnnotationProcessingException(null, "Method %s is not supported.", name);
+ }
+ typespecbuilder.addMethod(methodinfo.specbuilder.addCode(code.build()).build());
+ }
+ }
+
+ protected void buildEntityMethodSpecs(TypeSpec.Builder typespecbuilder) throws AnnotationProcessingException {
+ MethodInfo methodinfo;
+ CodeBlock.Builder code;
+ FieldInfo dynfieldinfo;
+ VariableElement arg0, arg1, arg2, arg3, arg4;
+ String unsafename = m_fieldsinfo.get("unsafe").name;
+ String holdername = m_fieldsinfo.get("holder").name;
+ String allocname = m_fieldsinfo.get("allocator").name;
+ String autoreclaimname = m_fieldsinfo.get("autoreclaim").name;
+ String factoryproxyname = m_fieldsinfo.get("factoryproxy").name;
+ String genericfieldname = m_fieldsinfo.get("genericfield").name;
+ for (String name : m_entitymtdinfo.keySet()) {
+ methodinfo = m_entitymtdinfo.get(name);
+ code = CodeBlock.builder();
+ arg0 = methodinfo.elem.getParameters().get(0);
+ arg1 = methodinfo.elem.getParameters().get(1);
+ arg2 = methodinfo.elem.getParameters().get(2);
+ switch (name) {
+ case "initializeNonVolatileEntity":
+ arg3 = methodinfo.elem.getParameters().get(3);
+ code.addStatement("$1N = $2L", allocname, arg0);
+ code.addStatement("$1N = $2L", factoryproxyname, arg1);
+ code.addStatement("$1N = $2L", genericfieldname, arg2);
+ code.addStatement("$1N = $2L", autoreclaimname, arg3);
+ code.beginControlFlow("try");
+ code.addStatement("$1N = $2T.getUnsafe()", unsafename, Utils.class);
+ code.nextControlFlow("catch (Exception e)");
+ code.addStatement("e.printStackTrace()");
+ code.endControlFlow();
+ break;
+ case "createNonVolatileEntity":
+ arg3 = methodinfo.elem.getParameters().get(3);
+ code.addStatement("initializeNonVolatileEntity($1L, $2L, $3L, $4L)", arg0, arg1, arg2, arg3);
+ code.addStatement("$1N = $2N.createChunk($3L, $4N)", holdername, allocname, m_holdersize, autoreclaimname);
+ code.beginControlFlow("if (null == $1N)", holdername);
+ code.addStatement("throw new OutOfPersistentMemory(\"Create Non-Volatile Entity Error!\")");
+ code.endControlFlow();
+ // code.beginControlFlow("try");
+ // for (String fname : m_dynfieldsinfo.keySet()) {
+ // dynfieldinfo = m_dynfieldsinfo.get(fname);
+ // if (isUnboxPrimitive(dynfieldinfo.type)) {
+ // code.addStatement("$1N($2L)", gsetterName(fname, false),
+ // getIntialValueLiteral(dynfieldinfo.type));
+ // } else {
+ // code.addStatement("$1N(null, false)", gsetterName(fname, false));
+ // }
+ // }
+ // code.nextControlFlow("catch(RetrieveNonVolatileEntityError ex)");
+ // code.endControlFlow();
+ code.addStatement("initializeAfterCreate()");
+ break;
+ case "restoreNonVolatileEntity":
+ arg3 = methodinfo.elem.getParameters().get(3);
+ arg4 = methodinfo.elem.getParameters().get(4);
+ code.addStatement("initializeNonVolatileEntity($1L, $2L, $3L, $4L)", arg0, arg1, arg2, arg4);
+ code.beginControlFlow("if (0L == $1L)", arg3);
+ code.addStatement("throw new RetrieveNonVolatileEntityError(\"Input handler is null on $1N.\")", name);
+ code.endControlFlow();
+ code.addStatement("$1N = $2N.retrieveChunk($3L, $4N)", holdername, allocname, arg3, autoreclaimname);
+ code.beginControlFlow("if (null == $1N)", holdername);
+ code.addStatement("throw new RetrieveNonVolatileEntityError(\"Retrieve Entity Failure!\")");
+ code.endControlFlow();
+ code.addStatement("initializeAfterRestore()");
+ break;
+ default:
+ throw new AnnotationProcessingException(null, "Method %s is not supported.", name);
+ }
+ typespecbuilder.addMethod(methodinfo.specbuilder.addCode(code.build()).build());
}
-
- protected void buildEntityMethodSpecs(TypeSpec.Builder typespecbuilder) throws AnnotationProcessingException {
- MethodInfo methodinfo;
- CodeBlock.Builder code;
- FieldInfo dynfieldinfo;
- VariableElement arg0, arg1, arg2, arg3, arg4;
- String unsafename = m_fieldsinfo.get("unsafe").name;
- String holdername = m_fieldsinfo.get("holder").name;
- String allocname = m_fieldsinfo.get("allocator").name;
- String autoreclaimname = m_fieldsinfo.get("autoreclaim").name;
- String factoryproxyname = m_fieldsinfo.get("factoryproxy").name;
- String genericfieldname = m_fieldsinfo.get("genericfield").name;
- for (String name : m_entitymtdinfo.keySet()) {
- methodinfo = m_entitymtdinfo.get(name);
- code = CodeBlock.builder();
- arg0 = methodinfo.elem.getParameters().get(0);
- arg1 = methodinfo.elem.getParameters().get(1);
- arg2 = methodinfo.elem.getParameters().get(2);
- switch(name) {
- case "initializeNonVolatileEntity" :
- arg3 = methodinfo.elem.getParameters().get(3);
- code.addStatement("$1N = $2L", allocname, arg0);
- code.addStatement("$1N = $2L", factoryproxyname, arg1);
- code.addStatement("$1N = $2L", genericfieldname, arg2);
- code.addStatement("$1N = $2L", autoreclaimname, arg3);
- code.beginControlFlow("try");
- code.addStatement("$1N = $2T.getUnsafe()", unsafename, Utils.class);
- code.nextControlFlow("catch (Exception e)");
- code.addStatement("e.printStackTrace()");
- code.endControlFlow();
- break;
- case "createNonVolatileEntity" :
- arg3 = methodinfo.elem.getParameters().get(3);
- code.addStatement("initializeNonVolatileEntity($1L, $2L, $3L, $4L)", arg0, arg1, arg2, arg3);
- code.addStatement("$1N = $2N.createChunk($3L, $4N)",
- holdername, allocname, m_holdersize, autoreclaimname);
- code.beginControlFlow("if (null == $1N)", holdername);
- code.addStatement("throw new OutOfPersistentMemory(\"Create Non-Volatile Entity Error!\")");
- code.endControlFlow();
- // code.beginControlFlow("try");
- // for (String fname : m_dynfieldsinfo.keySet()) {
- // dynfieldinfo = m_dynfieldsinfo.get(fname);
- // if (isUnboxPrimitive(dynfieldinfo.type)) {
- // code.addStatement("$1N($2L)", gsetterName(fname, false), getIntialValueLiteral(dynfieldinfo.type));
- // } else {
- // code.addStatement("$1N(null, false)", gsetterName(fname, false));
- // }
- // }
- // code.nextControlFlow("catch(RetrieveNonVolatileEntityError ex)");
- // code.endControlFlow();
- code.addStatement("initializeAfterCreate()");
- break;
- case "restoreNonVolatileEntity" :
- arg3 = methodinfo.elem.getParameters().get(3);
- arg4 = methodinfo.elem.getParameters().get(4);
- code.addStatement("initializeNonVolatileEntity($1L, $2L, $3L, $4L)", arg0, arg1, arg2, arg4);
- code.beginControlFlow("if (0L == $1L)", arg3);
- code.addStatement("throw new RetrieveNonVolatileEntityError(\"Input handler is null on $1N.\")", name);
- code.endControlFlow();
- code.addStatement("$1N = $2N.retrieveChunk($3L, $4N)",
- holdername, allocname, arg3, autoreclaimname);
- code.beginControlFlow("if (null == $1N)", holdername);
- code.addStatement("throw new RetrieveNonVolatileEntityError(\"Retrieve Entity Failure!\")");
- code.endControlFlow();
- code.addStatement("initializeAfterRestore()");
- break;
- default:
- throw new AnnotationProcessingException(null, "Method %s is not supported.",
- name);
- }
- typespecbuilder.addMethod(methodinfo.specbuilder.addCode(code.build()).build());
- }
+ }
+
+ protected void buildFieldSpecs(TypeSpec.Builder typespecbuilder, Map<String, FieldInfo> fieldinfos) {
+ FieldInfo fieldinfo;
+ for (String name : fieldinfos.keySet()) {
+ fieldinfo = fieldinfos.get(name);
+ if (null != fieldinfo.specbuilder) {
+ typespecbuilder.addField(fieldinfo.specbuilder.build());
+ }
}
-
- protected void buildFieldSpecs(TypeSpec.Builder typespecbuilder, Map<String, FieldInfo> fieldinfos) {
- FieldInfo fieldinfo;
- for (String name : fieldinfos.keySet()) {
- fieldinfo = fieldinfos.get(name);
- if (null != fieldinfo.specbuilder) {
- typespecbuilder.addField(fieldinfo.specbuilder.build());
- }
- }
+ }
+
+ protected void buildFactoryMethodSpecs(TypeSpec entityspec, TypeSpec.Builder typespecbuilder)
+ throws AnnotationProcessingException {
+ MethodSpec methodspec;
+ CodeBlock code;
+
+ TypeName entitytn = ParameterizedTypeName.get(ClassName.get(m_packagename, m_entityname),
+ entityspec.typeVariables.toArray(new TypeVariableName[0]));
+
+ ParameterSpec allocparam = ParameterSpec.builder(m_alloctypename, "allocator").build();
+ code = CodeBlock.builder().addStatement("return create($1L, false)", allocparam.name).build();
+ methodspec = MethodSpec.methodBuilder("create").addTypeVariables(entityspec.typeVariables)
+ .addException(OutOfPersistentMemory.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
+ .returns(TypeName.get(m_elem.asType())).addParameter(allocparam).addCode(code).build();
+ typespecbuilder.addMethod(methodspec);
+
+ ParameterSpec autoreclaimparam = ParameterSpec.builder(TypeName.BOOLEAN, "autoreclaim").build();
+ code = CodeBlock.builder()
+ .addStatement("return create($1L, null, null, $2L)", allocparam.name, autoreclaimparam.name).build();
+ methodspec = MethodSpec.methodBuilder("create").addTypeVariables(entityspec.typeVariables)
+ .addException(OutOfPersistentMemory.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
+ .returns(TypeName.get(m_elem.asType())).addParameter(allocparam).addParameter(autoreclaimparam).addCode(code)
+ .build();
+ typespecbuilder.addMethod(methodspec);
+
+ ParameterSpec factoryproxysparam = ParameterSpec.builder(m_factoryproxystypename, "factoryproxys").build();
+ ParameterSpec gfieldsparam = ParameterSpec.builder(m_gfieldstypename, "gfields").build();
+ code = CodeBlock.builder().addStatement("$1T entity = new $1T()", entitytn)
+ .addStatement("entity.setupGenericInfo($1N, $2N)", factoryproxysparam.name, gfieldsparam.name)
+ .addStatement("entity.createNonVolatileEntity($1L, $2L, $3L, $4L)", allocparam.name, factoryproxysparam.name,
+ gfieldsparam.name, autoreclaimparam.name)
+ .addStatement("return entity").build();
+ methodspec = MethodSpec.methodBuilder("create").addTypeVariables(entityspec.typeVariables)
+ .addException(OutOfPersistentMemory.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
+ .returns(TypeName.get(m_elem.asType())).addParameter(allocparam).addParameter(factoryproxysparam)
+ .addParameter(gfieldsparam).addParameter(autoreclaimparam).addCode(code).build();
+ typespecbuilder.addMethod(methodspec);
+
+ ParameterSpec phandlerparam = ParameterSpec.builder(TypeName.LONG, "phandler").build();
+ code = CodeBlock.builder().addStatement("return restore($1L, $2L, false)", allocparam.name, phandlerparam.name)
+ .build();
+ methodspec = MethodSpec.methodBuilder("restore").addTypeVariables(entityspec.typeVariables)
+ .addException(RetrieveNonVolatileEntityError.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
+ .returns(TypeName.get(m_elem.asType())).addParameter(allocparam).addParameter(phandlerparam).addCode(code)
+ .build();
+ typespecbuilder.addMethod(methodspec);
+
+ code = CodeBlock.builder().addStatement("return restore($1L, null, null, $2L, $3L)", allocparam.name,
+ phandlerparam.name, autoreclaimparam.name).build();
+ methodspec = MethodSpec.methodBuilder("restore").addTypeVariables(entityspec.typeVariables)
+ .addException(RetrieveNonVolatileEntityError.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
+ .returns(TypeName.get(m_elem.asType())).addParameter(allocparam).addParameter(phandlerparam)
+ .addParameter(autoreclaimparam).addCode(code).build();
+ typespecbuilder.addMethod(methodspec);
+
+ code = CodeBlock.builder().addStatement("$1T entity = new $1T()", entitytn)
+ .addStatement("entity.setupGenericInfo($1N, $2N)", factoryproxysparam.name, gfieldsparam.name)
+ .addStatement("entity.restoreNonVolatileEntity($1L, $2L, $3L, $4L, $5L)", allocparam.name,
+ factoryproxysparam.name, gfieldsparam.name, phandlerparam.name, autoreclaimparam.name)
+ .addStatement("return entity").build();
+ methodspec = MethodSpec.methodBuilder("restore").addTypeVariables(entityspec.typeVariables)
+ .addException(RetrieveNonVolatileEntityError.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
+ .returns(TypeName.get(m_elem.asType())).addParameter(allocparam).addParameter(factoryproxysparam)
+ .addParameter(gfieldsparam).addParameter(phandlerparam).addParameter(autoreclaimparam).addCode(code).build();
+ typespecbuilder.addMethod(methodspec);
+ }
+
+ public void generateCode(Filer filer) throws IOException, AnnotationProcessingException {
+ AnnotationSpec classannotation = AnnotationSpec.builder(SuppressWarnings.class)
+ .addMember("value", "$S", "restriction").build();
+
+ TypeSpec.Builder entitybuilder = TypeSpec.classBuilder(m_entityname).superclass(TypeName.get(m_elem.asType()))
+ .addModifiers(Modifier.PUBLIC).addAnnotation(classannotation)
+ .addSuperinterface(ParameterizedTypeName.get(ClassName.get(MemoryNonVolatileEntity.class), m_alloctypevarname))
+ .addTypeVariable(m_alloctypevarname);
+
+ for (TypeParameterElement tpe : m_elem.getTypeParameters()) {
+ entitybuilder.addTypeVariable(TypeVariableName.get(tpe));
+ }
+
+ buildFieldSpecs(entitybuilder, m_dynfieldsinfo);
+ buildFieldSpecs(entitybuilder, m_fieldsinfo);
+
+ buildGettersSpecs(entitybuilder);
+ buildSettersSpecs(entitybuilder);
+
+ buildDurableMethodSpecs(entitybuilder);
+ buildEntityMethodSpecs(entitybuilder);
+
+ TypeSpec entityspec = entitybuilder.build();
+
+ JavaFile entityFile = JavaFile.builder(m_packagename, entityspec).build();
+
+ entityFile.writeTo(filer);
+
+ TypeSpec.Builder factorybuilder = TypeSpec.classBuilder(m_factoryname).addModifiers(Modifier.PUBLIC);
+
+ buildFactoryMethodSpecs(entityspec, factorybuilder);
+
+ JavaFile factoryFile = JavaFile.builder(m_packagename, factorybuilder.build()).build();
+
+ factoryFile.writeTo(filer);
+
+ }
+
+ public static Builder overriding(ExecutableElement method, String varname) {
+
+ Set<Modifier> modifiers = method.getModifiers();
+ if (modifiers.contains(Modifier.PRIVATE) || modifiers.contains(Modifier.FINAL)
+ || modifiers.contains(Modifier.STATIC)) {
+ throw new IllegalArgumentException("cannot override method with modifiers: " + modifiers);
}
-
- protected void buildFactoryMethodSpecs(TypeSpec entityspec, TypeSpec.Builder typespecbuilder) throws AnnotationProcessingException {
- MethodSpec methodspec;
- CodeBlock code;
-
- TypeName entitytn= ParameterizedTypeName.get(ClassName.get(m_packagename, m_entityname), entityspec.typeVariables.toArray(new TypeVariableName[0]));
-
- ParameterSpec allocparam = ParameterSpec.builder(m_alloctypename, "allocator").build();
- code = CodeBlock.builder()
- .addStatement("return create($1L, false)", allocparam.name)
- .build();
- methodspec = MethodSpec.methodBuilder("create")
- .addTypeVariables(entityspec.typeVariables)
- .addException(OutOfPersistentMemory.class)
- .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
- .returns(TypeName.get(m_elem.asType()))
- .addParameter(allocparam)
- .addCode(code).build();
- typespecbuilder.addMethod(methodspec);
-
- ParameterSpec autoreclaimparam = ParameterSpec.builder(TypeName.BOOLEAN, "autoreclaim").build();
- code = CodeBlock.builder()
- .addStatement("return create($1L, null, null, $2L)", allocparam.name, autoreclaimparam.name)
- .build();
- methodspec = MethodSpec.methodBuilder("create")
- .addTypeVariables(entityspec.typeVariables)
- .addException(OutOfPersistentMemory.class)
- .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
- .returns(TypeName.get(m_elem.asType()))
- .addParameter(allocparam)
- .addParameter(autoreclaimparam)
- .addCode(code).build();
- typespecbuilder.addMethod(methodspec);
-
- ParameterSpec factoryproxysparam = ParameterSpec.builder(m_factoryproxystypename, "factoryproxys").build();
- ParameterSpec gfieldsparam = ParameterSpec.builder(m_gfieldstypename, "gfields").build();
- code = CodeBlock.builder()
- .addStatement("$1T entity = new $1T()", entitytn)
- .addStatement("entity.setupGenericInfo($1N, $2N)", factoryproxysparam.name, gfieldsparam.name)
- .addStatement("entity.createNonVolatileEntity($1L, $2L, $3L, $4L)",
- allocparam.name, factoryproxysparam.name, gfieldsparam.name, autoreclaimparam.name)
- .addStatement("return entity")
- .build();
- methodspec = MethodSpec.methodBuilder("create")
- .addTypeVariables(entityspec.typeVariables)
- .addException(OutOfPersistentMemory.class)
- .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
- .returns(TypeName.get(m_elem.asType()))
- .addParameter(allocparam)
- .addParameter(factoryproxysparam)
- .addParameter(gfieldsparam)
- .addParameter(autoreclaimparam)
- .addCode(code).build();
- typespecbuilder.addMethod(methodspec);
-
- ParameterSpec phandlerparam = ParameterSpec.builder(TypeName.LONG, "phandler").build();
- code = CodeBlock.builder()
- .addStatement("return restore($1L, $2L, false)", allocparam.name, phandlerparam.name)
- .build();
- methodspec = MethodSpec.methodBuilder("restore")
- .addTypeVariables(entityspec.typeVariables)
- .addException(RetrieveNonVolatileEntityError.class)
- .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
- .returns(TypeName.get(m_elem.asType()))
- .addParameter(allocparam)
- .addParameter(phandlerparam)
- .addCode(code).build();
- typespecbuilder.addMethod(methodspec);
-
- code = CodeBlock.builder()
- .addStatement("return restore($1L, null, null, $2L, $3L)", allocparam.name, phandlerparam.name, autoreclaimparam.name)
- .build();
- methodspec = MethodSpec.methodBuilder("restore")
- .addTypeVariables(entityspec.typeVariables)
- .addException(RetrieveNonVolatileEntityError.class)
- .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
- .returns(TypeName.get(m_elem.asType()))
- .addParameter(allocparam)
- .addParameter(phandlerparam)
- .addParameter(autoreclaimparam)
- .addCode(code).build();
- typespecbuilder.addMethod(methodspec);
-
- code = CodeBlock.builder()
- .addStatement("$1T entity = new $1T()", entitytn)
- .addStatement("entity.setupGenericInfo($1N, $2N)", factoryproxysparam.name, gfieldsparam.name)
- .addStatement("entity.restoreNonVolatileEntity($1L, $2L, $3L, $4L, $5L)",
- allocparam.name, factoryproxysparam.name, gfieldsparam.name, phandlerparam.name, autoreclaimparam.name)
- .addStatement("return entity")
- .build();
- methodspec = MethodSpec.methodBuilder("restore")
- .addTypeVariables(entityspec.typeVariables)
- .addException(RetrieveNonVolatileEntityError.class)
- .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
- .returns(TypeName.get(m_elem.asType()))
- .addParameter(allocparam)
- .addParameter(factoryproxysparam)
- .addParameter(gfieldsparam)
- .addParameter(phandlerparam)
- .addParameter(autoreclaimparam)
- .addCode(code).build();
- typespecbuilder.addMethod(methodspec);
+
+ String methodName = method.getSimpleName().toString();
+ MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(methodName);
+
+ methodBuilder.addAnnotation(Override.class);
+ for (AnnotationMirror mirror : method.getAnnotationMirrors()) {
+ AnnotationSpec annotationSpec = AnnotationSpec.get(mirror);
+ if (annotationSpec.type.equals(Override.class))
+ continue;
+ methodBuilder.addAnnotation(annotationSpec);
}
- public void generateCode(Filer filer) throws IOException, AnnotationProcessingException {
- AnnotationSpec classannotation = AnnotationSpec.builder(SuppressWarnings.class)
- .addMember("value", "$S", "restriction").build();
-
- TypeSpec.Builder entitybuilder = TypeSpec.classBuilder(m_entityname)
- .superclass(TypeName.get(m_elem.asType()))
- .addModifiers(Modifier.PUBLIC).addAnnotation(classannotation)
- .addSuperinterface(
- ParameterizedTypeName.get(ClassName.get(MemoryNonVolatileEntity.class), m_alloctypevarname))
- .addTypeVariable(m_alloctypevarname);
-
- for (TypeParameterElement tpe : m_elem.getTypeParameters()) {
- entitybuilder.addTypeVariable(TypeVariableName.get(tpe));
- }
-
- buildFieldSpecs(entitybuilder, m_dynfieldsinfo);
- buildFieldSpecs(entitybuilder, m_fieldsinfo);
-
- buildGettersSpecs(entitybuilder);
- buildSettersSpecs(entitybuilder);
-
- buildDurableMethodSpecs(entitybuilder);
- buildEntityMethodSpecs(entitybuilder);
-
- TypeSpec entityspec = entitybuilder.build();
-
- JavaFile entityFile = JavaFile
- .builder(m_packagename, entityspec).build();
-
- entityFile.writeTo(filer);
-
- TypeSpec.Builder factorybuilder = TypeSpec.classBuilder(m_factoryname)
- .addModifiers(Modifier.PUBLIC);
-
- buildFactoryMethodSpecs(entityspec, factorybuilder);
-
- JavaFile factoryFile = JavaFile
- .builder(m_packagename, factorybuilder.build()).build();
-
- factoryFile.writeTo(filer);
+ modifiers = new LinkedHashSet<>(modifiers);
+ modifiers.remove(Modifier.ABSTRACT);
+ methodBuilder.addModifiers(modifiers);
+ for (TypeParameterElement typeParameterElement : method.getTypeParameters()) {
+ TypeVariable var = (TypeVariable) typeParameterElement.asType();
+ methodBuilder.addTypeVariable(TypeVariableName.get(var));
}
- public static Builder overriding(ExecutableElement method, String varname) {
-
- Set<Modifier> modifiers = method.getModifiers();
- if (modifiers.contains(Modifier.PRIVATE) || modifiers.contains(Modifier.FINAL)
- || modifiers.contains(Modifier.STATIC)) {
- throw new IllegalArgumentException("cannot override method with modifiers: " + modifiers);
- }
-
- String methodName = method.getSimpleName().toString();
- MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(methodName);
-
- methodBuilder.addAnnotation(Override.class);
- for (AnnotationMirror mirror : method.getAnnotationMirrors()) {
- AnnotationSpec annotationSpec = AnnotationSpec.get(mirror);
- if (annotationSpec.type.equals(Override.class))
- continue;
- methodBuilder.addAnnotation(annotationSpec);
- }
-
- modifiers = new LinkedHashSet<>(modifiers);
- modifiers.remove(Modifier.ABSTRACT);
- methodBuilder.addModifiers(modifiers);
-
- for (TypeParameterElement typeParameterElement : method.getTypeParameters()) {
- TypeVariable var = (TypeVariable) typeParameterElement.asType();
- methodBuilder.addTypeVariable(TypeVariableName.get(var));
- }
-
- methodBuilder.returns(TypeName.get(method.getReturnType()));
-
- List<? extends VariableElement> parameters = method.getParameters();
- TypeName type;
- for (VariableElement parameter : parameters) {
- if (parameter.asType().getKind() == TypeKind.TYPEVAR && parameter.asType().toString().equals(varname)) {
- type = TypeVariableName.get(varname);
- } else {
- type = TypeName.get(parameter.asType());
- }
-
- String name = parameter.getSimpleName().toString();
- Set<Modifier> parameterModifiers = parameter.getModifiers();
- ParameterSpec.Builder parameterBuilder = ParameterSpec.builder(type, name)
- .addModifiers(parameterModifiers.toArray(new Modifier[parameterModifiers.size()]));
- for (AnnotationMirror mirror : parameter.getAnnotationMirrors()) {
- parameterBuilder.addAnnotation(AnnotationSpec.get(mirror));
- }
- methodBuilder.addParameter(parameterBuilder.build());
- }
- methodBuilder.varargs(method.isVarArgs());
-
- for (TypeMirror thrownType : method.getThrownTypes()) {
- methodBuilder.addException(TypeName.get(thrownType));
- }
-
- return methodBuilder;
+ methodBuilder.returns(TypeName.get(method.getReturnType()));
+
+ List<? extends VariableElement> parameters = method.getParameters();
+ TypeName type;
+ for (VariableElement parameter : parameters) {
+ if (parameter.asType().getKind() == TypeKind.TYPEVAR && parameter.asType().toString().equals(varname)) {
+ type = TypeVariableName.get(varname);
+ } else {
+ type = TypeName.get(parameter.asType());
+ }
+
+ String name = parameter.getSimpleName().toString();
+ Set<Modifier> parameterModifiers = parameter.getModifiers();
+ ParameterSpec.Builder parameterBuilder = ParameterSpec.builder(type, name)
+ .addModifiers(parameterModifiers.toArray(new Modifier[parameterModifiers.size()]));
+ for (AnnotationMirror mirror : parameter.getAnnotationMirrors()) {
+ parameterBuilder.addAnnotation(AnnotationSpec.get(mirror));
+ }
+ methodBuilder.addParameter(parameterBuilder.build());
}
+ methodBuilder.varargs(method.isVarArgs());
+
+ for (TypeMirror thrownType : method.getThrownTypes()) {
+ methodBuilder.addException(TypeName.get(thrownType));
+ }
+
+ return methodBuilder;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/AnnotationProcessingException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/AnnotationProcessingException.java b/core/src/main/java/org/apache/mnemonic/AnnotationProcessingException.java
index 83b42fe..d454b22 100644
--- a/core/src/main/java/org/apache/mnemonic/AnnotationProcessingException.java
+++ b/core/src/main/java/org/apache/mnemonic/AnnotationProcessingException.java
@@ -1,23 +1,40 @@
+/*
+ * 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.mnemonic;
import javax.lang.model.element.Element;
/**
- * this exception is used for non-volatile annotation processing
+ * this exception is used for non-volatile annotation processing
*
*/
public class AnnotationProcessingException extends Exception {
- private static final long serialVersionUID = 6911141027622831646L;
+ private static final long serialVersionUID = 6911141027622831646L;
- private Element element;
+ private Element element;
- public AnnotationProcessingException(Element element, String msg, Object... args) {
- super(String.format(msg, args));
- this.element = element;
- }
+ public AnnotationProcessingException(Element element, String msg, Object... args) {
+ super(String.format(msg, args));
+ this.element = element;
+ }
- public Element getElement() {
- return element;
- }
+ public Element getElement() {
+ return element;
+ }
}
[4/7] incubator-mnemonic git commit: format codestyle & add Apache
License
Posted by ga...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/BigDataMemAllocator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/BigDataMemAllocator.java b/core/src/main/java/org/apache/mnemonic/BigDataMemAllocator.java
index 3ed3181..f81a304 100644
--- a/core/src/main/java/org/apache/mnemonic/BigDataMemAllocator.java
+++ b/core/src/main/java/org/apache/mnemonic/BigDataMemAllocator.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import java.nio.ByteBuffer;
@@ -7,260 +24,255 @@ import org.flowcomputing.commons.primitives.*;
import org.apache.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService;
/**
- * manage a big native memory pool through libvmem.so that is provied by Intel nvml library.
+ * manage a big native memory pool through libvmem.so that is provied by Intel
+ * nvml library.
*
*
*/
public class BigDataMemAllocator extends CommonAllocator<BigDataMemAllocator> {
- private boolean m_activegc = true;
- private long m_gctimeout = 100;
- private long m_nid = -1;
- private VolatileMemoryAllocatorService m_vmasvc = null;
-
- /**
- * Constructor, it initializes and allocate a memory pool from specified uri
- * location with specified capacity and an allocator service instance.
- * usually, the uri points to a mounted
- * memory device or a location of file system.
- *
- * @param vmasvc
- * the volatile memory allocation service instance
- *
- * @param capacity
- * the capacity of memory pool
- *
- * @param uri
- * the location of memory pool will be created
- *
- * @param isnew
- * a place holder, always specify it as true
- */
- public BigDataMemAllocator(VolatileMemoryAllocatorService vmasvc, long capacity, String uri, boolean isnew) {
- assert null != vmasvc : "VolatileMemoryAllocatorService object is null";
- if (capacity <= 0) {
- throw new IllegalArgumentException("BigDataMemAllocator cannot be initialized with capacity <= 0.");
- }
-
- m_vmasvc = vmasvc;
- m_nid = m_vmasvc.init(capacity, uri, isnew);
-
- /**
- * create a resource collector to release specified bytebuffer that backed
- * by underlying big memory pool.
- */
- m_bufcollector = new ResCollector<MemBufferHolder<BigDataMemAllocator>, ByteBuffer>(
- new ResReclaim<ByteBuffer>() {
- @Override
- public void reclaim(ByteBuffer mres) {
- boolean cb_reclaimed = false;
- if (null != m_bufferreclaimer) {
- cb_reclaimed = m_bufferreclaimer.reclaim(mres, Long.valueOf(mres.capacity()));
- }
- if (!cb_reclaimed) {
- m_vmasvc.destroyByteBuffer(m_nid, mres);
- mres = null;
- }
- }
- });
+ private boolean m_activegc = true;
+ private long m_gctimeout = 100;
+ private long m_nid = -1;
+ private VolatileMemoryAllocatorService m_vmasvc = null;
- /**
- * create a resource collector to release specified chunk that backed by
- * underlying big memory pool.
- */
- m_chunkcollector = new ResCollector<MemChunkHolder<BigDataMemAllocator>, Long>(
- new ResReclaim<Long>() {
- @Override
- public void reclaim(Long mres) {
- // System.out.println(String.format("Reclaim: %X", mres));
- boolean cb_reclaimed = false;
- if (null != m_chunkreclaimer) {
- cb_reclaimed = m_chunkreclaimer.reclaim(mres, null);
- }
- if (!cb_reclaimed) {
- m_vmasvc.free(m_nid, mres);
- mres = null;
- }
- }
- });
+ /**
+ * Constructor, it initializes and allocate a memory pool from specified uri
+ * location with specified capacity and an allocator service instance.
+ * usually, the uri points to a mounted memory device or a location of file
+ * system.
+ *
+ * @param vmasvc
+ * the volatile memory allocation service instance
+ *
+ * @param capacity
+ * the capacity of memory pool
+ *
+ * @param uri
+ * the location of memory pool will be created
+ *
+ * @param isnew
+ * a place holder, always specify it as true
+ */
+ public BigDataMemAllocator(VolatileMemoryAllocatorService vmasvc, long capacity, String uri, boolean isnew) {
+ assert null != vmasvc : "VolatileMemoryAllocatorService object is null";
+ if (capacity <= 0) {
+ throw new IllegalArgumentException("BigDataMemAllocator cannot be initialized with capacity <= 0.");
}
- /**
- * enable active garbage collection. the GC will be forced to collect garbages when
- * there is no more space for current allocation request.
- *
- * @param timeout
- * the timeout is used to yield for GC performing
- *
- * @return this allocator
- */
- @Override
- public BigDataMemAllocator enableActiveGC(long timeout) {
- m_activegc = true;
- m_gctimeout = timeout;
- return this;
- }
+ m_vmasvc = vmasvc;
+ m_nid = m_vmasvc.init(capacity, uri, isnew);
/**
- * disable active garbage collection.
- *
- * @return this allocator
+ * create a resource collector to release specified bytebuffer that backed
+ * by underlying big memory pool.
*/
- @Override
- public BigDataMemAllocator disableActiveGC() {
- m_activegc = false;
- return this;
- }
+ m_bufcollector = new ResCollector<MemBufferHolder<BigDataMemAllocator>, ByteBuffer>(new ResReclaim<ByteBuffer>() {
+ @Override
+ public void reclaim(ByteBuffer mres) {
+ boolean cb_reclaimed = false;
+ if (null != m_bufferreclaimer) {
+ cb_reclaimed = m_bufferreclaimer.reclaim(mres, Long.valueOf(mres.capacity()));
+ }
+ if (!cb_reclaimed) {
+ m_vmasvc.destroyByteBuffer(m_nid, mres);
+ mres = null;
+ }
+ }
+ });
/**
- * release the memory pool and close it.
- *
+ * create a resource collector to release specified chunk that backed by
+ * underlying big memory pool.
*/
- @Override
- public void close() {
- super.close();
+ m_chunkcollector = new ResCollector<MemChunkHolder<BigDataMemAllocator>, Long>(new ResReclaim<Long>() {
+ @Override
+ public void reclaim(Long mres) {
+ // System.out.println(String.format("Reclaim: %X", mres));
+ boolean cb_reclaimed = false;
+ if (null != m_chunkreclaimer) {
+ cb_reclaimed = m_chunkreclaimer.reclaim(mres, null);
+ }
+ if (!cb_reclaimed) {
+ m_vmasvc.free(m_nid, mres);
+ mres = null;
+ }
+ }
+ });
+ }
+
+ /**
+ * enable active garbage collection. the GC will be forced to collect garbages
+ * when there is no more space for current allocation request.
+ *
+ * @param timeout
+ * the timeout is used to yield for GC performing
+ *
+ * @return this allocator
+ */
+ @Override
+ public BigDataMemAllocator enableActiveGC(long timeout) {
+ m_activegc = true;
+ m_gctimeout = timeout;
+ return this;
+ }
+
+ /**
+ * disable active garbage collection.
+ *
+ * @return this allocator
+ */
+ @Override
+ public BigDataMemAllocator disableActiveGC() {
+ m_activegc = false;
+ return this;
+ }
+
+ /**
+ * release the memory pool and close it.
+ *
+ */
+ @Override
+ public void close() {
+ super.close();
+ }
+
+ /**
+ * force to synchronize uncommitted data to backed memory pool (this is a
+ * placeholder).
+ *
+ */
+ @Override
+ public void sync() {
+ }
+
+ /**
+ * re-size a specified chunk on its backed memory pool.
+ *
+ * @param mholder
+ * the holder of memory chunk. it can be null.
+ *
+ * @param size
+ * specify a new size of memory chunk
+ *
+ * @return the resized memory chunk handler
+ */
+ @Override
+ public MemChunkHolder<BigDataMemAllocator> resizeChunk(MemChunkHolder<BigDataMemAllocator> mholder, long size) {
+ MemChunkHolder<BigDataMemAllocator> ret = null;
+ boolean ac = null != mholder.getRefId();
+ if (size > 0) {
+ Long addr = m_vmasvc.reallocate(m_nid, mholder.get(), size, true);
+ if (0 == addr && m_activegc) {
+ m_chunkcollector.waitReclaimCoolDown(m_gctimeout);
+ addr = m_vmasvc.reallocate(m_nid, mholder.get(), size, true);
+ }
+ if (0 != addr) {
+ mholder.clear();
+ mholder.destroy();
+ ret = new MemChunkHolder<BigDataMemAllocator>(this, addr, size);
+ if (ac) {
+ m_chunkcollector.register(ret);
+ }
+ }
}
+ return ret;
+ }
- /**
- * force to synchronize uncommitted data to backed memory pool
- * (this is a placeholder).
- *
- */
- @Override
- public void sync() {
+ /**
+ * resize a specified buffer on its backed memory pool.
+ *
+ * @param mholder
+ * the holder of memory buffer. it can be null.
+ *
+ * @param size
+ * specify a new size of memory chunk
+ *
+ * @return the resized memory buffer handler
+ *
+ */
+ @Override
+ public MemBufferHolder<BigDataMemAllocator> resizeBuffer(MemBufferHolder<BigDataMemAllocator> mholder, long size) {
+ MemBufferHolder<BigDataMemAllocator> ret = null;
+ boolean ac = null != mholder.getRefId();
+ if (size > 0) {
+ int bufpos = mholder.get().position();
+ int buflimit = mholder.get().limit();
+ ByteBuffer buf = m_vmasvc.resizeByteBuffer(m_nid, mholder.get(), size);
+ if (null == buf && m_activegc) {
+ m_bufcollector.waitReclaimCoolDown(m_gctimeout);
+ buf = m_vmasvc.resizeByteBuffer(m_nid, mholder.get(), size);
+ }
+ if (null != buf) {
+ mholder.clear();
+ mholder.destroy();
+ buf.position(bufpos <= size ? bufpos : 0);
+ buf.limit(buflimit <= size ? buflimit : (int) size);
+ ret = new MemBufferHolder<BigDataMemAllocator>(this, buf);
+ if (ac) {
+ m_bufcollector.register(ret);
+ }
+ }
}
+ return ret;
+ }
- /**
- * re-size a specified chunk on its backed memory pool.
- *
- * @param mholder
- * the holder of memory chunk. it can be
- * null.
- *
- * @param size
- * specify a new size of memory chunk
- *
- * @return the resized memory chunk handler
- */
- @Override
- public MemChunkHolder<BigDataMemAllocator> resizeChunk(MemChunkHolder<BigDataMemAllocator> mholder, long size){
- MemChunkHolder<BigDataMemAllocator> ret = null;
- boolean ac = null != mholder.getRefId();
- if (size > 0) {
- Long addr = m_vmasvc.reallocate(m_nid, mholder.get(), size, true);
- if (0 == addr && m_activegc) {
- m_chunkcollector.waitReclaimCoolDown(m_gctimeout);
- addr = m_vmasvc.reallocate(m_nid, mholder.get(), size, true);
- }
- if (0 != addr) {
- mholder.clear();
- mholder.destroy();
- ret = new MemChunkHolder<BigDataMemAllocator>(this, addr, size);
- if (ac) {
- m_chunkcollector.register(ret);
- }
- }
- }
- return ret;
+ /**
+ * create a memory chunk that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory chunk
+ *
+ * @param autoreclaim
+ * specify whether or not to reclaim this chunk automatically
+ *
+ * @return a holder contains a memory chunk
+ */
+ @Override
+ public MemChunkHolder<BigDataMemAllocator> createChunk(long size, boolean autoreclaim) {
+ MemChunkHolder<BigDataMemAllocator> ret = null;
+ Long addr = m_vmasvc.allocate(m_nid, size, true);
+ if (0 == addr && m_activegc) {
+ m_chunkcollector.waitReclaimCoolDown(m_gctimeout);
+ addr = m_vmasvc.allocate(m_nid, size, true);
}
-
- /**
- * resize a specified buffer on its backed memory pool.
- *
- * @param mholder
- * the holder of memory buffer. it can be
- * null.
- *
- * @param size
- * specify a new size of memory chunk
- *
- * @return the resized memory buffer handler
- *
- */
- @Override
- public MemBufferHolder<BigDataMemAllocator> resizeBuffer(MemBufferHolder<BigDataMemAllocator> mholder, long size) {
- MemBufferHolder<BigDataMemAllocator> ret = null;
- boolean ac = null != mholder.getRefId();
- if (size > 0) {
- int bufpos = mholder.get().position();
- int buflimit = mholder.get().limit();
- ByteBuffer buf = m_vmasvc.resizeByteBuffer(m_nid, mholder.get(), size);
- if (null == buf && m_activegc) {
- m_bufcollector.waitReclaimCoolDown(m_gctimeout);
- buf = m_vmasvc.resizeByteBuffer(m_nid, mholder.get(), size);
- }
- if (null != buf) {
- mholder.clear();
- mholder.destroy();
- buf.position(bufpos <= size ? bufpos : 0);
- buf.limit(buflimit <= size ? buflimit : (int)size);
- ret = new MemBufferHolder<BigDataMemAllocator>(this, buf);
- if (ac) {
- m_bufcollector.register(ret);
- }
- }
- }
- return ret;
+ if (0 != addr) {
+ ret = new MemChunkHolder<BigDataMemAllocator>(this, addr, size);
+ ret.setCollector(m_chunkcollector);
+ if (autoreclaim) {
+ m_chunkcollector.register(ret);
+ }
}
+ return ret;
+ }
- /**
- * create a memory chunk that is managed by its holder.
- *
- * @param size
- * specify the size of memory chunk
- *
- * @param autoreclaim
- * specify whether or not to reclaim this
- * chunk automatically
- *
- * @return a holder contains a memory chunk
- */
- @Override
- public MemChunkHolder<BigDataMemAllocator> createChunk(long size, boolean autoreclaim) {
- MemChunkHolder<BigDataMemAllocator> ret = null;
- Long addr = m_vmasvc.allocate(m_nid, size, true);
- if (0 == addr && m_activegc) {
- m_chunkcollector.waitReclaimCoolDown(m_gctimeout);
- addr = m_vmasvc.allocate(m_nid, size, true);
- }
- if (0 != addr) {
- ret = new MemChunkHolder<BigDataMemAllocator>(this, addr, size);
- ret.setCollector(m_chunkcollector);
- if (autoreclaim) {
- m_chunkcollector.register(ret);
- }
- }
- return ret;
+ /**
+ * create a memory buffer that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory buffer
+ *
+ * @param autoreclaim
+ * specify whether or not to reclaim this buffer automatically
+ *
+ * @return a holder contains a memory buffer
+ */
+ @Override
+ public MemBufferHolder<BigDataMemAllocator> createBuffer(long size, boolean autoreclaim) {
+ MemBufferHolder<BigDataMemAllocator> ret = null;
+ ByteBuffer bb = m_vmasvc.createByteBuffer(m_nid, size);
+ if (null == bb && m_activegc) {
+ m_bufcollector.waitReclaimCoolDown(m_gctimeout);
+ bb = m_vmasvc.createByteBuffer(m_nid, size);
}
-
- /**
- * create a memory buffer that is managed by its holder.
- *
- * @param size
- * specify the size of memory buffer
- *
- * @param autoreclaim
- * specify whether or not to reclaim this
- * buffer automatically
- *
- * @return a holder contains a memory buffer
- */
- @Override
- public MemBufferHolder<BigDataMemAllocator> createBuffer(long size, boolean autoreclaim) {
- MemBufferHolder<BigDataMemAllocator> ret = null;
- ByteBuffer bb = m_vmasvc.createByteBuffer(m_nid, size);
- if (null == bb && m_activegc) {
- m_bufcollector.waitReclaimCoolDown(m_gctimeout);
- bb = m_vmasvc.createByteBuffer(m_nid, size);
- }
- if (null != bb) {
- ret = new MemBufferHolder<BigDataMemAllocator>(this, bb);
- ret.setCollector(m_bufcollector);
- if (autoreclaim) {
- m_bufcollector.register(ret);
- }
- }
- return ret;
+ if (null != bb) {
+ ret = new MemBufferHolder<BigDataMemAllocator>(this, bb);
+ ret.setCollector(m_bufcollector);
+ if (autoreclaim) {
+ m_bufcollector.register(ret);
+ }
}
+ return ret;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/BigDataPMemAllocator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/BigDataPMemAllocator.java b/core/src/main/java/org/apache/mnemonic/BigDataPMemAllocator.java
index a067309..99af1b7 100644
--- a/core/src/main/java/org/apache/mnemonic/BigDataPMemAllocator.java
+++ b/core/src/main/java/org/apache/mnemonic/BigDataPMemAllocator.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import java.nio.ByteBuffer;
@@ -7,449 +24,447 @@ import org.flowcomputing.commons.primitives.*;
import org.apache.mnemonic.service.allocatorservice.NonVolatileMemoryAllocatorService;
/**
- * manage a big native persistent memory pool through libpmalloc.so provided by pmalloc project.
+ * manage a big native persistent memory pool through libpmalloc.so provided by
+ * pmalloc project.
*
*
*/
-public class BigDataPMemAllocator extends CommonPersistAllocator<BigDataPMemAllocator> implements PMAddressTranslator{
+public class BigDataPMemAllocator extends CommonPersistAllocator<BigDataPMemAllocator> implements PMAddressTranslator {
- private boolean m_activegc = true;
- private long m_gctimeout = 100;
- private long m_nid = -1;
- private long b_addr = 0;
- private NonVolatileMemoryAllocatorService m_nvmasvc = null;
+ private boolean m_activegc = true;
+ private long m_gctimeout = 100;
+ private long m_nid = -1;
+ private long b_addr = 0;
+ private NonVolatileMemoryAllocatorService m_nvmasvc = null;
- /**
- * Constructor, it initializes and allocate a memory pool from specified uri
- * location with specified capacity and an allocator service instance.
- * usually, the uri points to a mounted
- * non-volatile memory device or a location of file system.
- *
- * @param nvmasvc
- * the non-volatile memory allocation service instance
- *
- * @param capacity
- * the capacity of memory pool
- *
- * @param uri
- * the location of memory pool will be created
- *
- * @param isnew
- * a place holder, always specify it as true
- */
- public BigDataPMemAllocator(NonVolatileMemoryAllocatorService nvmasvc, long capacity, String uri, boolean isnew) {
- assert null != nvmasvc : "NonVolatileMemoryAllocatorService object is null";
- if (capacity <= 0) {
- throw new IllegalArgumentException("BigDataPMemAllocator cannot be initialized with capacity <= 0.");
- }
-
- m_nvmasvc = nvmasvc;
-
- m_nid = m_nvmasvc.init(capacity, uri, isnew);
- b_addr = m_nvmasvc.getBaseAddress(m_nid);
-
- /**
- * create a resource collector to release specified chunk that backed by
- * underlying big memory pool.
- */
- m_chunkcollector = new ResCollector<MemChunkHolder<BigDataPMemAllocator>, Long>(new ResReclaim<Long>() {
- @Override
- public void reclaim(Long mres) {
- // System.out.println(String.format("Reclaim: %X", mres));
- boolean cb_reclaimed = false;
- if (null != m_chunkreclaimer) {
- cb_reclaimed = m_chunkreclaimer.reclaim(mres, null);
- }
- if (!cb_reclaimed) {
- m_nvmasvc.free(m_nid, mres);
- mres = null;
- }
- }
- });
-
- /**
- * create a resource collector to release specified bytebuffer that backed
- * by underlying big memory pool.
- */
- m_bufcollector = new ResCollector<MemBufferHolder<BigDataPMemAllocator>, ByteBuffer>(
- new ResReclaim<ByteBuffer>() {
- @Override
- public void reclaim(ByteBuffer mres) {
- boolean cb_reclaimed = false;
- if (null != m_bufferreclaimer) {
- cb_reclaimed = m_bufferreclaimer.reclaim(mres, Long.valueOf(mres.capacity()));
- }
- if (!cb_reclaimed) {
- m_nvmasvc.destroyByteBuffer(m_nid, mres);
- mres = null;
- }
- }
- });
+ /**
+ * Constructor, it initializes and allocate a memory pool from specified uri
+ * location with specified capacity and an allocator service instance.
+ * usually, the uri points to a mounted non-volatile memory device or a
+ * location of file system.
+ *
+ * @param nvmasvc
+ * the non-volatile memory allocation service instance
+ *
+ * @param capacity
+ * the capacity of memory pool
+ *
+ * @param uri
+ * the location of memory pool will be created
+ *
+ * @param isnew
+ * a place holder, always specify it as true
+ */
+ public BigDataPMemAllocator(NonVolatileMemoryAllocatorService nvmasvc, long capacity, String uri, boolean isnew) {
+ assert null != nvmasvc : "NonVolatileMemoryAllocatorService object is null";
+ if (capacity <= 0) {
+ throw new IllegalArgumentException("BigDataPMemAllocator cannot be initialized with capacity <= 0.");
}
- /**
- * enable active garbage collection. the GC will be forced to collect garbages when
- * there is no more space for current allocation request.
- *
- * @param timeout
- * the timeout is used to yield for GC performing
- */
- @Override
- public BigDataPMemAllocator enableActiveGC(long timeout) {
- m_activegc = true;
- m_gctimeout = timeout;
- return this;
- }
+ m_nvmasvc = nvmasvc;
+
+ m_nid = m_nvmasvc.init(capacity, uri, isnew);
+ b_addr = m_nvmasvc.getBaseAddress(m_nid);
/**
- * disable active garbage collection.
- *
+ * create a resource collector to release specified chunk that backed by
+ * underlying big memory pool.
*/
- @Override
- public BigDataPMemAllocator disableActiveGC() {
- m_activegc = false;
- return this;
- }
+ m_chunkcollector = new ResCollector<MemChunkHolder<BigDataPMemAllocator>, Long>(new ResReclaim<Long>() {
+ @Override
+ public void reclaim(Long mres) {
+ // System.out.println(String.format("Reclaim: %X", mres));
+ boolean cb_reclaimed = false;
+ if (null != m_chunkreclaimer) {
+ cb_reclaimed = m_chunkreclaimer.reclaim(mres, null);
+ }
+ if (!cb_reclaimed) {
+ m_nvmasvc.free(m_nid, mres);
+ mres = null;
+ }
+ }
+ });
/**
- * Release the memory pool and close it.
- *
+ * create a resource collector to release specified bytebuffer that backed
+ * by underlying big memory pool.
*/
- @Override
- public void close() {
- super.close();
- m_nvmasvc.close(m_nid);
+ m_bufcollector = new ResCollector<MemBufferHolder<BigDataPMemAllocator>, ByteBuffer>(new ResReclaim<ByteBuffer>() {
+ @Override
+ public void reclaim(ByteBuffer mres) {
+ boolean cb_reclaimed = false;
+ if (null != m_bufferreclaimer) {
+ cb_reclaimed = m_bufferreclaimer.reclaim(mres, Long.valueOf(mres.capacity()));
+ }
+ if (!cb_reclaimed) {
+ m_nvmasvc.destroyByteBuffer(m_nid, mres);
+ mres = null;
+ }
+ }
+ });
+ }
+
+ /**
+ * enable active garbage collection. the GC will be forced to collect garbages
+ * when there is no more space for current allocation request.
+ *
+ * @param timeout
+ * the timeout is used to yield for GC performing
+ */
+ @Override
+ public BigDataPMemAllocator enableActiveGC(long timeout) {
+ m_activegc = true;
+ m_gctimeout = timeout;
+ return this;
+ }
+
+ /**
+ * disable active garbage collection.
+ *
+ */
+ @Override
+ public BigDataPMemAllocator disableActiveGC() {
+ m_activegc = false;
+ return this;
+ }
+
+ /**
+ * Release the memory pool and close it.
+ *
+ */
+ @Override
+ public void close() {
+ super.close();
+ m_nvmasvc.close(m_nid);
+ }
+
+ /**
+ * force to synchronize uncommitted data to backed memory pool (this is a
+ * placeholder).
+ *
+ */
+ @Override
+ public void sync() {
+ }
+
+ /**
+ * re-size a specified chunk on its backed memory pool.
+ *
+ * @param mholder
+ * the holder of memory chunk. it can be null.
+ *
+ * @param size
+ * specify a new size of memory chunk
+ *
+ * @return the resized memory chunk handler
+ */
+ @Override
+ public MemChunkHolder<BigDataPMemAllocator> resizeChunk(MemChunkHolder<BigDataPMemAllocator> mholder, long size) {
+ MemChunkHolder<BigDataPMemAllocator> ret = null;
+ boolean ac = null != mholder.getRefId();
+ if (size > 0) {
+ Long addr = m_nvmasvc.reallocate(m_nid, mholder.get(), size, true);
+ if (0 == addr && m_activegc) {
+ m_chunkcollector.waitReclaimCoolDown(m_gctimeout);
+ addr = m_nvmasvc.reallocate(m_nid, mholder.get(), size, true);
+ }
+ if (0 != addr) {
+ mholder.clear();
+ mholder.destroy();
+ ret = new MemChunkHolder<BigDataPMemAllocator>(this, addr, size);
+ if (ac) {
+ m_chunkcollector.register(ret);
+ }
+ }
}
+ return ret;
+ }
- /**
- * force to synchronize uncommitted data to backed memory pool
- * (this is a placeholder).
- *
- */
- @Override
- public void sync() {
+ /**
+ * resize a specified buffer on its backed memory pool.
+ *
+ * @param mholder
+ * the holder of memory buffer. it can be null.
+ *
+ * @param size
+ * specify a new size of memory chunk
+ *
+ * @return the resized memory buffer handler
+ *
+ */
+ @Override
+ public MemBufferHolder<BigDataPMemAllocator> resizeBuffer(MemBufferHolder<BigDataPMemAllocator> mholder, long size) {
+ MemBufferHolder<BigDataPMemAllocator> ret = null;
+ boolean ac = null != mholder.getRefId();
+ if (size > 0) {
+ int bufpos = mholder.get().position();
+ int buflimit = mholder.get().limit();
+ ByteBuffer buf = m_nvmasvc.resizeByteBuffer(m_nid, mholder.get(), size);
+ if (null == buf && m_activegc) {
+ m_bufcollector.waitReclaimCoolDown(m_gctimeout);
+ buf = m_nvmasvc.resizeByteBuffer(m_nid, mholder.get(), size);
+ }
+ if (null != buf) {
+ mholder.clear();
+ mholder.destroy();
+ buf.position(bufpos <= size ? bufpos : 0);
+ buf.limit(buflimit <= size ? buflimit : (int) size);
+ ret = new MemBufferHolder<BigDataPMemAllocator>(this, buf);
+ if (ac) {
+ m_bufcollector.register(ret);
+ }
+ }
}
+ return ret;
+ }
- /**
- * re-size a specified chunk on its backed memory pool.
- *
- * @param mholder
- * the holder of memory chunk. it can be
- * null.
- *
- * @param size
- * specify a new size of memory chunk
- *
- * @return the resized memory chunk handler
- */
- @Override
- public MemChunkHolder<BigDataPMemAllocator> resizeChunk(MemChunkHolder<BigDataPMemAllocator> mholder, long size){
- MemChunkHolder<BigDataPMemAllocator> ret = null;
- boolean ac = null != mholder.getRefId();
- if (size > 0) {
- Long addr = m_nvmasvc.reallocate(m_nid, mholder.get(), size, true);
- if (0 == addr && m_activegc) {
- m_chunkcollector.waitReclaimCoolDown(m_gctimeout);
- addr = m_nvmasvc.reallocate(m_nid, mholder.get(), size, true);
- }
- if (0 != addr) {
- mholder.clear();
- mholder.destroy();
- ret = new MemChunkHolder<BigDataPMemAllocator>(this, addr, size);
- if (ac) {
- m_chunkcollector.register(ret);
- }
- }
- }
- return ret;
+ /**
+ * create a memory chunk that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory chunk
+ *
+ * @param autoreclaim
+ * specify whether or not to reclaim this chunk automatically
+ *
+ * @return a holder contains a memory chunk
+ */
+ @Override
+ public MemChunkHolder<BigDataPMemAllocator> createChunk(long size, boolean autoreclaim) {
+ MemChunkHolder<BigDataPMemAllocator> ret = null;
+ Long addr = m_nvmasvc.allocate(m_nid, size, true);
+ if ((null == addr || 0 == addr) && m_activegc) {
+ m_chunkcollector.waitReclaimCoolDown(m_gctimeout);
+ addr = m_nvmasvc.allocate(m_nid, size, true);
}
-
- /**
- * resize a specified buffer on its backed memory pool.
- *
- * @param mholder
- * the holder of memory buffer. it can be
- * null.
- *
- * @param size
- * specify a new size of memory chunk
- *
- * @return the resized memory buffer handler
- *
- */
- @Override
- public MemBufferHolder<BigDataPMemAllocator> resizeBuffer(MemBufferHolder<BigDataPMemAllocator> mholder, long size) {
- MemBufferHolder<BigDataPMemAllocator> ret = null;
- boolean ac = null != mholder.getRefId();
- if (size > 0) {
- int bufpos = mholder.get().position();
- int buflimit = mholder.get().limit();
- ByteBuffer buf = m_nvmasvc.resizeByteBuffer(m_nid, mholder.get(), size);
- if (null == buf && m_activegc) {
- m_bufcollector.waitReclaimCoolDown(m_gctimeout);
- buf = m_nvmasvc.resizeByteBuffer(m_nid, mholder.get(), size);
- }
- if (null != buf) {
- mholder.clear();
- mholder.destroy();
- buf.position(bufpos <= size ? bufpos : 0);
- buf.limit(buflimit <= size ? buflimit : (int)size);
- ret = new MemBufferHolder<BigDataPMemAllocator>(this, buf);
- if (ac) {
- m_bufcollector.register(ret);
- }
- }
- }
- return ret;
+ if (null != addr && 0 != addr) {
+ ret = new MemChunkHolder<BigDataPMemAllocator>(this, addr, size);
+ ret.setCollector(m_chunkcollector);
+ if (autoreclaim) {
+ m_chunkcollector.register(ret);
+ }
}
+ return ret;
+ }
- /**
- * create a memory chunk that is managed by its holder.
- *
- * @param size
- * specify the size of memory chunk
- *
- * @param autoreclaim
- * specify whether or not to reclaim this
- * chunk automatically
- *
- * @return a holder contains a memory chunk
- */
- @Override
- public MemChunkHolder<BigDataPMemAllocator> createChunk(long size, boolean autoreclaim) {
- MemChunkHolder<BigDataPMemAllocator> ret = null;
- Long addr = m_nvmasvc.allocate(m_nid, size, true);
- if ((null == addr || 0 == addr) && m_activegc) {
- m_chunkcollector.waitReclaimCoolDown(m_gctimeout);
- addr = m_nvmasvc.allocate(m_nid, size, true);
- }
- if (null != addr && 0 != addr) {
- ret = new MemChunkHolder<BigDataPMemAllocator>(this, addr, size);
- ret.setCollector(m_chunkcollector);
- if (autoreclaim) {
- m_chunkcollector.register(ret);
- }
- }
- return ret;
+ /**
+ * create a memory buffer that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory buffer
+ *
+ * @param autoreclaim
+ * specify whether or not to reclaim this buffer automatically
+ *
+ * @return a holder contains a memory buffer
+ */
+ @Override
+ public MemBufferHolder<BigDataPMemAllocator> createBuffer(long size, boolean autoreclaim) {
+ MemBufferHolder<BigDataPMemAllocator> ret = null;
+ ByteBuffer bb = m_nvmasvc.createByteBuffer(m_nid, size);
+ if (null == bb && m_activegc) {
+ m_bufcollector.waitReclaimCoolDown(m_gctimeout);
+ bb = m_nvmasvc.createByteBuffer(m_nid, size);
}
-
- /**
- * create a memory buffer that is managed by its holder.
- *
- * @param size
- * specify the size of memory buffer
- *
- * @param autoreclaim
- * specify whether or not to reclaim this
- * buffer automatically
- *
- * @return a holder contains a memory buffer
- */
- @Override
- public MemBufferHolder<BigDataPMemAllocator> createBuffer(long size, boolean autoreclaim) {
- MemBufferHolder<BigDataPMemAllocator> ret = null;
- ByteBuffer bb = m_nvmasvc.createByteBuffer(m_nid, size);
- if (null == bb && m_activegc) {
- m_bufcollector.waitReclaimCoolDown(m_gctimeout);
- bb = m_nvmasvc.createByteBuffer(m_nid, size);
- }
- if (null != bb) {
- ret = new MemBufferHolder<BigDataPMemAllocator>(this, bb);
- ret.setCollector(m_bufcollector);
- if (autoreclaim) {
- m_bufcollector.register(ret);
- }
- }
- return ret;
+ if (null != bb) {
+ ret = new MemBufferHolder<BigDataPMemAllocator>(this, bb);
+ ret.setCollector(m_bufcollector);
+ if (autoreclaim) {
+ m_bufcollector.register(ret);
+ }
}
+ return ret;
+ }
- /**
- * retrieve a memory buffer from its backed memory allocator.
- *
- * @param phandler
- * specify the handler of memory buffer to retrieve
- *
- * @param autoreclaim
- * specify whether this retrieved memory buffer can be reclaimed automatically or not
- *
- * @return a holder contains the retrieved memory buffer
- */
- @Override
- public MemBufferHolder<BigDataPMemAllocator> retrieveBuffer(long phandler, boolean autoreclaim) {
- MemBufferHolder<BigDataPMemAllocator> ret = null;
- ByteBuffer bb = m_nvmasvc.retrieveByteBuffer(m_nid, getEffectiveAddress(phandler));
- if (null != bb) {
- ret = new MemBufferHolder<BigDataPMemAllocator>(this, bb);
- if (autoreclaim) {
- m_bufcollector.register(ret);
- }
- }
- return ret;
+ /**
+ * retrieve a memory buffer from its backed memory allocator.
+ *
+ * @param phandler
+ * specify the handler of memory buffer to retrieve
+ *
+ * @param autoreclaim
+ * specify whether this retrieved memory buffer can be reclaimed
+ * automatically or not
+ *
+ * @return a holder contains the retrieved memory buffer
+ */
+ @Override
+ public MemBufferHolder<BigDataPMemAllocator> retrieveBuffer(long phandler, boolean autoreclaim) {
+ MemBufferHolder<BigDataPMemAllocator> ret = null;
+ ByteBuffer bb = m_nvmasvc.retrieveByteBuffer(m_nid, getEffectiveAddress(phandler));
+ if (null != bb) {
+ ret = new MemBufferHolder<BigDataPMemAllocator>(this, bb);
+ if (autoreclaim) {
+ m_bufcollector.register(ret);
+ }
}
+ return ret;
+ }
- /**
- * retrieve a memory chunk from its backed memory allocator.
- *
- * @param phandler
- * specify the handler of memory chunk to retrieve
- *
- * @param autoreclaim
- * specify whether this retrieved memory chunk can be reclaimed automatically or not
- *
- * @return a holder contains the retrieved memory chunk
- */
- @Override
- public MemChunkHolder<BigDataPMemAllocator> retrieveChunk(long phandler, boolean autoreclaim) {
- MemChunkHolder<BigDataPMemAllocator> ret = null;
- long eaddr = getEffectiveAddress(phandler);
- long sz = m_nvmasvc.retrieveSize(m_nid, eaddr);
- if (sz > 0L) {
- ret = new MemChunkHolder<BigDataPMemAllocator>(this, eaddr, sz);
- if (autoreclaim) {
- m_chunkcollector.register(ret);
- }
- }
- return ret;
+ /**
+ * retrieve a memory chunk from its backed memory allocator.
+ *
+ * @param phandler
+ * specify the handler of memory chunk to retrieve
+ *
+ * @param autoreclaim
+ * specify whether this retrieved memory chunk can be reclaimed
+ * automatically or not
+ *
+ * @return a holder contains the retrieved memory chunk
+ */
+ @Override
+ public MemChunkHolder<BigDataPMemAllocator> retrieveChunk(long phandler, boolean autoreclaim) {
+ MemChunkHolder<BigDataPMemAllocator> ret = null;
+ long eaddr = getEffectiveAddress(phandler);
+ long sz = m_nvmasvc.retrieveSize(m_nid, eaddr);
+ if (sz > 0L) {
+ ret = new MemChunkHolder<BigDataPMemAllocator>(this, eaddr, sz);
+ if (autoreclaim) {
+ m_chunkcollector.register(ret);
+ }
}
+ return ret;
+ }
- /**
- * get the handler from a memory buffer holder.
- *
- * @param mbuf
- * specify the memory buffer holder
- *
- * @return a handler that could be used to retrieve its memory buffer
- */
- @Override
- public long getBufferHandler(MemBufferHolder<BigDataPMemAllocator> mbuf) {
- return getPortableAddress(m_nvmasvc.getByteBufferHandler(m_nid, mbuf.get()));
- }
+ /**
+ * get the handler from a memory buffer holder.
+ *
+ * @param mbuf
+ * specify the memory buffer holder
+ *
+ * @return a handler that could be used to retrieve its memory buffer
+ */
+ @Override
+ public long getBufferHandler(MemBufferHolder<BigDataPMemAllocator> mbuf) {
+ return getPortableAddress(m_nvmasvc.getByteBufferHandler(m_nid, mbuf.get()));
+ }
- /**
- * get the handler from a memory chunk holder.
- *
- * @param mchunk
- * specify the memory chunk holder
- *
- * @return a handler that could be used to retrieve its memory chunk
- */
- @Override
- public long getChunkHandler(MemChunkHolder<BigDataPMemAllocator> mchunk) {
- return getPortableAddress(mchunk.get());
- }
+ /**
+ * get the handler from a memory chunk holder.
+ *
+ * @param mchunk
+ * specify the memory chunk holder
+ *
+ * @return a handler that could be used to retrieve its memory chunk
+ */
+ @Override
+ public long getChunkHandler(MemChunkHolder<BigDataPMemAllocator> mchunk) {
+ return getPortableAddress(mchunk.get());
+ }
- /**
- * determine whether this allocator supports to store non-volatile handler or not.
- * (it is a placeholder)
- *
- * @return true if there is
- */
- @Override
- public boolean hasNonVolatileHandlerStore() {
- return true;
- }
+ /**
+ * determine whether this allocator supports to store non-volatile handler or
+ * not. (it is a placeholder)
+ *
+ * @return true if there is
+ */
+ @Override
+ public boolean hasNonVolatileHandlerStore() {
+ return true;
+ }
- /**
- * start a application level transaction on this allocator.
- * (it is a place holder)
- *
- */
- @Override
- public void beginTransaction() {
- throw new UnsupportedOperationException("Transaction Unsupported.");
- }
+ /**
+ * start a application level transaction on this allocator. (it is a place
+ * holder)
+ *
+ */
+ @Override
+ public void beginTransaction() {
+ throw new UnsupportedOperationException("Transaction Unsupported.");
+ }
- /**
- * end a application level transaction on this allocator.
- * (it is a place holder)
- *
- */
- @Override
- public void endTransaction() {
- throw new UnsupportedOperationException("Transaction Unsupported.");
- }
+ /**
+ * end a application level transaction on this allocator. (it is a place
+ * holder)
+ *
+ */
+ @Override
+ public void endTransaction() {
+ throw new UnsupportedOperationException("Transaction Unsupported.");
+ }
- /**
- * set a handler on key.
- *
- * @param key
- * the key to set its value
- *
- * @param handler
- * the handler
- */
- public void setHandler(long key, long handler) {
- m_nvmasvc.setHandler(m_nid, key, handler);
- }
+ /**
+ * set a handler on key.
+ *
+ * @param key
+ * the key to set its value
+ *
+ * @param handler
+ * the handler
+ */
+ public void setHandler(long key, long handler) {
+ m_nvmasvc.setHandler(m_nid, key, handler);
+ }
- /**
- * get a handler value.
- *
- * @param key
- * the key to set its value
- *
- * @return the value of handler
- */
- public long getHandler(long key) {
- return m_nvmasvc.getHandler(m_nid, key);
- }
-
- /**
- * return the capacity of non-volatile handler store.
- *
- * @return the capacity of handler store
- *
- */
- public long handlerCapacity() {
- return m_nvmasvc.handlerCapacity(m_nid);
- }
-
- /**
- * calculate the portable address
- *
- * @param addr
- * the address to be calculated
- *
- * @return the portable address
- */
- @Override
- public long getPortableAddress(long addr) {
- return addr - b_addr;
- }
+ /**
+ * get a handler value.
+ *
+ * @param key
+ * the key to set its value
+ *
+ * @return the value of handler
+ */
+ public long getHandler(long key) {
+ return m_nvmasvc.getHandler(m_nid, key);
+ }
- /**
- * calculate the effective address
- *
- * @param addr
- * the address to be calculated
- *
- * @return the effective address
- */
- @Override
- public long getEffectiveAddress(long addr) {
- return addr + b_addr;
- }
+ /**
+ * return the capacity of non-volatile handler store.
+ *
+ * @return the capacity of handler store
+ *
+ */
+ public long handlerCapacity() {
+ return m_nvmasvc.handlerCapacity(m_nid);
+ }
- /**
- * get the base address
- *
- * @return the base address
- */
- @Override
- public long getBaseAddress() {
- return b_addr;
- }
+ /**
+ * calculate the portable address
+ *
+ * @param addr
+ * the address to be calculated
+ *
+ * @return the portable address
+ */
+ @Override
+ public long getPortableAddress(long addr) {
+ return addr - b_addr;
+ }
- /**
- * set the base address for calculation
- *
- * @param addr
- * the base address
- *
- */
- @Override
- public long setBaseAddress(long addr) {
- return b_addr = addr;
- }
+ /**
+ * calculate the effective address
+ *
+ * @param addr
+ * the address to be calculated
+ *
+ * @return the effective address
+ */
+ @Override
+ public long getEffectiveAddress(long addr) {
+ return addr + b_addr;
+ }
+
+ /**
+ * get the base address
+ *
+ * @return the base address
+ */
+ @Override
+ public long getBaseAddress() {
+ return b_addr;
+ }
+
+ /**
+ * set the base address for calculation
+ *
+ * @param addr
+ * the base address
+ *
+ */
+ @Override
+ public long setBaseAddress(long addr) {
+ return b_addr = addr;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/ByteBufferBackedInputStream.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/ByteBufferBackedInputStream.java b/core/src/main/java/org/apache/mnemonic/ByteBufferBackedInputStream.java
index 046472b..7a554dd 100644
--- a/core/src/main/java/org/apache/mnemonic/ByteBufferBackedInputStream.java
+++ b/core/src/main/java/org/apache/mnemonic/ByteBufferBackedInputStream.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import java.io.IOException;
@@ -11,51 +28,51 @@ import java.nio.ByteBuffer;
*/
public class ByteBufferBackedInputStream extends InputStream {
- private ByteBuffer buf;
+ private ByteBuffer buf;
- /**
- * accept a ByteBuffer as backed object for inputStream.
- *
- * @param buf
- * specify a bytebuffer that is where any data is from
- */
- public ByteBufferBackedInputStream(ByteBuffer buf) {
- this.buf = buf;
- }
+ /**
+ * accept a ByteBuffer as backed object for inputStream.
+ *
+ * @param buf
+ * specify a bytebuffer that is where any data is from
+ */
+ public ByteBufferBackedInputStream(ByteBuffer buf) {
+ this.buf = buf;
+ }
- /**
- * read an integer value from backed ByteBuffer.
- *
- * @return a integer value from stream input
- */
- public int read() throws IOException {
- if (!buf.hasRemaining()) {
- return -1;
- }
- return buf.get() & 0xFF;
+ /**
+ * read an integer value from backed ByteBuffer.
+ *
+ * @return a integer value from stream input
+ */
+ public int read() throws IOException {
+ if (!buf.hasRemaining()) {
+ return -1;
}
+ return buf.get() & 0xFF;
+ }
- /**
- * read a specified range of byte array from backed ByteBuffer.
- *
- * @param bytes
- * specify a output byte array to store data
- *
- * @param off
- * specify the offset from ByteBuffer to read
- *
- * @param len
- * specify the length of bytes to read
- *
- * @return the number of bytes has been read
- */
- public int read(byte[] bytes, int off, int len) throws IOException {
- if (!buf.hasRemaining()) {
- return -1;
- }
-
- len = Math.min(len, buf.remaining());
- buf.get(bytes, off, len);
- return len;
+ /**
+ * read a specified range of byte array from backed ByteBuffer.
+ *
+ * @param bytes
+ * specify a output byte array to store data
+ *
+ * @param off
+ * specify the offset from ByteBuffer to read
+ *
+ * @param len
+ * specify the length of bytes to read
+ *
+ * @return the number of bytes has been read
+ */
+ public int read(byte[] bytes, int off, int len) throws IOException {
+ if (!buf.hasRemaining()) {
+ return -1;
}
+
+ len = Math.min(len, buf.remaining());
+ buf.get(bytes, off, len);
+ return len;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/ByteBufferBackedOutputStream.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/ByteBufferBackedOutputStream.java b/core/src/main/java/org/apache/mnemonic/ByteBufferBackedOutputStream.java
index 6755444..2a1792d 100644
--- a/core/src/main/java/org/apache/mnemonic/ByteBufferBackedOutputStream.java
+++ b/core/src/main/java/org/apache/mnemonic/ByteBufferBackedOutputStream.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import java.io.IOException;
@@ -11,46 +28,46 @@ import java.nio.ByteBuffer;
*/
public class ByteBufferBackedOutputStream extends OutputStream {
- private ByteBuffer buf;
-
- /**
- * accept a ByteBuffer to store external data, the capacity of it could be
- * extended at will.
- *
- * @param buf
- * specify a ByteBuffer object that is used to store external
- * data to its backed buffer
- *
- */
- public ByteBufferBackedOutputStream(ByteBuffer buf) {
- this.buf = buf;
- }
-
- /**
- * write an integer value to backed buffer.
- *
- * @param b
- * specify an integer value to be written
- */
- public void write(int b) throws IOException {
- buf.put((byte) b);
- }
-
- /**
- * write an array of bytes to a specified range of backed buffer
- *
- * @param bytes
- * specify a byte array to write
- *
- * @param off
- * specify the offset of backed buffer where is start point to be
- * written
- *
- * @param len
- * specify the length of bytes to be written
- */
- public void write(byte[] bytes, int off, int len) throws IOException {
- buf.put(bytes, off, len);
- }
+ private ByteBuffer buf;
+
+ /**
+ * accept a ByteBuffer to store external data, the capacity of it could be
+ * extended at will.
+ *
+ * @param buf
+ * specify a ByteBuffer object that is used to store external data to
+ * its backed buffer
+ *
+ */
+ public ByteBufferBackedOutputStream(ByteBuffer buf) {
+ this.buf = buf;
+ }
+
+ /**
+ * write an integer value to backed buffer.
+ *
+ * @param b
+ * specify an integer value to be written
+ */
+ public void write(int b) throws IOException {
+ buf.put((byte) b);
+ }
+
+ /**
+ * write an array of bytes to a specified range of backed buffer
+ *
+ * @param bytes
+ * specify a byte array to write
+ *
+ * @param off
+ * specify the offset of backed buffer where is start point to be
+ * written
+ *
+ * @param len
+ * specify the length of bytes to be written
+ */
+ public void write(byte[] bytes, int off, int len) throws IOException {
+ buf.put(bytes, off, len);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/ByteBufferSerializer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/ByteBufferSerializer.java b/core/src/main/java/org/apache/mnemonic/ByteBufferSerializer.java
index 7ed9f05..b6371d5 100644
--- a/core/src/main/java/org/apache/mnemonic/ByteBufferSerializer.java
+++ b/core/src/main/java/org/apache/mnemonic/ByteBufferSerializer.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import java.io.ByteArrayOutputStream;
@@ -15,135 +32,134 @@ import java.io.InputStream;
public class ByteBufferSerializer {
- /**
- * serialize object to a ByteBuffer object.
- *
- * @param <ValueT>
- * the type of object
- *
- * @param obj
- * specify a object that is serializable
- *
- * @throws IOException
- * the exception of serialization
- *
- * @return a ByteBuffer object contained serialized object
- */
- public static <ValueT> ByteBuffer toByteBuffer(ValueT obj)
- throws IOException {
- byte[] bytes = null;
- ByteArrayOutputStream bos = null;
- ObjectOutputStream oos = null;
- try {
- bos = new ByteArrayOutputStream();
- oos = new ObjectOutputStream(bos);
- oos.writeObject(obj);
- oos.flush();
- bytes = bos.toByteArray();
- } finally {
- if (oos != null) {
- oos.close();
- }
- if (bos != null) {
- bos.close();
- }
- }
- return ByteBuffer.wrap(bytes);
+ /**
+ * serialize object to a ByteBuffer object.
+ *
+ * @param <ValueT>
+ * the type of object
+ *
+ * @param obj
+ * specify a object that is serializable
+ *
+ * @throws IOException
+ * the exception of serialization
+ *
+ * @return a ByteBuffer object contained serialized object
+ */
+ public static <ValueT> ByteBuffer toByteBuffer(ValueT obj) throws IOException {
+ byte[] bytes = null;
+ ByteArrayOutputStream bos = null;
+ ObjectOutputStream oos = null;
+ try {
+ bos = new ByteArrayOutputStream();
+ oos = new ObjectOutputStream(bos);
+ oos.writeObject(obj);
+ oos.flush();
+ bytes = bos.toByteArray();
+ } finally {
+ if (oos != null) {
+ oos.close();
+ }
+ if (bos != null) {
+ bos.close();
+ }
}
+ return ByteBuffer.wrap(bytes);
+ }
- /**
- * de-serialize an object from a ByteBuffer object.
- *
- * @param <ValueT>
- * the type of object
- *
- * @param bf
- * specify an ByteBuffer contains data that can be de-serialized
- *
- * @throws IOException
- * the exception of deserialization
- *
- * @throws ClassNotFoundException
- * Not found class of de-serialized object
- *
- * @return a de-serialized object
- */
- @SuppressWarnings("unchecked")
- public static <ValueT> ValueT toObject(ByteBuffer bf) throws IOException,
- ClassNotFoundException {
- Object obj = null;
- InputStream is = null;
- ObjectInputStream ois = null;
- try {
- is = new ByteBufferBackedInputStream(bf);
- ois = new ObjectInputStream(is);
- obj = ois.readObject();
- } finally {
- if (is != null) {
- is.close();
- }
- if (ois != null) {
- ois.close();
- }
- }
- return (ValueT) obj;
+ /**
+ * de-serialize an object from a ByteBuffer object.
+ *
+ * @param <ValueT>
+ * the type of object
+ *
+ * @param bf
+ * specify an ByteBuffer contains data that can be de-serialized
+ *
+ * @throws IOException
+ * the exception of deserialization
+ *
+ * @throws ClassNotFoundException
+ * Not found class of de-serialized object
+ *
+ * @return a de-serialized object
+ */
+ @SuppressWarnings("unchecked")
+ public static <ValueT> ValueT toObject(ByteBuffer bf) throws IOException, ClassNotFoundException {
+ Object obj = null;
+ InputStream is = null;
+ ObjectInputStream ois = null;
+ try {
+ is = new ByteBufferBackedInputStream(bf);
+ ois = new ObjectInputStream(is);
+ obj = ois.readObject();
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ if (ois != null) {
+ ois.close();
+ }
}
+ return (ValueT) obj;
+ }
- /**
- * serialize object to a MemBufferHolder object.
- *
- * @param <A> the type of bound allocator
- *
- * @param <ValueT>
- * the type of object
- *
- * @param ar
- * specify an Allocator that is used to generate MemBufferHolder
- * which is backed by a native memory block
- *
- * @param obj
- * specify a object that is serializable
- *
- * @throws IOException
- * the exception of serialization
- *
- * @return a MemBufferHolder object contained serialized object
- */
- public static <A extends CommonAllocator<A>, ValueT> MemBufferHolder<A>
- toMemBufferHolder(A ar, ValueT obj) throws IOException {
- MemBufferHolder<A> ret = null;
- ByteBuffer bb = toByteBuffer(obj);
- if (null != bb && bb.remaining() > 0) {
- ret = ar.createBuffer(bb.remaining());
- ret.get().put(bb);
- ret.get().flip();
- }
- return ret;
+ /**
+ * serialize object to a MemBufferHolder object.
+ *
+ * @param <A>
+ * the type of bound allocator
+ *
+ * @param <ValueT>
+ * the type of object
+ *
+ * @param ar
+ * specify an Allocator that is used to generate MemBufferHolder
+ * which is backed by a native memory block
+ *
+ * @param obj
+ * specify a object that is serializable
+ *
+ * @throws IOException
+ * the exception of serialization
+ *
+ * @return a MemBufferHolder object contained serialized object
+ */
+ public static <A extends CommonAllocator<A>, ValueT> MemBufferHolder<A> toMemBufferHolder(A ar, ValueT obj)
+ throws IOException {
+ MemBufferHolder<A> ret = null;
+ ByteBuffer bb = toByteBuffer(obj);
+ if (null != bb && bb.remaining() > 0) {
+ ret = ar.createBuffer(bb.remaining());
+ ret.get().put(bb);
+ ret.get().flip();
}
+ return ret;
+ }
- /**
- * de-serialize an object from a MemBufferHolder object.
- *
- * @param <A> the type of bound allocator
- *
- * @param <ValueT>
- * the type of object
- *
- * @param mbh
- * specify an MemBufferHolder who contains data that can be
- * de-serialized
- *
- * @throws IOException
- * the exception of deserialization
- *
- * @throws ClassNotFoundException
- * Not found class of de-serialized object
- *
- * @return a de-serialized object
- */
- public static <A extends CommonAllocator<A>, ValueT> ValueT
- fromMemBufferHolder(MemBufferHolder<A> mbh)
- throws IOException, ClassNotFoundException {
- return toObject(mbh.get());
- }
+ /**
+ * de-serialize an object from a MemBufferHolder object.
+ *
+ * @param <A>
+ * the type of bound allocator
+ *
+ * @param <ValueT>
+ * the type of object
+ *
+ * @param mbh
+ * specify an MemBufferHolder who contains data that can be
+ * de-serialized
+ *
+ * @throws IOException
+ * the exception of deserialization
+ *
+ * @throws ClassNotFoundException
+ * Not found class of de-serialized object
+ *
+ * @return a de-serialized object
+ */
+ public static <A extends CommonAllocator<A>, ValueT> ValueT fromMemBufferHolder(MemBufferHolder<A> mbh)
+ throws IOException, ClassNotFoundException {
+ return toObject(mbh.get());
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/CachePool.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/CachePool.java b/core/src/main/java/org/apache/mnemonic/CachePool.java
index 8a9af75..37a87ee 100644
--- a/core/src/main/java/org/apache/mnemonic/CachePool.java
+++ b/core/src/main/java/org/apache/mnemonic/CachePool.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import java.util.Set;
@@ -11,134 +28,126 @@ import java.util.Map;
*
*
*/
-public abstract class CachePool<KeyT, ValueT> extends
- LinkedHashMap<KeyT, ValueT> {
+public abstract class CachePool<KeyT, ValueT> extends LinkedHashMap<KeyT, ValueT> {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
- public CachePool(int initialCapacity, float loadFactor) {
- super(initialCapacity, loadFactor);
- }
+ public CachePool(int initialCapacity, float loadFactor) {
+ super(initialCapacity, loadFactor);
+ }
- /**
- * Return available capacity for new entries.
- *
- * @return available capacity in this cache pool
- */
- public abstract long freeCapacity();
+ /**
+ * Return available capacity for new entries.
+ *
+ * @return available capacity in this cache pool
+ */
+ public abstract long freeCapacity();
- /**
- * Return the used capacity of cached entries.
- *
- * @return the used size of this cache pool
- */
- public abstract long usedCapacity();
+ /**
+ * Return the used capacity of cached entries.
+ *
+ * @return the used size of this cache pool
+ */
+ public abstract long usedCapacity();
- /**
- * Put an entry in this cache pool and evict eldest entries if necessary
- * that will free enough space to hold new entry, which entry could be
- * evicted that can be customized by ({@link EvictFilter}), regarding how
- * to post-process the eldest entry that can be customized by (
- * {@link DropEvent}). If this cache pool previously contained an entry for
- * the key, the old value will be replaced by the specified value
- *
- * @param k
- * the key whoes associated value is to be put
- *
- * @param v
- * the value to be put
- *
- * @param fsop
- * the customized operations to free space to hold new entry
- *
- * @param dfilter
- * the filter of entries for deletion
- *
- * @return <tt>true</tt> if the entry has been put into this container
- *
- */
- public abstract ValueT put(KeyT k, ValueT v, DropEvent<KeyT, ValueT> fsop,
- EvictFilter<KeyT, ValueT> dfilter);
+ /**
+ * Put an entry in this cache pool and evict eldest entries if necessary that
+ * will free enough space to hold new entry, which entry could be evicted that
+ * can be customized by ({@link EvictFilter}), regarding how to post-process
+ * the eldest entry that can be customized by ( {@link DropEvent}). If this
+ * cache pool previously contained an entry for the key, the old value will be
+ * replaced by the specified value
+ *
+ * @param k
+ * the key whoes associated value is to be put
+ *
+ * @param v
+ * the value to be put
+ *
+ * @param fsop
+ * the customized operations to free space to hold new entry
+ *
+ * @param dfilter
+ * the filter of entries for deletion
+ *
+ * @return <tt>true</tt> if the entry has been put into this container
+ *
+ */
+ public abstract ValueT put(KeyT k, ValueT v, DropEvent<KeyT, ValueT> fsop, EvictFilter<KeyT, ValueT> dfilter);
- /**
- * Put all entries into this cache pool and evict eldes entries if
- * necessary.
- *
- * @param m
- * the Map object that contains entries to be put
- *
- * @param fsop
- * the customized operations to free space to hold new entry
- *
- * @param dfilter
- * the filter of entries for deletion
- *
- */
- public abstract void putAll(
- Map<? extends KeyT, ? extends ValueT> m,
- DropEvent<KeyT, ValueT> fsop,
- EvictFilter<KeyT, ValueT> dfilter);
+ /**
+ * Put all entries into this cache pool and evict eldes entries if necessary.
+ *
+ * @param m
+ * the Map object that contains entries to be put
+ *
+ * @param fsop
+ * the customized operations to free space to hold new entry
+ *
+ * @param dfilter
+ * the filter of entries for deletion
+ *
+ */
+ public abstract void putAll(Map<? extends KeyT, ? extends ValueT> m, DropEvent<KeyT, ValueT> fsop,
+ EvictFilter<KeyT, ValueT> dfilter);
- /**
- * Returns a new {@link Set} view of the keys of this cache pool, It
- * contains the most recently visited keys
- *
- * @param n
- * the number of keys to retrieve
- *
- * @return a set of hot keys
- */
- public abstract Set<KeyT> hotKeySet(int n);
+ /**
+ * Returns a new {@link Set} view of the keys of this cache pool, It contains
+ * the most recently visited keys
+ *
+ * @param n
+ * the number of keys to retrieve
+ *
+ * @return a set of hot keys
+ */
+ public abstract Set<KeyT> hotKeySet(int n);
- /**
- * Ensure the free capacity is greater than the specified size
- *
- * @param freesz
- * the size of free capacity that needs to be secured
- *
- * @return <tt>true</tt> if the size of free capacity is greater than the
- * specified size after evacuation
- *
- * @see #ensureFreeSpace(long, DropEvent, EvictFilter)
- */
- public abstract boolean ensureFreeSpace(long freesz);
+ /**
+ * Ensure the free capacity is greater than the specified size
+ *
+ * @param freesz
+ * the size of free capacity that needs to be secured
+ *
+ * @return <tt>true</tt> if the size of free capacity is greater than the
+ * specified size after evacuation
+ *
+ * @see #ensureFreeSpace(long, DropEvent, EvictFilter)
+ */
+ public abstract boolean ensureFreeSpace(long freesz);
- /**
- * Removes a first qualified entry in this cache pool
- *
- * @param fsop
- * the customized callback to post-process its evicted entry
- *
- * @param dfilter
- * the filter for entry deletion
- *
- * @return <tt>true</tt> if there is one qualified entry that has been
- * dropped
- */
- public abstract boolean removeFirstEntry(DropEvent<KeyT, ValueT> fsop,
- EvictFilter<KeyT, ValueT> dfilter);
+ /**
+ * Removes a first qualified entry in this cache pool
+ *
+ * @param fsop
+ * the customized callback to post-process its evicted entry
+ *
+ * @param dfilter
+ * the filter for entry deletion
+ *
+ * @return <tt>true</tt> if there is one qualified entry that has been dropped
+ */
+ public abstract boolean removeFirstEntry(DropEvent<KeyT, ValueT> fsop, EvictFilter<KeyT, ValueT> dfilter);
- /**
- * Ensure the size of free capacity is greater than the specified size, the
- * entries will be filtered by {@link EvictFilter} before dropping, the
- * {@link DropEvent} is used for post-processing
- *
- * @param freesz
- * the size of free capacity that needs to be secured
- *
- * @param fsop
- * the customized operations to free space to hold new entry
- *
- * @param dfilter
- * the filter of entries for deletion
- *
- * @return <tt>true</tt> if the size of free capacity is greater than the
- * specified size after evication if necessary
- */
- public abstract boolean ensureFreeSpace(long freesz,
- DropEvent<KeyT, ValueT> fsop, EvictFilter<KeyT, ValueT> dfilter);
+ /**
+ * Ensure the size of free capacity is greater than the specified size, the
+ * entries will be filtered by {@link EvictFilter} before dropping, the
+ * {@link DropEvent} is used for post-processing
+ *
+ * @param freesz
+ * the size of free capacity that needs to be secured
+ *
+ * @param fsop
+ * the customized operations to free space to hold new entry
+ *
+ * @param dfilter
+ * the filter of entries for deletion
+ *
+ * @return <tt>true</tt> if the size of free capacity is greater than the
+ * specified size after evication if necessary
+ */
+ public abstract boolean ensureFreeSpace(long freesz, DropEvent<KeyT, ValueT> fsop, EvictFilter<KeyT, ValueT> dfilter);
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/CommonAllocator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/CommonAllocator.java b/core/src/main/java/org/apache/mnemonic/CommonAllocator.java
index 20a584b..643704c 100644
--- a/core/src/main/java/org/apache/mnemonic/CommonAllocator.java
+++ b/core/src/main/java/org/apache/mnemonic/CommonAllocator.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import java.nio.ByteBuffer;
@@ -11,94 +28,94 @@ import org.flowcomputing.commons.resgc.ResCollector;
*/
public abstract class CommonAllocator<A extends CommonAllocator<A>> implements Allocator<A> {
- protected Reclaim<Long> m_chunkreclaimer = null;
- protected Reclaim<ByteBuffer> m_bufferreclaimer = null;
-
- protected ResCollector<MemChunkHolder<A>, Long> m_chunkcollector = null;
- protected ResCollector<MemBufferHolder<A>, ByteBuffer> m_bufcollector = null;
-
- /**
- * set a reclaimer to reclaim memory buffer
- *
- * @param reclaimer
- * specify a reclaimer to accept reclaim request
- */
- public void setBufferReclaimer(Reclaim<ByteBuffer> reclaimer) {
- m_bufferreclaimer = reclaimer;
- }
+ protected Reclaim<Long> m_chunkreclaimer = null;
+ protected Reclaim<ByteBuffer> m_bufferreclaimer = null;
- /**
- * set a reclaimer to reclaim memory chunk
- *
- * @param reclaimer
- * specify a reclaimer to accept reclaim request
- */
- public void setChunkReclaimer(Reclaim<Long> reclaimer) {
- m_chunkreclaimer = reclaimer;
- }
-
- /**
- * create a memory chunk that is managed by its holder.
- *
- * @param size
- * specify the size of memory chunk
- *
- * @return a holder contains a memory chunk
- */
- @Override
- public MemChunkHolder<A> createChunk(long size) {
- return createChunk(size, true);
- }
+ protected ResCollector<MemChunkHolder<A>, Long> m_chunkcollector = null;
+ protected ResCollector<MemBufferHolder<A>, ByteBuffer> m_bufcollector = null;
- /**
- * create a memory buffer that is managed by its holder.
- *
- * @param size
- * specify the size of memory buffer
- *
- * @return a holder contains a memory buffer
- */
- @Override
- public MemBufferHolder<A> createBuffer(long size) {
- return createBuffer(size, true);
- }
+ /**
+ * set a reclaimer to reclaim memory buffer
+ *
+ * @param reclaimer
+ * specify a reclaimer to accept reclaim request
+ */
+ public void setBufferReclaimer(Reclaim<ByteBuffer> reclaimer) {
+ m_bufferreclaimer = reclaimer;
+ }
- /**
- * register a memory chunk for auto-reclaim
- *
- * @param mholder
- * specify a chunk holder to register
- */
- @Override
- public void registerChunkAutoReclaim(MemChunkHolder<A> mholder) {
- m_chunkcollector.register(mholder);
- }
+ /**
+ * set a reclaimer to reclaim memory chunk
+ *
+ * @param reclaimer
+ * specify a reclaimer to accept reclaim request
+ */
+ public void setChunkReclaimer(Reclaim<Long> reclaimer) {
+ m_chunkreclaimer = reclaimer;
+ }
- /**
- * register a memory buffer for auto-reclaim
- *
- * @param mholder
- * specify a buffer holder to register
- */
- @Override
- public void registerBufferAutoReclaim(MemBufferHolder<A> mholder) {
- m_bufcollector.register(mholder);
- }
+ /**
+ * create a memory chunk that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory chunk
+ *
+ * @return a holder contains a memory chunk
+ */
+ @Override
+ public MemChunkHolder<A> createChunk(long size) {
+ return createChunk(size, true);
+ }
+
+ /**
+ * create a memory buffer that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory buffer
+ *
+ * @return a holder contains a memory buffer
+ */
+ @Override
+ public MemBufferHolder<A> createBuffer(long size) {
+ return createBuffer(size, true);
+ }
+
+ /**
+ * register a memory chunk for auto-reclaim
+ *
+ * @param mholder
+ * specify a chunk holder to register
+ */
+ @Override
+ public void registerChunkAutoReclaim(MemChunkHolder<A> mholder) {
+ m_chunkcollector.register(mholder);
+ }
- /**
- * close both of resource collectors for this allocator
- *
- */
- @Override
- public void close() {
- if (null != m_chunkcollector) {
- m_chunkcollector.close();
- m_chunkcollector = null;
- }
- if (null != m_bufcollector) {
- m_bufcollector.close();
- m_bufcollector = null;
- }
+ /**
+ * register a memory buffer for auto-reclaim
+ *
+ * @param mholder
+ * specify a buffer holder to register
+ */
+ @Override
+ public void registerBufferAutoReclaim(MemBufferHolder<A> mholder) {
+ m_bufcollector.register(mholder);
+ }
+
+ /**
+ * close both of resource collectors for this allocator
+ *
+ */
+ @Override
+ public void close() {
+ if (null != m_chunkcollector) {
+ m_chunkcollector.close();
+ m_chunkcollector = null;
+ }
+ if (null != m_bufcollector) {
+ m_bufcollector.close();
+ m_bufcollector = null;
}
-
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/CommonPersistAllocator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/CommonPersistAllocator.java b/core/src/main/java/org/apache/mnemonic/CommonPersistAllocator.java
index 6e0374d..afc7e02 100644
--- a/core/src/main/java/org/apache/mnemonic/CommonPersistAllocator.java
+++ b/core/src/main/java/org/apache/mnemonic/CommonPersistAllocator.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -6,115 +23,118 @@ package org.apache.mnemonic;
*
*/
public abstract class CommonPersistAllocator<A extends CommonAllocator<A>> extends CommonAllocator<A> {
-
- /**
- * determine whether the allocator supports transaction feature or not
- *
- * @return true if supported
- */
- public boolean supportTransaction() {
- return false;
- }
- /**
- * determine whether the allocator does atomic operations on memory pool
- *
- * @return true if it is
- *
- */
- public boolean isAtomicOperation() {
- return false;
- }
+ /**
+ * determine whether the allocator supports transaction feature or not
+ *
+ * @return true if supported
+ */
+ public boolean supportTransaction() {
+ return false;
+ }
+
+ /**
+ * determine whether the allocator does atomic operations on memory pool
+ *
+ * @return true if it is
+ *
+ */
+ public boolean isAtomicOperation() {
+ return false;
+ }
- /**
- * determine whether this allocator supports to store non-volatile handler or not
- *
- * @return true if there is
- */
- public boolean hasNonVolatileHandlerStore() {
- return false;
- }
+ /**
+ * determine whether this allocator supports to store non-volatile handler or
+ * not
+ *
+ * @return true if there is
+ */
+ public boolean hasNonVolatileHandlerStore() {
+ return false;
+ }
- /**
- * retrieve a memory buffer from its backed memory allocator.
- *
- * @param phandler
- * specify the handler of memory buffer to retrieve
- *
- * @return a holder contains the retrieved memory buffer
- */
- public MemBufferHolder<A> retrieveBuffer(long phandler) {
- return retrieveBuffer(phandler, true);
- }
+ /**
+ * retrieve a memory buffer from its backed memory allocator.
+ *
+ * @param phandler
+ * specify the handler of memory buffer to retrieve
+ *
+ * @return a holder contains the retrieved memory buffer
+ */
+ public MemBufferHolder<A> retrieveBuffer(long phandler) {
+ return retrieveBuffer(phandler, true);
+ }
- /**
- * retrieve a memory chunk from its backed memory allocator.
- *
- * @param phandler
- * specify the handler of memory chunk to retrieve
- *
- * @return a holder contains the retrieved memory chunk
- */
- public MemChunkHolder<A> retrieveChunk(long phandler) {
- return retrieveChunk(phandler, true);
- }
+ /**
+ * retrieve a memory chunk from its backed memory allocator.
+ *
+ * @param phandler
+ * specify the handler of memory chunk to retrieve
+ *
+ * @return a holder contains the retrieved memory chunk
+ */
+ public MemChunkHolder<A> retrieveChunk(long phandler) {
+ return retrieveChunk(phandler, true);
+ }
- /**
- * retrieve a memory buffer from its backed memory allocator.
- *
- * @param phandler
- * specify the handler of memory buffer to retrieve
- *
- * @param autoreclaim
- * specify whether this retrieved memory buffer can be reclaimed automatically or not
- *
- * @return a holder contains the retrieved memory buffer
- */
- abstract public MemBufferHolder<A> retrieveBuffer(long phandler, boolean autoreclaim);
+ /**
+ * retrieve a memory buffer from its backed memory allocator.
+ *
+ * @param phandler
+ * specify the handler of memory buffer to retrieve
+ *
+ * @param autoreclaim
+ * specify whether this retrieved memory buffer can be reclaimed
+ * automatically or not
+ *
+ * @return a holder contains the retrieved memory buffer
+ */
+ abstract public MemBufferHolder<A> retrieveBuffer(long phandler, boolean autoreclaim);
- /**
- * retrieve a memory chunk from its backed memory allocator.
- *
- * @param phandler
- * specify the handler of memory chunk to retrieve
- *
- * @param autoreclaim
- * specify whether this retrieved memory chunk can be reclaimed automatically or not
- *
- * @return a holder contains the retrieved memory chunk
- */
- abstract public MemChunkHolder<A> retrieveChunk(long phandler, boolean autoreclaim);
+ /**
+ * retrieve a memory chunk from its backed memory allocator.
+ *
+ * @param phandler
+ * specify the handler of memory chunk to retrieve
+ *
+ * @param autoreclaim
+ * specify whether this retrieved memory chunk can be reclaimed
+ * automatically or not
+ *
+ * @return a holder contains the retrieved memory chunk
+ */
+ abstract public MemChunkHolder<A> retrieveChunk(long phandler, boolean autoreclaim);
- /**
- * get the handler from a memory buffer holder.
- *
- * @param mbuf
- * specify the memory buffer holder
- *
- * @return a handler that could be used to retrieve its memory buffer
- */
- abstract public long getBufferHandler(MemBufferHolder<A> mbuf);
+ /**
+ * get the handler from a memory buffer holder.
+ *
+ * @param mbuf
+ * specify the memory buffer holder
+ *
+ * @return a handler that could be used to retrieve its memory buffer
+ */
+ abstract public long getBufferHandler(MemBufferHolder<A> mbuf);
- /**
- * get the handler from a memory chunk holder.
- *
- * @param mchunk
- * specify the memory chunk holder
- *
- * @return a handler that could be used to retrieve its memory chunk
- */
- abstract public long getChunkHandler(MemChunkHolder<A> mchunk);
+ /**
+ * get the handler from a memory chunk holder.
+ *
+ * @param mchunk
+ * specify the memory chunk holder
+ *
+ * @return a handler that could be used to retrieve its memory chunk
+ */
+ abstract public long getChunkHandler(MemChunkHolder<A> mchunk);
- /**
- * start a application level transaction on this allocator.
- *
- */
- abstract public void beginTransaction();
+ /**
+ * start a application level transaction on this allocator.
+ *
+ */
+ abstract public void beginTransaction();
- /**
- * end a application level transaction on this allocator.
- *
- */
- abstract public void endTransaction();
+ /**
+ * end a application level transaction on this allocator.
+ *
+ */
+ abstract public void endTransaction();
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/ContainerOverflowException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/ContainerOverflowException.java b/core/src/main/java/org/apache/mnemonic/ContainerOverflowException.java
index d6c053a..1791602 100644
--- a/core/src/main/java/org/apache/mnemonic/ContainerOverflowException.java
+++ b/core/src/main/java/org/apache/mnemonic/ContainerOverflowException.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -6,15 +23,15 @@ package org.apache.mnemonic;
*/
public class ContainerOverflowException extends RuntimeException {
- private static final long serialVersionUID = -8515518456414990004L;
+ private static final long serialVersionUID = -8515518456414990004L;
- /**
- * accept a exception message to describe specific condition.
- *
- * @param message
- * exception message
- */
- public ContainerOverflowException(String message) {
- super(message);
- }
+ /**
+ * accept a exception message to describe specific condition.
+ *
+ * @param message
+ * exception message
+ */
+ public ContainerOverflowException(String message) {
+ super(message);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/DropEvent.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/DropEvent.java b/core/src/main/java/org/apache/mnemonic/DropEvent.java
index b3ca93f..f1bfa9c 100644
--- a/core/src/main/java/org/apache/mnemonic/DropEvent.java
+++ b/core/src/main/java/org/apache/mnemonic/DropEvent.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -6,19 +23,19 @@ package org.apache.mnemonic;
*
*/
public interface DropEvent<KeyT, ValueT> {
- /**
- * A call-back actor when an entry has been evicted. a customized drop
- * action can be implemented on this interface's method e.g. spill this
- * entry to disk or release associated resources etc.
- *
- * @param pool
- * the pool which an entry has been evicted from
- *
- * @param k
- * the key of an entry that has been evicted
- *
- * @param v
- * the value of an entry that has been evicted
- */
- public void drop(CachePool<KeyT, ValueT> pool, KeyT k, ValueT v);
+ /**
+ * A call-back actor when an entry has been evicted. a customized drop action
+ * can be implemented on this interface's method e.g. spill this entry to disk
+ * or release associated resources etc.
+ *
+ * @param pool
+ * the pool which an entry has been evicted from
+ *
+ * @param k
+ * the key of an entry that has been evicted
+ *
+ * @param v
+ * the value of an entry that has been evicted
+ */
+ public void drop(CachePool<KeyT, ValueT> pool, KeyT k, ValueT v);
}
[7/7] incubator-mnemonic git commit: format codestyle & add Apache
License
Posted by ga...@apache.org.
format codestyle & add Apache License
Project: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/commit/551c8247
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/tree/551c8247
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/diff/551c8247
Branch: refs/heads/master
Commit: 551c8247d07ead2ce64be0e8520bfd1e3d8875d3
Parents: af3bb70
Author: Wang, Gang(Gary) <ga...@intel.com>
Authored: Fri Apr 8 14:45:39 2016 -0700
Committer: Wang, Gang(Gary) <ga...@intel.com>
Committed: Fri Apr 8 14:45:39 2016 -0700
----------------------------------------------------------------------
.../internal/VMemServiceImpl.java | 137 +-
.../nvml-vmem-service/src/main/native/common.c | 38 +-
.../nvml-vmem-service/src/main/native/common.h | 18 +
..._allocatorservice_internal_VMemServiceImpl.c | 261 +--
..._allocatorservice_internal_VMemServiceImpl.h | 23 +-
.../internal/PMallocServiceImpl.java | 218 +--
.../pmalloc-service/src/main/native/common.c | 38 +-
.../pmalloc-service/src/main/native/common.h | 18 +
...locatorservice_internal_PMallocServiceImpl.c | 437 +++--
...locatorservice_internal_PMallocServiceImpl.h | 23 +-
.../collections/NonVolatileNodeValue.java | 250 +--
.../collections/NonVolatileNodeValueNGTest.java | 469 ++---
.../collections/NonVolatilePersonNGTest.java | 233 +--
.../apache/mnemonic/collections/Payload.java | 45 +-
.../org/apache/mnemonic/collections/Person.java | 123 +-
.../java/org/apache/mnemonic/Allocatable.java | 193 +-
.../java/org/apache/mnemonic/Allocator.java | 69 +-
.../AnnotatedNonVolatileEntityClass.java | 1807 +++++++++---------
.../mnemonic/AnnotationProcessingException.java | 37 +-
.../apache/mnemonic/BigDataMemAllocator.java | 476 ++---
.../apache/mnemonic/BigDataPMemAllocator.java | 831 ++++----
.../mnemonic/ByteBufferBackedInputStream.java | 101 +-
.../mnemonic/ByteBufferBackedOutputStream.java | 99 +-
.../apache/mnemonic/ByteBufferSerializer.java | 266 +--
.../java/org/apache/mnemonic/CachePool.java | 247 +--
.../org/apache/mnemonic/CommonAllocator.java | 185 +-
.../apache/mnemonic/CommonPersistAllocator.java | 220 ++-
.../mnemonic/ContainerOverflowException.java | 37 +-
.../java/org/apache/mnemonic/DropEvent.java | 47 +-
.../main/java/org/apache/mnemonic/Durable.java | 136 +-
.../org/apache/mnemonic/EntityFactoryProxy.java | 68 +-
.../java/org/apache/mnemonic/EvictFilter.java | 49 +-
.../java/org/apache/mnemonic/GenericField.java | 529 ++---
.../org/apache/mnemonic/MemBufferHolder.java | 104 +-
.../mnemonic/MemBufferHolderCachePool.java | 440 ++---
.../org/apache/mnemonic/MemChunkHolder.java | 113 +-
.../java/org/apache/mnemonic/MemClustering.java | 496 ++---
.../main/java/org/apache/mnemonic/MemFile.java | 86 +-
.../java/org/apache/mnemonic/MemHolder.java | 109 +-
.../mnemonic/MemoryNonVolatileEntity.java | 35 +-
.../org/apache/mnemonic/NonVolatileEntity.java | 20 +-
.../mnemonic/NonVolatileEntityProcessor.java | 218 ++-
.../org/apache/mnemonic/NonVolatileGetter.java | 28 +-
.../org/apache/mnemonic/NonVolatileSetter.java | 20 +-
.../apache/mnemonic/OutOfPersistentMemory.java | 25 +-
.../apache/mnemonic/PMAddressTranslator.java | 86 +-
.../main/java/org/apache/mnemonic/Reclaim.java | 45 +-
.../RetrieveNonVolatileEntityError.java | 32 +-
.../org/apache/mnemonic/SysMemAllocator.java | 517 ++---
.../main/java/org/apache/mnemonic/Utils.java | 664 +++----
.../NonVolatileMemoryAllocatorService.java | 189 +-
.../VolatileMemoryAllocatorService.java | 240 +--
.../mnemonic/BigDataMemAllocatorNGTest.java | 91 +-
.../mnemonic/BigDataPMemAllocatorNGTest.java | 228 +--
.../mnemonic/ByteBufferSerializerNGTest.java | 89 +-
.../MemBufferHolderCachePoolNGTest.java | 257 +--
.../apache/mnemonic/MemClusteringNGTest.java | 329 ++--
.../mnemonic/NonVolatilePersonNGTest.java | 234 +--
.../test/java/org/apache/mnemonic/Payload.java | 45 +-
.../test/java/org/apache/mnemonic/Person.java | 121 +-
.../java/org/apache/mnemonic/example/Main.java | 316 +--
61 files changed, 6873 insertions(+), 6032 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/allocator-services/nvml-vmem-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java
----------------------------------------------------------------------
diff --git a/allocator-services/nvml-vmem-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java b/allocator-services/nvml-vmem-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java
index 6e4558d..0bad38f 100644
--- a/allocator-services/nvml-vmem-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java
+++ b/allocator-services/nvml-vmem-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/VMemServiceImpl.java
@@ -1,94 +1,101 @@
+/*
+ * 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.mnemonic.service.allocatorservice.internal;
import org.apache.mnemonic.service.allocatorservice.VolatileMemoryAllocatorService;
import org.flowcomputing.commons.primitives.*;
import java.nio.ByteBuffer;
-
public class VMemServiceImpl implements VolatileMemoryAllocatorService {
- static {
- try {
- NativeLibraryLoader.loadFromJar("vmemallocator");
- } catch (Exception e) {
- throw new Error(e);
- }
- }
-
- @Override
- public String getServiceId() {
- return "vmem";
- }
-
- @Override
- public long init(long capacity, String uri, boolean isnew) {
- return ninit(capacity, uri, isnew);
- }
-
- @Override
- public void close(long id) {
- nclose(id);
- }
-
- @Override
- public void sync(long id) {
- nsync(id);
+ static {
+ try {
+ NativeLibraryLoader.loadFromJar("vmemallocator");
+ } catch (Exception e) {
+ throw new Error(e);
}
+ }
- @Override
- public long allocate(long id, long size, boolean initzero) {
- return nallocate(id, size, initzero);
- }
-
- @Override
- public long reallocate(long id, long address, long size, boolean initzero) {
- return nreallocate(id, address, size, initzero);
- }
-
- @Override
- public void free(long id, long address) {
- nfree(id, address);
- }
+ @Override
+ public String getServiceId() {
+ return "vmem";
+ }
- @Override
- public ByteBuffer createByteBuffer(long id, long size) {
- return ncreateByteBuffer(id, size);
- }
-
- @Override
- public ByteBuffer resizeByteBuffer(long id, ByteBuffer bytebuf, long size) {
- return nresizeByteBuffer(id, bytebuf, size);
- }
-
- @Override
- public void destroyByteBuffer(long id, ByteBuffer bytebuf) {
- ndestroyByteBuffer(id, bytebuf);
- }
+ @Override
+ public long init(long capacity, String uri, boolean isnew) {
+ return ninit(capacity, uri, isnew);
+ }
+ @Override
+ public void close(long id) {
+ nclose(id);
+ }
- protected native long ninit(long capacity, String uri, boolean isnew);
+ @Override
+ public void sync(long id) {
+ nsync(id);
+ }
+ @Override
+ public long allocate(long id, long size, boolean initzero) {
+ return nallocate(id, size, initzero);
+ }
- protected native void nclose(long id);
+ @Override
+ public long reallocate(long id, long address, long size, boolean initzero) {
+ return nreallocate(id, address, size, initzero);
+ }
+ @Override
+ public void free(long id, long address) {
+ nfree(id, address);
+ }
- protected native void nsync(long id);
+ @Override
+ public ByteBuffer createByteBuffer(long id, long size) {
+ return ncreateByteBuffer(id, size);
+ }
+ @Override
+ public ByteBuffer resizeByteBuffer(long id, ByteBuffer bytebuf, long size) {
+ return nresizeByteBuffer(id, bytebuf, size);
+ }
- protected native long nallocate(long id, long size, boolean initzero);
+ @Override
+ public void destroyByteBuffer(long id, ByteBuffer bytebuf) {
+ ndestroyByteBuffer(id, bytebuf);
+ }
+ protected native long ninit(long capacity, String uri, boolean isnew);
- protected native long nreallocate(long id, long address, long size, boolean initzero);
+ protected native void nclose(long id);
+ protected native void nsync(long id);
- protected native void nfree(long id, long address);
+ protected native long nallocate(long id, long size, boolean initzero);
+ protected native long nreallocate(long id, long address, long size, boolean initzero);
- protected native ByteBuffer ncreateByteBuffer(long id, long size);
+ protected native void nfree(long id, long address);
+ protected native ByteBuffer ncreateByteBuffer(long id, long size);
- protected native ByteBuffer nresizeByteBuffer(long id, ByteBuffer bytebuf, long size);
-
+ protected native ByteBuffer nresizeByteBuffer(long id, ByteBuffer bytebuf, long size);
- protected native void ndestroyByteBuffer(long id, ByteBuffer bytebuf);
+ protected native void ndestroyByteBuffer(long id, ByteBuffer bytebuf);
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/allocator-services/nvml-vmem-service/src/main/native/common.c
----------------------------------------------------------------------
diff --git a/allocator-services/nvml-vmem-service/src/main/native/common.c b/allocator-services/nvml-vmem-service/src/main/native/common.c
index e7d6772..143743e 100644
--- a/allocator-services/nvml-vmem-service/src/main/native/common.c
+++ b/allocator-services/nvml-vmem-service/src/main/native/common.c
@@ -1,10 +1,23 @@
-/****************************************************************************************
-Revise Date: 20 Apr. 2014
-*****************************************************************************************/
+/**
+ * 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.
+ */
#include <common.h>
-
/******************************************************************************
** Generally-useful functions for JNI programming.
*****************************************************************************/
@@ -13,13 +26,12 @@ Revise Date: 20 Apr. 2014
* Throws a RuntimeException, with either an explicit message or the message
* corresponding to the current system error value.
*/
-void throw(JNIEnv* env, const char* msg)
-{
- if (msg == NULL)
- msg = sys_errlist[errno];
+void throw(JNIEnv* env, const char* msg) {
+ if (msg == NULL)
+ msg = sys_errlist[errno];
- jclass xklass = (*env)->FindClass(env, "java/lang/RuntimeException");
- (*env)->ThrowNew(env, xklass, msg);
+ jclass xklass = (*env)->FindClass(env, "java/lang/RuntimeException");
+ (*env)->ThrowNew(env, xklass, msg);
}
void* addr_from_java(jlong addr) {
@@ -27,11 +39,11 @@ void* addr_from_java(jlong addr) {
// It is impossible to predict whether native code that converts
// pointers to longs will sign-extend or zero-extend the addresses.
//assert(addr == (uintptr_t)addr, "must not be odd high bits");
- return (void*)(uintptr_t)addr;
+ return (void*) (uintptr_t) addr;
}
jlong addr_to_java(void* p) {
- assert(p == (void*)(uintptr_t)p);
- return (long)(uintptr_t)p;
+ assert(p == (void*) (uintptr_t) p);
+ return (long) (uintptr_t) p;
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/allocator-services/nvml-vmem-service/src/main/native/common.h
----------------------------------------------------------------------
diff --git a/allocator-services/nvml-vmem-service/src/main/native/common.h b/allocator-services/nvml-vmem-service/src/main/native/common.h
index d2b8250..f03dbff 100644
--- a/allocator-services/nvml-vmem-service/src/main/native/common.h
+++ b/allocator-services/nvml-vmem-service/src/main/native/common.h
@@ -1,3 +1,21 @@
+/**
+ * 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.
+ */
+
#ifndef _COMMON_H
#define _COMMON_H
#ifdef __cplusplus
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c
----------------------------------------------------------------------
diff --git a/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c b/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c
index 824b703..eb02fe2 100644
--- a/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c
+++ b/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.c
@@ -1,6 +1,20 @@
-/****************************************************************************************
-Revise Date: 20 Apr. 2014
-*****************************************************************************************/
+/**
+ * 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.
+ */
#include "org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h"
@@ -18,168 +32,155 @@ static pthread_rwlock_t g_vmem_rwlock = PTHREAD_RWLOCK_INITIALIZER;
*****************************************************************************/
JNIEXPORT
-jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nallocate(
- JNIEnv* env,
- jobject this, jlong id,
- jlong size, jboolean initzero)
-{
- pthread_rwlock_rdlock(&g_vmem_rwlock);
- pthread_mutex_lock(g_vmem_mutex_ptr + id);
- void* nativebuf = initzero ? vmem_calloc(*(g_vmp_ptr + id), 1, size) : vmem_malloc(*(g_vmp_ptr + id), size);
- pthread_mutex_unlock(g_vmem_mutex_ptr + id);
- pthread_rwlock_unlock(&g_vmem_rwlock);
- return addr_to_java(nativebuf);
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nallocate(JNIEnv* env,
+ jobject this, jlong id, jlong size, jboolean initzero) {
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ void* nativebuf = initzero ? vmem_calloc(*(g_vmp_ptr + id), 1, size) : vmem_malloc(*(g_vmp_ptr + id), size);
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return addr_to_java(nativebuf);
}
JNIEXPORT
-jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nreallocate(
- JNIEnv* env,
- jobject this, jlong id,
- jlong address,
- jlong size, jboolean initzero)
-{
- pthread_rwlock_rdlock(&g_vmem_rwlock);
- pthread_mutex_lock(g_vmem_mutex_ptr + id);
-
- void* p = addr_from_java(address);
-
- void* nativebuf = vmem_realloc(*(g_vmp_ptr + id), p, size);
-
- pthread_mutex_unlock(g_vmem_mutex_ptr + id);
- pthread_rwlock_unlock(&g_vmem_rwlock);
- return addr_to_java(nativebuf);
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nreallocate(JNIEnv* env,
+ jobject this, jlong id, jlong address, jlong size, jboolean initzero) {
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+
+ void* p = addr_from_java(address);
+
+ void* nativebuf = vmem_realloc(*(g_vmp_ptr + id), p, size);
+
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return addr_to_java(nativebuf);
}
JNIEXPORT
void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nfree(
- JNIEnv* env,
- jobject this, jlong id,
- jlong address)
+ JNIEnv* env,
+ jobject this, jlong id,
+ jlong address)
{
- pthread_rwlock_rdlock(&g_vmem_rwlock);
- pthread_mutex_lock(g_vmem_mutex_ptr + id);
- void* nativebuf = addr_from_java(address);
- if (nativebuf != NULL)
- vmem_free(*(g_vmp_ptr + id), nativebuf);
- pthread_mutex_unlock(g_vmem_mutex_ptr + id);
- pthread_rwlock_unlock(&g_vmem_rwlock);
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ void* nativebuf = addr_from_java(address);
+ if (nativebuf != NULL)
+ vmem_free(*(g_vmp_ptr + id), nativebuf);
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
}
JNIEXPORT
void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nsync(
- JNIEnv* env,
- jobject this, jlong id)
+ JNIEnv* env,
+ jobject this, jlong id)
{
}
JNIEXPORT
jobject JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_ncreateByteBuffer(
- JNIEnv *env, jobject this, jlong id, jlong size)
-{
- pthread_rwlock_rdlock(&g_vmem_rwlock);
- pthread_mutex_lock(g_vmem_mutex_ptr + id);
- jobject ret = NULL;
- void* nativebuf = vmem_malloc(*(g_vmp_ptr + id), size);
- ret = NULL != nativebuf ? (*env)->NewDirectByteBuffer(env, nativebuf, size) : NULL;
- pthread_mutex_unlock(g_vmem_mutex_ptr + id);
- pthread_rwlock_unlock(&g_vmem_rwlock);
- return ret;
+ JNIEnv *env, jobject this, jlong id, jlong size) {
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ jobject ret = NULL;
+ void* nativebuf = vmem_malloc(*(g_vmp_ptr + id), size);
+ ret = NULL != nativebuf ? (*env)->NewDirectByteBuffer(env, nativebuf, size) : NULL;
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return ret;
}
JNIEXPORT
jobject JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nresizeByteBuffer(
- JNIEnv *env, jobject this, jlong id, jobject bytebuf, jlong size)
-{
- pthread_rwlock_rdlock(&g_vmem_rwlock);
- pthread_mutex_lock(g_vmem_mutex_ptr + id);
- jobject ret = NULL;
- if (NULL != bytebuf) {
- void* nativebuf = (void*)(*env)->GetDirectBufferAddress(env, bytebuf);
- if (nativebuf != NULL) {
- nativebuf = vmem_realloc(*(g_vmp_ptr + id), nativebuf, size);
- ret = NULL != nativebuf ? (*env)->NewDirectByteBuffer(env, nativebuf, size) : NULL;
- }
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf, jlong size) {
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ jobject ret = NULL;
+ if (NULL != bytebuf) {
+ void* nativebuf = (void*) (*env)->GetDirectBufferAddress(env, bytebuf);
+ if (nativebuf != NULL) {
+ nativebuf = vmem_realloc(*(g_vmp_ptr + id), nativebuf, size);
+ ret = NULL != nativebuf ? (*env)->NewDirectByteBuffer(env, nativebuf, size) : NULL;
}
- pthread_mutex_unlock(g_vmem_mutex_ptr + id);
- pthread_rwlock_unlock(&g_vmem_rwlock);
- return ret;
+ }
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return ret;
}
JNIEXPORT
void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_ndestroyByteBuffer(
- JNIEnv *env, jobject this, jlong id, jobject bytebuf)
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf)
{
- pthread_rwlock_rdlock(&g_vmem_rwlock);
- pthread_mutex_lock(g_vmem_mutex_ptr + id);
- if (NULL != bytebuf) {
- void* nativebuf = (void*)(*env)->GetDirectBufferAddress(env, bytebuf);
- if (nativebuf != NULL) {
- vmem_free(*(g_vmp_ptr + id), nativebuf);
- }
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ if (NULL != bytebuf) {
+ void* nativebuf = (void*)(*env)->GetDirectBufferAddress(env, bytebuf);
+ if (nativebuf != NULL) {
+ vmem_free(*(g_vmp_ptr + id), nativebuf);
}
- pthread_mutex_unlock(g_vmem_mutex_ptr + id);
- pthread_rwlock_unlock(&g_vmem_rwlock);
+ }
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
}
-JNIEXPORT
-jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_ninit
- (JNIEnv *env, jclass this, jlong capacity, jstring pathname, jboolean isnew)
-{
- pthread_rwlock_wrlock(&g_vmem_rwlock);
- size_t ret = -1;
- VMEM *vmp = NULL;
- const char* mpathname = (*env)->GetStringUTFChars(env, pathname, NULL);
- if (NULL == mpathname) {
- pthread_rwlock_unlock(&g_vmem_rwlock);
- throw(env, "Big memory path not specified!");
- }
- if ((vmp = vmem_create(mpathname, capacity)) == NULL) {
- pthread_rwlock_unlock(&g_vmem_rwlock);
- throw(env, "Big memory init failure!");
- }
- g_vmp_ptr = realloc(g_vmp_ptr, (g_vmp_count + 1) * sizeof(VMEM*));
- g_vmem_mutex_ptr =
- realloc(g_vmem_mutex_ptr, (g_vmp_count + 1) * sizeof(pthread_mutex_t));
- if (NULL != g_vmp_ptr && NULL != g_vmem_mutex_ptr) {
- g_vmp_ptr[g_vmp_count] = vmp;
- pthread_mutex_init(g_vmem_mutex_ptr + g_vmp_count, NULL);
- ret = g_vmp_count;
- g_vmp_count++;
- } else {
- pthread_rwlock_unlock(&g_vmem_rwlock);
- throw(env, "Big memory init Out of memory!");
- }
- pthread_rwlock_unlock(&g_vmem_rwlock);
- return ret;
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_ninit(JNIEnv *env, jclass this,
+ jlong capacity, jstring pathname, jboolean isnew) {
+ pthread_rwlock_wrlock(&g_vmem_rwlock);
+ size_t ret = -1;
+ VMEM *vmp = NULL;
+ const char* mpathname = (*env)->GetStringUTFChars(env, pathname, NULL);
+ if (NULL == mpathname) {
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ throw(env, "Big memory path not specified!");
+ }
+ if ((vmp = vmem_create(mpathname, capacity)) == NULL) {
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ throw(env, "Big memory init failure!");
+ }
+ g_vmp_ptr = realloc(g_vmp_ptr, (g_vmp_count + 1) * sizeof(VMEM*));
+ g_vmem_mutex_ptr = realloc(g_vmem_mutex_ptr, (g_vmp_count + 1) * sizeof(pthread_mutex_t));
+ if (NULL != g_vmp_ptr && NULL != g_vmem_mutex_ptr) {
+ g_vmp_ptr[g_vmp_count] = vmp;
+ pthread_mutex_init(g_vmem_mutex_ptr + g_vmp_count, NULL);
+ ret = g_vmp_count;
+ g_vmp_count++;
+ } else {
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ throw(env, "Big memory init Out of memory!");
+ }
+ pthread_rwlock_unlock(&g_vmem_rwlock);
+ return ret;
}
-JNIEXPORT
+JNIEXPORT
void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_nclose
- (JNIEnv *env, jobject this, jlong id)
+(JNIEnv *env, jobject this, jlong id)
{
- pthread_rwlock_rdlock(&g_vmem_rwlock);
- pthread_mutex_lock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_rdlock(&g_vmem_rwlock);
+ pthread_mutex_lock(g_vmem_mutex_ptr + id);
- pthread_mutex_unlock(g_vmem_mutex_ptr + id);
- pthread_rwlock_unlock(&g_vmem_rwlock);
+ pthread_mutex_unlock(g_vmem_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_vmem_rwlock);
}
-
-__attribute__((destructor)) void fini(void)
-{
- int i;
- if (NULL != g_vmp_ptr) {
- for (i = 0; i < g_vmp_count; ++i) {
- if (NULL != *(g_vmp_ptr + i)){
- /* vmem_close(*(g_vmp_ptr + i)); undefined function */
- *(g_vmp_ptr + i) = NULL;
- pthread_mutex_destroy(g_vmem_mutex_ptr + i);
- }
- }
- free(g_vmp_ptr);
- g_vmp_ptr = NULL;
- free(g_vmem_mutex_ptr);
- g_vmem_mutex_ptr = NULL;
- g_vmp_count = 0;
- }
+__attribute__((destructor)) void fini(void) {
+ int i;
+ if (NULL != g_vmp_ptr) {
+ for (i = 0; i < g_vmp_count; ++i) {
+ if (NULL != *(g_vmp_ptr + i)) {
+ /* vmem_close(*(g_vmp_ptr + i)); undefined function */
+ *(g_vmp_ptr + i) = NULL;
+ pthread_mutex_destroy(g_vmem_mutex_ptr + i);
+ }
+ }
+ free(g_vmp_ptr);
+ g_vmp_ptr = NULL;
+ free(g_vmem_mutex_ptr);
+ g_vmem_mutex_ptr = NULL;
+ g_vmp_count = 0;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h
----------------------------------------------------------------------
diff --git a/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h b/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h
index 9a2e73a..bdea3a7 100644
--- a/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h
+++ b/allocator-services/nvml-vmem-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl.h
@@ -1,4 +1,21 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
+/**
+ * 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.
+ */
+
#include <jni.h>
/* Header for class org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl */
@@ -15,7 +32,7 @@ extern "C" {
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_jniInit
- (JNIEnv *, jobject, jint, jint);
+(JNIEnv *, jobject, jint, jint);
/*
* Class: org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl
@@ -23,7 +40,7 @@ JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_allocatorservice_interna
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_VMemServiceImpl_jniTerm
- (JNIEnv *, jobject);
+(JNIEnv *, jobject);
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/allocator-services/pmalloc-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java
----------------------------------------------------------------------
diff --git a/allocator-services/pmalloc-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java b/allocator-services/pmalloc-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java
index f96d3b3..0a93f15 100644
--- a/allocator-services/pmalloc-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java
+++ b/allocator-services/pmalloc-service/src/main/java/org/apache/mnemonic/service/allocatorservice/internal/PMallocServiceImpl.java
@@ -1,150 +1,150 @@
+/*
+ * 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.mnemonic.service.allocatorservice.internal;
import org.apache.mnemonic.service.allocatorservice.NonVolatileMemoryAllocatorService;
import org.flowcomputing.commons.primitives.*;
import java.nio.ByteBuffer;
-
public class PMallocServiceImpl implements NonVolatileMemoryAllocatorService {
- static {
- try {
- NativeLibraryLoader.loadFromJar("pmallocallocator");
- } catch (Exception e) {
- throw new Error(e);
- }
- }
+ static {
+ try {
+ NativeLibraryLoader.loadFromJar("pmallocallocator");
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
+
+ @Override
+ public String getServiceId() {
+ return "pmalloc";
+ }
- @Override
- public String getServiceId() {
- return "pmalloc";
- }
+ @Override
+ public long init(long capacity, String uri, boolean isnew) {
+ return ninit(capacity, uri, isnew);
+ }
- @Override
- public long init(long capacity, String uri, boolean isnew) {
- return ninit(capacity, uri, isnew);
- }
-
- @Override
- public void close(long id) {
- nclose(id);
- }
+ @Override
+ public void close(long id) {
+ nclose(id);
+ }
- @Override
- public void sync(long id) {
- nsync(id);
- }
+ @Override
+ public void sync(long id) {
+ nsync(id);
+ }
- @Override
- public long allocate(long id, long size, boolean initzero) {
- return nallocate(id, size, initzero);
- }
+ @Override
+ public long allocate(long id, long size, boolean initzero) {
+ return nallocate(id, size, initzero);
+ }
- @Override
- public long reallocate(long id, long address, long size, boolean initzero) {
- return nreallocate(id, address, size, initzero);
- }
+ @Override
+ public long reallocate(long id, long address, long size, boolean initzero) {
+ return nreallocate(id, address, size, initzero);
+ }
- @Override
- public void free(long id, long address) {
- nfree(id, address);
- }
+ @Override
+ public void free(long id, long address) {
+ nfree(id, address);
+ }
- @Override
- public ByteBuffer createByteBuffer(long id, long size) {
- return ncreateByteBuffer(id, size);
- }
+ @Override
+ public ByteBuffer createByteBuffer(long id, long size) {
+ return ncreateByteBuffer(id, size);
+ }
- @Override
- public ByteBuffer resizeByteBuffer(long id, ByteBuffer bytebuf, long size) {
- return nresizeByteBuffer(id, bytebuf, size);
- }
+ @Override
+ public ByteBuffer resizeByteBuffer(long id, ByteBuffer bytebuf, long size) {
+ return nresizeByteBuffer(id, bytebuf, size);
+ }
- @Override
- public void destroyByteBuffer(long id, ByteBuffer bytebuf) {
- ndestroyByteBuffer(id, bytebuf);
- }
+ @Override
+ public void destroyByteBuffer(long id, ByteBuffer bytebuf) {
+ ndestroyByteBuffer(id, bytebuf);
+ }
- @Override
- public ByteBuffer retrieveByteBuffer(long id, long handler) {
- return nretrieveByteBuffer(id, handler);
- }
-
- @Override
- public long retrieveSize(long id, long handler) {
- return nretrieveSize(id, handler);
- }
-
- @Override
- public long getByteBufferHandler(long id, ByteBuffer buf) {
- return ngetByteBufferHandler(id, buf);
- }
-
- @Override
- public void setHandler(long id, long key, long handler) {
- nsetHandler(id, key, handler);
- }
-
- @Override
- public long getHandler(long id, long key) {
- return ngetHandler(id, key);
- }
-
- @Override
- public long handlerCapacity(long id) {
- return nhandlerCapacity(id);
- }
-
- @Override
- public long getBaseAddress(long id) {
- return ngetBaseAddress(id);
- }
+ @Override
+ public ByteBuffer retrieveByteBuffer(long id, long handler) {
+ return nretrieveByteBuffer(id, handler);
+ }
- protected native long ninit(long capacity, String uri, boolean isnew);
+ @Override
+ public long retrieveSize(long id, long handler) {
+ return nretrieveSize(id, handler);
+ }
+ @Override
+ public long getByteBufferHandler(long id, ByteBuffer buf) {
+ return ngetByteBufferHandler(id, buf);
+ }
- protected native void nclose(long id);
+ @Override
+ public void setHandler(long id, long key, long handler) {
+ nsetHandler(id, key, handler);
+ }
+ @Override
+ public long getHandler(long id, long key) {
+ return ngetHandler(id, key);
+ }
- protected native void nsync(long id);
+ @Override
+ public long handlerCapacity(long id) {
+ return nhandlerCapacity(id);
+ }
+ @Override
+ public long getBaseAddress(long id) {
+ return ngetBaseAddress(id);
+ }
- protected native long nallocate(long id, long size, boolean initzero);
+ protected native long ninit(long capacity, String uri, boolean isnew);
+ protected native void nclose(long id);
- protected native long nreallocate(long id, long address, long size, boolean initzero);
+ protected native void nsync(long id);
+ protected native long nallocate(long id, long size, boolean initzero);
- protected native void nfree(long id, long address);
+ protected native long nreallocate(long id, long address, long size, boolean initzero);
+ protected native void nfree(long id, long address);
- protected native ByteBuffer ncreateByteBuffer(long id, long size);
+ protected native ByteBuffer ncreateByteBuffer(long id, long size);
+ protected native ByteBuffer nresizeByteBuffer(long id, ByteBuffer bytebuf, long size);
- protected native ByteBuffer nresizeByteBuffer(long id, ByteBuffer bytebuf, long size);
-
+ protected native void ndestroyByteBuffer(long id, ByteBuffer bytebuf);
- protected native void ndestroyByteBuffer(long id, ByteBuffer bytebuf);
-
+ protected native ByteBuffer nretrieveByteBuffer(long id, long handler);
- protected native ByteBuffer nretrieveByteBuffer(long id, long handler);
-
-
- protected native long nretrieveSize(long id, long handler);
-
+ protected native long nretrieveSize(long id, long handler);
- protected native long ngetByteBufferHandler(long id, ByteBuffer buf);
-
+ protected native long ngetByteBufferHandler(long id, ByteBuffer buf);
- protected native void nsetHandler(long id, long key, long handler);
-
+ protected native void nsetHandler(long id, long key, long handler);
- protected native long ngetHandler(long id, long key);
-
+ protected native long ngetHandler(long id, long key);
- protected native long nhandlerCapacity(long id);
-
+ protected native long nhandlerCapacity(long id);
- protected native long ngetBaseAddress(long id);
+ protected native long ngetBaseAddress(long id);
-
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/allocator-services/pmalloc-service/src/main/native/common.c
----------------------------------------------------------------------
diff --git a/allocator-services/pmalloc-service/src/main/native/common.c b/allocator-services/pmalloc-service/src/main/native/common.c
index e7d6772..143743e 100644
--- a/allocator-services/pmalloc-service/src/main/native/common.c
+++ b/allocator-services/pmalloc-service/src/main/native/common.c
@@ -1,10 +1,23 @@
-/****************************************************************************************
-Revise Date: 20 Apr. 2014
-*****************************************************************************************/
+/**
+ * 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.
+ */
#include <common.h>
-
/******************************************************************************
** Generally-useful functions for JNI programming.
*****************************************************************************/
@@ -13,13 +26,12 @@ Revise Date: 20 Apr. 2014
* Throws a RuntimeException, with either an explicit message or the message
* corresponding to the current system error value.
*/
-void throw(JNIEnv* env, const char* msg)
-{
- if (msg == NULL)
- msg = sys_errlist[errno];
+void throw(JNIEnv* env, const char* msg) {
+ if (msg == NULL)
+ msg = sys_errlist[errno];
- jclass xklass = (*env)->FindClass(env, "java/lang/RuntimeException");
- (*env)->ThrowNew(env, xklass, msg);
+ jclass xklass = (*env)->FindClass(env, "java/lang/RuntimeException");
+ (*env)->ThrowNew(env, xklass, msg);
}
void* addr_from_java(jlong addr) {
@@ -27,11 +39,11 @@ void* addr_from_java(jlong addr) {
// It is impossible to predict whether native code that converts
// pointers to longs will sign-extend or zero-extend the addresses.
//assert(addr == (uintptr_t)addr, "must not be odd high bits");
- return (void*)(uintptr_t)addr;
+ return (void*) (uintptr_t) addr;
}
jlong addr_to_java(void* p) {
- assert(p == (void*)(uintptr_t)p);
- return (long)(uintptr_t)p;
+ assert(p == (void*) (uintptr_t) p);
+ return (long) (uintptr_t) p;
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/allocator-services/pmalloc-service/src/main/native/common.h
----------------------------------------------------------------------
diff --git a/allocator-services/pmalloc-service/src/main/native/common.h b/allocator-services/pmalloc-service/src/main/native/common.h
index d2b8250..f03dbff 100644
--- a/allocator-services/pmalloc-service/src/main/native/common.h
+++ b/allocator-services/pmalloc-service/src/main/native/common.h
@@ -1,3 +1,21 @@
+/**
+ * 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.
+ */
+
#ifndef _COMMON_H
#define _COMMON_H
#ifdef __cplusplus
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c
----------------------------------------------------------------------
diff --git a/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c b/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c
index c377e82..b3bf391 100644
--- a/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c
+++ b/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.c
@@ -1,14 +1,28 @@
-/****************************************************************************************
-Revise Date: 20 Apr. 2014
-*****************************************************************************************/
+/**
+ * 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.
+ */
#include "org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h"
#include <pmalloc.h>
typedef struct {
- //size_t size;
- jlong size;
+ //size_t size;
+ jlong size;
} PMBHeader;
#define PMBHSZ (sizeof(PMBHeader))
@@ -25,295 +39,276 @@ static pthread_rwlock_t g_pmp_rwlock = PTHREAD_RWLOCK_INITIALIZER;
*****************************************************************************/
JNIEXPORT
-jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nallocate(
- JNIEnv* env,
- jobject this, jlong id,
- jlong size, jboolean initzero)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- jlong ret = 0L;
- void *md = *(g_pmp_ptr + id);
- void* nativebuf = initzero ? pmcalloc(md, 1, size + PMBHSZ) : pmalloc(md, size + PMBHSZ);
- if (NULL != nativebuf) {
- ((PMBHeader *)nativebuf)->size = size + PMBHSZ;
- ret = addr_to_java(nativebuf + PMBHSZ);
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nallocate(JNIEnv* env,
+ jobject this, jlong id, jlong size, jboolean initzero) {
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ jlong ret = 0L;
+ void *md = *(g_pmp_ptr + id);
+ void* nativebuf = initzero ? pmcalloc(md, 1, size + PMBHSZ) : pmalloc(md, size + PMBHSZ);
+ if (NULL != nativebuf) {
+ ((PMBHeader *) nativebuf)->size = size + PMBHSZ;
+ ret = addr_to_java(nativebuf + PMBHSZ);
// fprintf(stderr, "### nallocate size: %lld, %X, header size: %ld ### \n",
// ((PMBHeader *)nativebuf)->size, nativebuf-b_addr(*(g_pmp_ptr + id)), PMBHSZ);
- }
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
- return ret;
+ }
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
}
JNIEXPORT
-jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nreallocate(
- JNIEnv* env,
- jobject this, jlong id,
- jlong address,
- jlong size, jboolean initzero)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- jlong ret = 0L;
- void *md = *(g_pmp_ptr + id);
- void* nativebuf = NULL;
- void* p = addr_from_java(address);
- if (NULL != p) {
- nativebuf = pmrealloc(md, p - PMBHSZ, size + PMBHSZ);
- } else {
- nativebuf = initzero ? pmcalloc(md, 1, size + PMBHSZ) : pmalloc(md, size + PMBHSZ);
- }
- if (nativebuf != NULL) {
- ((PMBHeader *)nativebuf)->size = size + PMBHSZ;
- ret = addr_to_java(nativebuf + PMBHSZ);
- }
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
- return ret;
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nreallocate(JNIEnv* env,
+ jobject this, jlong id, jlong address, jlong size, jboolean initzero) {
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ jlong ret = 0L;
+ void *md = *(g_pmp_ptr + id);
+ void* nativebuf = NULL;
+ void* p = addr_from_java(address);
+ if (NULL != p) {
+ nativebuf = pmrealloc(md, p - PMBHSZ, size + PMBHSZ);
+ } else {
+ nativebuf = initzero ? pmcalloc(md, 1, size + PMBHSZ) : pmalloc(md, size + PMBHSZ);
+ }
+ if (nativebuf != NULL) {
+ ((PMBHeader *) nativebuf)->size = size + PMBHSZ;
+ ret = addr_to_java(nativebuf + PMBHSZ);
+ }
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
}
JNIEXPORT
void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nfree(
- JNIEnv* env,
- jobject this, jlong id,
- jlong address)
+ JNIEnv* env,
+ jobject this, jlong id,
+ jlong address)
{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- //fprintf(stderr, "nfree Get Called %ld, %X\n", id, address);
- void *md = *(g_pmp_ptr + id);
- void* nativebuf = addr_from_java(address);
- if (nativebuf != NULL) {
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ //fprintf(stderr, "nfree Get Called %ld, %X\n", id, address);
+ void *md = *(g_pmp_ptr + id);
+ void* nativebuf = addr_from_java(address);
+ if (nativebuf != NULL) {
// fprintf(stderr, "### nfree size: %lld, %X ###, header size: %ld \n",
// ((PMBHeader *)(nativebuf - PMBHSZ))->size, nativebuf - PMBHSZ-b_addr(*(g_pmp_ptr + id)), PMBHSZ);
- pmfree(md, nativebuf - PMBHSZ);
- }
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
+ pmfree(md, nativebuf - PMBHSZ);
+ }
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
}
JNIEXPORT
void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nsync(
- JNIEnv* env,
- jobject this, jlong id)
+ JNIEnv* env,
+ jobject this, jlong id)
{
}
JNIEXPORT
jobject JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ncreateByteBuffer(
- JNIEnv *env, jobject this, jlong id, jlong size)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- jobject ret = NULL;
- void *md = *(g_pmp_ptr + id);
- void* nativebuf = pmalloc(md, size + PMBHSZ);
- if (NULL != nativebuf) {
- ((PMBHeader *)nativebuf)->size = size + PMBHSZ;
- ret = (*env)->NewDirectByteBuffer(env, nativebuf + PMBHSZ, size);
+ JNIEnv *env, jobject this, jlong id, jlong size) {
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ jobject ret = NULL;
+ void *md = *(g_pmp_ptr + id);
+ void* nativebuf = pmalloc(md, size + PMBHSZ);
+ if (NULL != nativebuf) {
+ ((PMBHeader *) nativebuf)->size = size + PMBHSZ;
+ ret = (*env)->NewDirectByteBuffer(env, nativebuf + PMBHSZ, size);
// fprintf(stderr, "### ncreateByteBuffer size: %lld, %X ###, header size: %ld \n",
// ((PMBHeader *)nativebuf)->size, nativebuf-b_addr(*(g_pmp_ptr + id)), PMBHSZ);
- }
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
- return ret;
+ }
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
}
JNIEXPORT
jobject JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nretrieveByteBuffer(
- JNIEnv *env, jobject this, jlong id, jlong e_addr)
-{
- jobject ret = NULL;
- void* p = addr_from_java(e_addr);
- if (NULL != p) {
- void* nativebuf = p - PMBHSZ;
- ret = (*env)->NewDirectByteBuffer(env, p, ((PMBHeader *)nativebuf)->size - PMBHSZ);
- }
- return ret;
+ JNIEnv *env, jobject this, jlong id, jlong e_addr) {
+ jobject ret = NULL;
+ void* p = addr_from_java(e_addr);
+ if (NULL != p) {
+ void* nativebuf = p - PMBHSZ;
+ ret = (*env)->NewDirectByteBuffer(env, p, ((PMBHeader *) nativebuf)->size - PMBHSZ);
+ }
+ return ret;
}
JNIEXPORT
-jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nretrieveSize(
- JNIEnv *env, jobject this, jlong id, jlong e_addr)
-{
- jlong ret = 0L;
- void* p = addr_from_java(e_addr);
- if (NULL != p) {
- void* nativebuf = p - PMBHSZ;
- ret = ((PMBHeader *)nativebuf)->size - PMBHSZ;
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nretrieveSize(JNIEnv *env,
+ jobject this, jlong id, jlong e_addr) {
+ jlong ret = 0L;
+ void* p = addr_from_java(e_addr);
+ if (NULL != p) {
+ void* nativebuf = p - PMBHSZ;
+ ret = ((PMBHeader *) nativebuf)->size - PMBHSZ;
// fprintf(stderr, "### nretrieveSize size: %lld, %X ###, header size: %ld \n",
// ((PMBHeader *)nativebuf)->size, nativebuf-b_addr(*(g_pmp_ptr + id)), PMBHSZ);
- }
- return ret;
+ }
+ return ret;
}
JNIEXPORT
jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ngetByteBufferHandler(
- JNIEnv *env, jobject this, jlong id, jobject bytebuf)
-{
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf) {
// fprintf(stderr, "ngetByteBufferAddress Get Called %X, %X\n", env, bytebuf);
- jlong ret = 0L;
- if (NULL != bytebuf) {
- void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
+ jlong ret = 0L;
+ if (NULL != bytebuf) {
+ void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
// fprintf(stderr, "ngetByteBufferAddress Get Native address %X\n", nativebuf);
- ret = addr_to_java(nativebuf);
- }
+ ret = addr_to_java(nativebuf);
+ }
// fprintf(stderr, "ngetByteBufferAddress returned address %016lx\n", ret);
- return ret;
+ return ret;
}
JNIEXPORT
jobject JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nresizeByteBuffer(
- JNIEnv *env, jobject this, jlong id, jobject bytebuf, jlong size)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- jobject ret = NULL;
- void *md = *(g_pmp_ptr + id);
- if (NULL != bytebuf) {
- void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
- if (nativebuf != NULL) {
- nativebuf = pmrealloc(md, nativebuf - PMBHSZ, size + PMBHSZ);
- if (NULL != nativebuf) {
- ((PMBHeader *)nativebuf)->size = size + PMBHSZ;
- ret = (*env)->NewDirectByteBuffer(env, nativebuf + PMBHSZ, size);
- }
- }
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf, jlong size) {
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ jobject ret = NULL;
+ void *md = *(g_pmp_ptr + id);
+ if (NULL != bytebuf) {
+ void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
+ if (nativebuf != NULL) {
+ nativebuf = pmrealloc(md, nativebuf - PMBHSZ, size + PMBHSZ);
+ if (NULL != nativebuf) {
+ ((PMBHeader *) nativebuf)->size = size + PMBHSZ;
+ ret = (*env)->NewDirectByteBuffer(env, nativebuf + PMBHSZ, size);
+ }
}
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
- return ret;
+ }
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
}
JNIEXPORT
void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ndestroyByteBuffer(
- JNIEnv *env, jobject this, jlong id, jobject bytebuf)
+ JNIEnv *env, jobject this, jlong id, jobject bytebuf)
{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- void *md = *(g_pmp_ptr + id);
- if (NULL != bytebuf) {
- void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
- if (nativebuf != NULL) {
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ void *md = *(g_pmp_ptr + id);
+ if (NULL != bytebuf) {
+ void* nativebuf = (*env)->GetDirectBufferAddress(env, bytebuf);
+ if (nativebuf != NULL) {
// fprintf(stderr, "### ndestroyByteBuffer size: %lld, %X, header size: %ld ### \n",
// ((PMBHeader *)(nativebuf - PMBHSZ))->size, nativebuf - PMBHSZ -b_addr(*(g_pmp_ptr + id)), PMBHSZ);
- pmfree(md, nativebuf - PMBHSZ);
- }
+ pmfree(md, nativebuf - PMBHSZ);
}
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
+ }
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
}
JNIEXPORT
void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nsetHandler(
- JNIEnv *env, jobject this, jlong id, jlong key, jlong value)
+ JNIEnv *env, jobject this, jlong id, jlong key, jlong value)
{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- void *md = *(g_pmp_ptr + id);
- if (id < PMALLOC_KEYS && id >= 0) {
- pmalloc_setkey(md, key, (void*)value);
- }
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ void *md = *(g_pmp_ptr + id);
+ if (id < PMALLOC_KEYS && id >= 0) {
+ pmalloc_setkey(md, key, (void*)value);
+ }
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
}
JNIEXPORT
-jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ngetHandler(
- JNIEnv *env, jobject this, jlong id, jlong key)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- void *md = *(g_pmp_ptr + id);
- jlong ret = (id < PMALLOC_KEYS && id >= 0) ? (long)pmalloc_getkey(md, key) : 0;
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
- return ret;
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ngetHandler(JNIEnv *env,
+ jobject this, jlong id, jlong key) {
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ void *md = *(g_pmp_ptr + id);
+ jlong ret = (id < PMALLOC_KEYS && id >= 0) ? (long) pmalloc_getkey(md, key) : 0;
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
}
JNIEXPORT
jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nhandlerCapacity(
- JNIEnv *env, jobject this)
-{
- return PMALLOC_KEYS;
+ JNIEnv *env, jobject this) {
+ return PMALLOC_KEYS;
}
JNIEXPORT
-jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ngetBaseAddress(
- JNIEnv *env, jobject this, jlong id)
-{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- void *md = *(g_pmp_ptr + id);
- jlong ret = (long)b_addr(md);
- pthread_rwlock_unlock(&g_pmp_rwlock);
- return ret;
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ngetBaseAddress(JNIEnv *env,
+ jobject this, jlong id) {
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ void *md = *(g_pmp_ptr + id);
+ jlong ret = (long) b_addr(md);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
}
-JNIEXPORT
-jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ninit
- (JNIEnv *env, jclass this, jlong capacity, jstring pathname, jboolean isnew)
-{
- pthread_rwlock_wrlock(&g_pmp_rwlock);
- size_t ret = -1;
- void *md = NULL;
- const char* mpathname = (*env)->GetStringUTFChars(env, pathname, NULL);
- if (NULL == mpathname) {
- pthread_rwlock_unlock(&g_pmp_rwlock);
- throw(env, "Big memory path not specified!");
- }
- if ((md = pmopen(mpathname, NULL, capacity)) == NULL) {
- pthread_rwlock_unlock(&g_pmp_rwlock);
- throw(env, "Big memory init failure!");
- }
- (*env)->ReleaseStringUTFChars(env, pathname, mpathname);
- g_pmp_ptr = realloc(g_pmp_ptr, (g_pmp_count + 1) * sizeof(void*));
- g_pmalloc_mutex_ptr =
- realloc(g_pmalloc_mutex_ptr, (g_pmp_count + 1) * sizeof(pthread_mutex_t));
- if (NULL != g_pmp_ptr && NULL != g_pmalloc_mutex_ptr) {
- *(g_pmp_ptr + g_pmp_count) = md;
- pthread_mutex_init(g_pmalloc_mutex_ptr + g_pmp_count, NULL);
- ret = g_pmp_count;
- ++g_pmp_count;
- } else {
- pthread_rwlock_unlock(&g_pmp_rwlock);
- throw(env, "Big memory init Out of memory!");
- }
- pthread_rwlock_unlock(&g_pmp_rwlock);
- return ret;
+JNIEXPORT
+jlong JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_ninit(JNIEnv *env,
+ jclass this, jlong capacity, jstring pathname, jboolean isnew) {
+ pthread_rwlock_wrlock(&g_pmp_rwlock);
+ size_t ret = -1;
+ void *md = NULL;
+ const char* mpathname = (*env)->GetStringUTFChars(env, pathname, NULL);
+ if (NULL == mpathname) {
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ throw(env, "Big memory path not specified!");
+ }
+ if ((md = pmopen(mpathname, NULL, capacity)) == NULL) {
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ throw(env, "Big memory init failure!");
+ }
+ (*env)->ReleaseStringUTFChars(env, pathname, mpathname);
+ g_pmp_ptr = realloc(g_pmp_ptr, (g_pmp_count + 1) * sizeof(void*));
+ g_pmalloc_mutex_ptr = realloc(g_pmalloc_mutex_ptr, (g_pmp_count + 1) * sizeof(pthread_mutex_t));
+ if (NULL != g_pmp_ptr && NULL != g_pmalloc_mutex_ptr) {
+ *(g_pmp_ptr + g_pmp_count) = md;
+ pthread_mutex_init(g_pmalloc_mutex_ptr + g_pmp_count, NULL);
+ ret = g_pmp_count;
+ ++g_pmp_count;
+ } else {
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ throw(env, "Big memory init Out of memory!");
+ }
+ pthread_rwlock_unlock(&g_pmp_rwlock);
+ return ret;
}
-JNIEXPORT
+JNIEXPORT
void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_nclose
- (JNIEnv *env, jobject this, jlong id)
+(JNIEnv *env, jobject this, jlong id)
{
- pthread_rwlock_rdlock(&g_pmp_rwlock);
- pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
- void *md = *(g_pmp_ptr + id);
- pmclose(md);
- *(g_pmp_ptr + id) = NULL;
- pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
- pthread_mutex_destroy(g_pmalloc_mutex_ptr + id);
- pthread_rwlock_unlock(&g_pmp_rwlock);
+ pthread_rwlock_rdlock(&g_pmp_rwlock);
+ pthread_mutex_lock(g_pmalloc_mutex_ptr + id);
+ void *md = *(g_pmp_ptr + id);
+ pmclose(md);
+ *(g_pmp_ptr + id) = NULL;
+ pthread_mutex_unlock(g_pmalloc_mutex_ptr + id);
+ pthread_mutex_destroy(g_pmalloc_mutex_ptr + id);
+ pthread_rwlock_unlock(&g_pmp_rwlock);
}
-
-__attribute__((destructor)) void fini(void)
-{
- int i;
- if (NULL != g_pmp_ptr) {
- for (i = 0; i < g_pmp_count; ++i) {
- if (NULL != *(g_pmp_ptr + i)){
- pmclose(*(g_pmp_ptr + i));
- *(g_pmp_ptr + i) = NULL;
- pthread_mutex_destroy(g_pmalloc_mutex_ptr + i);
- }
- }
- free(g_pmp_ptr);
- g_pmp_ptr = NULL;
- free(g_pmalloc_mutex_ptr);
- g_pmalloc_mutex_ptr = NULL;
- g_pmp_count = 0;
- }
- pthread_rwlock_destroy(&g_pmp_rwlock);
+__attribute__((destructor)) void fini(void) {
+ int i;
+ if (NULL != g_pmp_ptr) {
+ for (i = 0; i < g_pmp_count; ++i) {
+ if (NULL != *(g_pmp_ptr + i)) {
+ pmclose(*(g_pmp_ptr + i));
+ *(g_pmp_ptr + i) = NULL;
+ pthread_mutex_destroy(g_pmalloc_mutex_ptr + i);
+ }
+ }
+ free(g_pmp_ptr);
+ g_pmp_ptr = NULL;
+ free(g_pmalloc_mutex_ptr);
+ g_pmalloc_mutex_ptr = NULL;
+ g_pmp_count = 0;
+ }
+ pthread_rwlock_destroy(&g_pmp_rwlock);
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h
----------------------------------------------------------------------
diff --git a/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h b/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h
index 4b119c7..7550462 100644
--- a/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h
+++ b/allocator-services/pmalloc-service/src/main/native/org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl.h
@@ -1,4 +1,21 @@
-/* DO NOT EDIT THIS FILE - it is machine generated */
+/**
+ * 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.
+ */
+
#include <jni.h>
/* Header for class PMallocServiceImpl */
@@ -15,7 +32,7 @@ extern "C" {
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_jniInit
- (JNIEnv *, jobject, jint, jint);
+(JNIEnv *, jobject, jint, jint);
/*
* Class: org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl
@@ -23,7 +40,7 @@ JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_allocatorservice_interna
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_allocatorservice_internal_PMallocServiceImpl_jniTerm
- (JNIEnv *, jobject);
+(JNIEnv *, jobject);
#ifdef __cplusplus
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/collections/src/main/java/org/apache/mnemonic/collections/NonVolatileNodeValue.java
----------------------------------------------------------------------
diff --git a/collections/src/main/java/org/apache/mnemonic/collections/NonVolatileNodeValue.java b/collections/src/main/java/org/apache/mnemonic/collections/NonVolatileNodeValue.java
index d7f45e4..98375e9 100644
--- a/collections/src/main/java/org/apache/mnemonic/collections/NonVolatileNodeValue.java
+++ b/collections/src/main/java/org/apache/mnemonic/collections/NonVolatileNodeValue.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic.collections;
import java.util.Arrays;
@@ -7,144 +24,145 @@ import java.util.NoSuchElementException;
import org.apache.mnemonic.*;
/**
- * this class defines a non-volatile node for a generic value to form a unidirectional link
+ * this class defines a non-volatile node for a generic value to form a
+ * unidirectional link
*
*/
@NonVolatileEntity
-public abstract class NonVolatileNodeValue<E>
- implements Durable, Iterable<E> {
- protected transient EntityFactoryProxy[] m_node_efproxies;
- protected transient GenericField.GType[] m_node_gftypes;
+public abstract class NonVolatileNodeValue<E> implements Durable, Iterable<E> {
+ protected transient EntityFactoryProxy[] m_node_efproxies;
+ protected transient GenericField.GType[] m_node_gftypes;
- /**
- * creation callback for initialization
- *
- */
- @Override
- public void initializeAfterCreate() {
- // System.out.println("Initializing After Created");
- }
+ /**
+ * creation callback for initialization
+ *
+ */
+ @Override
+ public void initializeAfterCreate() {
+ // System.out.println("Initializing After Created");
+ }
- /**
- * restore callback for initialization
- *
- */
- @Override
- public void initializeAfterRestore() {
- // System.out.println("Initializing After Restored");
- }
+ /**
+ * restore callback for initialization
+ *
+ */
+ @Override
+ public void initializeAfterRestore() {
+ // System.out.println("Initializing After Restored");
+ }
- /**
- * this function will be invoked by its factory to setup generic related info to avoid expensive operations from reflection
- *
- * @param efproxies
- * specify a array of factory to proxy the restoring of its generic field objects
- *
- * @param gftypes
- * specify a array of types corresponding to efproxies
- */
- @Override
- public void setupGenericInfo(EntityFactoryProxy[] efproxies, GenericField.GType[] gftypes) {
- m_node_efproxies = efproxies;
- m_node_gftypes = gftypes;
- }
+ /**
+ * this function will be invoked by its factory to setup generic related info
+ * to avoid expensive operations from reflection
+ *
+ * @param efproxies
+ * specify a array of factory to proxy the restoring of its generic
+ * field objects
+ *
+ * @param gftypes
+ * specify a array of types corresponding to efproxies
+ */
+ @Override
+ public void setupGenericInfo(EntityFactoryProxy[] efproxies, GenericField.GType[] gftypes) {
+ m_node_efproxies = efproxies;
+ m_node_gftypes = gftypes;
+ }
- /**
- * get the item value of this node
- *
- * @return the item value of this node
- */
- @NonVolatileGetter(Id = 1L, EntityFactoryProxies = "m_node_efproxies", GenericFieldTypes = "m_node_gftypes")
- abstract public E getItem();
+ /**
+ * get the item value of this node
+ *
+ * @return the item value of this node
+ */
+ @NonVolatileGetter(Id = 1L, EntityFactoryProxies = "m_node_efproxies", GenericFieldTypes = "m_node_gftypes")
+ abstract public E getItem();
- /**
- * set a value to this node item
- *
- * @param value
- * the value to be set
- *
- * @param destroy
- * true if want to destroy exist one
- *
- */
- @NonVolatileSetter
- abstract public void setItem(E value, boolean destroy);
+ /**
+ * set a value to this node item
+ *
+ * @param value
+ * the value to be set
+ *
+ * @param destroy
+ * true if want to destroy exist one
+ *
+ */
+ @NonVolatileSetter
+ abstract public void setItem(E value, boolean destroy);
+
+ /**
+ * get next node
+ *
+ * @return the next node
+ *
+ */
+ @NonVolatileGetter(Id = 2L, EntityFactoryProxies = "m_node_efproxies", GenericFieldTypes = "m_node_gftypes")
+ abstract public NonVolatileNodeValue<E> getNext();
+
+ /**
+ * set next node
+ *
+ * @param next
+ * specify the next node
+ *
+ * @param destroy
+ * true if want to destroy the exist node
+ */
+ @NonVolatileSetter
+ abstract public void setNext(NonVolatileNodeValue<E> next, boolean destroy);
+
+ /**
+ * get an iterator instance of this list
+ *
+ * @return an iterator of this list
+ */
+ @Override
+ public Iterator<E> iterator() {
+ return new Intr(this);
+ }
+
+ /**
+ * this class defines a iterator for this non-volatile list
+ *
+ */
+ private class Intr implements Iterator<E> {
+
+ protected NonVolatileNodeValue<E> next = null;
/**
- * get next node
+ * Constructor
*
- * @return the next node
+ * @param head
+ * the start point for this iterator
*
*/
- @NonVolatileGetter(Id = 2L, EntityFactoryProxies = "m_node_efproxies", GenericFieldTypes = "m_node_gftypes")
- abstract public NonVolatileNodeValue<E> getNext();
+ Intr(NonVolatileNodeValue<E> head) {
+ next = head;
+ }
/**
- * set next node
+ * determine the existing of next
*
- * @param next
- * specify the next node
- *
- * @param destroy
- * true if want to destroy the exist node
- */
- @NonVolatileSetter
- abstract public void setNext(NonVolatileNodeValue<E> next, boolean destroy);
-
-
- /**
- * get an iterator instance of this list
+ * @return true if there is a next node
*
- * @return an iterator of this list
*/
@Override
- public Iterator<E> iterator() {
- return new Intr(this);
+ public boolean hasNext() {
+ return null != next;
}
-
+
/**
- * this class defines a iterator for this non-volatile list
+ * get next node
*
+ * @return the next node
*/
- private class Intr implements Iterator<E> {
-
- protected NonVolatileNodeValue<E> next = null;
-
- /**
- * Constructor
- *
- * @param head
- * the start point for this iterator
- *
- */
- Intr(NonVolatileNodeValue<E> head) {
- next = head;
- }
-
- /**
- * determine the existing of next
- *
- * @return true if there is a next node
- *
- */
- @Override
- public boolean hasNext() {
- return null != next;
- }
-
- /**
- * get next node
- *
- * @return the next node
- */
- @Override
- public E next() {
- if (null == next) {
- new NoSuchElementException();
- }
- E ret = next.getItem();
- next = next.getNext();
- return ret;
- }
+ @Override
+ public E next() {
+ if (null == next) {
+ new NoSuchElementException();
+ }
+ E ret = next.getItem();
+ next = next.getNext();
+ return ret;
}
+ }
}
[2/7] incubator-mnemonic git commit: format codestyle & add Apache
License
Posted by ga...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/PMAddressTranslator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/PMAddressTranslator.java b/core/src/main/java/org/apache/mnemonic/PMAddressTranslator.java
index 1b1028d..b7a1600 100644
--- a/core/src/main/java/org/apache/mnemonic/PMAddressTranslator.java
+++ b/core/src/main/java/org/apache/mnemonic/PMAddressTranslator.java
@@ -1,5 +1,21 @@
-package org.apache.mnemonic;
+/*
+ * 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.mnemonic;
/**
* translate persistent memory address for allocator
@@ -7,39 +23,39 @@ package org.apache.mnemonic;
*/
public interface PMAddressTranslator {
- /**
- * calculate the portable address
- *
- * @param addr
- * the address to be calculated
- *
- * @return the portable address
- */
- public long getPortableAddress(long addr);
+ /**
+ * calculate the portable address
+ *
+ * @param addr
+ * the address to be calculated
+ *
+ * @return the portable address
+ */
+ public long getPortableAddress(long addr);
+
+ /**
+ * calculate the effective address
+ *
+ * @param addr
+ * the address to be calculated
+ *
+ * @return the effective address
+ */
+ public long getEffectiveAddress(long addr);
+
+ /**
+ * get the base address
+ *
+ * @return the base address
+ */
+ public long getBaseAddress();
- /**
- * calculate the effective address
- *
- * @param addr
- * the address to be calculated
- *
- * @return the effective address
- */
- public long getEffectiveAddress(long addr);
-
- /**
- * get the base address
- *
- * @return the base address
- */
- public long getBaseAddress();
-
- /**
- * set the base address for calculation
- *
- * @param addr
- * the base address
- *
- */
- public long setBaseAddress(long addr);
+ /**
+ * set the base address for calculation
+ *
+ * @param addr
+ * the base address
+ *
+ */
+ public long setBaseAddress(long addr);
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/Reclaim.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/Reclaim.java b/core/src/main/java/org/apache/mnemonic/Reclaim.java
index 7a43cb3..80d923f 100644
--- a/core/src/main/java/org/apache/mnemonic/Reclaim.java
+++ b/core/src/main/java/org/apache/mnemonic/Reclaim.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -6,18 +23,18 @@ package org.apache.mnemonic;
*/
public interface Reclaim<MRES> {
- /**
- * reclaim specified resources.
- *
- * @param mres
- * a resource to be reclaimed
- *
- * @param size
- * the size of resource, it will be set as null if unknown
- *
- * @return <tt>true</tt> if this resource has been reclaimed by this
- * callback. <tt>false</tt> if this resource needs to be claimed by
- * default reclaimer
- */
- public boolean reclaim(MRES mres, Long size);
+ /**
+ * reclaim specified resources.
+ *
+ * @param mres
+ * a resource to be reclaimed
+ *
+ * @param size
+ * the size of resource, it will be set as null if unknown
+ *
+ * @return <tt>true</tt> if this resource has been reclaimed by this callback.
+ * <tt>false</tt> if this resource needs to be claimed by default
+ * reclaimer
+ */
+ public boolean reclaim(MRES mres, Long size);
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/RetrieveNonVolatileEntityError.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/RetrieveNonVolatileEntityError.java b/core/src/main/java/org/apache/mnemonic/RetrieveNonVolatileEntityError.java
index 22a0811..b38af5e 100644
--- a/core/src/main/java/org/apache/mnemonic/RetrieveNonVolatileEntityError.java
+++ b/core/src/main/java/org/apache/mnemonic/RetrieveNonVolatileEntityError.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -5,15 +22,14 @@ package org.apache.mnemonic;
*
*/
-
public class RetrieveNonVolatileEntityError extends RuntimeException {
- /**
- *
- */
- private static final long serialVersionUID = 3985459401986971131L;
+ /**
+ *
+ */
+ private static final long serialVersionUID = 3985459401986971131L;
- public RetrieveNonVolatileEntityError(String s) {
- super(s);
- }
+ public RetrieveNonVolatileEntityError(String s) {
+ super(s);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/SysMemAllocator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/SysMemAllocator.java b/core/src/main/java/org/apache/mnemonic/SysMemAllocator.java
index 8889d48..36346ee 100644
--- a/core/src/main/java/org/apache/mnemonic/SysMemAllocator.java
+++ b/core/src/main/java/org/apache/mnemonic/SysMemAllocator.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import java.lang.reflect.*;
@@ -18,276 +35,268 @@ import sun.misc.Cleaner;
@SuppressWarnings("restriction")
public class SysMemAllocator extends CommonAllocator<SysMemAllocator> {
- private boolean m_activegc = true;
- private long m_gctimeout = 100;
- private Unsafe m_unsafe = null;
- private AtomicLong currentMemory = new AtomicLong(0L);
- private long maxStoreCapacity = 0L;
- private Map<Long, Long> m_chunksize = new ConcurrentHashMap<Long, Long>();
-
+ private boolean m_activegc = true;
+ private long m_gctimeout = 100;
+ private Unsafe m_unsafe = null;
+ private AtomicLong currentMemory = new AtomicLong(0L);
+ private long maxStoreCapacity = 0L;
+ private Map<Long, Long> m_chunksize = new ConcurrentHashMap<Long, Long>();
+ /**
+ * Constructor, it initialize and allocate a memory pool from Java off-heap
+ * with specified capacity.
+ *
+ * @param capacity
+ * specify the capacity of a system memory pool
+ *
+ * @param isnew
+ * a place holder, always specify it as true
+ *
+ * @throws Exception
+ * fail to retrieve Unsafe object
+ *
+ */
+ public SysMemAllocator(long capacity, boolean isnew) throws Exception {
+ m_unsafe = Utils.getUnsafe();
+ maxStoreCapacity = capacity;
/**
- * Constructor, it initialize and allocate a memory pool from Java off-heap
- * with specified capacity.
- *
- * @param capacity
- * specify the capacity of a system memory pool
- *
- * @param isnew
- * a place holder, always specify it as true
- *
- * @throws Exception
- * fail to retrieve Unsafe object
- *
+ * create a resource collector to release specified bytebuffer that backed
+ * by Java off-heap.
*/
- public SysMemAllocator(long capacity, boolean isnew) throws Exception {
- m_unsafe = Utils.getUnsafe();
- maxStoreCapacity = capacity;
- /**
- * create a resource collector to release specified bytebuffer that backed
- * by Java off-heap.
- */
- m_bufcollector = new ResCollector<MemBufferHolder<SysMemAllocator>, ByteBuffer>(
- new ResReclaim<ByteBuffer>() {
- @Override
- public synchronized void reclaim(ByteBuffer mres) {
- Long sz = Long.valueOf(mres.capacity());
- boolean cb_reclaimed = false;
- if (null != m_bufferreclaimer) {
- cb_reclaimed = m_bufferreclaimer.reclaim(mres, sz);
- }
- if (!cb_reclaimed) {
- try {
- Field cleanerField;
- cleanerField = mres.getClass().getDeclaredField(
- "cleaner");
- cleanerField.setAccessible(true);
- Cleaner cleaner = (Cleaner) cleanerField.get(mres);
- cleaner.clean();
- } catch (NoSuchFieldException | SecurityException
- | IllegalArgumentException | IllegalAccessException e) {
- e.printStackTrace();
- }
- mres = null;
- }
- currentMemory.addAndGet(-sz);
- }
- });
-
- /**
- * create a resource collector to release specified chunk that backed by
- * Java off-heap.
- */
- m_chunkcollector = new ResCollector<MemChunkHolder<SysMemAllocator>, Long>(
- new ResReclaim<Long>() {
- @Override
- public synchronized void reclaim(Long mres) {
- // System.out.println(String.format("Reclaim: %X ...", mres));
- Long sz = m_chunksize.remove(mres);
- boolean cb_reclaimed = false;
- if (null != m_chunkreclaimer) {
- cb_reclaimed = m_chunkreclaimer.reclaim(mres, sz);
- }
- if (!cb_reclaimed) {
- m_unsafe.freeMemory(mres);
- mres = null;
- }
- if (null != sz) {
- currentMemory.addAndGet(-sz);
- }
- }
- });
- }
+ m_bufcollector = new ResCollector<MemBufferHolder<SysMemAllocator>, ByteBuffer>(new ResReclaim<ByteBuffer>() {
+ @Override
+ public synchronized void reclaim(ByteBuffer mres) {
+ Long sz = Long.valueOf(mres.capacity());
+ boolean cb_reclaimed = false;
+ if (null != m_bufferreclaimer) {
+ cb_reclaimed = m_bufferreclaimer.reclaim(mres, sz);
+ }
+ if (!cb_reclaimed) {
+ try {
+ Field cleanerField;
+ cleanerField = mres.getClass().getDeclaredField("cleaner");
+ cleanerField.setAccessible(true);
+ Cleaner cleaner = (Cleaner) cleanerField.get(mres);
+ cleaner.clean();
+ } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ mres = null;
+ }
+ currentMemory.addAndGet(-sz);
+ }
+ });
/**
- * enable active garbage collection. the GC will be forced to collect garbages when
- * there is no more space for current allocation request.
- *
- * @param timeout
- * the timeout is used to yield for GC performing
- *
- * @return this allocator
+ * create a resource collector to release specified chunk that backed by
+ * Java off-heap.
*/
- @Override
- public SysMemAllocator enableActiveGC(long timeout) {
- m_activegc = true;
- m_gctimeout = timeout;
- return this;
- }
+ m_chunkcollector = new ResCollector<MemChunkHolder<SysMemAllocator>, Long>(new ResReclaim<Long>() {
+ @Override
+ public synchronized void reclaim(Long mres) {
+ // System.out.println(String.format("Reclaim: %X ...", mres));
+ Long sz = m_chunksize.remove(mres);
+ boolean cb_reclaimed = false;
+ if (null != m_chunkreclaimer) {
+ cb_reclaimed = m_chunkreclaimer.reclaim(mres, sz);
+ }
+ if (!cb_reclaimed) {
+ m_unsafe.freeMemory(mres);
+ mres = null;
+ }
+ if (null != sz) {
+ currentMemory.addAndGet(-sz);
+ }
+ }
+ });
+ }
- /**
- * disable active garbage collection.
- *
- * @return this allocator
- */
- @Override
- public SysMemAllocator disableActiveGC() {
- m_activegc = false;
- return this;
- }
+ /**
+ * enable active garbage collection. the GC will be forced to collect garbages
+ * when there is no more space for current allocation request.
+ *
+ * @param timeout
+ * the timeout is used to yield for GC performing
+ *
+ * @return this allocator
+ */
+ @Override
+ public SysMemAllocator enableActiveGC(long timeout) {
+ m_activegc = true;
+ m_gctimeout = timeout;
+ return this;
+ }
- /**
- * release the memory pool and close it.
- *
- */
- @Override
- public void close() {
- super.close();
+ /**
+ * disable active garbage collection.
+ *
+ * @return this allocator
+ */
+ @Override
+ public SysMemAllocator disableActiveGC() {
+ m_activegc = false;
+ return this;
+ }
+
+ /**
+ * release the memory pool and close it.
+ *
+ */
+ @Override
+ public void close() {
+ super.close();
+ }
+
+ /**
+ * force to synchronize uncommitted data to backed memory pool (this is a
+ * placeholder).
+ *
+ */
+ @Override
+ public void sync() {
+ }
+
+ /**
+ * re-size a specified chunk on its backed memory pool.
+ *
+ * @param mholder
+ * the holder of memory chunk. it can be null.
+ *
+ * @param size
+ * specify a new size of memory chunk
+ *
+ * @return the resized memory chunk handler
+ */
+ @Override
+ public MemChunkHolder<SysMemAllocator> resizeChunk(MemChunkHolder<SysMemAllocator> mholder, long size) {
+ MemChunkHolder<SysMemAllocator> ret = null;
+ boolean ac = null != mholder.getRefId();
+ if (size > 0) {
+ if (currentMemory.get() + size > maxStoreCapacity) {
+ if (m_activegc) {
+ m_chunkcollector.waitReclaimCoolDown(m_gctimeout);
+ }
+ }
+ if (currentMemory.get() + size <= maxStoreCapacity) {
+ Long addr = m_unsafe.reallocateMemory(mholder.get(), size);
+ if (0 != addr) {
+ mholder.clear();
+ mholder.destroy();
+ ret = new MemChunkHolder<SysMemAllocator>(this, addr, size);
+ if (ac) {
+ m_chunkcollector.register(ret);
+ }
+ }
+ }
}
+ return ret;
+ }
- /**
- * force to synchronize uncommitted data to backed memory pool
- * (this is a placeholder).
- *
- */
- @Override
- public void sync() {
+ /**
+ * resize a specified buffer on its backed memory pool.
+ *
+ * @param mholder
+ * the holder of memory buffer. it can be null.
+ *
+ * @param size
+ * specify a new size of memory chunk
+ *
+ * @return the resized memory buffer handler
+ *
+ */
+ @Override
+ public MemBufferHolder<SysMemAllocator> resizeBuffer(MemBufferHolder<SysMemAllocator> mholder, long size) {
+ MemBufferHolder<SysMemAllocator> ret = null;
+ boolean ac = null != mholder.getRefId();
+ if (size > 0) {
+ int bufpos = mholder.get().position();
+ int buflimit = mholder.get().limit();
+ if (currentMemory.get() + size > maxStoreCapacity) {
+ if (m_activegc) {
+ m_bufcollector.waitReclaimCoolDown(m_gctimeout);
+ }
+ }
+ if (currentMemory.get() + size <= maxStoreCapacity) {
+ ByteBuffer buf = Utils.resizeByteBuffer(mholder.get(), size);
+ if (null != buf) {
+ mholder.clear();
+ mholder.destroy();
+ buf.position(bufpos <= size ? bufpos : 0);
+ buf.limit(buflimit <= size ? buflimit : (int) size);
+ ret = new MemBufferHolder<SysMemAllocator>(this, buf);
+ if (ac) {
+ m_bufcollector.register(ret);
+ }
+ }
+ }
}
+ return ret;
+ }
- /**
- * re-size a specified chunk on its backed memory pool.
- *
- * @param mholder
- * the holder of memory chunk. it can be
- * null.
- *
- * @param size
- * specify a new size of memory chunk
- *
- * @return the resized memory chunk handler
- */
- @Override
- public MemChunkHolder<SysMemAllocator> resizeChunk(MemChunkHolder<SysMemAllocator> mholder, long size){
- MemChunkHolder<SysMemAllocator> ret = null;
- boolean ac = null != mholder.getRefId();
- if (size > 0) {
- if (currentMemory.get() + size > maxStoreCapacity) {
- if (m_activegc) {
- m_chunkcollector.waitReclaimCoolDown(m_gctimeout);
- }
- }
- if (currentMemory.get() + size <= maxStoreCapacity) {
- Long addr = m_unsafe.reallocateMemory(mholder.get(), size);
- if (0 != addr) {
- mholder.clear();
- mholder.destroy();
- ret = new MemChunkHolder<SysMemAllocator>(this, addr, size);
- if (ac) {
- m_chunkcollector.register(ret);
- }
- }
- }
- }
- return ret;
+ /**
+ * create a memory chunk that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory chunk
+ *
+ * @param autoreclaim
+ * specify whether or not to reclaim this chunk automatically
+ *
+ * @return a holder contains a memory chunk
+ */
+ @Override
+ public MemChunkHolder<SysMemAllocator> createChunk(long size, boolean autoreclaim) {
+ MemChunkHolder<SysMemAllocator> ret = null;
+ Long addr = null;
+ if (currentMemory.get() + size > maxStoreCapacity) {
+ if (m_activegc) {
+ m_chunkcollector.waitReclaimCoolDown(m_gctimeout);
+ }
}
-
- /**
- * resize a specified buffer on its backed memory pool.
- *
- * @param mholder
- * the holder of memory buffer. it can be
- * null.
- *
- * @param size
- * specify a new size of memory chunk
- *
- * @return the resized memory buffer handler
- *
- */
- @Override
- public MemBufferHolder<SysMemAllocator> resizeBuffer(MemBufferHolder<SysMemAllocator> mholder, long size) {
- MemBufferHolder<SysMemAllocator> ret = null;
- boolean ac = null != mholder.getRefId();
- if (size > 0) {
- int bufpos = mholder.get().position();
- int buflimit = mholder.get().limit();
- if (currentMemory.get() + size > maxStoreCapacity) {
- if (m_activegc) {
- m_bufcollector.waitReclaimCoolDown(m_gctimeout);
- }
- }
- if (currentMemory.get() + size <= maxStoreCapacity) {
- ByteBuffer buf = Utils.resizeByteBuffer(mholder.get(), size);
- if (null != buf) {
- mholder.clear();
- mholder.destroy();
- buf.position(bufpos <= size ? bufpos : 0);
- buf.limit(buflimit <= size ? buflimit : (int)size);
- ret = new MemBufferHolder<SysMemAllocator>(this, buf);
- if (ac) {
- m_bufcollector.register(ret);
- }
- }
- }
- }
- return ret;
+ if (currentMemory.get() + size <= maxStoreCapacity) {
+ addr = m_unsafe.allocateMemory(size);
}
-
- /**
- * create a memory chunk that is managed by its holder.
- *
- * @param size
- * specify the size of memory chunk
- *
- * @param autoreclaim
- * specify whether or not to reclaim this
- * chunk automatically
- *
- * @return a holder contains a memory chunk
- */
- @Override
- public MemChunkHolder<SysMemAllocator> createChunk(long size, boolean autoreclaim) {
- MemChunkHolder<SysMemAllocator> ret = null;
- Long addr = null;
- if (currentMemory.get() + size > maxStoreCapacity) {
- if (m_activegc) {
- m_chunkcollector.waitReclaimCoolDown(m_gctimeout);
- }
- }
- if (currentMemory.get() + size <= maxStoreCapacity) {
- addr = m_unsafe.allocateMemory(size);
- }
- if (null != addr && 0 != addr) {
- ret = new MemChunkHolder<SysMemAllocator>(this, addr, size);
- ret.setCollector(m_chunkcollector);
- if (autoreclaim) {
- m_chunkcollector.register(ret);
- }
- m_chunksize.put(addr, size);
- currentMemory.getAndAdd(size);
- }
- return ret;
+ if (null != addr && 0 != addr) {
+ ret = new MemChunkHolder<SysMemAllocator>(this, addr, size);
+ ret.setCollector(m_chunkcollector);
+ if (autoreclaim) {
+ m_chunkcollector.register(ret);
+ }
+ m_chunksize.put(addr, size);
+ currentMemory.getAndAdd(size);
}
+ return ret;
+ }
- /**
- * create a memory buffer that is managed by its holder.
- *
- * @param size
- * specify the size of memory buffer
- *
- * @return a holder contains a memory buffer
- */
- @Override
- public MemBufferHolder<SysMemAllocator> createBuffer(long size, boolean autoreclaim) {
- MemBufferHolder<SysMemAllocator> ret = null;
- ByteBuffer bb = null;
- if (currentMemory.get() + size > maxStoreCapacity) {
- if (m_activegc) {
- m_bufcollector.waitReclaimCoolDown(m_gctimeout);
- }
- }
- if (currentMemory.get() + size <= maxStoreCapacity) {
- bb = ByteBuffer.allocateDirect((int) size);
- }
- if (null != bb) {
- ret = new MemBufferHolder<SysMemAllocator>(this, bb);
- ret.setCollector(m_bufcollector);
- if (autoreclaim) {
- m_bufcollector.register(ret);
- }
- currentMemory.getAndAdd(size);
- }
- return ret;
+ /**
+ * create a memory buffer that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory buffer
+ *
+ * @return a holder contains a memory buffer
+ */
+ @Override
+ public MemBufferHolder<SysMemAllocator> createBuffer(long size, boolean autoreclaim) {
+ MemBufferHolder<SysMemAllocator> ret = null;
+ ByteBuffer bb = null;
+ if (currentMemory.get() + size > maxStoreCapacity) {
+ if (m_activegc) {
+ m_bufcollector.waitReclaimCoolDown(m_gctimeout);
+ }
+ }
+ if (currentMemory.get() + size <= maxStoreCapacity) {
+ bb = ByteBuffer.allocateDirect((int) size);
+ }
+ if (null != bb) {
+ ret = new MemBufferHolder<SysMemAllocator>(this, bb);
+ ret.setCollector(m_bufcollector);
+ if (autoreclaim) {
+ m_bufcollector.register(ret);
+ }
+ currentMemory.getAndAdd(size);
}
+ return ret;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/Utils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/Utils.java b/core/src/main/java/org/apache/mnemonic/Utils.java
index 73f7a82..9425b98 100644
--- a/core/src/main/java/org/apache/mnemonic/Utils.java
+++ b/core/src/main/java/org/apache/mnemonic/Utils.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import java.lang.reflect.Field;
@@ -25,360 +42,361 @@ import org.apache.mnemonic.service.allocatorservice.NonVolatileMemoryAllocatorSe
*/
@SuppressWarnings("restriction")
public class Utils {
- private static long fSLEEP_INTERVAL = 100;
+ private static long fSLEEP_INTERVAL = 100;
+
+ public static final String ANSI_RESET = "\u001B[0m";
+ public static final String ANSI_BLACK = "\u001B[30m";
+ public static final String ANSI_RED = "\u001B[31m";
+ public static final String ANSI_GREEN = "\u001B[32m";
+ public static final String ANSI_YELLOW = "\u001B[33m";
+ public static final String ANSI_BLUE = "\u001B[34m";
+ public static final String ANSI_PURPLE = "\u001B[35m";
+ public static final String ANSI_CYAN = "\u001B[36m";
+ public static final String ANSI_WHITE = "\u001B[37m";
- public static final String ANSI_RESET = "\u001B[0m";
- public static final String ANSI_BLACK = "\u001B[30m";
- public static final String ANSI_RED = "\u001B[31m";
- public static final String ANSI_GREEN = "\u001B[32m";
- public static final String ANSI_YELLOW = "\u001B[33m";
- public static final String ANSI_BLUE = "\u001B[34m";
- public static final String ANSI_PURPLE = "\u001B[35m";
- public static final String ANSI_CYAN = "\u001B[36m";
- public static final String ANSI_WHITE = "\u001B[37m";
-
- private static Unsafe m_unsafe = null;
+ private static Unsafe m_unsafe = null;
- private static ServiceLoader<VolatileMemoryAllocatorService> m_vmasvcloader = null;
- private static ServiceLoader<NonVolatileMemoryAllocatorService> m_nvmasvcloader = null;
+ private static ServiceLoader<VolatileMemoryAllocatorService> m_vmasvcloader = null;
+ private static ServiceLoader<NonVolatileMemoryAllocatorService> m_nvmasvcloader = null;
- /**
- * retrieve a volatile memory allocator service
- *
- * @param id
- * specify a name of allocator to retrieve
- *
- * @return the volatile memory allocator service instance
- */
- public static VolatileMemoryAllocatorService getVolatileMemoryAllocatorService(String id) {
- return getVolatileMemoryAllocatorService(id, true);
+ /**
+ * retrieve a volatile memory allocator service
+ *
+ * @param id
+ * specify a name of allocator to retrieve
+ *
+ * @return the volatile memory allocator service instance
+ */
+ public static VolatileMemoryAllocatorService getVolatileMemoryAllocatorService(String id) {
+ return getVolatileMemoryAllocatorService(id, true);
+ }
+
+ /**
+ * retrieve a volatile memory allocator service
+ *
+ * @param id
+ * specify a name of allocator to retrieve
+ *
+ * @param allownvmsvc
+ * specify whether allow to treat non-volatile memory allocator as
+ * volatile one during searching
+ *
+ * @return the volatile memory allocator service instance
+ */
+ public static VolatileMemoryAllocatorService getVolatileMemoryAllocatorService(String id, boolean allownvmsvc) {
+ VolatileMemoryAllocatorService ret = null;
+ if (null == m_vmasvcloader) {
+ m_vmasvcloader = ServiceLoader.load(VolatileMemoryAllocatorService.class);
}
-
- /**
- * retrieve a volatile memory allocator service
- *
- * @param id
- * specify a name of allocator to retrieve
- *
- * @param allownvmsvc
- * specify whether allow to treat non-volatile memory allocator as volatile one during searching
- *
- * @return the volatile memory allocator service instance
- */
- public static VolatileMemoryAllocatorService getVolatileMemoryAllocatorService(String id, boolean allownvmsvc) {
- VolatileMemoryAllocatorService ret = null;
- if (null == m_vmasvcloader) {
- m_vmasvcloader = ServiceLoader.load(VolatileMemoryAllocatorService.class);
- }
- Iterator<VolatileMemoryAllocatorService> svcit = m_vmasvcloader.iterator();
- VolatileMemoryAllocatorService svc = null;
- while (null == ret && svcit.hasNext()) {
- svc = svcit.next();
- if (svc.getServiceId().equals(id)) {
- ret = svc;
- }
- }
- if (null == ret && allownvmsvc) {
- ret = getNonVolatileMemoryAllocatorService(id);
- }
- assert null != ret : "VolatileMemoryAllocatorService \'" + id + "\' not found!";
- return ret;
+ Iterator<VolatileMemoryAllocatorService> svcit = m_vmasvcloader.iterator();
+ VolatileMemoryAllocatorService svc = null;
+ while (null == ret && svcit.hasNext()) {
+ svc = svcit.next();
+ if (svc.getServiceId().equals(id)) {
+ ret = svc;
+ }
}
-
- /**
- * retrieve a non-volatile memory allocator service
- *
- * @param id
- * specify a name of allocator to retrieve
- *
- * @return the non-volatile memory allocator service instance
- */
- public static NonVolatileMemoryAllocatorService getNonVolatileMemoryAllocatorService(String id) {
- NonVolatileMemoryAllocatorService ret = null;
- if (null == m_nvmasvcloader) {
- m_nvmasvcloader = ServiceLoader.load(NonVolatileMemoryAllocatorService.class);
- }
- Iterator<NonVolatileMemoryAllocatorService> svcit = m_nvmasvcloader.iterator();
- NonVolatileMemoryAllocatorService svc = null;
- while (null == ret && svcit.hasNext()) {
- svc = svcit.next();
- if (svc.getServiceId().equals(id)) {
- ret = svc;
- }
- }
- assert null != ret : "NonVolatileMemoryAllocatorService \'" + id + "\' not found!";
- return ret;
+ if (null == ret && allownvmsvc) {
+ ret = getNonVolatileMemoryAllocatorService(id);
}
+ assert null != ret : "VolatileMemoryAllocatorService \'" + id + "\' not found!";
+ return ret;
+ }
- /**
- * Generates a unique name that contains current timestamp.
- *
- * @param format
- * the template that is used to generate unique name.
- *
- * @return unique path name.
- */
- public static String genUniquePathname(String format) {
- String ret = null;
- if (null != format && !format.isEmpty()) {
- ret = String.format(format, (new SimpleDateFormat(
- "ddMMyy-hhmmss.SSS").format(new Date())));
- }
- return ret;
+ /**
+ * retrieve a non-volatile memory allocator service
+ *
+ * @param id
+ * specify a name of allocator to retrieve
+ *
+ * @return the non-volatile memory allocator service instance
+ */
+ public static NonVolatileMemoryAllocatorService getNonVolatileMemoryAllocatorService(String id) {
+ NonVolatileMemoryAllocatorService ret = null;
+ if (null == m_nvmasvcloader) {
+ m_nvmasvcloader = ServiceLoader.load(NonVolatileMemoryAllocatorService.class);
}
-
- /**
- * retrieve the usage of memory.
- *
- * @return the size of memory has been occupied
- */
- public static long getMemoryUse() {
- putOutTheGarbage();
- long totalMemory = Runtime.getRuntime().totalMemory();
- putOutTheGarbage();
- long freeMemory = Runtime.getRuntime().freeMemory();
- return (totalMemory - freeMemory);
+ Iterator<NonVolatileMemoryAllocatorService> svcit = m_nvmasvcloader.iterator();
+ NonVolatileMemoryAllocatorService svc = null;
+ while (null == ret && svcit.hasNext()) {
+ svc = svcit.next();
+ if (svc.getServiceId().equals(id)) {
+ ret = svc;
+ }
}
+ assert null != ret : "NonVolatileMemoryAllocatorService \'" + id + "\' not found!";
+ return ret;
+ }
- /**
- * run garbage collections.
- */
- private static void putOutTheGarbage() {
- collectGarbage();
- collectGarbage();
+ /**
+ * Generates a unique name that contains current timestamp.
+ *
+ * @param format
+ * the template that is used to generate unique name.
+ *
+ * @return unique path name.
+ */
+ public static String genUniquePathname(String format) {
+ String ret = null;
+ if (null != format && !format.isEmpty()) {
+ ret = String.format(format, (new SimpleDateFormat("ddMMyy-hhmmss.SSS").format(new Date())));
}
+ return ret;
+ }
- /**
- * run a garbage collection.
- */
- public static void collectGarbage() {
- try {
- System.gc();
- Thread.sleep(fSLEEP_INTERVAL);
- System.runFinalization();
- Thread.sleep(fSLEEP_INTERVAL);
- } catch (InterruptedException ex) {
- ex.printStackTrace();
- }
- }
+ /**
+ * retrieve the usage of memory.
+ *
+ * @return the size of memory has been occupied
+ */
+ public static long getMemoryUse() {
+ putOutTheGarbage();
+ long totalMemory = Runtime.getRuntime().totalMemory();
+ putOutTheGarbage();
+ long freeMemory = Runtime.getRuntime().freeMemory();
+ return (totalMemory - freeMemory);
+ }
- /**
- * Retrieve an Unsafe object.
- *
- * @throws Exception
- * Error when get Unsafe object from runtime
- *
- * @return an unsafe object
- */
- public static Unsafe getUnsafe() throws Exception {
- if (null == m_unsafe) {
- Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
- field.setAccessible(true);
- m_unsafe = (sun.misc.Unsafe) field.get(null);
- }
- return m_unsafe;
- }
+ /**
+ * run garbage collections.
+ */
+ private static void putOutTheGarbage() {
+ collectGarbage();
+ collectGarbage();
+ }
- /**
- * resize a bytebuffer with a new instance
- *
- * @param buf
- * specify a buf to resize
- *
- * @param size
- * specify the size for resizing
- *
- * @return the resized bytebuffer instance
- */
- public static ByteBuffer resizeByteBuffer(ByteBuffer buf, long size) {
- ByteBuffer ret = ByteBuffer.allocateDirect((int) size);
- if (ret != null) {
- if (null != buf) {
- ret.put(buf);
- ret.flip();
- }
- }
- return ret;
+ /**
+ * run a garbage collection.
+ */
+ public static void collectGarbage() {
+ try {
+ System.gc();
+ Thread.sleep(fSLEEP_INTERVAL);
+ System.runFinalization();
+ Thread.sleep(fSLEEP_INTERVAL);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
}
+ }
- /**
- * create a new instance of Random using default fixed seed
- *
- * @return the instance of Random
- */
- public static Random createRandom() {
- return createRandom(0L);
+ /**
+ * Retrieve an Unsafe object.
+ *
+ * @throws Exception
+ * Error when get Unsafe object from runtime
+ *
+ * @return an unsafe object
+ */
+ public static Unsafe getUnsafe() throws Exception {
+ if (null == m_unsafe) {
+ Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
+ field.setAccessible(true);
+ m_unsafe = (sun.misc.Unsafe) field.get(null);
}
+ return m_unsafe;
+ }
- /**
- * create a new instance of Random
- *
- * @param rgenseed
- * specify a random seed
- *
- * @return the instance of Random
- */
- public static Random createRandom(long rgenseed) {
- Random ret = new Random();
- if (0L == rgenseed) {
- rgenseed = System.currentTimeMillis();
- System.out.println("Random number generator seed is " + rgenseed);
- } else {
- System.out.println("Fixed Random number generator seed is " + rgenseed);
- }
- ret.setSeed(rgenseed);
- return ret;
+ /**
+ * resize a bytebuffer with a new instance
+ *
+ * @param buf
+ * specify a buf to resize
+ *
+ * @param size
+ * specify the size for resizing
+ *
+ * @return the resized bytebuffer instance
+ */
+ public static ByteBuffer resizeByteBuffer(ByteBuffer buf, long size) {
+ ByteBuffer ret = ByteBuffer.allocateDirect((int) size);
+ if (ret != null) {
+ if (null != buf) {
+ ret.put(buf);
+ ret.flip();
+ }
}
+ return ret;
+ }
- /**
- * generate a random string with fixed length
- *
- * @return the random string
- */
- public static String genRandomString() {
- return genRandomString(6);
- }
+ /**
+ * create a new instance of Random using default fixed seed
+ *
+ * @return the instance of Random
+ */
+ public static Random createRandom() {
+ return createRandom(0L);
+ }
- /**
- * generate a random string
- *
- * @param len
- * specify the length of this random string
- *
- * @return the random string
- */
- public static String genRandomString(int len) {
- return UUID.randomUUID().toString().replaceAll("-", "").toUpperCase().substring(0, len);
+ /**
+ * create a new instance of Random
+ *
+ * @param rgenseed
+ * specify a random seed
+ *
+ * @return the instance of Random
+ */
+ public static Random createRandom(long rgenseed) {
+ Random ret = new Random();
+ if (0L == rgenseed) {
+ rgenseed = System.currentTimeMillis();
+ System.out.println("Random number generator seed is " + rgenseed);
+ } else {
+ System.out.println("Fixed Random number generator seed is " + rgenseed);
}
+ ret.setSeed(rgenseed);
+ return ret;
+ }
- /**
- * assert the equality of two generic objects using compareTo() operator
- *
- * @param <T> the type of comparable objects
- *
- * @param actual
- * specify a object to be compared
- *
- * @param expected
- * specify a object to be expected
- *
- * @return true if equal according to compareTo()
- */
- public static <T extends Comparable<T>>boolean assertComparison(T actual, T expected) {
- boolean ret = false;
- if ((expected == null) && (actual == null)) {
- ret = true;
- } else if (expected != null) {
- ret = expected.compareTo(actual) == 0;
- }
- return ret;
- }
+ /**
+ * generate a random string with fixed length
+ *
+ * @return the random string
+ */
+ public static String genRandomString() {
+ return genRandomString(6);
+ }
+
+ /**
+ * generate a random string
+ *
+ * @param len
+ * specify the length of this random string
+ *
+ * @return the random string
+ */
+ public static String genRandomString(int len) {
+ return UUID.randomUUID().toString().replaceAll("-", "").toUpperCase().substring(0, len);
+ }
- /**
- * convert a long array to a initializer literal string.
- *
- * @param larr
- * specify a long array to be converted
- *
- * @return a literal string represent the initializer
- */
- public static String toInitLiteral(long[] larr) {
- return Arrays.toString(larr).replaceAll("\\[", "{").replaceAll("\\]", "}");
+ /**
+ * assert the equality of two generic objects using compareTo() operator
+ *
+ * @param <T>
+ * the type of comparable objects
+ *
+ * @param actual
+ * specify a object to be compared
+ *
+ * @param expected
+ * specify a object to be expected
+ *
+ * @return true if equal according to compareTo()
+ */
+ public static <T extends Comparable<T>> boolean assertComparison(T actual, T expected) {
+ boolean ret = false;
+ if ((expected == null) && (actual == null)) {
+ ret = true;
+ } else if (expected != null) {
+ ret = expected.compareTo(actual) == 0;
}
+ return ret;
+ }
- /**
- * convert a list of long array to a initializer literal string.
- *
- * @param llarr
- * specify a list of long array to be converted
- *
- * @return a literal string represent the initializer
- */
- public static String toInitLiteral(List<long[]> llarr) {
- List<String> slist = new ArrayList<String>();
- for (long[] larr : llarr) {
- slist.add(toInitLiteral(larr));
- }
- return "{" + String.join(",", slist) + "}";
+ /**
+ * convert a long array to a initializer literal string.
+ *
+ * @param larr
+ * specify a long array to be converted
+ *
+ * @return a literal string represent the initializer
+ */
+ public static String toInitLiteral(long[] larr) {
+ return Arrays.toString(larr).replaceAll("\\[", "{").replaceAll("\\]", "}");
+ }
+
+ /**
+ * convert a list of long array to a initializer literal string.
+ *
+ * @param llarr
+ * specify a list of long array to be converted
+ *
+ * @return a literal string represent the initializer
+ */
+ public static String toInitLiteral(List<long[]> llarr) {
+ List<String> slist = new ArrayList<String>();
+ for (long[] larr : llarr) {
+ slist.add(toInitLiteral(larr));
}
+ return "{" + String.join(",", slist) + "}";
+ }
- /**
- * retrieve a set of native field info from a list of object field info according to the field
- * id info. it forms a value info stack for native code to use as one standardized parameter
- *
- * @param objstack
- * a stack of object info retrieved from Durable.getNativeFieldInfo(), order matters
- *
- * @param fidinfostack
- * a stack of field id in the form of (next_fid, next_level_fid) order follows objstack
- * the last next_level_fid specifies the value's fid.
- * the last item of next_fid could be null if there is no next node
- * if it is null that means the last item is a object instead of node
- *
- * @return the stack of native field info
- *
- */
- public static List<long[]> getNativeParamForm(List<long[][]> objstack, long[][] fidinfostack) {
- List<long[]> ret = new ArrayList<long[]>();
- if (null == objstack ||
- null == fidinfostack ||
- fidinfostack.length != objstack.size()) {
- throw new IllegalArgumentException("Not the same depth");
- }
- for (int idx = 0; idx < fidinfostack.length; ++idx) {
- ret.add(genNativeStackItem(objstack.get(idx), fidinfostack[idx],
- idx == fidinfostack.length - 1));
- }
- return ret;
+ /**
+ * retrieve a set of native field info from a list of object field info
+ * according to the field id info. it forms a value info stack for native code
+ * to use as one standardized parameter
+ *
+ * @param objstack
+ * a stack of object info retrieved from
+ * Durable.getNativeFieldInfo(), order matters
+ *
+ * @param fidinfostack
+ * a stack of field id in the form of (next_fid, next_level_fid)
+ * order follows objstack the last next_level_fid specifies the
+ * value's fid. the last item of next_fid could be null if there is
+ * no next node if it is null that means the last item is a object
+ * instead of node
+ *
+ * @return the stack of native field info
+ *
+ */
+ public static List<long[]> getNativeParamForm(List<long[][]> objstack, long[][] fidinfostack) {
+ List<long[]> ret = new ArrayList<long[]>();
+ if (null == objstack || null == fidinfostack || fidinfostack.length != objstack.size()) {
+ throw new IllegalArgumentException("Not the same depth");
+ }
+ for (int idx = 0; idx < fidinfostack.length; ++idx) {
+ ret.add(genNativeStackItem(objstack.get(idx), fidinfostack[idx], idx == fidinfostack.length - 1));
}
+ return ret;
+ }
- /**
- * generate an item of native stack.
- *
- * @param oinfo
- * a object field info
- *
- * @param fidinfo
- * a pair of field id info
- *
- * @param allowfidnull
- * allow the first field id is null
- *
- * @return the native item
- */
- public static long[] genNativeStackItem(long[][] oinfo, long[] fidinfo, boolean allowfidnull) {
- long[] ret = new long[4];
- long fid;
- boolean found;
- if (fidinfo.length != 2) {
- throw new IllegalArgumentException("the length of field id array is not exactly 2");
+ /**
+ * generate an item of native stack.
+ *
+ * @param oinfo
+ * a object field info
+ *
+ * @param fidinfo
+ * a pair of field id info
+ *
+ * @param allowfidnull
+ * allow the first field id is null
+ *
+ * @return the native item
+ */
+ public static long[] genNativeStackItem(long[][] oinfo, long[] fidinfo, boolean allowfidnull) {
+ long[] ret = new long[4];
+ long fid;
+ boolean found;
+ if (fidinfo.length != 2) {
+ throw new IllegalArgumentException("the length of field id array is not exactly 2");
+ }
+ for (int idx = 0; idx < fidinfo.length; ++idx) {
+ ret[idx * 2] = 0;
+ ret[idx * 2 + 1] = 0;
+ fid = fidinfo[idx];
+ if (fid <= 0) {
+ if (allowfidnull && 0 == idx) {
+ continue;
+ } else {
+ throw new IllegalArgumentException("the field id is not greater than 0");
+ }
+ }
+ found = false;
+ for (long[] finfo : oinfo) {
+ if (finfo.length != 3) {
+ throw new IllegalArgumentException("the length of field array is not exactly 3");
}
- for (int idx = 0; idx < fidinfo.length; ++idx) {
- ret[idx*2] = 0;
- ret[idx*2 + 1] = 0;
- fid = fidinfo[idx];
- if (fid <= 0) {
- if (allowfidnull && 0 == idx) {
- continue;
- } else {
- throw new IllegalArgumentException("the field id is not greater than 0");
- }
- }
- found = false;
- for (long[] finfo : oinfo) {
- if (finfo.length != 3) {
- throw new IllegalArgumentException("the length of field array is not exactly 3");
- }
- if (fid == finfo[0]) {
- ret[idx*2] = finfo[1];
- ret[idx*2 + 1] = finfo[2];
- found = true;
- }
- }
- if (!found) {
- throw new IllegalArgumentException("field id not found");
- }
+ if (fid == finfo[0]) {
+ ret[idx * 2] = finfo[1];
+ ret[idx * 2 + 1] = finfo[2];
+ found = true;
}
- return ret;
+ }
+ if (!found) {
+ throw new IllegalArgumentException("field id not found");
+ }
}
+ return ret;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/service/allocatorservice/NonVolatileMemoryAllocatorService.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/service/allocatorservice/NonVolatileMemoryAllocatorService.java b/core/src/main/java/org/apache/mnemonic/service/allocatorservice/NonVolatileMemoryAllocatorService.java
index 6549273..1007708 100644
--- a/core/src/main/java/org/apache/mnemonic/service/allocatorservice/NonVolatileMemoryAllocatorService.java
+++ b/core/src/main/java/org/apache/mnemonic/service/allocatorservice/NonVolatileMemoryAllocatorService.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic.service.allocatorservice;
import org.flowcomputing.commons.primitives.*;
@@ -5,93 +22,93 @@ import java.nio.ByteBuffer;
public interface NonVolatileMemoryAllocatorService extends VolatileMemoryAllocatorService {
- /**
- * retrieve a bytebuffer from its handler
- *
- * @param id
- * the identifier of backed memory pool
- *
- * @param handler
- * the handler of a nonvolatile bytebuffer
- *
- * @return the nonvolatile bytebuffer
- *
- */
- public ByteBuffer retrieveByteBuffer(long id, long handler);
+ /**
+ * retrieve a bytebuffer from its handler
+ *
+ * @param id
+ * the identifier of backed memory pool
+ *
+ * @param handler
+ * the handler of a nonvolatile bytebuffer
+ *
+ * @return the nonvolatile bytebuffer
+ *
+ */
+ public ByteBuffer retrieveByteBuffer(long id, long handler);
+
+ /**
+ * retrieve the size of a nonvolatile memory object
+ *
+ * @param id
+ * the identifier of backed memory pool
+ *
+ * @param handler
+ * the handler of a nonvolatile object
+ *
+ * @return the size of nonvolatile object
+ *
+ */
+ public long retrieveSize(long id, long handler);
+
+ /**
+ * get the handler of a nonvolatile bytebuffer
+ *
+ * @param id
+ * the identifier of backed memory pool
+ *
+ * @param buf
+ * the nonvolatile bytebuffer
+ *
+ * @return the handler of this specified nonvolatile bytebuffer
+ *
+ */
+ public long getByteBufferHandler(long id, ByteBuffer buf);
+
+ /**
+ * set a handler to a key.
+ *
+ * @param id
+ * the identifier of backed memory pool
+ *
+ * @param key
+ * the key to set this handler
+ *
+ * @param handler
+ * the handler
+ */
+ public void setHandler(long id, long key, long handler);
+
+ /**
+ * get a handler from specified key.
+ *
+ * @param id
+ * the identifier of backed memory pool
+ *
+ * @param key
+ * the key to get its handler
+ *
+ * @return the handler of the specified key
+ */
+ public long getHandler(long id, long key);
- /**
- * retrieve the size of a nonvolatile memory object
- *
- * @param id
- * the identifier of backed memory pool
- *
- * @param handler
- * the handler of a nonvolatile object
- *
- * @return the size of nonvolatile object
- *
- */
- public long retrieveSize(long id, long handler);
-
- /**
- * get the handler of a nonvolatile bytebuffer
- *
- * @param id
- * the identifier of backed memory pool
- *
- * @param buf
- * the nonvolatile bytebuffer
- *
- * @return the handler of this specified nonvolatile bytebuffer
- *
- */
- public long getByteBufferHandler(long id, ByteBuffer buf);
+ /**
+ * return the number of available keys to use.
+ *
+ * @param id
+ * the identifier of backed memory pool
+ *
+ * @return the number of keys
+ */
+ public long handlerCapacity(long id);
- /**
- * set a handler to a key.
- *
- * @param id
- * the identifier of backed memory pool
- *
- * @param key
- * the key to set this handler
- *
- * @param handler
- * the handler
- */
- public void setHandler(long id, long key, long handler);
-
- /**
- * get a handler from specified key.
- *
- * @param id
- * the identifier of backed memory pool
- *
- * @param key
- * the key to get its handler
- *
- * @return the handler of the specified key
- */
- public long getHandler(long id, long key);
-
- /**
- * return the number of available keys to use.
- *
- * @param id
- * the identifier of backed memory pool
- *
- * @return the number of keys
- */
- public long handlerCapacity(long id);
-
- /**
- * return the base address of this persistent memory pool.
- *
- * @param id
- * the identifier of backed memory pool
- *
- * @return the base address of this pmem pool
- */
- public long getBaseAddress(long id);
+ /**
+ * return the base address of this persistent memory pool.
+ *
+ * @param id
+ * the identifier of backed memory pool
+ *
+ * @return the base address of this pmem pool
+ */
+ public long getBaseAddress(long id);
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/service/allocatorservice/VolatileMemoryAllocatorService.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/service/allocatorservice/VolatileMemoryAllocatorService.java b/core/src/main/java/org/apache/mnemonic/service/allocatorservice/VolatileMemoryAllocatorService.java
index 5d506c8..32f7c33 100644
--- a/core/src/main/java/org/apache/mnemonic/service/allocatorservice/VolatileMemoryAllocatorService.java
+++ b/core/src/main/java/org/apache/mnemonic/service/allocatorservice/VolatileMemoryAllocatorService.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic.service.allocatorservice;
import org.flowcomputing.commons.primitives.*;
@@ -5,126 +22,123 @@ import java.nio.ByteBuffer;
public interface VolatileMemoryAllocatorService {
- /**
- * Provide the service identifier for this allocator
- *
- * @return the service identifer of this allocator
- */
- public String getServiceId();
+ /**
+ * Provide the service identifier for this allocator
+ *
+ * @return the service identifer of this allocator
+ */
+ public String getServiceId();
- /**
- * Initialize a memory pool through native interface backed by native
- * library.
- *
- * @param capacity
- * the capacity of memory pool
- *
- * @param uri
- * the location of memory pool will be created
- *
- * @param isnew
- * a place holder, always specify it as true
- *
- * @return the identifier of created memory pool
- */
- public long init(long capacity, String uri, boolean isnew);
+ /**
+ * Initialize a memory pool through native interface backed by native library.
+ *
+ * @param capacity
+ * the capacity of memory pool
+ *
+ * @param uri
+ * the location of memory pool will be created
+ *
+ * @param isnew
+ * a place holder, always specify it as true
+ *
+ * @return the identifier of created memory pool
+ */
+ public long init(long capacity, String uri, boolean isnew);
- /**
- * close the memory pool through native interface.
- *
- */
- public void close(long id);
+ /**
+ * close the memory pool through native interface.
+ *
+ */
+ public void close(long id);
+ /**
+ * force to synchronize uncommitted data to backed memory pool through native
+ * interface.
+ */
+ public void sync(long id);
- /**
- * force to synchronize uncommitted data to backed memory pool through
- * native interface.
- */
- public void sync(long id);
+ /**
+ * allocate specified size of memory block from backed memory pool.
+ *
+ * @param id
+ * the identifier of backed memory pool
+ *
+ * @param size
+ * specify size of memory block to be allocated
+ *
+ * @return the address of allocated memory block from native memory pool
+ */
+ public long allocate(long id, long size, boolean initzero);
- /**
- * allocate specified size of memory block from backed memory pool.
- *
- * @param id
- * the identifier of backed memory pool
- *
- * @param size
- * specify size of memory block to be allocated
- *
- * @return the address of allocated memory block from native memory pool
- */
- public long allocate(long id, long size, boolean initzero);
+ /**
+ * reallocate a specified size of memory block from backed memory pool.
+ *
+ * @param id
+ * the identifier of backed memory pool
+ *
+ * @param address
+ * the address of previous allocated memory block. it can be null.
+ *
+ * @param size
+ * specify new size of memory block to be reallocated
+ *
+ * @return the address of reallocated memory block from native memory pool
+ */
+ public long reallocate(long id, long address, long size, boolean initzero);
- /**
- * reallocate a specified size of memory block from backed memory pool.
- *
- * @param id
- * the identifier of backed memory pool
- *
- * @param address
- * the address of previous allocated memory block. it can be
- * null.
- *
- * @param size
- * specify new size of memory block to be reallocated
- *
- * @return the address of reallocated memory block from native memory pool
- */
- public long reallocate(long id, long address, long size, boolean initzero);
+ /**
+ * free a memory block by specify its address into backed memory pool.
+ *
+ * @param id
+ * the identifier of backed memory pool
+ *
+ * @param address
+ * the address of allocated memory block.
+ */
+ public void free(long id, long address);
- /**
- * free a memory block by specify its address into backed memory pool.
- *
- * @param id
- * the identifier of backed memory pool
- *
- * @param address
- * the address of allocated memory block.
- */
- public void free(long id, long address);
+ /**
+ * create a ByteBuffer object which backed buffer is coming from backed native
+ * memory pool.
+ *
+ * @param id
+ * the identifier of backed memory pool
+ *
+ * @param size
+ * the size of backed buffer that is managed by created ByteBuffer
+ * object.
+ *
+ * @return a created ByteBuffer object with a backed native memory block
+ */
+ public ByteBuffer createByteBuffer(long id, long size);
- /**
- * create a ByteBuffer object which backed buffer is coming from backed
- * native memory pool.
- *
- * @param id
- * the identifier of backed memory pool
- *
- * @param size
- * the size of backed buffer that is managed by created
- * ByteBuffer object.
- *
- * @return a created ByteBuffer object with a backed native memory block
- */
- public ByteBuffer createByteBuffer(long id, long size);
+ /**
+ * resize a ByteBuffer object which backed buffer is coming from backed native
+ * memory pool. NOTE: the ByteBuffer object will be renewed and lost metadata
+ * e.g. position, mark and etc.
+ *
+ * @param id
+ * the identifier of backed memory pool
+ *
+ * @param bytebuf
+ * the specified ByteBuffer object to be destroyed
+ *
+ * @param size
+ * the new size of backed buffer that is managed by created
+ * ByteBuffer object.
+ *
+ * @return a created ByteBuffer object with a backed native memory block
+ */
+ public ByteBuffer resizeByteBuffer(long id, ByteBuffer bytebuf, long size);
- /**
- * resize a ByteBuffer object which backed buffer is coming from backed
- * native memory pool.
- * NOTE: the ByteBuffer object will be renewed and lost metadata e.g. position, mark and etc.
- *
- * @param id
- * the identifier of backed memory pool
- *
- * @param bytebuf
- * the specified ByteBuffer object to be destroyed
- *
- * @param size
- * the new size of backed buffer that is managed by created
- * ByteBuffer object.
- *
- * @return a created ByteBuffer object with a backed native memory block
- */
- public ByteBuffer resizeByteBuffer(long id, ByteBuffer bytebuf, long size);
-
- /**
- * destroy a native memory block backed ByteBuffer object.
- *
- * @param id
- * the identifier of backed memory pool
- *
- * @param bytebuf
- * the specified ByteBuffer object to be destroyed
- */
- public void destroyByteBuffer(long id, ByteBuffer bytebuf);
+ /**
+ * destroy a native memory block backed ByteBuffer object.
+ *
+ * @param id
+ * the identifier of backed memory pool
+ *
+ * @param bytebuf
+ * the specified ByteBuffer object to be destroyed
+ */
+ public void destroyByteBuffer(long id, ByteBuffer bytebuf);
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/test/java/org/apache/mnemonic/BigDataMemAllocatorNGTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/mnemonic/BigDataMemAllocatorNGTest.java b/core/src/test/java/org/apache/mnemonic/BigDataMemAllocatorNGTest.java
index 6497879..61ea2ed 100644
--- a/core/src/test/java/org/apache/mnemonic/BigDataMemAllocatorNGTest.java
+++ b/core/src/test/java/org/apache/mnemonic/BigDataMemAllocatorNGTest.java
@@ -1,3 +1,19 @@
+/*
+ * 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.mnemonic;
@@ -13,46 +29,45 @@ import java.util.Random;
/**
* test the functionality of BigMemAllocator class.
*
- * @author Wang, Gang(Gary) {@literal <ga...@intel.com>}
*/
public class BigDataMemAllocatorNGTest {
- /**
- * test to allocate MemBufferHolder objects and then verify them.
- */
- @Test
- public void testMemByteBuffer() {
- Random randomGenerator = new Random();
- Allocator<BigDataMemAllocator> act = new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 1024, ".", true);
- MemBufferHolder<?> mbh;
- for (int idx = 1; idx <= 5; ++idx) {
- int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
- mbh = act.createBuffer(size);
- for (int i = 0; i < size; i++) {
- mbh.get().put((byte) randomGenerator.nextInt(255));
- }
- // if (bb.hasArray()) randomGenerator.nextBytes(bb.array());
- System.out.println(String.format("[Seq.%d] size %d - %d, (%s)",
- idx, size, mbh.get().capacity(), size == mbh.get()
- .capacity() ? "Correct" : "Failed!!!"));
- // mbh.destroy();
- }
- }
+ /**
+ * test to allocate MemBufferHolder objects and then verify them.
+ */
+ @Test
+ public void testMemByteBuffer() {
+ Random randomGenerator = new Random();
+ Allocator<BigDataMemAllocator> act = new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"),
+ 1024 * 1024 * 1024, ".", true);
+ MemBufferHolder<?> mbh;
+ for (int idx = 1; idx <= 5; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mbh = act.createBuffer(size);
+ for (int i = 0; i < size; i++) {
+ mbh.get().put((byte) randomGenerator.nextInt(255));
+ }
+ // if (bb.hasArray()) randomGenerator.nextBytes(bb.array());
+ System.out.println(String.format("[Seq.%d] size %d - %d, (%s)", idx, size, mbh.get().capacity(),
+ size == mbh.get().capacity() ? "Correct" : "Failed!!!"));
+ // mbh.destroy();
+ }
+ }
- /**
- * test to allocate MemChunkHolder objects and then verify them.
- */
- @Test
- public void testMemChunk() {
- Random randomGenerator = new Random();
- Allocator<BigDataMemAllocator> act = new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 1024, ".", true);
- MemChunkHolder<?> mch;
- for (int idx = 1; idx <= 5; ++idx) {
- int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
- mch = act.createChunk(size);
- System.out.println(String.format("[Seq.%d] addr : %X", idx, size,
- mch.get()));
- mch.destroy();
- }
- }
+ /**
+ * test to allocate MemChunkHolder objects and then verify them.
+ */
+ @Test
+ public void testMemChunk() {
+ Random randomGenerator = new Random();
+ Allocator<BigDataMemAllocator> act = new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"),
+ 1024 * 1024 * 1024, ".", true);
+ MemChunkHolder<?> mch;
+ for (int idx = 1; idx <= 5; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mch = act.createChunk(size);
+ System.out.println(String.format("[Seq.%d] addr : %X", idx, size, mch.get()));
+ mch.destroy();
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/test/java/org/apache/mnemonic/BigDataPMemAllocatorNGTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/mnemonic/BigDataPMemAllocatorNGTest.java b/core/src/test/java/org/apache/mnemonic/BigDataPMemAllocatorNGTest.java
index b515ef0..ee8b0c6 100644
--- a/core/src/test/java/org/apache/mnemonic/BigDataPMemAllocatorNGTest.java
+++ b/core/src/test/java/org/apache/mnemonic/BigDataPMemAllocatorNGTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import java.nio.ByteBuffer;
@@ -9,116 +26,109 @@ import org.testng.annotations.Test;
/**
*
- * @author Wang, Gang {@literal <ga...@intel.com>}
- *
*/
public class BigDataPMemAllocatorNGTest {
- @Test
- public void testPMemByteBuffer() {
- Random randomGenerator = new Random();
- BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 1024, "./pmtest.dat", true);
- act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
- @Override
- public boolean reclaim(ByteBuffer mres, Long sz) {
- System.out.println(String.format(
- "Reclaim Memory Buffer: %X Size: %s", System
- .identityHashCode(mres),
- null == sz ? "NULL" : sz.toString()));
- return false;
- }
- });
- MemBufferHolder<?> mbh;
- for (int idx = 1; idx <= 500; ++idx) {
- int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
- mbh = act.createBuffer(size);
- Assert.assertNotNull(mbh);
- for (int i = 0; i < size; i++) {
- mbh.get().put((byte) randomGenerator.nextInt(255));
- }
- // if (bb.hasArray()) randomGenerator.nextBytes(bb.array());
- Assert.assertEquals(size, mbh.get().capacity());
- System.out.println(String.format("[Seq.%d] size %d - %d, (%s)",
- idx, size, mbh.get().capacity(), size == mbh.get()
- .capacity() ? "Correct" : "Failed!!!"));
- // mbh.destroy();
- }
- act.close();
- }
-
- @Test
- public void testGetBufferAddress() {
- BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 1024, "./pmtest_buffer.dat", true);
- MemBufferHolder<BigDataPMemAllocator> mbh;
- mbh = act.createBuffer(20000);
- long phandler = act.getBufferHandler(mbh);
- System.out.println(String.format("**** 0x%X", phandler));
- act.close();
- }
-
- @Test
- public void testGenPMemByteBufferWithKey() {
- Random randomGenerator = Utils.createRandom();
- BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 1024, "./pmtest_key.dat", true);
- act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
- @Override
- public boolean reclaim(ByteBuffer mres, Long sz) {
- System.out.println(String.format(
- "Reclaim Memory Buffer: %X Size: %s", System
- .identityHashCode(mres),
- null == sz ? "NULL" : sz.toString()));
- return false;
- }
- });
- MemBufferHolder<BigDataPMemAllocator> mbh;
- Long phandler;
- long keycount = act.handlerCapacity();
- for (int idx = 0; idx < keycount; ++idx) {
- int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
- mbh = act.createBuffer(size);
- if (6 == idx) {
- size += 2000;
- mbh = mbh.resize(size);
- }
- Assert.assertNotNull(mbh);
- mbh.get().putInt(size);
- Assert.assertEquals(size, mbh.get().capacity());
- System.out.println(String.format("Generating PKey Value [Seq.%d] size %d - %d, (%s)",
- idx, size, mbh.get().capacity(), size == mbh.get()
- .capacity() ? "Correct" : "Failed!!!"));
- phandler = act.getBufferHandler(mbh);
- System.out.println(String.format("---- 0x%X", phandler));
- act.setHandler(idx, phandler);
- mbh.cancelAutoReclaim();
- }
- act.close();
- }
-
- @Test(dependsOnMethods = {"testGenPMemByteBufferWithKey"})
- public void testCheckPMemByteBufferWithKey() {
- BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 1024, "./pmtest_key.dat", true);
- act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
- @Override
- public boolean reclaim(ByteBuffer mres, Long sz) {
- System.out.println(String.format(
- "Reclaim Memory Buffer: %X Size: %s", System
- .identityHashCode(mres),
- null == sz ? "NULL" : sz.toString()));
- return false;
- }
- });
- MemBufferHolder<BigDataPMemAllocator> mbh;
- for (int idx = 0; idx < act.handlerCapacity(); ++idx) {
- long phandler = act.getHandler(idx);
- mbh = act.retrieveBuffer(phandler);
- Assert.assertNotNull(mbh);
- int val = mbh.get().getInt();
- Assert.assertEquals(val, mbh.get().capacity());
- System.out.println(String.format("Checking PKey Value [Seq.%d] size %d - %d, (%s)",
- idx, val, mbh.get().capacity(), val == mbh.get()
- .capacity() ? "Correct" : "Failed!!!"));
- }
- act.close();
- }
-
+ @Test
+ public void testPMemByteBuffer() {
+ Random randomGenerator = new Random();
+ BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
+ 1024 * 1024 * 1024, "./pmtest.dat", true);
+ act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
+ @Override
+ public boolean reclaim(ByteBuffer mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Buffer: %X Size: %s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+ MemBufferHolder<?> mbh;
+ for (int idx = 1; idx <= 500; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mbh = act.createBuffer(size);
+ Assert.assertNotNull(mbh);
+ for (int i = 0; i < size; i++) {
+ mbh.get().put((byte) randomGenerator.nextInt(255));
+ }
+ // if (bb.hasArray()) randomGenerator.nextBytes(bb.array());
+ Assert.assertEquals(size, mbh.get().capacity());
+ System.out.println(String.format("[Seq.%d] size %d - %d, (%s)", idx, size, mbh.get().capacity(),
+ size == mbh.get().capacity() ? "Correct" : "Failed!!!"));
+ // mbh.destroy();
+ }
+ act.close();
+ }
+
+ @Test
+ public void testGetBufferAddress() {
+ BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
+ 1024 * 1024 * 1024, "./pmtest_buffer.dat", true);
+ MemBufferHolder<BigDataPMemAllocator> mbh;
+ mbh = act.createBuffer(20000);
+ long phandler = act.getBufferHandler(mbh);
+ System.out.println(String.format("**** 0x%X", phandler));
+ act.close();
+ }
+
+ @Test
+ public void testGenPMemByteBufferWithKey() {
+ Random randomGenerator = Utils.createRandom();
+ BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
+ 1024 * 1024 * 1024, "./pmtest_key.dat", true);
+ act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
+ @Override
+ public boolean reclaim(ByteBuffer mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Buffer: %X Size: %s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+ MemBufferHolder<BigDataPMemAllocator> mbh;
+ Long phandler;
+ long keycount = act.handlerCapacity();
+ for (int idx = 0; idx < keycount; ++idx) {
+ int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024;
+ mbh = act.createBuffer(size);
+ if (6 == idx) {
+ size += 2000;
+ mbh = mbh.resize(size);
+ }
+ Assert.assertNotNull(mbh);
+ mbh.get().putInt(size);
+ Assert.assertEquals(size, mbh.get().capacity());
+ System.out.println(String.format("Generating PKey Value [Seq.%d] size %d - %d, (%s)", idx, size,
+ mbh.get().capacity(), size == mbh.get().capacity() ? "Correct" : "Failed!!!"));
+ phandler = act.getBufferHandler(mbh);
+ System.out.println(String.format("---- 0x%X", phandler));
+ act.setHandler(idx, phandler);
+ mbh.cancelAutoReclaim();
+ }
+ act.close();
+ }
+
+ @Test(dependsOnMethods = { "testGenPMemByteBufferWithKey" })
+ public void testCheckPMemByteBufferWithKey() {
+ BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
+ 1024 * 1024 * 1024, "./pmtest_key.dat", true);
+ act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
+ @Override
+ public boolean reclaim(ByteBuffer mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Buffer: %X Size: %s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+ MemBufferHolder<BigDataPMemAllocator> mbh;
+ for (int idx = 0; idx < act.handlerCapacity(); ++idx) {
+ long phandler = act.getHandler(idx);
+ mbh = act.retrieveBuffer(phandler);
+ Assert.assertNotNull(mbh);
+ int val = mbh.get().getInt();
+ Assert.assertEquals(val, mbh.get().capacity());
+ System.out.println(String.format("Checking PKey Value [Seq.%d] size %d - %d, (%s)", idx, val,
+ mbh.get().capacity(), val == mbh.get().capacity() ? "Correct" : "Failed!!!"));
+ }
+ act.close();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/test/java/org/apache/mnemonic/ByteBufferSerializerNGTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/mnemonic/ByteBufferSerializerNGTest.java b/core/src/test/java/org/apache/mnemonic/ByteBufferSerializerNGTest.java
index 6150efe..883a00e 100644
--- a/core/src/test/java/org/apache/mnemonic/ByteBufferSerializerNGTest.java
+++ b/core/src/test/java/org/apache/mnemonic/ByteBufferSerializerNGTest.java
@@ -1,3 +1,19 @@
+/*
+ * 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.mnemonic;
@@ -16,50 +32,43 @@ import java.io.IOException;
/**
* test the functionalities of ByteBufferSerializer class
*
- * @author Wang, Gang(Gary) {@literal <ga...@intel.com>}
*/
public class ByteBufferSerializerNGTest {
- /**
- * test to convert any serializable object from/to ByteBuffer object that is
- * backed by Java heap.
- */
- @Test
- public void testToFromByteBuffer() throws IOException,
- ClassNotFoundException {
- Random randomGenerator = new Random();
- for (int idx = 0; idx < 100; idx++) {
- Payload pl = new Payload(randomGenerator.nextInt(1024 * 1024),
- String.format("Str is %d",
- randomGenerator.nextInt(1024 * 1024)),
- randomGenerator.nextDouble());
- ByteBuffer bb = ByteBufferSerializer.toByteBuffer(pl);
- Payload rpl = ByteBufferSerializer.toObject(bb);
- assertTrue(pl.compareTo(rpl) == 0);
- }
- }
+ /**
+ * test to convert any serializable object from/to ByteBuffer object that is
+ * backed by Java heap.
+ */
+ @Test
+ public void testToFromByteBuffer() throws IOException, ClassNotFoundException {
+ Random randomGenerator = new Random();
+ for (int idx = 0; idx < 100; idx++) {
+ Payload pl = new Payload(randomGenerator.nextInt(1024 * 1024),
+ String.format("Str is %d", randomGenerator.nextInt(1024 * 1024)), randomGenerator.nextDouble());
+ ByteBuffer bb = ByteBufferSerializer.toByteBuffer(pl);
+ Payload rpl = ByteBufferSerializer.toObject(bb);
+ assertTrue(pl.compareTo(rpl) == 0);
+ }
+ }
- /**
- * test to convert any serializable object from/to MemBufferHolder object
- * that is backed by native memory pool.
- */
- @Test
- public void testToFromMemBufferHolder() throws IOException,
- ClassNotFoundException {
- BigDataMemAllocator act = new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"), 1024 * 1024 * 1024, ".", true);
+ /**
+ * test to convert any serializable object from/to MemBufferHolder object that
+ * is backed by native memory pool.
+ */
+ @Test
+ public void testToFromMemBufferHolder() throws IOException, ClassNotFoundException {
+ BigDataMemAllocator act = new BigDataMemAllocator(Utils.getVolatileMemoryAllocatorService("vmem"),
+ 1024 * 1024 * 1024, ".", true);
- Random randomGenerator = new Random();
- for (int idx = 0; idx < 100; idx++) {
- Payload pl = new Payload(randomGenerator.nextInt(1024 * 1024),
- String.format("Str is %d",
- randomGenerator.nextInt(1024 * 1024)),
- randomGenerator.nextDouble());
- MemBufferHolder<BigDataMemAllocator> mbh =
- ByteBufferSerializer.toMemBufferHolder(act, pl);
- Payload rpl = ByteBufferSerializer.fromMemBufferHolder(mbh);
- mbh.destroy();
- assertTrue(pl.compareTo(rpl) == 0);
- }
+ Random randomGenerator = new Random();
+ for (int idx = 0; idx < 100; idx++) {
+ Payload pl = new Payload(randomGenerator.nextInt(1024 * 1024),
+ String.format("Str is %d", randomGenerator.nextInt(1024 * 1024)), randomGenerator.nextDouble());
+ MemBufferHolder<BigDataMemAllocator> mbh = ByteBufferSerializer.toMemBufferHolder(act, pl);
+ Payload rpl = ByteBufferSerializer.fromMemBufferHolder(mbh);
+ mbh.destroy();
+ assertTrue(pl.compareTo(rpl) == 0);
+ }
- }
+ }
}
[3/7] incubator-mnemonic git commit: format codestyle & add Apache
License
Posted by ga...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/Durable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/Durable.java b/core/src/main/java/org/apache/mnemonic/Durable.java
index 0649dda..85d3a17 100644
--- a/core/src/main/java/org/apache/mnemonic/Durable.java
+++ b/core/src/main/java/org/apache/mnemonic/Durable.java
@@ -1,74 +1,96 @@
+/*
+ * 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.mnemonic;
/**
- * this interface defines the interactive functionalities with Mnenomic core part.
+ * this interface defines the interactive functionalities with Mnenomic core
+ * part.
*
*/
-
public interface Durable {
- /**
- * this function will be invoked after this non-volatile object is created brandly new
- *
- */
- public void initializeAfterCreate();
+ /**
+ * this function will be invoked after this non-volatile object is created
+ * brandly new
+ *
+ */
+ public void initializeAfterCreate();
- /**
- * this function will be invoked after this non-volatile object is restored from its allocator
- *
- */
- public void initializeAfterRestore();
-
+ /**
+ * this function will be invoked after this non-volatile object is restored
+ * from its allocator
+ *
+ */
+ public void initializeAfterRestore();
- /**
- * this function will be invoked by its factory to setup generic related info to avoid expensive operations from reflection
- *
- * @param efproxies
- * specify a array of factory to proxy the restoring of its generic field objects
- *
- * @param gftypes
- * specify a array of types corresponding to efproxies
- */
- public void setupGenericInfo(EntityFactoryProxy[] efproxies, GenericField.GType[] gftypes);
+ /**
+ * this function will be invoked by its factory to setup generic related info
+ * to avoid expensive operations from reflection
+ *
+ * @param efproxies
+ * specify a array of factory to proxy the restoring of its generic
+ * field objects
+ *
+ * @param gftypes
+ * specify a array of types corresponding to efproxies
+ */
+ public void setupGenericInfo(EntityFactoryProxy[] efproxies, GenericField.GType[] gftypes);
- /**
- * this function could be called by user code to disable auto-reclaim for this non-volatile object
- *
- */
- public void cancelAutoReclaim();
+ /**
+ * this function could be called by user code to disable auto-reclaim for this
+ * non-volatile object
+ *
+ */
+ public void cancelAutoReclaim();
- /**
- * this function could be called by user code to register this object for auto-reclaim
- *
- */
- public void registerAutoReclaim();
+ /**
+ * this function could be called by user code to register this object for
+ * auto-reclaim
+ *
+ */
+ public void registerAutoReclaim();
- /**
- * this function returns its bound handler for this object
- *
- * @return the handler of this object
- */
- public long getNonVolatileHandler();
+ /**
+ * this function returns its bound handler for this object
+ *
+ * @return the handler of this object
+ */
+ public long getNonVolatileHandler();
- /**
- * return the setting for auto-reclaim
- *
- * @return the status of the auto-reclaim setting
- */
- public boolean autoReclaim();
+ /**
+ * return the setting for auto-reclaim
+ *
+ * @return the status of the auto-reclaim setting
+ */
+ public boolean autoReclaim();
- /**
- * manually destroy this object and release its memory resource
- *
- */
- public void destroy() throws RetrieveNonVolatileEntityError;
+ /**
+ * manually destroy this object and release its memory resource
+ *
+ */
+ public void destroy() throws RetrieveNonVolatileEntityError;
- /**
- * return the native field map info for native processing.
- *
- * @return the native field map info
- *
- */
- public long[][] getNativeFieldInfo();
+ /**
+ * return the native field map info for native processing.
+ *
+ * @return the native field map info
+ *
+ */
+ public long[][] getNativeFieldInfo();
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/EntityFactoryProxy.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/EntityFactoryProxy.java b/core/src/main/java/org/apache/mnemonic/EntityFactoryProxy.java
index 89e3ca9..06caac5 100644
--- a/core/src/main/java/org/apache/mnemonic/EntityFactoryProxy.java
+++ b/core/src/main/java/org/apache/mnemonic/EntityFactoryProxy.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -5,31 +22,32 @@ package org.apache.mnemonic;
*
*/
-
public interface EntityFactoryProxy {
- /**
- * restore a durable object from persistent allocator using a handler of non-volatile object
- *
- * @param allocator
- * specify a persistent allocator instance
- *
- * @param factoryproxys
- * specify an array of factory proxies for its restored non-volatile object
- *
- * @param gfields
- * specify an array of generic types of its generic fields corresponding to factoryproxys
- *
- * @param phandler
- * specify a non-volatile handler to restore
- *
- * @param autoreclaim
- * specify auto-reclaim for this restored non-volatile object
- *
- * @return the restored non-volatile object from this factory proxy
- *
- */
- public abstract <A extends CommonPersistAllocator<A>> Durable restore(A allocator,
- EntityFactoryProxy[] factoryproxys, GenericField.GType[] gfields, long phandler,
- boolean autoreclaim);
+ /**
+ * restore a durable object from persistent allocator using a handler of
+ * non-volatile object
+ *
+ * @param allocator
+ * specify a persistent allocator instance
+ *
+ * @param factoryproxys
+ * specify an array of factory proxies for its restored non-volatile
+ * object
+ *
+ * @param gfields
+ * specify an array of generic types of its generic fields
+ * corresponding to factoryproxys
+ *
+ * @param phandler
+ * specify a non-volatile handler to restore
+ *
+ * @param autoreclaim
+ * specify auto-reclaim for this restored non-volatile object
+ *
+ * @return the restored non-volatile object from this factory proxy
+ *
+ */
+ public abstract <A extends CommonPersistAllocator<A>> Durable restore(A allocator, EntityFactoryProxy[] factoryproxys,
+ GenericField.GType[] gfields, long phandler, boolean autoreclaim);
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/EvictFilter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/EvictFilter.java b/core/src/main/java/org/apache/mnemonic/EvictFilter.java
index f3a65dd..6411ee2 100644
--- a/core/src/main/java/org/apache/mnemonic/EvictFilter.java
+++ b/core/src/main/java/org/apache/mnemonic/EvictFilter.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -5,20 +22,20 @@ package org.apache.mnemonic;
*
*/
public interface EvictFilter<KeyT, ValueT> {
- /**
- * A call-back validator when an entry will be evicted.
- *
- * @param pool
- * the pool which an entry has been evicted from
- *
- * @param k
- * the entry's key
- *
- * @param v
- * the entry's value
- *
- * @return <tt>true</tt> if the entry is allowed to be dropped from its
- * cache pool.
- */
- public boolean validate(CachePool<KeyT, ValueT> pool, KeyT k, ValueT v);
+ /**
+ * A call-back validator when an entry will be evicted.
+ *
+ * @param pool
+ * the pool which an entry has been evicted from
+ *
+ * @param k
+ * the entry's key
+ *
+ * @param v
+ * the entry's value
+ *
+ * @return <tt>true</tt> if the entry is allowed to be dropped from its cache
+ * pool.
+ */
+ public boolean validate(CachePool<KeyT, ValueT> pool, KeyT k, ValueT v);
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/GenericField.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/GenericField.java b/core/src/main/java/org/apache/mnemonic/GenericField.java
index 0f674a8..a1d3c9e 100644
--- a/core/src/main/java/org/apache/mnemonic/GenericField.java
+++ b/core/src/main/java/org/apache/mnemonic/GenericField.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -10,279 +27,279 @@ import sun.misc.Unsafe;
@SuppressWarnings("restriction")
public class GenericField<A extends CommonPersistAllocator<A>, E> implements Durable {
- /**
- * defines the types of generic field
- *
- */
- public enum GType {
- BOOLEAN, CHARACTER, BYTE, SHORT, INTEGER, LONG, FLOAT, DOUBLE, STRING, DURABLE
- };
+ /**
+ * defines the types of generic field
+ *
+ */
+ public enum GType {
+ BOOLEAN, CHARACTER, BYTE, SHORT, INTEGER, LONG, FLOAT, DOUBLE, STRING, DURABLE
+ };
- private Unsafe m_unsafe;
- private long m_fpos;
- private GType m_dgftype = null;
- private Durable m_field = null;
- private MemBufferHolder<A> m_strfield = null;
- private A m_allocator;
- private boolean m_autoreclaim;
- private EntityFactoryProxy m_defproxy = null;
- private EntityFactoryProxy[] m_efproxies;
- private GType[] m_gftypes;
+ private Unsafe m_unsafe;
+ private long m_fpos;
+ private GType m_dgftype = null;
+ private Durable m_field = null;
+ private MemBufferHolder<A> m_strfield = null;
+ private A m_allocator;
+ private boolean m_autoreclaim;
+ private EntityFactoryProxy m_defproxy = null;
+ private EntityFactoryProxy[] m_efproxies;
+ private GType[] m_gftypes;
- /**
- * Constructor: initialize this generic field
- *
- * @param defproxy
- * specify its entity factory proxy
- *
- * @param dgftype
- * specify its type
- *
- * @param efproxies
- * specify an array of containing entity factory proxies
- *
- * @param gftypes
- * specify an array of containing types corresponding to dfproxies
- *
- * @param allocator
- * specify the allocator this field sit on
- *
- * @param unsafe
- * specify the unsafe instance
- *
- * @param autoreclaim
- * specify true if ask for auto-reclaim for this field
- *
- * @param fpos
- * specify the field position
- *
- */
- public GenericField(EntityFactoryProxy defproxy, GType dgftype, EntityFactoryProxy[] efproxies, GType[] gftypes,
- A allocator, Unsafe unsafe, boolean autoreclaim, Long fpos) {
- m_unsafe = unsafe;
- m_fpos = fpos;
- m_allocator = allocator;
- m_autoreclaim = autoreclaim;
- m_efproxies = efproxies;
- m_gftypes = gftypes;
- m_defproxy = defproxy;
- m_dgftype = dgftype;
+ /**
+ * Constructor: initialize this generic field
+ *
+ * @param defproxy
+ * specify its entity factory proxy
+ *
+ * @param dgftype
+ * specify its type
+ *
+ * @param efproxies
+ * specify an array of containing entity factory proxies
+ *
+ * @param gftypes
+ * specify an array of containing types corresponding to dfproxies
+ *
+ * @param allocator
+ * specify the allocator this field sit on
+ *
+ * @param unsafe
+ * specify the unsafe instance
+ *
+ * @param autoreclaim
+ * specify true if ask for auto-reclaim for this field
+ *
+ * @param fpos
+ * specify the field position
+ *
+ */
+ public GenericField(EntityFactoryProxy defproxy, GType dgftype, EntityFactoryProxy[] efproxies, GType[] gftypes,
+ A allocator, Unsafe unsafe, boolean autoreclaim, Long fpos) {
+ m_unsafe = unsafe;
+ m_fpos = fpos;
+ m_allocator = allocator;
+ m_autoreclaim = autoreclaim;
+ m_efproxies = efproxies;
+ m_gftypes = gftypes;
+ m_defproxy = defproxy;
+ m_dgftype = dgftype;
+ }
+
+ /**
+ * set a value to this field
+ *
+ * @param e
+ * specify a value to set
+ *
+ * @param destroy
+ * specify true if want to destroy the original value
+ */
+ public void set(E e, boolean destroy) {
+ boolean isnull = null == e;
+ switch (m_dgftype) {
+ case BYTE:
+ m_unsafe.putByte(m_fpos, isnull ? (byte) 0 : (Byte) e);
+ break;
+ case BOOLEAN:
+ m_unsafe.putByte(m_fpos, isnull ? (byte) 0 : ((Boolean) e ? (byte) 1 : (byte) 0));
+ break;
+ case CHARACTER:
+ m_unsafe.putChar(m_fpos, isnull ? (char) 0 : (Character) e);
+ break;
+ case SHORT:
+ m_unsafe.putShort(m_fpos, isnull ? (short) 0 : (Short) e);
+ break;
+ case INTEGER:
+ m_unsafe.putInt(m_fpos, isnull ? (int) 0 : (Integer) e);
+ break;
+ case LONG:
+ m_unsafe.putLong(m_fpos, isnull ? (long) 0 : (Long) e);
+ break;
+ case FLOAT:
+ m_unsafe.putFloat(m_fpos, isnull ? (float) 0 : (Float) e);
+ break;
+ case DOUBLE:
+ m_unsafe.putDouble(m_fpos, isnull ? (double) 0 : (Double) e);
+ break;
+ case STRING:
+ String str = (String) e;
+ if (destroy && null != get()) {
+ m_strfield.destroy();
+ m_strfield = null;
+ m_unsafe.putAddress(m_fpos, 0L);
+ }
+ if (null == str) {
+ m_unsafe.putAddress(m_fpos, 0L);
+ } else {
+ m_strfield = m_allocator.createBuffer(str.length() * 2, m_autoreclaim);
+ if (null == m_strfield) {
+ throw new OutOfPersistentMemory("Create Persistent String Error!");
+ }
+ m_strfield.get().asCharBuffer().put(str);
+ m_unsafe.putAddress(m_fpos, m_allocator.getBufferHandler(m_strfield));
+ }
+ break;
+ case DURABLE:
+ if (destroy && null != get()) {
+ m_field.destroy();
+ m_field = null;
+ m_unsafe.putAddress(m_fpos, 0L);
+ }
+ m_field = (Durable) e;
+ m_unsafe.putAddress(m_fpos, null == m_field ? 0L : m_field.getNonVolatileHandler());
+ break;
}
- /**
- * set a value to this field
- *
- * @param e
- * specify a value to set
- *
- * @param destroy
- * specify true if want to destroy the original value
- */
- public void set(E e, boolean destroy) {
- boolean isnull = null == e;
- switch (m_dgftype) {
- case BYTE:
- m_unsafe.putByte(m_fpos, isnull ? (byte)0 : (Byte) e);
- break;
- case BOOLEAN:
- m_unsafe.putByte(m_fpos, isnull ? (byte)0 : ((Boolean) e ? (byte)1 : (byte)0));
- break;
- case CHARACTER:
- m_unsafe.putChar(m_fpos, isnull ? (char)0 : (Character) e);
- break;
- case SHORT:
- m_unsafe.putShort(m_fpos, isnull ? (short)0 : (Short) e);
- break;
- case INTEGER:
- m_unsafe.putInt(m_fpos, isnull ? (int)0 : (Integer) e);
- break;
- case LONG:
- m_unsafe.putLong(m_fpos, isnull ? (long)0 : (Long) e);
- break;
- case FLOAT:
- m_unsafe.putFloat(m_fpos, isnull ? (float)0 : (Float) e);
- break;
- case DOUBLE:
- m_unsafe.putDouble(m_fpos, isnull ? (double)0 : (Double) e);
- break;
- case STRING:
- String str = (String) e;
- if (destroy && null != get()) {
- m_strfield.destroy();
- m_strfield = null;
- m_unsafe.putAddress(m_fpos, 0L);
- }
- if (null == str) {
- m_unsafe.putAddress(m_fpos, 0L);
- } else {
- m_strfield = m_allocator.createBuffer(str.length() * 2, m_autoreclaim);
- if (null == m_strfield) {
- throw new OutOfPersistentMemory("Create Persistent String Error!");
- }
- m_strfield.get().asCharBuffer().put(str);
- m_unsafe.putAddress(m_fpos, m_allocator.getBufferHandler(m_strfield));
- }
- break;
- case DURABLE:
- if (destroy && null != get()) {
- m_field.destroy();
- m_field = null;
- m_unsafe.putAddress(m_fpos, 0L);
- }
- m_field = (Durable) e;
- m_unsafe.putAddress(m_fpos, null == m_field ? 0L : m_field.getNonVolatileHandler());
- break;
- }
+ }
+ /**
+ * get the value of this field
+ *
+ * @return the field value
+ */
+ @SuppressWarnings("unchecked")
+ public E get() {
+ E ret = null;
+ switch (m_dgftype) {
+ case BYTE:
+ ret = (E) Byte.valueOf(m_unsafe.getByte(m_fpos));
+ break;
+ case BOOLEAN:
+ ret = (E) Boolean.valueOf(1 == m_unsafe.getByte(m_fpos));
+ break;
+ case CHARACTER:
+ ret = (E) Character.valueOf(m_unsafe.getChar(m_fpos));
+ break;
+ case SHORT:
+ ret = (E) Short.valueOf(m_unsafe.getShort(m_fpos));
+ break;
+ case INTEGER:
+ ret = (E) Integer.valueOf(m_unsafe.getInt(m_fpos));
+ break;
+ case LONG:
+ ret = (E) Long.valueOf(m_unsafe.getLong(m_fpos));
+ break;
+ case FLOAT:
+ ret = (E) Float.valueOf(m_unsafe.getFloat(m_fpos));
+ break;
+ case DOUBLE:
+ ret = (E) Double.valueOf(m_unsafe.getDouble(m_fpos));
+ break;
+ case STRING:
+ if (null == m_strfield) {
+ long phandler = m_unsafe.getAddress(m_fpos);
+ if (0L != phandler) {
+ m_strfield = m_allocator.retrieveBuffer(phandler, m_autoreclaim);
+ if (null == m_strfield) {
+ throw new RetrieveNonVolatileEntityError("Retrieve String Buffer Failure.");
+ }
+ }
+ }
+ ret = (E) (null == m_strfield ? null : m_strfield.get().asCharBuffer().toString());
+ break;
+ case DURABLE:
+ if (null == m_field) {
+ long phandler = m_unsafe.getAddress(m_fpos);
+ if (0L != phandler) {
+ if (null == m_defproxy) {
+ throw new RetrieveNonVolatileEntityError("Proxy not specified for Non-Volatile Generic entity.");
+ }
+ m_field = m_defproxy.restore(m_allocator, m_efproxies, m_gftypes, phandler, m_autoreclaim);
+ }
+ }
+ ret = (E) m_field;
+ break;
}
+ return ret;
+ }
- /**
- * get the value of this field
- *
- * @return the field value
- */
- @SuppressWarnings("unchecked")
- public E get() {
- E ret = null;
- switch (m_dgftype) {
- case BYTE:
- ret = (E) Byte.valueOf(m_unsafe.getByte(m_fpos));
- break;
- case BOOLEAN:
- ret = (E) Boolean.valueOf(1 == m_unsafe.getByte(m_fpos));
- break;
- case CHARACTER:
- ret = (E) Character.valueOf(m_unsafe.getChar(m_fpos));
- break;
- case SHORT:
- ret = (E) Short.valueOf(m_unsafe.getShort(m_fpos));
- break;
- case INTEGER:
- ret = (E) Integer.valueOf(m_unsafe.getInt(m_fpos));
- break;
- case LONG:
- ret = (E) Long.valueOf(m_unsafe.getLong(m_fpos));
- break;
- case FLOAT:
- ret = (E) Float.valueOf(m_unsafe.getFloat(m_fpos));
- break;
- case DOUBLE:
- ret = (E) Double.valueOf(m_unsafe.getDouble(m_fpos));
- break;
- case STRING:
- if (null == m_strfield) {
- long phandler = m_unsafe.getAddress(m_fpos);
- if (0L != phandler) {
- m_strfield = m_allocator.retrieveBuffer(phandler, m_autoreclaim);
- if (null == m_strfield) {
- throw new RetrieveNonVolatileEntityError("Retrieve String Buffer Failure.");
- }
- }
- }
- ret = (E) (null == m_strfield ? null : m_strfield.get().asCharBuffer().toString());
- break;
- case DURABLE:
- if (null == m_field) {
- long phandler = m_unsafe.getAddress(m_fpos);
- if (0L != phandler) {
- if (null == m_defproxy) {
- throw new RetrieveNonVolatileEntityError("Proxy not specified for Non-Volatile Generic entity.");
- }
- m_field = m_defproxy.restore(m_allocator, m_efproxies, m_gftypes, phandler, m_autoreclaim);
- }
- }
- ret = (E) m_field;
- break;
- }
- return ret;
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void initializeAfterCreate() {
+ throw new UnsupportedOperationException("GenericField.initializeAfterCreate()");
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void initializeAfterCreate() {
- throw new UnsupportedOperationException("GenericField.initializeAfterCreate()");
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void initializeAfterRestore() {
+ throw new UnsupportedOperationException("GenericField.initializeAfterRestore()");
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void initializeAfterRestore() {
- throw new UnsupportedOperationException("GenericField.initializeAfterRestore()");
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void cancelAutoReclaim() {
+ if (null != m_field) {
+ m_field.cancelAutoReclaim();
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void cancelAutoReclaim() {
- if (null != m_field) {
- m_field.cancelAutoReclaim();
- }
- if (null != m_strfield) {
- m_strfield.cancelAutoReclaim();
- }
- m_autoreclaim = false;
+ if (null != m_strfield) {
+ m_strfield.cancelAutoReclaim();
}
+ m_autoreclaim = false;
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void registerAutoReclaim() {
- if (null != m_field) {
- m_field.registerAutoReclaim();
- }
- if (null != m_strfield) {
- m_strfield.registerAutoReclaim();
- }
- m_autoreclaim = true;
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void registerAutoReclaim() {
+ if (null != m_field) {
+ m_field.registerAutoReclaim();
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public long getNonVolatileHandler() {
- throw new UnsupportedOperationException("GenericField.getNonVolatileHandler()");
+ if (null != m_strfield) {
+ m_strfield.registerAutoReclaim();
}
+ m_autoreclaim = true;
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean autoReclaim() {
- return m_autoreclaim;
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public long getNonVolatileHandler() {
+ throw new UnsupportedOperationException("GenericField.getNonVolatileHandler()");
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void destroy() throws RetrieveNonVolatileEntityError {
- if (null != m_field) {
- m_field.destroy();
- }
- if (null != m_strfield) {
- m_strfield.destroy();
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean autoReclaim() {
+ return m_autoreclaim;
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void setupGenericInfo(EntityFactoryProxy[] efproxies, GType[] gftypes) {
- throw new UnsupportedOperationException("GenericField.setupGenericInfo()");
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void destroy() throws RetrieveNonVolatileEntityError {
+ if (null != m_field) {
+ m_field.destroy();
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public long[][] getNativeFieldInfo() {
- throw new UnsupportedOperationException("getNativeFieldInfo() on Generic Field.");
+ if (null != m_strfield) {
+ m_strfield.destroy();
}
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setupGenericInfo(EntityFactoryProxy[] efproxies, GType[] gftypes) {
+ throw new UnsupportedOperationException("GenericField.setupGenericInfo()");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public long[][] getNativeFieldInfo() {
+ throw new UnsupportedOperationException("getNativeFieldInfo() on Generic Field.");
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/MemBufferHolder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/MemBufferHolder.java b/core/src/main/java/org/apache/mnemonic/MemBufferHolder.java
index 66ee0bf..c14ecc3 100644
--- a/core/src/main/java/org/apache/mnemonic/MemBufferHolder.java
+++ b/core/src/main/java/org/apache/mnemonic/MemBufferHolder.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import java.nio.ByteBuffer;
@@ -8,49 +25,48 @@ import java.nio.ByteBuffer;
*/
public class MemBufferHolder<A extends CommonAllocator<A>> extends MemHolder<A, ByteBuffer, MemBufferHolder<A>> {
-
- /**
- * Constructor: initialize with a bytebuffer.
- *
- * @param ar
- * specify an Allocator for this holder
- *
- * @param mres
- * specify a chunk to be holden
- *
- */
- public MemBufferHolder(A ar, ByteBuffer mres) {
- super(mres, ar);
- }
-
- /**
- * get the size of its held bytebuffer
- *
- * @return the size
- */
- @Override
- public long getSize() {
- return m_mres.capacity();
- }
-
- /**
- * resize its held buffer
- *
- * @param size
- * specify the new size for its held buffer
- */
- @Override
- public MemBufferHolder<A> resize(long size) {
- return m_allocator.resizeBuffer(this, size);
- }
-
- /**
- * register its held buffer for auto-reclaim
- *
- */
- @Override
- public void registerAutoReclaim() {
- m_allocator.registerBufferAutoReclaim(this);
- }
+ /**
+ * Constructor: initialize with a bytebuffer.
+ *
+ * @param ar
+ * specify an Allocator for this holder
+ *
+ * @param mres
+ * specify a chunk to be holden
+ *
+ */
+ public MemBufferHolder(A ar, ByteBuffer mres) {
+ super(mres, ar);
+ }
+
+ /**
+ * get the size of its held bytebuffer
+ *
+ * @return the size
+ */
+ @Override
+ public long getSize() {
+ return m_mres.capacity();
+ }
+
+ /**
+ * resize its held buffer
+ *
+ * @param size
+ * specify the new size for its held buffer
+ */
+ @Override
+ public MemBufferHolder<A> resize(long size) {
+ return m_allocator.resizeBuffer(this, size);
+ }
+
+ /**
+ * register its held buffer for auto-reclaim
+ *
+ */
+ @Override
+ public void registerAutoReclaim() {
+ m_allocator.registerBufferAutoReclaim(this);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/MemBufferHolderCachePool.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/MemBufferHolderCachePool.java b/core/src/main/java/org/apache/mnemonic/MemBufferHolderCachePool.java
index 7634206..d5afd30 100644
--- a/core/src/main/java/org/apache/mnemonic/MemBufferHolderCachePool.java
+++ b/core/src/main/java/org/apache/mnemonic/MemBufferHolderCachePool.java
@@ -1,3 +1,19 @@
+/*
+ * 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.mnemonic;
@@ -14,223 +30,211 @@ import java.util.concurrent.atomic.AtomicLong;
* that is backed by native memory pool.
*
*/
-public class MemBufferHolderCachePool<KeyT> extends
- CachePool<KeyT, MemBufferHolder<?>> {
-
- private static final long serialVersionUID = 684275993324558070L;
-
- private AtomicLong currentMemory = new AtomicLong(0L);
-
- private long maxStoreCapacity = 0L;
-
- /**
- * Constructs an empty cache pool with specified capacity.
- *
- * @param maxCapacity
- * the capacity of this cache pool
- *
- */
- public MemBufferHolderCachePool(long maxCapacity) {
- super(512, 0.75f);
- maxStoreCapacity = maxCapacity;
- }
-
- /**
- * @see CachePool#freeCapacity()
- */
- @Override
- public long freeCapacity() {
- return maxStoreCapacity - currentMemory.get();
- }
-
- /**
- * @see CachePool#usedCapacity()
- */
- @Override
- public long usedCapacity() {
- return currentMemory.get();
- }
-
- /**
- * @see Map#remove(Object)
- */
- @Override
- public synchronized MemBufferHolder<?> remove(Object k) {
- MemBufferHolder<?> ret = super.remove(k);
- if (null != ret) {
- currentMemory.getAndAdd(-ret.getSize());
- }
- return ret;
- }
-
- /**
- * Associates the specified value with the specified key in this map
- * (optional operation). If the map previously contained a mapping for the
- * key, the old value is replaced by the specified value. (A map m is said
- * to contain a mapping for a key k if and only if m.containsKey(k) would
- * return true.)
- *
- * @param k
- * key with which the specified value is to be associated
- *
- * @param v
- * MemBufferHolder value to be associated with the specified key
- *
- * @return the previous value associated with key, or null if there was no
- * mapping for key. (A null return can also indicate that the map
- * previously associated null with key, if the implementation
- * supports null values.)
- */
- @Override
- public MemBufferHolder<?> put(KeyT k, MemBufferHolder<?> v) {
- return put(k, v, null, null);
- }
-
- /**
- * @see CachePool#put(Object, Object, DropEvent, EvictFilter)
- */
- @Override
- public MemBufferHolder<?> put(KeyT k, MemBufferHolder<?> v,
- DropEvent<KeyT, MemBufferHolder<?>> fsop,
- EvictFilter<KeyT, MemBufferHolder<?>> dfilter) {
- MemBufferHolder<?> ret = null;
- long sz = v.getSize();
- if (containsKey(k)) {
- sz -= get(k).getSize();
- }
- if (sz <= maxStoreCapacity && ensureFreeSpace(sz, fsop, dfilter)) {
- currentMemory.addAndGet(sz);
- ret = super.put(k, v);
- } else {
- throw new ContainerOverflowException(
- "Out of capacity of MemBufferHolderCachePool.");
- }
- return ret;
- }
-
- /**
- * @see Map#putAll(Map)
- */
- @Override
- public void putAll(
- Map<? extends KeyT, ? extends MemBufferHolder<?>> m) {
- putAll(m, null, null);
- }
-
- /**
- * @see CachePool#putAll(Map, DropEvent, EvictFilter)
- */
- @Override
- public void putAll(
- Map<? extends KeyT, ? extends MemBufferHolder<?>> m,
- DropEvent<KeyT, MemBufferHolder<?>> fsop,
- EvictFilter<KeyT, MemBufferHolder<?>> dfilter) {
-
- long reqsz = 0;
- for (KeyT k : m.keySet()) {
- reqsz += m.get(k).getSize();
- }
-
- if (reqsz <= maxStoreCapacity && ensureFreeSpace(reqsz, fsop, dfilter)) {
- currentMemory.addAndGet(reqsz);
- super.putAll(m);
- } else {
- throw new ContainerOverflowException(
- "Out of capacity of MemBufferHolderCachePool.");
- }
- }
-
- /**
- * @see CachePool#hotKeySet(int)
- */
- @Override
- public Set<KeyT> hotKeySet(int n) {
- Set<KeyT> ret = new HashSet<KeyT>();
- ArrayList<KeyT> keys = new ArrayList<KeyT>(keySet());
- int endindex = keys.size() > n ? keys.size() - n : 0;
- for (int i = keys.size(); i > endindex; i--) {
- ret.add(keys.get(i - 1));
- }
- return ret;
- }
-
- /**
- * @see CachePool#ensureFreeSpace(long)
- */
- @Override
- public boolean ensureFreeSpace(long freesz) {
- return ensureFreeSpace(freesz, null, null);
- }
-
- /**
- * @see CachePool#removeFirstEntry(DropEvent, EvictFilter)
- */
- @Override
- public boolean removeFirstEntry(
- DropEvent<KeyT, MemBufferHolder<?>> fsop,
- EvictFilter<KeyT, MemBufferHolder<?>> dfilter) {
- boolean ret = false;
- boolean delible = true;
- for (Map.Entry<KeyT, MemBufferHolder<?>> entry : entrySet()) {
- if (null != dfilter) {
- delible = dfilter.validate(this, entry.getKey(),
- entry.getValue());
- }
- if (delible) {
- KeyT k = entry.getKey();
- MemBufferHolder<?> v = remove(k);
- if (null != fsop) {
- fsop.drop(this, k, v);
- }
- ret = true;
- break;
- }
- }
- return ret;
- }
-
- /**
- * @see CachePool#ensureFreeSpace(long, DropEvent, EvictFilter)
- */
- @Override
- public boolean ensureFreeSpace(long freesz,
- DropEvent<KeyT, MemBufferHolder<?>> fsop,
- EvictFilter<KeyT, MemBufferHolder<?>> dfilter) {
- boolean ret = false;
-
- if (freesz <= freeCapacity())
- return true;
-
- if (freesz > maxStoreCapacity)
- return false;
-
- long selectedMemory = 0L;
- Set<KeyT> selected = new HashSet<KeyT>();
-
- boolean delible = true;
- for (Map.Entry<KeyT, MemBufferHolder<?>> entry : entrySet()) {
- if (null != dfilter) {
- delible = dfilter.validate(this, entry.getKey(),
- entry.getValue());
- }
- if (delible) {
- selectedMemory += entry.getValue().getSize();
- selected.add(entry.getKey());
- if (freesz <= freeCapacity() + selectedMemory) {
- ret = true;
- break;
- }
- }
- }
- if (ret) {
- for (KeyT k : selected) {
- MemBufferHolder<?> mbh = remove(k);
- if (null != fsop) {
- fsop.drop(this, k, mbh);
- }
- }
- }
- return ret;
- }
+public class MemBufferHolderCachePool<KeyT> extends CachePool<KeyT, MemBufferHolder<?>> {
+
+ private static final long serialVersionUID = 684275993324558070L;
+
+ private AtomicLong currentMemory = new AtomicLong(0L);
+
+ private long maxStoreCapacity = 0L;
+
+ /**
+ * Constructs an empty cache pool with specified capacity.
+ *
+ * @param maxCapacity
+ * the capacity of this cache pool
+ *
+ */
+ public MemBufferHolderCachePool(long maxCapacity) {
+ super(512, 0.75f);
+ maxStoreCapacity = maxCapacity;
+ }
+
+ /**
+ * @see CachePool#freeCapacity()
+ */
+ @Override
+ public long freeCapacity() {
+ return maxStoreCapacity - currentMemory.get();
+ }
+
+ /**
+ * @see CachePool#usedCapacity()
+ */
+ @Override
+ public long usedCapacity() {
+ return currentMemory.get();
+ }
+
+ /**
+ * @see Map#remove(Object)
+ */
+ @Override
+ public synchronized MemBufferHolder<?> remove(Object k) {
+ MemBufferHolder<?> ret = super.remove(k);
+ if (null != ret) {
+ currentMemory.getAndAdd(-ret.getSize());
+ }
+ return ret;
+ }
+
+ /**
+ * Associates the specified value with the specified key in this map (optional
+ * operation). If the map previously contained a mapping for the key, the old
+ * value is replaced by the specified value. (A map m is said to contain a
+ * mapping for a key k if and only if m.containsKey(k) would return true.)
+ *
+ * @param k
+ * key with which the specified value is to be associated
+ *
+ * @param v
+ * MemBufferHolder value to be associated with the specified key
+ *
+ * @return the previous value associated with key, or null if there was no
+ * mapping for key. (A null return can also indicate that the map
+ * previously associated null with key, if the implementation supports
+ * null values.)
+ */
+ @Override
+ public MemBufferHolder<?> put(KeyT k, MemBufferHolder<?> v) {
+ return put(k, v, null, null);
+ }
+
+ /**
+ * @see CachePool#put(Object, Object, DropEvent, EvictFilter)
+ */
+ @Override
+ public MemBufferHolder<?> put(KeyT k, MemBufferHolder<?> v, DropEvent<KeyT, MemBufferHolder<?>> fsop,
+ EvictFilter<KeyT, MemBufferHolder<?>> dfilter) {
+ MemBufferHolder<?> ret = null;
+ long sz = v.getSize();
+ if (containsKey(k)) {
+ sz -= get(k).getSize();
+ }
+ if (sz <= maxStoreCapacity && ensureFreeSpace(sz, fsop, dfilter)) {
+ currentMemory.addAndGet(sz);
+ ret = super.put(k, v);
+ } else {
+ throw new ContainerOverflowException("Out of capacity of MemBufferHolderCachePool.");
+ }
+ return ret;
+ }
+
+ /**
+ * @see Map#putAll(Map)
+ */
+ @Override
+ public void putAll(Map<? extends KeyT, ? extends MemBufferHolder<?>> m) {
+ putAll(m, null, null);
+ }
+
+ /**
+ * @see CachePool#putAll(Map, DropEvent, EvictFilter)
+ */
+ @Override
+ public void putAll(Map<? extends KeyT, ? extends MemBufferHolder<?>> m, DropEvent<KeyT, MemBufferHolder<?>> fsop,
+ EvictFilter<KeyT, MemBufferHolder<?>> dfilter) {
+
+ long reqsz = 0;
+ for (KeyT k : m.keySet()) {
+ reqsz += m.get(k).getSize();
+ }
+
+ if (reqsz <= maxStoreCapacity && ensureFreeSpace(reqsz, fsop, dfilter)) {
+ currentMemory.addAndGet(reqsz);
+ super.putAll(m);
+ } else {
+ throw new ContainerOverflowException("Out of capacity of MemBufferHolderCachePool.");
+ }
+ }
+
+ /**
+ * @see CachePool#hotKeySet(int)
+ */
+ @Override
+ public Set<KeyT> hotKeySet(int n) {
+ Set<KeyT> ret = new HashSet<KeyT>();
+ ArrayList<KeyT> keys = new ArrayList<KeyT>(keySet());
+ int endindex = keys.size() > n ? keys.size() - n : 0;
+ for (int i = keys.size(); i > endindex; i--) {
+ ret.add(keys.get(i - 1));
+ }
+ return ret;
+ }
+
+ /**
+ * @see CachePool#ensureFreeSpace(long)
+ */
+ @Override
+ public boolean ensureFreeSpace(long freesz) {
+ return ensureFreeSpace(freesz, null, null);
+ }
+
+ /**
+ * @see CachePool#removeFirstEntry(DropEvent, EvictFilter)
+ */
+ @Override
+ public boolean removeFirstEntry(DropEvent<KeyT, MemBufferHolder<?>> fsop,
+ EvictFilter<KeyT, MemBufferHolder<?>> dfilter) {
+ boolean ret = false;
+ boolean delible = true;
+ for (Map.Entry<KeyT, MemBufferHolder<?>> entry : entrySet()) {
+ if (null != dfilter) {
+ delible = dfilter.validate(this, entry.getKey(), entry.getValue());
+ }
+ if (delible) {
+ KeyT k = entry.getKey();
+ MemBufferHolder<?> v = remove(k);
+ if (null != fsop) {
+ fsop.drop(this, k, v);
+ }
+ ret = true;
+ break;
+ }
+ }
+ return ret;
+ }
+
+ /**
+ * @see CachePool#ensureFreeSpace(long, DropEvent, EvictFilter)
+ */
+ @Override
+ public boolean ensureFreeSpace(long freesz, DropEvent<KeyT, MemBufferHolder<?>> fsop,
+ EvictFilter<KeyT, MemBufferHolder<?>> dfilter) {
+ boolean ret = false;
+
+ if (freesz <= freeCapacity())
+ return true;
+
+ if (freesz > maxStoreCapacity)
+ return false;
+
+ long selectedMemory = 0L;
+ Set<KeyT> selected = new HashSet<KeyT>();
+
+ boolean delible = true;
+ for (Map.Entry<KeyT, MemBufferHolder<?>> entry : entrySet()) {
+ if (null != dfilter) {
+ delible = dfilter.validate(this, entry.getKey(), entry.getValue());
+ }
+ if (delible) {
+ selectedMemory += entry.getValue().getSize();
+ selected.add(entry.getKey());
+ if (freesz <= freeCapacity() + selectedMemory) {
+ ret = true;
+ break;
+ }
+ }
+ }
+ if (ret) {
+ for (KeyT k : selected) {
+ MemBufferHolder<?> mbh = remove(k);
+ if (null != fsop) {
+ fsop.drop(this, k, mbh);
+ }
+ }
+ }
+ return ret;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/MemChunkHolder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/MemChunkHolder.java b/core/src/main/java/org/apache/mnemonic/MemChunkHolder.java
index 28dd639..308539f 100644
--- a/core/src/main/java/org/apache/mnemonic/MemChunkHolder.java
+++ b/core/src/main/java/org/apache/mnemonic/MemChunkHolder.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -6,53 +23,53 @@ package org.apache.mnemonic;
*/
public class MemChunkHolder<A extends CommonAllocator<A>> extends MemHolder<A, Long, MemChunkHolder<A>> {
- protected long m_size;
-
- /**
- * Constructor: initialize with a memory chunk.
- *
- * @param ar
- * specify an Allocator for this holder
- *
- * @param mres
- * specify a chunk to be holden
- *
- * @param size
- * specify the size of this memory chunk
- */
- public MemChunkHolder(A ar, Long mres, long size) {
- super(mres, ar);
- m_size = size;
- }
-
- /**
- * get the size of its held memory chunk
- *
- * @return the size
- */
- @Override
- public long getSize() {
- return m_size;
- }
-
- /**
- * resize its held chunk
- *
- * @param size
- * specify the new size for its held chunk
- */
- @Override
- public MemChunkHolder<A> resize(long size) {
- return m_allocator.resizeChunk(this, size);
- }
-
- /**
- * register its held chunk for auto-reclaim
- *
- */
- @Override
- public void registerAutoReclaim() {
- m_allocator.registerChunkAutoReclaim(this);
- }
+ protected long m_size;
+
+ /**
+ * Constructor: initialize with a memory chunk.
+ *
+ * @param ar
+ * specify an Allocator for this holder
+ *
+ * @param mres
+ * specify a chunk to be holden
+ *
+ * @param size
+ * specify the size of this memory chunk
+ */
+ public MemChunkHolder(A ar, Long mres, long size) {
+ super(mres, ar);
+ m_size = size;
+ }
+
+ /**
+ * get the size of its held memory chunk
+ *
+ * @return the size
+ */
+ @Override
+ public long getSize() {
+ return m_size;
+ }
+
+ /**
+ * resize its held chunk
+ *
+ * @param size
+ * specify the new size for its held chunk
+ */
+ @Override
+ public MemChunkHolder<A> resize(long size) {
+ return m_allocator.resizeChunk(this, size);
+ }
+
+ /**
+ * register its held chunk for auto-reclaim
+ *
+ */
+ @Override
+ public void registerAutoReclaim() {
+ m_allocator.registerChunkAutoReclaim(this);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/MemClustering.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/MemClustering.java b/core/src/main/java/org/apache/mnemonic/MemClustering.java
index 8494cbb..30c8483 100644
--- a/core/src/main/java/org/apache/mnemonic/MemClustering.java
+++ b/core/src/main/java/org/apache/mnemonic/MemClustering.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import java.util.*;
@@ -10,288 +27,283 @@ import java.util.*;
*/
public class MemClustering {
- /**
- * an interface of event for performance level change.
- *
- */
- public interface PerformanceLevelChange {
-
- /**
- * callback if performance level changed
- *
- * @param prevlvl
- * the perf. level before change
- *
- * @param tgtlvl
- * the perf. level after change
- *
- */
- public void changed(PerformanceLevel prevlvl, PerformanceLevel tgtlvl);
- }
+ /**
+ * an interface of event for performance level change.
+ *
+ */
+ public interface PerformanceLevelChange {
/**
- * an interface of event for CommonAllocator change.
+ * callback if performance level changed
*
- */
- public interface AllocatorChange {
-
- /**
- * callback if allocator changed
- *
- * @param lvl
- * the perf. level after changed
- *
- * @param prevallocator
- * the allocator before change
- *
- * @param tgtallocator
- * the allocator after change
- */
- public void changed(PerformanceLevel lvl, CommonAllocator<?> prevallocator,
- CommonAllocator<?> tgtallocator);
- }
-
- /**
- * an interface to assist the creation of memory holder.
+ * @param prevlvl
+ * the perf. level before change
*
- * @param <H>
- * the holder type of memory resource
+ * @param tgtlvl
+ * the perf. level after change
*
- * @param bma
- * specify an allocator for this holder
- *
- * @param size
- * specify the size of this memory resource
- *
- * @return the holder created
*/
- private interface MemCreate<H extends MemHolder<? extends CommonAllocator<?>, ?, ?>> {
- public H create(CommonAllocator<?> bma, long size);
- }
+ public void changed(PerformanceLevel prevlvl, PerformanceLevel tgtlvl);
+ }
-
- private MemCreate<MemChunkHolder<?>> m_memchunkcreate = new MemCreate<MemChunkHolder<?>>() {
- @Override
- public MemChunkHolder<?> create(CommonAllocator<?> bma, long size) {
- return bma.createChunk(size);
- }
- };
-
- private MemCreate<MemBufferHolder<?>> m_membuffercreate = new MemCreate<MemBufferHolder<?>>() {
- @Override
- public MemBufferHolder<?> create(CommonAllocator<?> bma, long size) {
- return bma.createBuffer(size);
- }
- };
+ /**
+ * an interface of event for CommonAllocator change.
+ *
+ */
+ public interface AllocatorChange {
/**
- * performance level categories.
+ * callback if allocator changed
*
- */
- public static enum PerformanceLevel {
- FASTEST, FAST, NORMAL, SLOW, SLOWEST
- }
-
- /**
- * configuration for each allocator node.
+ * @param lvl
+ * the perf. level after changed
+ *
+ * @param prevallocator
+ * the allocator before change
*
+ * @param tgtallocator
+ * the allocator after change
*/
- public static class NodeConfig<A extends CommonAllocator<A>> {
- private A m_allocator;
- private PerformanceLevel m_level;
+ public void changed(PerformanceLevel lvl, CommonAllocator<?> prevallocator, CommonAllocator<?> tgtallocator);
+ }
- /**
- * Constructor: initialize this instance with specified allocator and perf. level.
- *
- * @param a
- * specify an allocator for this node
- *
- * @param l
- * specify a performance level
- */
- public NodeConfig(A a, PerformanceLevel l) {
- m_allocator = a;
- m_level = l;
- }
+ /**
+ * an interface to assist the creation of memory holder.
+ *
+ * @param <H>
+ * the holder type of memory resource
+ *
+ * @param bma
+ * specify an allocator for this holder
+ *
+ * @param size
+ * specify the size of this memory resource
+ *
+ * @return the holder created
+ */
+ private interface MemCreate<H extends MemHolder<? extends CommonAllocator<?>, ?, ?>> {
+ public H create(CommonAllocator<?> bma, long size);
+ }
- /**
- * retrieve the allocator of this node.
- *
- * @return allocator of this node
- */
- public A getAllocator() {
- return m_allocator;
- }
-
- /**
- * retrieve the performance level of this node.
- *
- * @return level of this node
- */
- public PerformanceLevel getPerformanceLevel() {
- return m_level;
- }
+ private MemCreate<MemChunkHolder<?>> m_memchunkcreate = new MemCreate<MemChunkHolder<?>>() {
+ @Override
+ public MemChunkHolder<?> create(CommonAllocator<?> bma, long size) {
+ return bma.createChunk(size);
}
+ };
- private PerformanceLevelChange m_bwlvlchange = null;
- private AllocatorChange m_allocatorChange = null;
- private PerformanceLevel m_prevbwlevel = null;
- private CommonAllocator<?> m_prevallocator = null;
+ private MemCreate<MemBufferHolder<?>> m_membuffercreate = new MemCreate<MemBufferHolder<?>>() {
+ @Override
+ public MemBufferHolder<?> create(CommonAllocator<?> bma, long size) {
+ return bma.createBuffer(size);
+ }
+ };
+ /**
+ * performance level categories.
+ *
+ */
+ public static enum PerformanceLevel {
+ FASTEST, FAST, NORMAL, SLOW, SLOWEST
+ }
- private Map<PerformanceLevel, List<CommonAllocator<?>>> m_info;
+ /**
+ * configuration for each allocator node.
+ *
+ */
+ public static class NodeConfig<A extends CommonAllocator<A>> {
+ private A m_allocator;
+ private PerformanceLevel m_level;
/**
- * Constructor: initialize a memory clustering instance.
+ * Constructor: initialize this instance with specified allocator and perf.
+ * level.
*
- * @param ncs
- * specify a set of node with specified configuration respectively
- */
- public MemClustering(NodeConfig<? extends CommonAllocator<?>>[] ncs) {
- m_info = new EnumMap<PerformanceLevel, List<CommonAllocator<?>>>(
- PerformanceLevel.class);
- for (PerformanceLevel lvl : PerformanceLevel.values()) {
- m_info.put(lvl, new ArrayList<CommonAllocator<?>>());
- }
-
- for (NodeConfig<? extends CommonAllocator<?>> nc : ncs) {
- m_info.get(nc.getPerformanceLevel()).add(nc.getAllocator());
- }
-
- }
-
- /**
- * set a callback of event for performance level change.
+ * @param a
+ * specify an allocator for this node
*
- * @param bwlvlchange
- * specify a callback object for perf. level change
+ * @param l
+ * specify a performance level
*/
- public void setPerformanceLevelChange(PerformanceLevelChange bwlvlchange) {
- m_bwlvlchange = bwlvlchange;
+ public NodeConfig(A a, PerformanceLevel l) {
+ m_allocator = a;
+ m_level = l;
}
/**
- * set a callback of event for allocator change.
+ * retrieve the allocator of this node.
*
- * @param allocatorChange
- * specify a callback object for allocator change
+ * @return allocator of this node
*/
- public <A extends CommonAllocator<A>> void setAllocatorChange(AllocatorChange allocatorChange) {
- m_allocatorChange = allocatorChange;
+ public A getAllocator() {
+ return m_allocator;
}
/**
- * a factory to create memory resource.
- *
- * @param <H> the type of holder
- *
- * @param creator
- * specify a creator to delegate concrete holder creation
- *
- * @param startlevel
- * specify a perf. level that is the start level for memory resource
- * allocation
+ * retrieve the performance level of this node.
*
- * @param size
- * specify a size to request memory resource
- *
- * @return a new created holder held an allocated memory resource
+ * @return level of this node
*/
- protected <H extends MemHolder<? extends CommonAllocator<?>, ?, ?>> H
- create(MemCreate<H> creator, PerformanceLevel startlevel, long size) {
- H ret = null;
- boolean eligible = false;
- for (PerformanceLevel lvl : m_info.keySet()) {
- if (!eligible && startlevel == lvl) {
- eligible = true;
- }
- if (eligible) {
- int distance = 0;
- List<CommonAllocator<?>> bmas = m_info.get(lvl);
- for (CommonAllocator<?> bma : bmas) {
- ret = creator.create(bma, size);
- if (null == ret) {
- distance++;
- } else {
- if (null != m_bwlvlchange && m_prevbwlevel != lvl) {
- m_bwlvlchange.changed(m_prevbwlevel, lvl);
- m_prevbwlevel = lvl;
- }
- if (null != m_allocatorChange && m_prevallocator != bma) {
- m_allocatorChange.changed(lvl, m_prevallocator, bma);
- m_prevallocator = bma;
- }
- break;
- }
- }
- Collections.rotate(bmas, distance);
- }
- if (null != ret) {
- break;
- }
- }
- return ret;
+ public PerformanceLevel getPerformanceLevel() {
+ return m_level;
}
+ }
- /**
- * create a chunk from this clustering.
- *
- * @param size
- * specify the size of memory chunk
- *
- * @return a holder with a created chunk
- *
- */
- //@Override
- public MemChunkHolder<?> createChunk(long size) {
- return createChunk(PerformanceLevel.FASTEST, size);
- }
+ private PerformanceLevelChange m_bwlvlchange = null;
+ private AllocatorChange m_allocatorChange = null;
+ private PerformanceLevel m_prevbwlevel = null;
+ private CommonAllocator<?> m_prevallocator = null;
- /**
- * create a chunk from this clustering
- *
- * @param startlevel
- * specify the perf. level from which to search qualified
- * node.
- *
- * @param size
- * specify the size of memory chunk
- *
- * @return a holder with a created chunk
- */
- public MemChunkHolder<?> createChunk(PerformanceLevel startlevel, long size) {
- return create(m_memchunkcreate, startlevel, size);
+ private Map<PerformanceLevel, List<CommonAllocator<?>>> m_info;
+
+ /**
+ * Constructor: initialize a memory clustering instance.
+ *
+ * @param ncs
+ * specify a set of node with specified configuration respectively
+ */
+ public MemClustering(NodeConfig<? extends CommonAllocator<?>>[] ncs) {
+ m_info = new EnumMap<PerformanceLevel, List<CommonAllocator<?>>>(PerformanceLevel.class);
+ for (PerformanceLevel lvl : PerformanceLevel.values()) {
+ m_info.put(lvl, new ArrayList<CommonAllocator<?>>());
}
- /**
- * create a buffer from this clustering.
- *
- * @param size
- * specify the size of memory buffer
- *
- * @return a holder with a created buffer
- *
- */
- //@Override
- public MemBufferHolder<?> createBuffer(long size) {
- return createBuffer(PerformanceLevel.FASTEST, size);
+ for (NodeConfig<? extends CommonAllocator<?>> nc : ncs) {
+ m_info.get(nc.getPerformanceLevel()).add(nc.getAllocator());
}
- /**
- * create a buffer from this clustering
- *
- * @param startlevel
- * specify the perf. level from which to search qualified
- * node.
- *
- * @param size
- * specify the size of memory buffer
- *
- * @return a holder with a created buffer
- */
- public MemBufferHolder<?> createBuffer(PerformanceLevel startlevel,
- long size) {
- return create(m_membuffercreate, startlevel, size);
+ }
+
+ /**
+ * set a callback of event for performance level change.
+ *
+ * @param bwlvlchange
+ * specify a callback object for perf. level change
+ */
+ public void setPerformanceLevelChange(PerformanceLevelChange bwlvlchange) {
+ m_bwlvlchange = bwlvlchange;
+ }
+
+ /**
+ * set a callback of event for allocator change.
+ *
+ * @param allocatorChange
+ * specify a callback object for allocator change
+ */
+ public <A extends CommonAllocator<A>> void setAllocatorChange(AllocatorChange allocatorChange) {
+ m_allocatorChange = allocatorChange;
+ }
+
+ /**
+ * a factory to create memory resource.
+ *
+ * @param <H>
+ * the type of holder
+ *
+ * @param creator
+ * specify a creator to delegate concrete holder creation
+ *
+ * @param startlevel
+ * specify a perf. level that is the start level for memory resource
+ * allocation
+ *
+ * @param size
+ * specify a size to request memory resource
+ *
+ * @return a new created holder held an allocated memory resource
+ */
+ protected <H extends MemHolder<? extends CommonAllocator<?>, ?, ?>> H create(MemCreate<H> creator,
+ PerformanceLevel startlevel, long size) {
+ H ret = null;
+ boolean eligible = false;
+ for (PerformanceLevel lvl : m_info.keySet()) {
+ if (!eligible && startlevel == lvl) {
+ eligible = true;
+ }
+ if (eligible) {
+ int distance = 0;
+ List<CommonAllocator<?>> bmas = m_info.get(lvl);
+ for (CommonAllocator<?> bma : bmas) {
+ ret = creator.create(bma, size);
+ if (null == ret) {
+ distance++;
+ } else {
+ if (null != m_bwlvlchange && m_prevbwlevel != lvl) {
+ m_bwlvlchange.changed(m_prevbwlevel, lvl);
+ m_prevbwlevel = lvl;
+ }
+ if (null != m_allocatorChange && m_prevallocator != bma) {
+ m_allocatorChange.changed(lvl, m_prevallocator, bma);
+ m_prevallocator = bma;
+ }
+ break;
+ }
+ }
+ Collections.rotate(bmas, distance);
+ }
+ if (null != ret) {
+ break;
+ }
}
+ return ret;
+ }
+
+ /**
+ * create a chunk from this clustering.
+ *
+ * @param size
+ * specify the size of memory chunk
+ *
+ * @return a holder with a created chunk
+ *
+ */
+ // @Override
+ public MemChunkHolder<?> createChunk(long size) {
+ return createChunk(PerformanceLevel.FASTEST, size);
+ }
+
+ /**
+ * create a chunk from this clustering
+ *
+ * @param startlevel
+ * specify the perf. level from which to search qualified node.
+ *
+ * @param size
+ * specify the size of memory chunk
+ *
+ * @return a holder with a created chunk
+ */
+ public MemChunkHolder<?> createChunk(PerformanceLevel startlevel, long size) {
+ return create(m_memchunkcreate, startlevel, size);
+ }
+
+ /**
+ * create a buffer from this clustering.
+ *
+ * @param size
+ * specify the size of memory buffer
+ *
+ * @return a holder with a created buffer
+ *
+ */
+ // @Override
+ public MemBufferHolder<?> createBuffer(long size) {
+ return createBuffer(PerformanceLevel.FASTEST, size);
+ }
+
+ /**
+ * create a buffer from this clustering
+ *
+ * @param startlevel
+ * specify the perf. level from which to search qualified node.
+ *
+ * @param size
+ * specify the size of memory buffer
+ *
+ * @return a holder with a created buffer
+ */
+ public MemBufferHolder<?> createBuffer(PerformanceLevel startlevel, long size) {
+ return create(m_membuffercreate, startlevel, size);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/MemFile.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/MemFile.java b/core/src/main/java/org/apache/mnemonic/MemFile.java
index 08fb0d7..c4a1c06 100644
--- a/core/src/main/java/org/apache/mnemonic/MemFile.java
+++ b/core/src/main/java/org/apache/mnemonic/MemFile.java
@@ -1,3 +1,19 @@
+/*
+ * 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.mnemonic;
@@ -12,40 +28,40 @@ import java.io.File;
*/
public class MemFile extends File {
- private static final long serialVersionUID = 6579668848729471173L;
- private String uri, id;
-
- /**
- * initialize the memory file.
- *
- * @param uri
- * specify the location of memory file
- *
- * @param id
- * specify the id of memory file
- */
- public MemFile(String uri, String id) {
- super(uri, id);
- this.uri = uri;
- this.id = id;
- }
-
- /**
- * retrieve the uri of this memory file.
- *
- * @return the uri of memory file
- */
- public String getUri() {
- return this.uri;
- }
-
- /**
- * retrieve the id of this memory file.
- *
- * @return the id of memory file
- */
- public String getId() {
- return this.id;
- }
+ private static final long serialVersionUID = 6579668848729471173L;
+ private String uri, id;
+
+ /**
+ * initialize the memory file.
+ *
+ * @param uri
+ * specify the location of memory file
+ *
+ * @param id
+ * specify the id of memory file
+ */
+ public MemFile(String uri, String id) {
+ super(uri, id);
+ this.uri = uri;
+ this.id = id;
+ }
+
+ /**
+ * retrieve the uri of this memory file.
+ *
+ * @return the uri of memory file
+ */
+ public String getUri() {
+ return this.uri;
+ }
+
+ /**
+ * retrieve the id of this memory file.
+ *
+ * @return the id of memory file
+ */
+ public String getId() {
+ return this.id;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/MemHolder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/MemHolder.java b/core/src/main/java/org/apache/mnemonic/MemHolder.java
index b52e50a..b4ce1a6 100644
--- a/core/src/main/java/org/apache/mnemonic/MemHolder.java
+++ b/core/src/main/java/org/apache/mnemonic/MemHolder.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
import org.flowcomputing.commons.resgc.*;
@@ -8,51 +25,51 @@ import org.flowcomputing.commons.resgc.*;
*/
public abstract class MemHolder<A extends CommonAllocator<A>, T, H extends MemHolder<A, T, H>> extends ResHolder<T, H> {
- protected A m_allocator;
-
- /**
- * Constructor: initialize with resource.
- *
- * @param mres
- * specify a resource to be holden
- *
- * @param ar
- * specify an Allocator for this holder
- *
- */
- public MemHolder(T mres, A ar) {
- super(mres);
- m_allocator = ar;
- }
-
- /**
- * get its allocator
- *
- * @return the allocator
- */
- public A getAllocator() {
- return m_allocator;
- }
-
- /**
- * resize its held resource
- *
- * @param size
- * specify the new size for its held resource
- */
- abstract public MemHolder<A, T, H> resize(long size);
-
- /**
- * get the size of its held memory resource.
- *
- * @return the size
- */
- abstract public long getSize();
-
- /**
- * register its held resource for auto-reclaim
- *
- */
- abstract public void registerAutoReclaim();
+ protected A m_allocator;
+
+ /**
+ * Constructor: initialize with resource.
+ *
+ * @param mres
+ * specify a resource to be holden
+ *
+ * @param ar
+ * specify an Allocator for this holder
+ *
+ */
+ public MemHolder(T mres, A ar) {
+ super(mres);
+ m_allocator = ar;
+ }
+
+ /**
+ * get its allocator
+ *
+ * @return the allocator
+ */
+ public A getAllocator() {
+ return m_allocator;
+ }
+
+ /**
+ * resize its held resource
+ *
+ * @param size
+ * specify the new size for its held resource
+ */
+ abstract public MemHolder<A, T, H> resize(long size);
+
+ /**
+ * get the size of its held memory resource.
+ *
+ * @return the size
+ */
+ abstract public long getSize();
+
+ /**
+ * register its held resource for auto-reclaim
+ *
+ */
+ abstract public void registerAutoReclaim();
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/MemoryNonVolatileEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/MemoryNonVolatileEntity.java b/core/src/main/java/org/apache/mnemonic/MemoryNonVolatileEntity.java
index 87010d5..47124b6 100644
--- a/core/src/main/java/org/apache/mnemonic/MemoryNonVolatileEntity.java
+++ b/core/src/main/java/org/apache/mnemonic/MemoryNonVolatileEntity.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -5,15 +22,15 @@ package org.apache.mnemonic;
*
*/
-
public interface MemoryNonVolatileEntity<ALLOC_PMem3C93D24F59 extends CommonPersistAllocator<ALLOC_PMem3C93D24F59>> {
- public void initializeNonVolatileEntity(ALLOC_PMem3C93D24F59 allocator, EntityFactoryProxy[] efproxys, GenericField.GType[] gfields, boolean autoreclaim);
-
- public void createNonVolatileEntity(ALLOC_PMem3C93D24F59 allocator, EntityFactoryProxy[] efproxys, GenericField.GType[] gfields, boolean autoreclaim)
- throws OutOfPersistentMemory;
-
- public void restoreNonVolatileEntity(ALLOC_PMem3C93D24F59 allocator, EntityFactoryProxy[] efproxys, GenericField.GType[] gfields, long phandler, boolean autoreclaim)
- throws RetrieveNonVolatileEntityError;
-
+ public void initializeNonVolatileEntity(ALLOC_PMem3C93D24F59 allocator, EntityFactoryProxy[] efproxys,
+ GenericField.GType[] gfields, boolean autoreclaim);
+
+ public void createNonVolatileEntity(ALLOC_PMem3C93D24F59 allocator, EntityFactoryProxy[] efproxys,
+ GenericField.GType[] gfields, boolean autoreclaim) throws OutOfPersistentMemory;
+
+ public void restoreNonVolatileEntity(ALLOC_PMem3C93D24F59 allocator, EntityFactoryProxy[] efproxys,
+ GenericField.GType[] gfields, long phandler, boolean autoreclaim) throws RetrieveNonVolatileEntityError;
+
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/NonVolatileEntity.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/NonVolatileEntity.java b/core/src/main/java/org/apache/mnemonic/NonVolatileEntity.java
index 6c2aabb..0ac0f77 100644
--- a/core/src/main/java/org/apache/mnemonic/NonVolatileEntity.java
+++ b/core/src/main/java/org/apache/mnemonic/NonVolatileEntity.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -7,7 +24,8 @@ package org.apache.mnemonic;
import java.lang.annotation.*;
-@Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS)
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.CLASS)
public @interface NonVolatileEntity {
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/NonVolatileEntityProcessor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/NonVolatileEntityProcessor.java b/core/src/main/java/org/apache/mnemonic/NonVolatileEntityProcessor.java
index b9e83c6..6aa7160 100644
--- a/core/src/main/java/org/apache/mnemonic/NonVolatileEntityProcessor.java
+++ b/core/src/main/java/org/apache/mnemonic/NonVolatileEntityProcessor.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -27,108 +44,107 @@ import javax.tools.Diagnostic;
import com.squareup.javapoet.MethodSpec;
public class NonVolatileEntityProcessor extends AbstractProcessor {
- private Types typeUtils;
- private Elements elementUtils;
- private Filer filer;
- private Messager messager;
- // private Map<String, FactoryGroupedClasses> factoryClasses = new
- // LinkedHashMap<String, FactoryGroupedClasses>();
-
- /**
- * {@inheritDoc}
- */
- @Override
- public synchronized void init(ProcessingEnvironment processingEnv) {
- super.init(processingEnv);
- typeUtils = processingEnv.getTypeUtils();
- elementUtils = processingEnv.getElementUtils();
- filer = processingEnv.getFiler();
- messager = processingEnv.getMessager();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Set<String> getSupportedAnnotationTypes() {
- Set<String> annotataions = new LinkedHashSet<String>();
- annotataions.add(NonVolatileEntity.class.getCanonicalName());
- return annotataions;
+ private Types typeUtils;
+ private Elements elementUtils;
+ private Filer filer;
+ private Messager messager;
+ // private Map<String, FactoryGroupedClasses> factoryClasses = new
+ // LinkedHashMap<String, FactoryGroupedClasses>();
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public synchronized void init(ProcessingEnvironment processingEnv) {
+ super.init(processingEnv);
+ typeUtils = processingEnv.getTypeUtils();
+ elementUtils = processingEnv.getElementUtils();
+ filer = processingEnv.getFiler();
+ messager = processingEnv.getMessager();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<String> getSupportedAnnotationTypes() {
+ Set<String> annotataions = new LinkedHashSet<String>();
+ annotataions.add(NonVolatileEntity.class.getCanonicalName());
+ return annotataions;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SourceVersion getSupportedSourceVersion() {
+ return SourceVersion.latestSupported();
+ }
+
+ /**
+ * triggered if an error issued during processing
+ *
+ * @param e
+ * the element in question
+ *
+ * @param msg
+ * the message issued
+ */
+ public void error(Element e, String msg) {
+ messager.printMessage(Diagnostic.Kind.ERROR, msg, e);
+ }
+
+ /**
+ * triggered if a note issued during processing
+ *
+ * @param e
+ * the element in question
+ *
+ * @param msg
+ * the message issued
+ */
+ public void note(Element e, String msg) {
+ messager.printMessage(Diagnostic.Kind.NOTE, msg, e);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+
+ try {
+
+ for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(NonVolatileEntity.class)) {
+
+ String outputstr = String.format("++++++++++%s+++++++++++", annotatedElement.getSimpleName());
+ note(annotatedElement, outputstr);
+ // System.err.println(outputstr);
+
+ if (annotatedElement.getKind() != ElementKind.CLASS) {
+ throw new AnnotationProcessingException(annotatedElement, "Only classes can be annotated with @%s",
+ NonVolatileEntity.class.getSimpleName());
+ }
+
+ // We can cast it, because we know that it of ElementKind.CLASS
+ TypeElement typeelem = (TypeElement) annotatedElement;
+
+ AnnotatedNonVolatileEntityClass annotatedClass = new AnnotatedNonVolatileEntityClass(typeelem, typeUtils,
+ elementUtils, messager);
+
+ annotatedClass.prepareProcessing();
+
+ annotatedClass.generateCode(filer);
+
+ }
+
+ } catch (AnnotationProcessingException e) {
+ error(e.getElement(), e.getMessage());
+ } catch (IOException e) {
+ error(null, e.getMessage());
}
- /**
- * {@inheritDoc}
- */
- @Override
- public SourceVersion getSupportedSourceVersion() {
- return SourceVersion.latestSupported();
- }
-
- /**
- * triggered if an error issued during processing
- *
- * @param e
- * the element in question
- *
- * @param msg
- * the message issued
- */
- public void error(Element e, String msg) {
- messager.printMessage(Diagnostic.Kind.ERROR, msg, e);
- }
-
- /**
- * triggered if a note issued during processing
- *
- * @param e
- * the element in question
- *
- * @param msg
- * the message issued
- */
- public void note(Element e, String msg) {
- messager.printMessage(Diagnostic.Kind.NOTE, msg, e);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
-
- try {
-
- for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(NonVolatileEntity.class)) {
-
- String outputstr = String.format("++++++++++%s+++++++++++", annotatedElement.getSimpleName());
- note(annotatedElement, outputstr);
- // System.err.println(outputstr);
-
- if (annotatedElement.getKind() != ElementKind.CLASS) {
- throw new AnnotationProcessingException(
- annotatedElement, "Only classes can be annotated with @%s",
- NonVolatileEntity.class.getSimpleName());
- }
-
- // We can cast it, because we know that it of ElementKind.CLASS
- TypeElement typeelem = (TypeElement) annotatedElement;
-
- AnnotatedNonVolatileEntityClass annotatedClass =
- new AnnotatedNonVolatileEntityClass(typeelem, typeUtils, elementUtils, messager);
-
- annotatedClass.prepareProcessing();
-
- annotatedClass.generateCode(filer);
-
- }
-
- } catch (AnnotationProcessingException e) {
- error(e.getElement(), e.getMessage());
- } catch (IOException e) {
- error(null, e.getMessage());
- }
-
- return true;
- }
+ return true;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/NonVolatileGetter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/NonVolatileGetter.java b/core/src/main/java/org/apache/mnemonic/NonVolatileGetter.java
index be88be8..39f49a4 100644
--- a/core/src/main/java/org/apache/mnemonic/NonVolatileGetter.java
+++ b/core/src/main/java/org/apache/mnemonic/NonVolatileGetter.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -10,9 +27,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-@Target(ElementType.METHOD) @Retention(RetentionPolicy.CLASS)
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.CLASS)
public @interface NonVolatileGetter {
- String EntityFactoryProxies() default "null";
- String GenericFieldTypes() default "null";
- long Id() default -1L;
+ String EntityFactoryProxies() default "null";
+
+ String GenericFieldTypes() default "null";
+
+ long Id() default -1L;
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/NonVolatileSetter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/NonVolatileSetter.java b/core/src/main/java/org/apache/mnemonic/NonVolatileSetter.java
index 11dfba2..31cf4d1 100644
--- a/core/src/main/java/org/apache/mnemonic/NonVolatileSetter.java
+++ b/core/src/main/java/org/apache/mnemonic/NonVolatileSetter.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -10,7 +27,8 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-@Target(ElementType.METHOD) @Retention(RetentionPolicy.CLASS)
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.CLASS)
public @interface NonVolatileSetter {
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/OutOfPersistentMemory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/OutOfPersistentMemory.java b/core/src/main/java/org/apache/mnemonic/OutOfPersistentMemory.java
index bb1d042..390790a 100644
--- a/core/src/main/java/org/apache/mnemonic/OutOfPersistentMemory.java
+++ b/core/src/main/java/org/apache/mnemonic/OutOfPersistentMemory.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -7,9 +24,9 @@ package org.apache.mnemonic;
public class OutOfPersistentMemory extends RuntimeException {
- private static final long serialVersionUID = -6315943783592441148L;
+ private static final long serialVersionUID = -6315943783592441148L;
- public OutOfPersistentMemory(String s) {
- super(s);
- }
+ public OutOfPersistentMemory(String s) {
+ super(s);
+ }
}
[6/7] incubator-mnemonic git commit: format codestyle & add Apache
License
Posted by ga...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/collections/src/test/java/org/apache/mnemonic/collections/NonVolatileNodeValueNGTest.java
----------------------------------------------------------------------
diff --git a/collections/src/test/java/org/apache/mnemonic/collections/NonVolatileNodeValueNGTest.java b/collections/src/test/java/org/apache/mnemonic/collections/NonVolatileNodeValueNGTest.java
index 82829ef..2cda052 100644
--- a/collections/src/test/java/org/apache/mnemonic/collections/NonVolatileNodeValueNGTest.java
+++ b/collections/src/test/java/org/apache/mnemonic/collections/NonVolatileNodeValueNGTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic.collections;
import java.nio.ByteBuffer;
@@ -24,232 +41,232 @@ import org.testng.annotations.Test;
*
*/
-
public class NonVolatileNodeValueNGTest {
- private long KEYCAPACITY;
- private Random m_rand;
- private BigDataPMemAllocator m_act;
-
- @BeforeClass
- public void setUp() {
- m_rand = Utils.createRandom();
- m_act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 1024, "./pobj_NodeValue.dat", true);
- KEYCAPACITY = m_act.handlerCapacity();
- m_act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
- @Override
- public boolean reclaim(ByteBuffer mres, Long sz) {
- System.out.println(String.format("Reclaim Memory Buffer: %X Size: %s", System.identityHashCode(mres),
- null == sz ? "NULL" : sz.toString()));
- return false;
- }
- });
- m_act.setChunkReclaimer(new Reclaim<Long>() {
- @Override
- public boolean reclaim(Long mres, Long sz) {
- System.out.println(String.format("Reclaim Memory Chunk: %X Size: %s", System.identityHashCode(mres),
- null == sz ? "NULL" : sz.toString()));
- return false;
- }
- });
-
- for (long i = 0; i < KEYCAPACITY; ++i) {
- m_act.setHandler(i, 0L);
- }
- }
-
- @AfterClass
- public void tearDown() {
- m_act.close();
- }
-
- @Test(enabled = false)
- public void testSingleNodeValueWithInteger() {
- int val = m_rand.nextInt();
- GenericField.GType gtypes[] = {GenericField.GType.INTEGER};
- NonVolatileNodeValue<Integer> plln = NonVolatileNodeValueFactory.create(m_act, null, gtypes, false);
- plln.setItem(val, false);
- Long handler = plln.getNonVolatileHandler();
- System.err.println("-------------Start to Restore Integer -----------");
- NonVolatileNodeValue<Integer> plln2 = NonVolatileNodeValueFactory.restore(m_act, null, gtypes, handler, false);
- AssertJUnit.assertEquals(val, (int)plln2.getItem());
- }
-
- @Test(enabled = false)
- public void testNodeValueWithString() {
- String val = Utils.genRandomString();
- GenericField.GType gtypes[] = {GenericField.GType.STRING};
- NonVolatileNodeValue<String> plln = NonVolatileNodeValueFactory.create(m_act, null, gtypes, false);
- plln.setItem(val, false);
- Long handler = plln.getNonVolatileHandler();
- System.err.println("-------------Start to Restore String-----------");
- NonVolatileNodeValue<String> plln2 = NonVolatileNodeValueFactory.restore(m_act, null, gtypes, handler, false);
- AssertJUnit.assertEquals(val, plln2.getItem());
- }
-
- @Test(enabled = false)
- public void testNodeValueWithPerson() {
-
- Person<Long> person = PersonFactory.create(m_act);
- person.setAge((short)31);
-
- GenericField.GType gtypes[] = {GenericField.GType.DURABLE};
- EntityFactoryProxy efproxies[] = {new EntityFactoryProxy(){
- @Override
- public <A extends CommonPersistAllocator<A>> Durable restore(A allocator,
- EntityFactoryProxy[] factoryproxys, GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
- return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
- }
- }
- };
-
- NonVolatileNodeValue<Person<Long>> plln = NonVolatileNodeValueFactory.create(m_act, efproxies, gtypes, false);
- plln.setItem(person, false);
- Long handler = plln.getNonVolatileHandler();
-
- NonVolatileNodeValue<Person<Long>> plln2 = NonVolatileNodeValueFactory.restore(m_act, efproxies, gtypes, handler, false);
- AssertJUnit.assertEquals(31, (int)plln2.getItem().getAge());
-
- }
- @Test(enabled = false)
- public void testLinkedNodeValueWithPerson() {
-
- int elem_count = 10;
- List<Long> referlist = new ArrayList();
-
- GenericField.GType listgftypes[] = {GenericField.GType.DURABLE};
- EntityFactoryProxy listefproxies[] = {
- new EntityFactoryProxy(){
- @Override
- public <A extends CommonPersistAllocator<A>> Durable restore(A allocator,
- EntityFactoryProxy[] factoryproxys, GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
- return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
- }
- }
- };
-
- NonVolatileNodeValue<Person<Long>> firstnv = NonVolatileNodeValueFactory.create(m_act, listefproxies, listgftypes, false);
-
- NonVolatileNodeValue<Person<Long>> nextnv = firstnv;
-
- Person<Long> person;
- long val;
- NonVolatileNodeValue<Person<Long>> newnv;
- for (int i = 0; i < elem_count; ++i) {
- person = PersonFactory.create(m_act);
- person.setAge((short)m_rand.nextInt(50));
- person.setName(String.format("Name: [%s]", Utils.genRandomString()), true);
- nextnv.setItem(person, false);
- newnv = NonVolatileNodeValueFactory.create(m_act, listefproxies, listgftypes, false);
- nextnv.setNext(newnv, false);
- nextnv = newnv;
- }
-
- Person<Long> eval;
- NonVolatileNodeValue<Person<Long>> iternv = firstnv;
- while(null != iternv) {
- System.out.printf(" Stage 1 --->\n");
- eval = iternv.getItem();
- if (null != eval)
- eval.testOutput();
- iternv = iternv.getNext();
- }
-
- long handler = firstnv.getNonVolatileHandler();
-
- NonVolatileNodeValue<Person<Long>> firstnv2 = NonVolatileNodeValueFactory.restore(m_act, listefproxies, listgftypes, handler, false);
-
- for (Person<Long> eval2 : firstnv2) {
- System.out.printf(" Stage 2 ---> \n");
- if (null != eval2)
- eval2.testOutput();
- }
-
- //Assert.assert, expected);(plist, plist2);
-
- }
-
- @Test(enabled = true)
- public void testLinkedNodeValueWithLinkedNodeValue() {
-
- int elem_count = 10;
- long slotKeyId = 10;
-
- GenericField.GType[] elem_gftypes = {GenericField.GType.DOUBLE};
- EntityFactoryProxy[] elem_efproxies = null;
-
- GenericField.GType linkedgftypes[] = {GenericField.GType.DURABLE, GenericField.GType.DOUBLE};
- EntityFactoryProxy linkedefproxies[] = {
- new EntityFactoryProxy(){
- @Override
- public <A extends CommonPersistAllocator<A>> Durable restore(A allocator,
- EntityFactoryProxy[] factoryproxys, GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
- EntityFactoryProxy[] val_efproxies = null;
- GenericField.GType[] val_gftypes = null;
- if ( null != factoryproxys && factoryproxys.length >= 2 ) {
- val_efproxies = Arrays.copyOfRange(factoryproxys, 1, factoryproxys.length);
- }
- if ( null != gfields && gfields.length >= 2 ) {
- val_gftypes = Arrays.copyOfRange(gfields, 1, gfields.length);
- }
- return NonVolatileNodeValueFactory.restore(allocator, val_efproxies, val_gftypes, phandler, autoreclaim);
- }
- }
- };
-
- NonVolatileNodeValue<NonVolatileNodeValue<Double>> nextnv = null, pre_nextnv = null;
- NonVolatileNodeValue<Double> elem = null, pre_elem = null, first_elem = null;
-
- Long linkhandler = 0L;
-
- System.out.printf(" Stage 1 -testLinkedNodeValueWithLinkedNodeValue--> \n");
-
- pre_nextnv = null;
- Double val;
- for (int i=0; i< elem_count; ++i) {
- first_elem = null;
- pre_elem = null;
- for (int v=0; v<3 ; ++v) {
- elem = NonVolatileNodeValueFactory.create(m_act, elem_efproxies, elem_gftypes, false);
- val = m_rand.nextDouble();
- elem.setItem(val, false);
- if (null == pre_elem) {
- first_elem = elem;
- } else {
- pre_elem.setNext(elem, false);
- }
- pre_elem = elem;
- System.out.printf("%f ", val);
- }
-
- nextnv = NonVolatileNodeValueFactory.create(m_act, linkedefproxies, linkedgftypes, false);
- nextnv.setItem(first_elem, false);
- if (null == pre_nextnv) {
- linkhandler = nextnv.getNonVolatileHandler();
- } else {
- pre_nextnv.setNext(nextnv, false);
- }
- pre_nextnv = nextnv;
- System.out.printf(" generated an item... \n");
- }
- m_act.setHandler(slotKeyId, linkhandler);
-
- long handler = m_act.getHandler(slotKeyId);
-
- NonVolatileNodeValue<NonVolatileNodeValue<Double>> linkedvals = NonVolatileNodeValueFactory.restore(m_act, linkedefproxies, linkedgftypes, handler, false);
- Iterator<NonVolatileNodeValue<Double>> iter = linkedvals.iterator();
- Iterator<Double> elemiter = null;
-
- System.out.printf(" Stage 2 -testLinkedNodeValueWithLinkedNodeValue--> \n");
- while(iter.hasNext()) {
- elemiter = iter.next().iterator();
- while(elemiter.hasNext()) {
- System.out.printf("%f ", elemiter.next());
- }
- System.out.printf(" Fetched an item... \n");
- }
-
- //Assert.assert, expected);(plist, plist2);
-
- }
+ private long KEYCAPACITY;
+ private Random m_rand;
+ private BigDataPMemAllocator m_act;
+
+ @BeforeClass
+ public void setUp() {
+ m_rand = Utils.createRandom();
+ m_act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 1024,
+ "./pobj_NodeValue.dat", true);
+ KEYCAPACITY = m_act.handlerCapacity();
+ m_act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
+ @Override
+ public boolean reclaim(ByteBuffer mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Buffer: %X Size: %s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+ m_act.setChunkReclaimer(new Reclaim<Long>() {
+ @Override
+ public boolean reclaim(Long mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Chunk: %X Size: %s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+
+ for (long i = 0; i < KEYCAPACITY; ++i) {
+ m_act.setHandler(i, 0L);
+ }
+ }
+
+ @AfterClass
+ public void tearDown() {
+ m_act.close();
+ }
+
+ @Test(enabled = false)
+ public void testSingleNodeValueWithInteger() {
+ int val = m_rand.nextInt();
+ GenericField.GType gtypes[] = { GenericField.GType.INTEGER };
+ NonVolatileNodeValue<Integer> plln = NonVolatileNodeValueFactory.create(m_act, null, gtypes, false);
+ plln.setItem(val, false);
+ Long handler = plln.getNonVolatileHandler();
+ System.err.println("-------------Start to Restore Integer -----------");
+ NonVolatileNodeValue<Integer> plln2 = NonVolatileNodeValueFactory.restore(m_act, null, gtypes, handler, false);
+ AssertJUnit.assertEquals(val, (int) plln2.getItem());
+ }
+
+ @Test(enabled = false)
+ public void testNodeValueWithString() {
+ String val = Utils.genRandomString();
+ GenericField.GType gtypes[] = { GenericField.GType.STRING };
+ NonVolatileNodeValue<String> plln = NonVolatileNodeValueFactory.create(m_act, null, gtypes, false);
+ plln.setItem(val, false);
+ Long handler = plln.getNonVolatileHandler();
+ System.err.println("-------------Start to Restore String-----------");
+ NonVolatileNodeValue<String> plln2 = NonVolatileNodeValueFactory.restore(m_act, null, gtypes, handler, false);
+ AssertJUnit.assertEquals(val, plln2.getItem());
+ }
+
+ @Test(enabled = false)
+ public void testNodeValueWithPerson() {
+
+ Person<Long> person = PersonFactory.create(m_act);
+ person.setAge((short) 31);
+
+ GenericField.GType gtypes[] = { GenericField.GType.DURABLE };
+ EntityFactoryProxy efproxies[] = { new EntityFactoryProxy() {
+ @Override
+ public <A extends CommonPersistAllocator<A>> Durable restore(A allocator, EntityFactoryProxy[] factoryproxys,
+ GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
+ return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
+ }
+ } };
+
+ NonVolatileNodeValue<Person<Long>> plln = NonVolatileNodeValueFactory.create(m_act, efproxies, gtypes, false);
+ plln.setItem(person, false);
+ Long handler = plln.getNonVolatileHandler();
+
+ NonVolatileNodeValue<Person<Long>> plln2 = NonVolatileNodeValueFactory.restore(m_act, efproxies, gtypes, handler,
+ false);
+ AssertJUnit.assertEquals(31, (int) plln2.getItem().getAge());
+
+ }
+
+ @Test(enabled = false)
+ public void testLinkedNodeValueWithPerson() {
+
+ int elem_count = 10;
+ List<Long> referlist = new ArrayList();
+
+ GenericField.GType listgftypes[] = { GenericField.GType.DURABLE };
+ EntityFactoryProxy listefproxies[] = { new EntityFactoryProxy() {
+ @Override
+ public <A extends CommonPersistAllocator<A>> Durable restore(A allocator, EntityFactoryProxy[] factoryproxys,
+ GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
+ return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
+ }
+ } };
+
+ NonVolatileNodeValue<Person<Long>> firstnv = NonVolatileNodeValueFactory.create(m_act, listefproxies, listgftypes,
+ false);
+
+ NonVolatileNodeValue<Person<Long>> nextnv = firstnv;
+
+ Person<Long> person;
+ long val;
+ NonVolatileNodeValue<Person<Long>> newnv;
+ for (int i = 0; i < elem_count; ++i) {
+ person = PersonFactory.create(m_act);
+ person.setAge((short) m_rand.nextInt(50));
+ person.setName(String.format("Name: [%s]", Utils.genRandomString()), true);
+ nextnv.setItem(person, false);
+ newnv = NonVolatileNodeValueFactory.create(m_act, listefproxies, listgftypes, false);
+ nextnv.setNext(newnv, false);
+ nextnv = newnv;
+ }
+
+ Person<Long> eval;
+ NonVolatileNodeValue<Person<Long>> iternv = firstnv;
+ while (null != iternv) {
+ System.out.printf(" Stage 1 --->\n");
+ eval = iternv.getItem();
+ if (null != eval)
+ eval.testOutput();
+ iternv = iternv.getNext();
+ }
+
+ long handler = firstnv.getNonVolatileHandler();
+
+ NonVolatileNodeValue<Person<Long>> firstnv2 = NonVolatileNodeValueFactory.restore(m_act, listefproxies, listgftypes,
+ handler, false);
+
+ for (Person<Long> eval2 : firstnv2) {
+ System.out.printf(" Stage 2 ---> \n");
+ if (null != eval2)
+ eval2.testOutput();
+ }
+
+ // Assert.assert, expected);(plist, plist2);
+
+ }
+
+ @Test(enabled = true)
+ public void testLinkedNodeValueWithLinkedNodeValue() {
+
+ int elem_count = 10;
+ long slotKeyId = 10;
+
+ GenericField.GType[] elem_gftypes = { GenericField.GType.DOUBLE };
+ EntityFactoryProxy[] elem_efproxies = null;
+
+ GenericField.GType linkedgftypes[] = { GenericField.GType.DURABLE, GenericField.GType.DOUBLE };
+ EntityFactoryProxy linkedefproxies[] = { new EntityFactoryProxy() {
+ @Override
+ public <A extends CommonPersistAllocator<A>> Durable restore(A allocator, EntityFactoryProxy[] factoryproxys,
+ GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
+ EntityFactoryProxy[] val_efproxies = null;
+ GenericField.GType[] val_gftypes = null;
+ if (null != factoryproxys && factoryproxys.length >= 2) {
+ val_efproxies = Arrays.copyOfRange(factoryproxys, 1, factoryproxys.length);
+ }
+ if (null != gfields && gfields.length >= 2) {
+ val_gftypes = Arrays.copyOfRange(gfields, 1, gfields.length);
+ }
+ return NonVolatileNodeValueFactory.restore(allocator, val_efproxies, val_gftypes, phandler, autoreclaim);
+ }
+ } };
+
+ NonVolatileNodeValue<NonVolatileNodeValue<Double>> nextnv = null, pre_nextnv = null;
+ NonVolatileNodeValue<Double> elem = null, pre_elem = null, first_elem = null;
+
+ Long linkhandler = 0L;
+
+ System.out.printf(" Stage 1 -testLinkedNodeValueWithLinkedNodeValue--> \n");
+
+ pre_nextnv = null;
+ Double val;
+ for (int i = 0; i < elem_count; ++i) {
+ first_elem = null;
+ pre_elem = null;
+ for (int v = 0; v < 3; ++v) {
+ elem = NonVolatileNodeValueFactory.create(m_act, elem_efproxies, elem_gftypes, false);
+ val = m_rand.nextDouble();
+ elem.setItem(val, false);
+ if (null == pre_elem) {
+ first_elem = elem;
+ } else {
+ pre_elem.setNext(elem, false);
+ }
+ pre_elem = elem;
+ System.out.printf("%f ", val);
+ }
+
+ nextnv = NonVolatileNodeValueFactory.create(m_act, linkedefproxies, linkedgftypes, false);
+ nextnv.setItem(first_elem, false);
+ if (null == pre_nextnv) {
+ linkhandler = nextnv.getNonVolatileHandler();
+ } else {
+ pre_nextnv.setNext(nextnv, false);
+ }
+ pre_nextnv = nextnv;
+ System.out.printf(" generated an item... \n");
+ }
+ m_act.setHandler(slotKeyId, linkhandler);
+
+ long handler = m_act.getHandler(slotKeyId);
+
+ NonVolatileNodeValue<NonVolatileNodeValue<Double>> linkedvals = NonVolatileNodeValueFactory.restore(m_act,
+ linkedefproxies, linkedgftypes, handler, false);
+ Iterator<NonVolatileNodeValue<Double>> iter = linkedvals.iterator();
+ Iterator<Double> elemiter = null;
+
+ System.out.printf(" Stage 2 -testLinkedNodeValueWithLinkedNodeValue--> \n");
+ while (iter.hasNext()) {
+ elemiter = iter.next().iterator();
+ while (elemiter.hasNext()) {
+ System.out.printf("%f ", elemiter.next());
+ }
+ System.out.printf(" Fetched an item... \n");
+ }
+
+ // Assert.assert, expected);(plist, plist2);
+
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/collections/src/test/java/org/apache/mnemonic/collections/NonVolatilePersonNGTest.java
----------------------------------------------------------------------
diff --git a/collections/src/test/java/org/apache/mnemonic/collections/NonVolatilePersonNGTest.java b/collections/src/test/java/org/apache/mnemonic/collections/NonVolatilePersonNGTest.java
index fb75eac..d5efb7e 100644
--- a/collections/src/test/java/org/apache/mnemonic/collections/NonVolatilePersonNGTest.java
+++ b/collections/src/test/java/org/apache/mnemonic/collections/NonVolatilePersonNGTest.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic.collections;
import org.apache.mnemonic.*;
@@ -17,118 +34,112 @@ public class NonVolatilePersonNGTest {
@Test(expectedExceptions = { OutOfPersistentMemory.class })
public void testGenPeople() throws OutOfPersistentMemory, RetrieveNonVolatileEntityError {
- Random rand = Utils.createRandom();
- BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 8, "./pobj_person.dat", true);
- KEYCAPACITY = act.handlerCapacity();
- act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
- @Override
- public boolean reclaim(ByteBuffer mres, Long sz) {
- System.out.println(String.format(
- "Reclaim Memory Buffer: %X Size: %s", System
- .identityHashCode(mres),
- null == sz ? "NULL" : sz.toString()));
- return false;
- }
- });
- act.setChunkReclaimer(new Reclaim<Long>() {
- @Override
- public boolean reclaim(Long mres, Long sz) {
- System.out.println(String.format(
- "Reclaim Memory Chunk: %X Size: %s", System
- .identityHashCode(mres),
- null == sz ? "NULL" : sz.toString()));
- return false;
- }
- });
-
- for (long i = 0; i < KEYCAPACITY; ++i) {
- act.setHandler(i, 0L);
- }
-
- Person<Integer> mother;
- Person<Integer> person;
-
- long keyidx = 0;
- long val;
-
- try {
- while(true) {
- //if (keyidx >= KEYCAPACITY) break;
-
- keyidx %= KEYCAPACITY;
-
- System.out.printf("************ Generating People on Key %d ***********\n", keyidx);
-
- val = act.getHandler(keyidx);
- if (0L != val) {
- PersonFactory.restore(act, val, true);
- }
-
- person = PersonFactory.create(act);
- person.setAge((short)rand.nextInt(50));
- person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
- person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
- person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
- person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
-
- act.setHandler(keyidx, person.getNonVolatileHandler());
-
- for (int deep = 0; deep < rand.nextInt(100); ++deep) {
-
- mother = PersonFactory.create(act);
- mother.setAge((short)(50 + rand.nextInt(50)));
- mother.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
-
- person.setMother(mother, true);
-
- person = mother;
-
- }
- ++keyidx;
- }
- }finally {
- act.close();
- }
+ Random rand = Utils.createRandom();
+ BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
+ 1024 * 1024 * 8, "./pobj_person.dat", true);
+ KEYCAPACITY = act.handlerCapacity();
+ act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
+ @Override
+ public boolean reclaim(ByteBuffer mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Buffer: %X Size: %s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+ act.setChunkReclaimer(new Reclaim<Long>() {
+ @Override
+ public boolean reclaim(Long mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Chunk: %X Size: %s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+
+ for (long i = 0; i < KEYCAPACITY; ++i) {
+ act.setHandler(i, 0L);
+ }
+
+ Person<Integer> mother;
+ Person<Integer> person;
+
+ long keyidx = 0;
+ long val;
+
+ try {
+ while (true) {
+ // if (keyidx >= KEYCAPACITY) break;
+
+ keyidx %= KEYCAPACITY;
+
+ System.out.printf("************ Generating People on Key %d ***********\n", keyidx);
+
+ val = act.getHandler(keyidx);
+ if (0L != val) {
+ PersonFactory.restore(act, val, true);
+ }
+
+ person = PersonFactory.create(act);
+ person.setAge((short) rand.nextInt(50));
+ person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
+ person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
+ person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
+ person.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
+
+ act.setHandler(keyidx, person.getNonVolatileHandler());
+
+ for (int deep = 0; deep < rand.nextInt(100); ++deep) {
+
+ mother = PersonFactory.create(act);
+ mother.setAge((short) (50 + rand.nextInt(50)));
+ mother.setName(String.format("Name: [%s]", UUID.randomUUID().toString()), true);
+
+ person.setMother(mother, true);
+
+ person = mother;
+
+ }
+ ++keyidx;
+ }
+ } finally {
+ act.close();
+ }
}
- @Test(dependsOnMethods = {"testGenPeople"})
+ @Test(dependsOnMethods = { "testGenPeople" })
public void testCheckPeople() throws RetrieveNonVolatileEntityError {
- BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 8, "./pobj_person.dat", true);
- act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
- @Override
- public boolean reclaim(ByteBuffer mres, Long sz) {
- System.out.println(String.format(
- "Reclaim Memory Buffer: %X Size: %s", System
- .identityHashCode(mres),
- null == sz ? "NULL" : sz.toString()));
- return false;
- }
- });
- act.setChunkReclaimer(new Reclaim<Long>() {
- @Override
- public boolean reclaim(Long mres, Long sz) {
- System.out.println(String.format(
- "Reclaim Memory Chunk: %X Size: %s", System
- .identityHashCode(mres),
- null == sz ? "NULL" : sz.toString()));
- return false;
- }
- });
-
- long val;
- for (long i = 0; i < KEYCAPACITY; ++i) {
- System.out.printf("----------Key %d--------------\n", i);
- val = act.getHandler(i);
- if (0L == val) {
- break;
- }
- Person<Integer> person = PersonFactory.restore(act, val, true);
- while (null != person) {
- person.testOutput();
- person = person.getMother();
- }
- }
-
- act.close();
- }
+ BigDataPMemAllocator act = new BigDataPMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"),
+ 1024 * 1024 * 8, "./pobj_person.dat", true);
+ act.setBufferReclaimer(new Reclaim<ByteBuffer>() {
+ @Override
+ public boolean reclaim(ByteBuffer mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Buffer: %X Size: %s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+ act.setChunkReclaimer(new Reclaim<Long>() {
+ @Override
+ public boolean reclaim(Long mres, Long sz) {
+ System.out.println(String.format("Reclaim Memory Chunk: %X Size: %s", System.identityHashCode(mres),
+ null == sz ? "NULL" : sz.toString()));
+ return false;
+ }
+ });
+
+ long val;
+ for (long i = 0; i < KEYCAPACITY; ++i) {
+ System.out.printf("----------Key %d--------------\n", i);
+ val = act.getHandler(i);
+ if (0L == val) {
+ break;
+ }
+ Person<Integer> person = PersonFactory.restore(act, val, true);
+ while (null != person) {
+ person.testOutput();
+ person = person.getMother();
+ }
+ }
+
+ act.close();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/collections/src/test/java/org/apache/mnemonic/collections/Payload.java
----------------------------------------------------------------------
diff --git a/collections/src/test/java/org/apache/mnemonic/collections/Payload.java b/collections/src/test/java/org/apache/mnemonic/collections/Payload.java
index 31945bd..a6f6518 100644
--- a/collections/src/test/java/org/apache/mnemonic/collections/Payload.java
+++ b/collections/src/test/java/org/apache/mnemonic/collections/Payload.java
@@ -1,3 +1,19 @@
+/*
+ * 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.mnemonic.collections;
@@ -8,22 +24,21 @@ package org.apache.mnemonic.collections;
*
*/
public class Payload implements java.io.Serializable, Comparable<Payload> {
-
- private static final long serialVersionUID = 187397440699436500L;
- public Payload(int iv, String strv, double dv) {
- ival = iv;
- strval = strv;
- dval = dv;
- }
+ private static final long serialVersionUID = 187397440699436500L;
+
+ public Payload(int iv, String strv, double dv) {
+ ival = iv;
+ strval = strv;
+ dval = dv;
+ }
- public int ival;
- public String strval;
- public double dval;
+ public int ival;
+ public String strval;
+ public double dval;
- @Override
- public int compareTo(Payload pl) {
- return ival == pl.ival && strval.equals(pl.strval) && dval == pl.dval ? 0
- : 1;
- }
+ @Override
+ public int compareTo(Payload pl) {
+ return ival == pl.ival && strval.equals(pl.strval) && dval == pl.dval ? 0 : 1;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/collections/src/test/java/org/apache/mnemonic/collections/Person.java
----------------------------------------------------------------------
diff --git a/collections/src/test/java/org/apache/mnemonic/collections/Person.java b/collections/src/test/java/org/apache/mnemonic/collections/Person.java
index c7afa64..bf2a0d3 100644
--- a/collections/src/test/java/org/apache/mnemonic/collections/Person.java
+++ b/collections/src/test/java/org/apache/mnemonic/collections/Person.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic.collections;
import org.apache.mnemonic.*;
@@ -11,54 +28,60 @@ import java.util.List;
@NonVolatileEntity
public abstract class Person<E> implements Durable, Comparable<Person<E>> {
- E element;
-
- @Override
- public void initializeAfterCreate() {
- System.out.println("Initializing After Created");
- }
-
- @Override
- public void initializeAfterRestore() {
- System.out.println("Initializing After Restored");
- }
-
- @Override
- public void setupGenericInfo(EntityFactoryProxy[] efproxies, GenericField.GType[] gftypes) {
-
- }
-
- @Test
- public void testOutput() throws RetrieveNonVolatileEntityError {
- System.out.printf("Person %s, Age: %d ( %s ) \n", getName(), getAge(),
- null == getMother()? "No Recorded Mother" : "Has Recorded Mother");
- }
-
- public int compareTo(Person<E> anotherPerson) {
- int ret = 0;
- if (0 == ret) ret = getAge().compareTo(anotherPerson.getAge());
- if (0 == ret) ret = getName().compareTo(anotherPerson.getName());
- return ret;
- }
-
- @NonVolatileGetter(Id = 1L)
- abstract public Short getAge();
- @NonVolatileSetter
- abstract public void setAge(Short age);
-
- @NonVolatileGetter(Id = 2L)
- abstract public String getName() throws RetrieveNonVolatileEntityError;
- @NonVolatileSetter
- abstract public void setName(String name, boolean destroy) throws OutOfPersistentMemory, RetrieveNonVolatileEntityError;
-
- @NonVolatileGetter(Id = 3L)
- abstract public Person<E> getMother() throws RetrieveNonVolatileEntityError;
- @NonVolatileSetter
- abstract public void setMother(Person<E> mother, boolean destroy) throws RetrieveNonVolatileEntityError;
-
- @NonVolatileGetter(Id = 4L)
- abstract public Person<E> getFather() throws RetrieveNonVolatileEntityError;
- @NonVolatileSetter
- abstract public void setFather(Person<E> mother, boolean destroy) throws RetrieveNonVolatileEntityError;
-}
+ E element;
+
+ @Override
+ public void initializeAfterCreate() {
+ System.out.println("Initializing After Created");
+ }
+
+ @Override
+ public void initializeAfterRestore() {
+ System.out.println("Initializing After Restored");
+ }
+
+ @Override
+ public void setupGenericInfo(EntityFactoryProxy[] efproxies, GenericField.GType[] gftypes) {
+
+ }
+
+ @Test
+ public void testOutput() throws RetrieveNonVolatileEntityError {
+ System.out.printf("Person %s, Age: %d ( %s ) \n", getName(), getAge(),
+ null == getMother() ? "No Recorded Mother" : "Has Recorded Mother");
+ }
+ public int compareTo(Person<E> anotherPerson) {
+ int ret = 0;
+ if (0 == ret)
+ ret = getAge().compareTo(anotherPerson.getAge());
+ if (0 == ret)
+ ret = getName().compareTo(anotherPerson.getName());
+ return ret;
+ }
+
+ @NonVolatileGetter(Id = 1L)
+ abstract public Short getAge();
+
+ @NonVolatileSetter
+ abstract public void setAge(Short age);
+
+ @NonVolatileGetter(Id = 2L)
+ abstract public String getName() throws RetrieveNonVolatileEntityError;
+
+ @NonVolatileSetter
+ abstract public void setName(String name, boolean destroy)
+ throws OutOfPersistentMemory, RetrieveNonVolatileEntityError;
+
+ @NonVolatileGetter(Id = 3L)
+ abstract public Person<E> getMother() throws RetrieveNonVolatileEntityError;
+
+ @NonVolatileSetter
+ abstract public void setMother(Person<E> mother, boolean destroy) throws RetrieveNonVolatileEntityError;
+
+ @NonVolatileGetter(Id = 4L)
+ abstract public Person<E> getFather() throws RetrieveNonVolatileEntityError;
+
+ @NonVolatileSetter
+ abstract public void setFather(Person<E> mother, boolean destroy) throws RetrieveNonVolatileEntityError;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/Allocatable.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/Allocatable.java b/core/src/main/java/org/apache/mnemonic/Allocatable.java
index 76ec38d..1009316 100644
--- a/core/src/main/java/org/apache/mnemonic/Allocatable.java
+++ b/core/src/main/java/org/apache/mnemonic/Allocatable.java
@@ -1,102 +1,117 @@
+/*
+ * 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.mnemonic;
/**
- * an interface to allocate memory resources from any underlying memory kind
- * of storage.
+ * an interface to allocate memory resources from any underlying memory kind of
+ * storage.
*
*/
public interface Allocatable<A extends CommonAllocator<A>> {
-
- /**
- * create a memory chunk that is managed by its holder.
- *
- * @param size
- * specify the size of memory chunk
- *
- * @param autoreclaim
- * specify whether or not to reclaim this
- * chunk automatically
- *
- * @return a holder contains a memory chunk
- */
- public MemChunkHolder<A> createChunk(long size, boolean autoreclaim);
- /**
- * create a memory chunk that is managed by its holder.
- *
- * @param size
- * specify the size of memory chunk
- *
- * @return a holder contains a memory chunk
- */
- public MemChunkHolder<A> createChunk(long size);
+ /**
+ * create a memory chunk that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory chunk
+ *
+ * @param autoreclaim
+ * specify whether or not to reclaim this chunk automatically
+ *
+ * @return a holder contains a memory chunk
+ */
+ public MemChunkHolder<A> createChunk(long size, boolean autoreclaim);
+
+ /**
+ * create a memory chunk that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory chunk
+ *
+ * @return a holder contains a memory chunk
+ */
+ public MemChunkHolder<A> createChunk(long size);
+
+ /**
+ * create a memory buffer that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory buffer
+ *
+ * @param autoreclaim
+ * specify whether or not to reclaim this buffer automatically
+ *
+ * @return a holder contains a memory buffer
+ */
+ public MemBufferHolder<A> createBuffer(long size, boolean autoreclaim);
+
+ /**
+ * create a memory buffer that is managed by its holder.
+ *
+ * @param size
+ * specify the size of memory buffer
+ *
+ * @return a holder contains a memory buffer
+ */
+ public MemBufferHolder<A> createBuffer(long size);
- /**
- * create a memory buffer that is managed by its holder.
- *
- * @param size
- * specify the size of memory buffer
- *
- * @param autoreclaim
- * specify whether or not to reclaim this
- * buffer automatically
- *
- * @return a holder contains a memory buffer
- */
- public MemBufferHolder<A> createBuffer(long size, boolean autoreclaim);
-
- /**
- * create a memory buffer that is managed by its holder.
- *
- * @param size
- * specify the size of memory buffer
- *
- * @return a holder contains a memory buffer
- */
- public MemBufferHolder<A> createBuffer(long size);
+ /**
+ * register a memory chunk for auto-reclaim
+ *
+ * @param mholder
+ * specify a chunk holder to register
+ */
+ public void registerChunkAutoReclaim(MemChunkHolder<A> mholder);
- /**
- * register a memory chunk for auto-reclaim
- *
- * @param mholder
- * specify a chunk holder to register
- */
- public void registerChunkAutoReclaim(MemChunkHolder<A> mholder);
+ /**
+ * register a memory buffer for auto-reclaim
+ *
+ * @param mholder
+ * specify a buffer holder to register
+ */
+ public void registerBufferAutoReclaim(MemBufferHolder<A> mholder);
- /**
- * register a memory buffer for auto-reclaim
- *
- * @param mholder
- * specify a buffer holder to register
- */
- public void registerBufferAutoReclaim(MemBufferHolder<A> mholder);
+ /**
+ * resize a memory chunk.
+ *
+ * @param mholder
+ * specify a chunk holder for resizing
+ *
+ * @param size
+ * specify a new size of this memory chunk
+ *
+ * @return the resized memory chunk holder
+ *
+ */
+ public MemChunkHolder<A> resizeChunk(MemChunkHolder<A> mholder, long size);
- /**
- * resize a memory chunk.
- *
- * @param mholder
- * specify a chunk holder for resizing
- *
- * @param size
- * specify a new size of this memory chunk
- *
- * @return the resized memory chunk holder
- *
- */
- public MemChunkHolder<A> resizeChunk(MemChunkHolder<A> mholder, long size);
-
- /**
- * resize a memory buffer.
- *
- * @param mholder
- * specify a buffer holder for resizing
- *
- * @param size
- * specify a new size of this memory buffer
- *
- * @return the resized memory buffer holder
- *
- */
- public MemBufferHolder<A> resizeBuffer(MemBufferHolder<A> mholder, long size);
+ /**
+ * resize a memory buffer.
+ *
+ * @param mholder
+ * specify a buffer holder for resizing
+ *
+ * @param size
+ * specify a new size of this memory buffer
+ *
+ * @return the resized memory buffer holder
+ *
+ */
+ public MemBufferHolder<A> resizeBuffer(MemBufferHolder<A> mholder, long size);
}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/551c8247/core/src/main/java/org/apache/mnemonic/Allocator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/mnemonic/Allocator.java b/core/src/main/java/org/apache/mnemonic/Allocator.java
index c887b07..950b890 100644
--- a/core/src/main/java/org/apache/mnemonic/Allocator.java
+++ b/core/src/main/java/org/apache/mnemonic/Allocator.java
@@ -1,3 +1,20 @@
+/*
+ * 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.mnemonic;
/**
@@ -6,34 +23,34 @@ package org.apache.mnemonic;
*/
public interface Allocator<A extends CommonAllocator<A>> extends Allocatable<A> {
- /**
- * release the underlying memory pool and close it.
- *
- */
- public void close();
+ /**
+ * release the underlying memory pool and close it.
+ *
+ */
+ public void close();
- /**
- * sync. dirty data to underlying memory-like device
- *
- */
- public void sync();
+ /**
+ * sync. dirty data to underlying memory-like device
+ *
+ */
+ public void sync();
- /**
- * enable active garbage collection. the GC will be forced to collect garbages when
- * there is no more space for current allocation request.
- *
- * @param timeout
- * the timeout is used to yield for GC performing
- *
- * @return this allocator
- */
- public A enableActiveGC(long timeout);
+ /**
+ * enable active garbage collection. the GC will be forced to collect garbages
+ * when there is no more space for current allocation request.
+ *
+ * @param timeout
+ * the timeout is used to yield for GC performing
+ *
+ * @return this allocator
+ */
+ public A enableActiveGC(long timeout);
- /**
- * disable active garbage collection.
- *
- * @return this allocator
- */
- public A disableActiveGC();
+ /**
+ * disable active garbage collection.
+ *
+ * @return this allocator
+ */
+ public A disableActiveGC();
}