mnemonic-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject incubator-mnemonic git commit: MNEMONIC-59: Extract transaction interface from abstract class CommonDurableAllocator MNEMONIC-58: Extract handler store interface from abstract class CommonDurableAllocator and NonVolatileMemAllocator MNEMONIC-57: Extract
Date Sun, 12 Jun 2016 19:08:41 GMT
Repository: incubator-mnemonic
Updated Branches:
  refs/heads/master f8f4708f3 -> 43e0ddb7f


MNEMONIC-59: Extract transaction interface from abstract class CommonDurableAllocator
MNEMONIC-58: Extract handler store interface from abstract class CommonDurableAllocator and
NonVolatileMemAllocator
MNEMONIC-57: Extract retrievable interface from abstract class CommonDurableAllocator
MNEMONIC-56: Abstract restorable interface from class NonVolatileMemAllocator
MNEMONIC-61: Create an RestoreDurableEntityError exception for restoring operations


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

Branch: refs/heads/master
Commit: 43e0ddb7fd1d23dbb304ad68e3716351b79d1428
Parents: f8f4708
Author: Wang, Gang(Gary) <gang1.wang@intel.com>
Authored: Thu Jun 9 11:04:40 2016 -0700
Committer: Wang, Gang(Gary) <gang1.wang@intel.com>
Committed: Sun Jun 12 11:53:08 2016 -0700

----------------------------------------------------------------------
 .../collections/DurableNodeValueNGTest.java     |   8 +-
 .../DurableNodeValueNGPrintTest.java            |   6 +-
 .../org/apache/mnemonic/AddressTranslator.java  |  61 ++++++++
 .../mnemonic/AnnotatedDurableEntityClass.java   |  17 ++-
 .../apache/mnemonic/CommonDurableAllocator.java | 140 -------------------
 .../org/apache/mnemonic/EntityFactoryProxy.java |   2 +-
 .../java/org/apache/mnemonic/GenericField.java  |   2 +-
 .../java/org/apache/mnemonic/HandlerStore.java  |  35 +++++
 .../apache/mnemonic/MemoryDurableEntity.java    |   4 +-
 .../apache/mnemonic/NVMAddressTranslator.java   |  61 --------
 .../mnemonic/NonVolatileMemAllocator.java       |  27 +++-
 .../apache/mnemonic/RestorableAllocator.java    |  22 +++
 .../mnemonic/RestoreDurableEntityError.java     |  39 ++++++
 .../apache/mnemonic/RetrievableAllocator.java   |  96 +++++++++++++
 .../java/org/apache/mnemonic/Transaction.java   |  49 +++++++
 15 files changed, 349 insertions(+), 220 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/43e0ddb7/mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableNodeValueNGTest.java
----------------------------------------------------------------------
diff --git a/mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableNodeValueNGTest.java
b/mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableNodeValueNGTest.java
index 0cc0095..bbb9ccc 100644
--- a/mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableNodeValueNGTest.java
+++ b/mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableNodeValueNGTest.java
@@ -25,7 +25,7 @@ import java.util.List;
 import java.util.Random;
 
 import org.apache.mnemonic.NonVolatileMemAllocator;
-import org.apache.mnemonic.CommonDurableAllocator;
+import org.apache.mnemonic.RestorableAllocator;
 import org.apache.mnemonic.Durable;
 import org.apache.mnemonic.EntityFactoryProxy;
 import org.apache.mnemonic.GenericField;
@@ -112,7 +112,7 @@ public class DurableNodeValueNGTest {
     GenericField.GType gtypes[] = {GenericField.GType.DURABLE};
     EntityFactoryProxy efproxies[] = {new EntityFactoryProxy() {
       @Override
-      public <A extends CommonDurableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
+      public <A extends RestorableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
           GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
         return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
       }
@@ -137,7 +137,7 @@ public class DurableNodeValueNGTest {
     GenericField.GType listgftypes[] = {GenericField.GType.DURABLE};
     EntityFactoryProxy listefproxies[] = {new EntityFactoryProxy() {
       @Override
-      public <A extends CommonDurableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
+      public <A extends RestorableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
           GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
         return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
       }
@@ -200,7 +200,7 @@ public class DurableNodeValueNGTest {
     GenericField.GType linkedgftypes[] = {GenericField.GType.DURABLE, GenericField.GType.DOUBLE};
     EntityFactoryProxy linkedefproxies[] = {new EntityFactoryProxy() {
       @Override
-      public <A extends CommonDurableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
+      public <A extends RestorableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
           GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
         EntityFactoryProxy[] val_efproxies = null;
         GenericField.GType[] val_gftypes = null;

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/43e0ddb7/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableNodeValueNGPrintTest.java
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableNodeValueNGPrintTest.java
b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableNodeValueNGPrintTest.java
index e3ec195..fd26017 100644
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableNodeValueNGPrintTest.java
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableNodeValueNGPrintTest.java
@@ -27,7 +27,7 @@ import java.nio.file.Files;
 import java.nio.file.Paths;
 
 import org.apache.mnemonic.NonVolatileMemAllocator;
-import org.apache.mnemonic.CommonDurableAllocator;
+import org.apache.mnemonic.RestorableAllocator;
 import org.apache.mnemonic.Durable;
 import org.apache.mnemonic.EntityFactoryProxy;
 import org.apache.mnemonic.GenericField;
@@ -75,7 +75,7 @@ public class DurableNodeValueNGPrintTest {
     GenericField.GType listgftypes[] = {GenericField.GType.DURABLE};
     EntityFactoryProxy listefproxies[] = {new EntityFactoryProxy() {
       @Override
-      public <A extends CommonDurableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
+      public <A extends RestorableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
           GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
         return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
       }
@@ -144,7 +144,7 @@ public class DurableNodeValueNGPrintTest {
     GenericField.GType linkedgftypes[] = {GenericField.GType.DURABLE, GenericField.GType.DOUBLE};
     EntityFactoryProxy linkedefproxies[] = {new EntityFactoryProxy() {
       @Override
-      public <A extends CommonDurableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
+      public <A extends RestorableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
           GenericField.GType[] gfields, long phandler, boolean autoreclaim) {
         EntityFactoryProxy[] val_efproxies = null;
         GenericField.GType[] val_gftypes = null;

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/43e0ddb7/mnemonic-core/src/main/java/org/apache/mnemonic/AddressTranslator.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/AddressTranslator.java b/mnemonic-core/src/main/java/org/apache/mnemonic/AddressTranslator.java
new file mode 100644
index 0000000..89d4708
--- /dev/null
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/AddressTranslator.java
@@ -0,0 +1,61 @@
+/*
+ * 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
+ *
+ */
+public interface AddressTranslator {
+
+  /**
+   * calculate the portable address
+   *
+   * @param addr
+   *          the address to be calculated
+   *
+   * @return the portable address
+   */
+  long getPortableAddress(long addr);
+
+  /**
+   * calculate the effective address
+   *
+   * @param addr
+   *          the address to be calculated
+   *
+   * @return the effective address
+   */
+  long getEffectiveAddress(long addr);
+
+  /**
+   * get the base address
+   *
+   * @return the base address
+   */
+  long getBaseAddress();
+
+  /**
+   * set the base address for calculation
+   *
+   * @param addr
+   *          the base address
+   *
+   */
+  long setBaseAddress(long addr);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/43e0ddb7/mnemonic-core/src/main/java/org/apache/mnemonic/AnnotatedDurableEntityClass.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/AnnotatedDurableEntityClass.java
b/mnemonic-core/src/main/java/org/apache/mnemonic/AnnotatedDurableEntityClass.java
index 7f25b33..4f2099e 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/AnnotatedDurableEntityClass.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/AnnotatedDurableEntityClass.java
@@ -105,7 +105,7 @@ public class AnnotatedDurableEntityClass {
   private TypeName m_factoryproxystypename = TypeName.get(EntityFactoryProxy[].class);
   private TypeName m_gfieldstypename = TypeName.get(GenericField.GType[].class);
   private TypeVariableName m_alloctypevarname = TypeVariableName.get(cALLOCTYPENAME,
-      ParameterizedTypeName.get(ClassName.get(CommonDurableAllocator.class), TypeVariableName.get(cALLOCTYPENAME)));
+      ParameterizedTypeName.get(ClassName.get(RestorableAllocator.class), TypeVariableName.get(cALLOCTYPENAME)));
 
   private Map<String, MethodInfo> m_gettersinfo = new HashMap<String, MethodInfo>();
   private Map<String, MethodInfo> m_settersinfo = new HashMap<String, MethodInfo>();
@@ -751,13 +751,18 @@ public class AnnotatedDurableEntityClass {
       case "restoreDurableEntity":
         arg3 = methodinfo.elem.getParameters().get(3);
         arg4 = methodinfo.elem.getParameters().get(4);
+//        code.beginControlFlow("if ($1L instanceof RestorableAllocator)", arg0);
+//        code.addStatement(
+//               "throw new RestoreDurableEntityError(\"Allocator does not support restore
operation in $1N.\")",
+//               name);
+//        code.endControlFlow();
         code.addStatement("initializeDurableEntity($1L, $2L, $3L, $4L)", arg0, arg1, arg2,
arg4);
         code.beginControlFlow("if (0L == $1L)", arg3);
-        code.addStatement("throw new RetrieveDurableEntityError(\"Input handler is null on
$1N.\")", name);
+        code.addStatement("throw new RestoreDurableEntityError(\"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 RetrieveDurableEntityError(\"Retrieve Entity Failure!\")");
+        code.addStatement("throw new RestoreDurableEntityError(\"Retrieve Entity Failure!\")");
         code.endControlFlow();
         code.addStatement("initializeAfterRestore()");
         break;
@@ -819,7 +824,7 @@ public class AnnotatedDurableEntityClass {
     code = CodeBlock.builder().addStatement("return restore($1L, $2L, false)", allocparam.name,
phandlerparam.name)
         .build();
     methodspec = MethodSpec.methodBuilder("restore").addTypeVariables(entityspec.typeVariables)
-        .addException(RetrieveDurableEntityError.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
+        .addException(RestoreDurableEntityError.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
         .returns(TypeName.get(m_elem.asType())).addParameter(allocparam).addParameter(phandlerparam).addCode(code)
         .build();
     typespecbuilder.addMethod(methodspec);
@@ -827,7 +832,7 @@ public class AnnotatedDurableEntityClass {
     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(RetrieveDurableEntityError.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
+        .addException(RestoreDurableEntityError.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
         .returns(TypeName.get(m_elem.asType())).addParameter(allocparam).addParameter(phandlerparam)
         .addParameter(autoreclaimparam).addCode(code).build();
     typespecbuilder.addMethod(methodspec);
@@ -838,7 +843,7 @@ public class AnnotatedDurableEntityClass {
             factoryproxysparam.name, gfieldsparam.name, phandlerparam.name, autoreclaimparam.name)
         .addStatement("return entity").build();
     methodspec = MethodSpec.methodBuilder("restore").addTypeVariables(entityspec.typeVariables)
-        .addException(RetrieveDurableEntityError.class).addModifiers(Modifier.PUBLIC, Modifier.STATIC)
+        .addException(RestoreDurableEntityError.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);

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/43e0ddb7/mnemonic-core/src/main/java/org/apache/mnemonic/CommonDurableAllocator.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/CommonDurableAllocator.java b/mnemonic-core/src/main/java/org/apache/mnemonic/CommonDurableAllocator.java
deleted file mode 100644
index af27f22..0000000
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/CommonDurableAllocator.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * 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 abstract common class for persistent memory allocator to provide common
- * functionalities.
- *
- */
-public abstract class CommonDurableAllocator<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 this allocator supports to store durable handler or
-   * not
-   *
-   * @return true if there is
-   */
-  public boolean hasDurableHandlerStore() {
-    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 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
-   */
-  public abstract 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
-   */
-  public abstract 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
-   */
-  public abstract 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
-   */
-  public abstract long getChunkHandler(MemChunkHolder<A> mchunk);
-
-  /**
-   * start a application level transaction on this allocator.
-   *
-   */
-  public abstract void beginTransaction();
-
-  /**
-   * end a application level transaction on this allocator.
-   *
-   */
-  public abstract void endTransaction();
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/43e0ddb7/mnemonic-core/src/main/java/org/apache/mnemonic/EntityFactoryProxy.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/EntityFactoryProxy.java b/mnemonic-core/src/main/java/org/apache/mnemonic/EntityFactoryProxy.java
index 0a36b02..4711d2c 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/EntityFactoryProxy.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/EntityFactoryProxy.java
@@ -48,6 +48,6 @@ public interface EntityFactoryProxy {
    * @return the restored non-volatile object from this factory proxy
    *
    */
-  <A extends CommonDurableAllocator<A>> Durable restore(A allocator, EntityFactoryProxy[]
factoryproxys,
+  <A extends RestorableAllocator<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/43e0ddb7/mnemonic-core/src/main/java/org/apache/mnemonic/GenericField.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/GenericField.java b/mnemonic-core/src/main/java/org/apache/mnemonic/GenericField.java
index b9d1df6..37c507b 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/GenericField.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/GenericField.java
@@ -25,7 +25,7 @@ package org.apache.mnemonic;
 import sun.misc.Unsafe;
 
 @SuppressWarnings("restriction")
-public class GenericField<A extends CommonDurableAllocator<A>, E> implements
Durable {
+public class GenericField<A extends RestorableAllocator<A>, E> implements Durable
{
 
   /**
    * defines the types of generic field

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/43e0ddb7/mnemonic-core/src/main/java/org/apache/mnemonic/HandlerStore.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/HandlerStore.java b/mnemonic-core/src/main/java/org/apache/mnemonic/HandlerStore.java
new file mode 100644
index 0000000..5df0747
--- /dev/null
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/HandlerStore.java
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+public interface HandlerStore {
+
+  /**
+   * determine whether this allocator supports to store durable handler or
+   * not
+   *
+   * @return true if there is
+   */
+  boolean hasDurableHandlerStore();
+
+  long handlerCapacity();
+
+  long getHandler(long key);
+
+  void setHandler(long key, long handler);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/43e0ddb7/mnemonic-core/src/main/java/org/apache/mnemonic/MemoryDurableEntity.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/MemoryDurableEntity.java b/mnemonic-core/src/main/java/org/apache/mnemonic/MemoryDurableEntity.java
index a2c56bf..8df7140 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/MemoryDurableEntity.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/MemoryDurableEntity.java
@@ -22,7 +22,7 @@ package org.apache.mnemonic;
  *
  */
 
-public interface MemoryDurableEntity<ALLOC_PMem3C93D24F59 extends CommonDurableAllocator<ALLOC_PMem3C93D24F59>>
{
+public interface MemoryDurableEntity<ALLOC_PMem3C93D24F59 extends RestorableAllocator<ALLOC_PMem3C93D24F59>>
{
 
   void initializeDurableEntity(ALLOC_PMem3C93D24F59 allocator, EntityFactoryProxy[] efproxys,
       GenericField.GType[] gfields, boolean autoreclaim);
@@ -31,6 +31,6 @@ public interface MemoryDurableEntity<ALLOC_PMem3C93D24F59 extends CommonDurableA
       GenericField.GType[] gfields, boolean autoreclaim) throws OutOfHybridMemory;
 
   void restoreDurableEntity(ALLOC_PMem3C93D24F59 allocator, EntityFactoryProxy[] efproxys,
-      GenericField.GType[] gfields, long phandler, boolean autoreclaim) throws RetrieveDurableEntityError;
+      GenericField.GType[] gfields, long phandler, boolean autoreclaim) throws RestoreDurableEntityError;
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/43e0ddb7/mnemonic-core/src/main/java/org/apache/mnemonic/NVMAddressTranslator.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/NVMAddressTranslator.java b/mnemonic-core/src/main/java/org/apache/mnemonic/NVMAddressTranslator.java
deleted file mode 100644
index 0c4ff32..0000000
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/NVMAddressTranslator.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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
- *
- */
-public interface NVMAddressTranslator {
-
-  /**
-   * calculate the portable address
-   *
-   * @param addr
-   *          the address to be calculated
-   *
-   * @return the portable address
-   */
-  long getPortableAddress(long addr);
-
-  /**
-   * calculate the effective address
-   *
-   * @param addr
-   *          the address to be calculated
-   *
-   * @return the effective address
-   */
-  long getEffectiveAddress(long addr);
-
-  /**
-   * get the base address
-   *
-   * @return the base address
-   */
-  long getBaseAddress();
-
-  /**
-   * set the base address for calculation
-   *
-   * @param addr
-   *          the base address
-   *
-   */
-  long setBaseAddress(long addr);
-}

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/43e0ddb7/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
b/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
index 6c07c31..580f057 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/NonVolatileMemAllocator.java
@@ -29,8 +29,8 @@ import org.flowcomputing.commons.resgc.ResReclaim;
  * 
  *
  */
-public class NonVolatileMemAllocator extends CommonDurableAllocator<NonVolatileMemAllocator>
-    implements NVMAddressTranslator {
+public class NonVolatileMemAllocator extends RestorableAllocator<NonVolatileMemAllocator>
+    implements AddressTranslator {
 
   private boolean m_activegc = true;
   private long m_gctimeout = 100;
@@ -369,6 +369,16 @@ public class NonVolatileMemAllocator extends CommonDurableAllocator<NonVolatileM
   }
 
   /**
+   * determine whether the allocator supports transaction feature or not
+   *
+   * @return true if supported
+   */
+  @Override
+  public boolean supportTransaction() {
+    return false;
+  }
+
+  /**
    * start a application level transaction on this allocator. (it is a place
    * holder)
    *
@@ -389,6 +399,17 @@ public class NonVolatileMemAllocator extends CommonDurableAllocator<NonVolatileM
   }
 
   /**
+   * determine whether the allocator does atomic operations on memory pool
+   *
+   * @return true if it does
+   *
+   */
+  @Override
+  public boolean isAtomicOperation() {
+    return false;
+  }
+
+  /**
    * set a handler on key.
    * 
    * @param key
@@ -397,6 +418,7 @@ public class NonVolatileMemAllocator extends CommonDurableAllocator<NonVolatileM
    * @param handler
    *          the handler
    */
+  @Override
   public void setHandler(long key, long handler) {
     m_nvmasvc.setHandler(m_nid, key, handler);
   }
@@ -409,6 +431,7 @@ public class NonVolatileMemAllocator extends CommonDurableAllocator<NonVolatileM
    * 
    * @return the value of handler
    */
+  @Override
   public long getHandler(long key) {
     return m_nvmasvc.getHandler(m_nid, key);
   }

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/43e0ddb7/mnemonic-core/src/main/java/org/apache/mnemonic/RestorableAllocator.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/RestorableAllocator.java b/mnemonic-core/src/main/java/org/apache/mnemonic/RestorableAllocator.java
new file mode 100644
index 0000000..7410c4d
--- /dev/null
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/RestorableAllocator.java
@@ -0,0 +1,22 @@
+/*
+ * 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;
+
+public abstract class RestorableAllocator<A extends RetrievableAllocator<A>>
extends RetrievableAllocator<A> {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/43e0ddb7/mnemonic-core/src/main/java/org/apache/mnemonic/RestoreDurableEntityError.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/RestoreDurableEntityError.java
b/mnemonic-core/src/main/java/org/apache/mnemonic/RestoreDurableEntityError.java
new file mode 100644
index 0000000..1c64ffe
--- /dev/null
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/RestoreDurableEntityError.java
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+/**
+ *
+ *
+ */
+
+public class RestoreDurableEntityError extends RuntimeException {
+
+  /**
+   *
+   */
+  private static final long serialVersionUID = -2433590448661478594L;
+
+  /**
+   *
+   */
+
+  public RestoreDurableEntityError(String s) {
+    super(s);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/43e0ddb7/mnemonic-core/src/main/java/org/apache/mnemonic/RetrievableAllocator.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/RetrievableAllocator.java b/mnemonic-core/src/main/java/org/apache/mnemonic/RetrievableAllocator.java
new file mode 100644
index 0000000..8140aa6
--- /dev/null
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/RetrievableAllocator.java
@@ -0,0 +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;
+
+public abstract class RetrievableAllocator<A extends CommonAllocator<A>> extends
CommonAllocator<A>
+  implements AddressTranslator, HandlerStore, Transaction {
+
+  /**
+   * 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 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
+   */
+  public abstract 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
+   */
+  public abstract 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
+   */
+  public abstract 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
+   */
+  public abstract long getChunkHandler(MemChunkHolder<A> mchunk);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/43e0ddb7/mnemonic-core/src/main/java/org/apache/mnemonic/Transaction.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/Transaction.java b/mnemonic-core/src/main/java/org/apache/mnemonic/Transaction.java
new file mode 100644
index 0000000..d054ac8
--- /dev/null
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/Transaction.java
@@ -0,0 +1,49 @@
+/*
+ * 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;
+
+public interface Transaction {
+
+  /**
+   * determine whether the allocator supports transaction feature or not
+   *
+   * @return true if supported
+   */
+  boolean supportTransaction();
+
+  /**
+   * determine whether the allocator does atomic operations on memory pool
+   *
+   * @return true if it does
+   *
+   */
+  boolean isAtomicOperation();
+
+  /**
+   * start a application level transaction on this allocator.
+   *
+   */
+  void beginTransaction();
+
+  /**
+   * end a application level transaction on this allocator.
+   *
+   */
+  void endTransaction();
+
+}



Mime
View raw message