mnemonic-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject [2/2] incubator-mnemonic git commit: MNEMONIC-185: Hide contained durable object factories for creation
Date Thu, 26 Jan 2017 21:57:09 GMT
MNEMONIC-185: Hide contained durable object factories for creation


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

Branch: refs/heads/0.5.0-dev
Commit: b2d186022089ba5390822626c44102b3a6d5971e
Parents: 8ca921c
Author: Wang, Gang(Gary) <gang1.wang@intel.com>
Authored: Thu Jan 26 10:15:56 2017 -0800
Committer: Wang, Gang(Gary) <gang1.wang@intel.com>
Committed: Thu Jan 26 13:51:13 2017 -0800

----------------------------------------------------------------------
 .../DurableSinglyLinkedListNGTest.java          | 42 +++++++++++++++++---
 .../DurableSinglyLinkedListNGPrintTest.java     | 22 +++++++++-
 .../DurableSinglyLinkedListNGSortTest.java      | 22 +++++++++-
 .../apache/mnemonic/ConfigurationException.java | 29 ++++++++++++++
 .../org/apache/mnemonic/EntityFactoryProxy.java | 28 ++++++++++++-
 .../main/java/org/apache/mnemonic/Utils.java    | 24 +++++++++++
 6 files changed, 158 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/b2d18602/mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableSinglyLinkedListNGTest.java
----------------------------------------------------------------------
diff --git a/mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableSinglyLinkedListNGTest.java
b/mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableSinglyLinkedListNGTest.java
index b90dc81..09e00d7 100644
--- a/mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableSinglyLinkedListNGTest.java
+++ b/mnemonic-collections/src/test/java/org/apache/mnemonic/collections/DurableSinglyLinkedListNGTest.java
@@ -108,18 +108,26 @@ public class DurableSinglyLinkedListNGTest {
   @Test(enabled = false)
   public void testNodeValueWithPerson() {
 
-    Person<Long> person = PersonFactory.create(m_act);
-    person.setAge((short) 31);
-
     DurableType gtypes[] = {DurableType.DURABLE};
     EntityFactoryProxy efproxies[] = {new EntityFactoryProxy() {
       @Override
-      public <A extends RestorableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
+      public <A extends RestorableAllocator<A>> Person<Long> restore(
+          A allocator, EntityFactoryProxy[] factoryproxys,
           DurableType[] gfields, long phandler, boolean autoreclaim) {
         return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
       }
+      @Override
+      public <A extends RestorableAllocator<A>> Person<Long> create(
+          A allocator, EntityFactoryProxy[] factoryproxys,
+          DurableType[] gfields, boolean autoreclaim) {
+        return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim);
+      }
     } };
 
+    @SuppressWarnings("unchecked")
+    Person<Long> person =  (Person<Long>) efproxies[0].create(m_act, null, null,
false);
+    person.setAge((short) 31);
+
     DurableSinglyLinkedList<Person<Long>> plln = DurableSinglyLinkedListFactory.create(m_act,
efproxies, gtypes, false);
     plln.setItem(person, false);
     Long handler = plln.getHandler();
@@ -130,6 +138,7 @@ public class DurableSinglyLinkedListNGTest {
 
   }
 
+  @SuppressWarnings("unchecked")
   @Test(enabled = false)
   public void testLinkedNodeValueWithPerson() {
 
@@ -139,10 +148,17 @@ public class DurableSinglyLinkedListNGTest {
     DurableType listgftypes[] = {DurableType.DURABLE};
     EntityFactoryProxy listefproxies[] = {new EntityFactoryProxy() {
       @Override
-      public <A extends RestorableAllocator<A>> Durable restore(A allocator,
EntityFactoryProxy[] factoryproxys,
+      public <A extends RestorableAllocator<A>> Person<Long> restore(
+          A allocator, EntityFactoryProxy[] factoryproxys,
           DurableType[] gfields, long phandler, boolean autoreclaim) {
         return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
       }
+      @Override
+      public <A extends RestorableAllocator<A>> Person<Long> create(
+          A allocator, EntityFactoryProxy[] factoryproxys,
+          DurableType[] gfields, boolean autoreclaim) {
+        return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim);
+      }
     } };
 
     DurableSinglyLinkedList<Person<Long>> firstnv = DurableSinglyLinkedListFactory.create(m_act,
listefproxies, 
@@ -154,7 +170,7 @@ public class DurableSinglyLinkedListNGTest {
     long val;
     DurableSinglyLinkedList<Person<Long>> newnv;
     for (int i = 0; i < elem_count; ++i) {
-      person = PersonFactory.create(m_act);
+      person = (Person<Long>) listefproxies[0].create(m_act, null, null, false);
       person.setAge((short) m_rand.nextInt(50));
       person.setName(String.format("Name: [%s]", Utils.genRandomString()), true);
       nextnv.setItem(person, false);
@@ -214,6 +230,20 @@ public class DurableSinglyLinkedListNGTest {
         }
         return DurableSinglyLinkedListFactory.restore(allocator, val_efproxies, val_gftypes,
phandler, autoreclaim);
       }
+      @Override
+      public <A extends RestorableAllocator<A>> Durable create(
+          A allocator, EntityFactoryProxy[] factoryproxys,
+          DurableType[] gfields, boolean autoreclaim) {
+        EntityFactoryProxy[] val_efproxies = null;
+        DurableType[] 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 DurableSinglyLinkedListFactory.create(allocator, val_efproxies, val_gftypes,
autoreclaim);
+      }
     } };
 
     DurableSinglyLinkedList<DurableSinglyLinkedList<Double>> nextnv = null, pre_nextnv
= null;

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/b2d18602/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGPrintTest.java
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGPrintTest.java
b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGPrintTest.java
index 7a4038e..b64bfe2 100644
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGPrintTest.java
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGPrintTest.java
@@ -66,6 +66,7 @@ public class DurableSinglyLinkedListNGPrintTest {
     m_act.close();
   }
 
+  @SuppressWarnings("unchecked")
   @Test(enabled = true)
   public void testDurableSinglyLinkedListWithPerson() {
 
@@ -78,6 +79,12 @@ public class DurableSinglyLinkedListNGPrintTest {
           DurableType[] gfields, long phandler, boolean autoreclaim) {
         return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
       }
+      @Override
+      public <A extends RestorableAllocator<A>> Durable create(
+          A allocator, EntityFactoryProxy[] factoryproxys,
+          DurableType[] gfields, boolean autoreclaim) {
+        return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim);
+      }
     } };
 
     DurableSinglyLinkedList<Person<Long>> firstnv = DurableSinglyLinkedListFactory.create(m_act,
listefproxies, 
@@ -89,7 +96,7 @@ public class DurableSinglyLinkedListNGPrintTest {
     long val;
     DurableSinglyLinkedList<Person<Long>> newnv;
     for (int i = 0; i < elem_count; ++i) {
-      person = PersonFactory.create(m_act);
+      person = (Person<Long>) listefproxies[0].create(m_act, null, null, false);
       person.setAge((short) m_rand.nextInt(50));
       person.setName(String.format("Name: [%s]", Utils.genRandomString()), true);
       nextnv.setItem(person, false);
@@ -165,6 +172,19 @@ public class DurableSinglyLinkedListNGPrintTest {
         }
         return DurableSinglyLinkedListFactory.restore(allocator, val_efproxies, val_gftypes,
phandler, autoreclaim);
       }
+      @Override
+      public <A extends RestorableAllocator<A>> Durable create(A allocator, EntityFactoryProxy[]
factoryproxys,
+          DurableType[] gfields, boolean autoreclaim) {
+        EntityFactoryProxy[] val_efproxies = null;
+        DurableType[] 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 DurableSinglyLinkedListFactory.create(allocator, val_efproxies, val_gftypes,
autoreclaim);
+      }
     } };
 
     DurableSinglyLinkedList<DurableSinglyLinkedList<Double>> nextnv = null, pre_nextnv
= null;

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/b2d18602/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGSortTest.java
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGSortTest.java
b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGSortTest.java
index 1697341..9389d74 100644
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGSortTest.java
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computingservice/DurableSinglyLinkedListNGSortTest.java
@@ -67,6 +67,7 @@ public class DurableSinglyLinkedListNGSortTest {
     m_act.close();
   }
 
+  @SuppressWarnings("unchecked")
   @Test(enabled = true)
   public void testDurableSinglyLinkedListWithPerson() {
 
@@ -79,6 +80,12 @@ public class DurableSinglyLinkedListNGSortTest {
           DurableType[] gfields, long phandler, boolean autoreclaim) {
         return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim);
       }
+      @Override
+      public <A extends RestorableAllocator<A>> Durable create(
+          A allocator, EntityFactoryProxy[] factoryproxys,
+          DurableType[] gfields, boolean autoreclaim) {
+        return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim);
+      }
     } };
 
     DurableSinglyLinkedList<Person<Long>> firstnv = DurableSinglyLinkedListFactory.create(m_act,
listefproxies, 
@@ -90,7 +97,7 @@ public class DurableSinglyLinkedListNGSortTest {
     long val;
     DurableSinglyLinkedList<Person<Long>> newnv;
     for (int i = 0; i < elem_count; ++i) {
-      person = PersonFactory.create(m_act);
+      person = (Person<Long>) listefproxies[0].create(m_act, null, null, false);
       person.setAge((short) m_rand.nextInt(50));
       person.setName(String.format("Name: [%s]", Utils.genRandomString()), true);
       nextnv.setItem(person, false);
@@ -190,6 +197,19 @@ public class DurableSinglyLinkedListNGSortTest {
         }
         return DurableSinglyLinkedListFactory.restore(allocator, val_efproxies, val_gftypes,
phandler, autoreclaim);
       }
+      @Override
+      public <A extends RestorableAllocator<A>> Durable create(A allocator, EntityFactoryProxy[]
factoryproxys,
+          DurableType[] gfields, boolean autoreclaim) {
+        EntityFactoryProxy[] val_efproxies = null;
+        DurableType[] 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 DurableSinglyLinkedListFactory.create(allocator, val_efproxies, val_gftypes,
autoreclaim);
+      }
     } };
 
     DurableSinglyLinkedList<DurableSinglyLinkedList<Double>> nextnv = null, pre_nextnv
= null;

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

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/b2d18602/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 5cee281..ce65fee 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/EntityFactoryProxy.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/EntityFactoryProxy.java
@@ -18,11 +18,37 @@
 package org.apache.mnemonic;
 
 /**
- * proxy the restoring of generic non-volatile object fields
+ * delegate the restoration/creation of generic non-volatile object fields
  *
  */
 
 public interface EntityFactoryProxy {
+  /**
+   * create a durable object from persistent allocator using a handler of
+   * non-volatile object
+   *
+   * @param <A>
+   *          indicates that for this instantiation of the allocator.
+   *
+   * @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 factory proxies
+   *
+   * @param autoreclaim
+   *          specify auto-reclaim for this restored non-volatile object
+   *
+   * @return the created non-volatile object from this factory proxy
+   *
+   */
+  <A extends RestorableAllocator<A>> Durable create(A allocator, EntityFactoryProxy[]
factoryproxys,
+      DurableType[] gfields, boolean autoreclaim);
 
   /**
    * restore a durable object from persistent allocator using a handler of

http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/b2d18602/mnemonic-core/src/main/java/org/apache/mnemonic/Utils.java
----------------------------------------------------------------------
diff --git a/mnemonic-core/src/main/java/org/apache/mnemonic/Utils.java b/mnemonic-core/src/main/java/org/apache/mnemonic/Utils.java
index 3aab83a..c448138 100644
--- a/mnemonic-core/src/main/java/org/apache/mnemonic/Utils.java
+++ b/mnemonic-core/src/main/java/org/apache/mnemonic/Utils.java
@@ -472,4 +472,28 @@ public class Utils {
     }
     return ret;
   }
+
+  /**
+   * instantiate an array of entity factory proxy classes.
+   *
+   * @param proxyclses
+   *          an array of entity factory proxy classes
+   *
+   * @return the array of instances
+   */
+  public static EntityFactoryProxy[] instantiateEntityFactoryProxies(Class<?>[] proxyclses)
{
+    List<EntityFactoryProxy> ret = new ArrayList<EntityFactoryProxy>();
+    try {
+      for (Class<?> itm : proxyclses) {
+        if (EntityFactoryProxy.class.isAssignableFrom(itm)) {
+            ret.add((EntityFactoryProxy)itm.newInstance());
+        } else {
+          throw new ConfigurationException(String.format("%s is not EntityFactoryProxy",
itm.getName()));
+        }
+      }
+    } catch (InstantiationException | IllegalAccessException e) {
+      throw new IllegalArgumentException("Failed to instantiate assigned EntityFactoryProxy
classes.", e);
+    }
+    return ret.toArray(new EntityFactoryProxy[0]);
+  }
 }


Mime
View raw message