Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 19401200C08 for ; Thu, 26 Jan 2017 22:57:16 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 1800A160B50; Thu, 26 Jan 2017 21:57:16 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id EEDAC160B31 for ; Thu, 26 Jan 2017 22:57:14 +0100 (CET) Received: (qmail 67699 invoked by uid 500); 26 Jan 2017 21:57:14 -0000 Mailing-List: contact commits-help@mnemonic.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mnemonic.incubator.apache.org Delivered-To: mailing list commits@mnemonic.incubator.apache.org Received: (qmail 67690 invoked by uid 99); 26 Jan 2017 21:57:14 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Jan 2017 21:57:14 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id A65C3C18F1 for ; Thu, 26 Jan 2017 21:57:13 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.218 X-Spam-Level: X-Spam-Status: No, score=-6.218 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id NVKG1v9rHkrn for ; Thu, 26 Jan 2017 21:57:10 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id E29B55F47A for ; Thu, 26 Jan 2017 21:57:08 +0000 (UTC) Received: (qmail 67445 invoked by uid 99); 26 Jan 2017 21:57:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Jan 2017 21:57:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0C0A8DFCC0; Thu, 26 Jan 2017 21:57:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: garyw@apache.org To: commits@mnemonic.incubator.apache.org Date: Thu, 26 Jan 2017 21:57:09 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/2] incubator-mnemonic git commit: MNEMONIC-185: Hide contained durable object factories for creation archived-at: Thu, 26 Jan 2017 21:57:16 -0000 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) Authored: Thu Jan 26 10:15:56 2017 -0800 Committer: Wang, Gang(Gary) 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 person = PersonFactory.create(m_act); - person.setAge((short) 31); - DurableType gtypes[] = {DurableType.DURABLE}; EntityFactoryProxy efproxies[] = {new EntityFactoryProxy() { @Override - public > Durable restore(A allocator, EntityFactoryProxy[] factoryproxys, + public > Person restore( + A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields, long phandler, boolean autoreclaim) { return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim); } + @Override + public > Person create( + A allocator, EntityFactoryProxy[] factoryproxys, + DurableType[] gfields, boolean autoreclaim) { + return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim); + } } }; + @SuppressWarnings("unchecked") + Person person = (Person) efproxies[0].create(m_act, null, null, false); + person.setAge((short) 31); + DurableSinglyLinkedList> 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 > Durable restore(A allocator, EntityFactoryProxy[] factoryproxys, + public > Person restore( + A allocator, EntityFactoryProxy[] factoryproxys, DurableType[] gfields, long phandler, boolean autoreclaim) { return PersonFactory.restore(allocator, factoryproxys, gfields, phandler, autoreclaim); } + @Override + public > Person create( + A allocator, EntityFactoryProxy[] factoryproxys, + DurableType[] gfields, boolean autoreclaim) { + return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim); + } } }; DurableSinglyLinkedList> firstnv = DurableSinglyLinkedListFactory.create(m_act, listefproxies, @@ -154,7 +170,7 @@ public class DurableSinglyLinkedListNGTest { long val; DurableSinglyLinkedList> newnv; for (int i = 0; i < elem_count; ++i) { - person = PersonFactory.create(m_act); + person = (Person) 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 > 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> 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 > Durable create( + A allocator, EntityFactoryProxy[] factoryproxys, + DurableType[] gfields, boolean autoreclaim) { + return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim); + } } }; DurableSinglyLinkedList> firstnv = DurableSinglyLinkedListFactory.create(m_act, listefproxies, @@ -89,7 +96,7 @@ public class DurableSinglyLinkedListNGPrintTest { long val; DurableSinglyLinkedList> newnv; for (int i = 0; i < elem_count; ++i) { - person = PersonFactory.create(m_act); + person = (Person) 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 > 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> 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 > Durable create( + A allocator, EntityFactoryProxy[] factoryproxys, + DurableType[] gfields, boolean autoreclaim) { + return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim); + } } }; DurableSinglyLinkedList> firstnv = DurableSinglyLinkedListFactory.create(m_act, listefproxies, @@ -90,7 +97,7 @@ public class DurableSinglyLinkedListNGSortTest { long val; DurableSinglyLinkedList> newnv; for (int i = 0; i < elem_count; ++i) { - person = PersonFactory.create(m_act); + person = (Person) 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 > 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> 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 + * 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 + * + */ + > 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 ret = new ArrayList(); + 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]); + } }