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 2017/08/10 22:33:34 UTC
[5/5] incubator-mnemonic git commit: MNEMONIC-330: Refactor service
package name
MNEMONIC-330: Refactor service package name
Project: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/commit/a4bb10eb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/tree/a4bb10eb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/diff/a4bb10eb
Branch: refs/heads/master
Commit: a4bb10ebdd40018209b1513406567a36d01b15db
Parents: cda2b43
Author: Wang, Gang(Gary) <ga...@intel.com>
Authored: Thu Aug 10 12:57:09 2017 -0700
Committer: Wang, Gang(Gary) <ga...@intel.com>
Committed: Thu Aug 10 14:48:41 2017 -0700
----------------------------------------------------------------------
.../apache/mnemonic/bench/DNCSTextFileSort.java | 18 +-
.../computing/internal/PrintServiceImpl.java | 60 +++
.../computing/internal/SortServiceImpl.java | 66 +++
.../internal/PrintServiceImpl.java | 60 ---
.../internal/SortServiceImpl.java | 66 ---
.../src/main/native/CMakeLists.txt | 4 +-
.../src/main/native/common.c | 2 +-
...ervice_computing_internal_PrintServiceImpl.c | 106 +++++
...ervice_computing_internal_PrintServiceImpl.h | 48 +++
...service_computing_internal_SortServiceImpl.c | 249 +++++++++++
...service_computing_internal_SortServiceImpl.h | 48 +++
...computingservice_internal_PrintServiceImpl.c | 106 -----
...computingservice_internal_PrintServiceImpl.h | 48 ---
..._computingservice_internal_SortServiceImpl.c | 249 -----------
..._computingservice_internal_SortServiceImpl.h | 48 ---
...ic.service.computing.GeneralComputingService | 2 +
...ice.computingservice.GeneralComputingService | 2 -
.../DurableSinglyLinkedListNGPrintTest.java | 271 ++++++++++++
.../DurableSinglyLinkedListNGSortTest.java | 323 +++++++++++++++
.../mnemonic/service/computing/Person.java | 99 +++++
.../DurableSinglyLinkedListNGPrintTest.java | 271 ------------
.../DurableSinglyLinkedListNGSortTest.java | 323 ---------------
.../service/computingservice/Person.java | 99 -----
.../src/test/resources/testng.xml | 4 +-
.../mnemonic/NonVolatileMemAllocator.java | 4 +-
.../main/java/org/apache/mnemonic/Utils.java | 18 +-
.../apache/mnemonic/VolatileMemAllocator.java | 13 +-
.../mnemonic/query/memory/AttributeInfo.java | 62 +++
.../mnemonic/query/memory/EntityInfo.java | 50 +++
.../apache/mnemonic/query/memory/Queryable.java | 115 ++++++
.../apache/mnemonic/query/memory/ResultSet.java | 43 ++
.../apache/mnemonic/query/memory/SortOrder.java | 35 ++
.../computing/GeneralComputingService.java | 51 +++
.../mnemonic/service/computing/ValueInfo.java | 44 ++
.../GeneralComputingService.java | 51 ---
.../service/computingservice/ValueInfo.java | 44 --
.../service/memory/MemoryServiceFeature.java | 36 ++
.../NonVolatileMemoryAllocatorService.java | 157 +++++++
.../service/memory/QueryableService.java | 20 +
.../memory/VolatileMemoryAllocatorService.java | 308 ++++++++++++++
.../memoryservice/MemoryServiceFeature.java | 36 --
.../NonVolatileMemoryAllocatorService.java | 157 -------
.../VolatileMemoryAllocatorService.java | 308 --------------
.../src/test/resources/testng.xml | 2 +-
.../memory/internal/JavaVMemServiceImpl.java | 238 +++++++++++
.../internal/JavaVMemServiceImpl.java | 238 -----------
...ervice.memory.VolatileMemoryAllocatorService | 1 +
...memoryservice.VolatileMemoryAllocatorService | 1 -
.../internal/JavaVMemServiceImplNGTest.java | 155 +++++++
.../internal/JavaVMemServiceImplNGTest.java | 154 -------
.../src/test/resources/testng.xml | 2 +-
.../memory/internal/PMemServiceImpl.java | 215 ++++++++++
.../memoryservice/internal/PMemServiceImpl.java | 215 ----------
.../src/main/native/CMakeLists.txt | 2 +-
...ic_service_memory_internal_PMemServiceImpl.c | 414 +++++++++++++++++++
...ic_service_memory_internal_PMemServiceImpl.h | 48 +++
...ice_memoryservice_internal_PMemServiceImpl.c | 414 -------------------
...ice_memoryservice_internal_PMemServiceImpl.h | 48 ---
...ice.memory.NonVolatileMemoryAllocatorService | 1 +
...oryservice.NonVolatileMemoryAllocatorService | 1 -
.../memory/internal/VMemServiceImpl.java | 201 +++++++++
.../memoryservice/internal/VMemServiceImpl.java | 201 ---------
.../src/main/native/CMakeLists.txt | 2 +-
...ic_service_memory_internal_VMemServiceImpl.c | 279 +++++++++++++
...ic_service_memory_internal_VMemServiceImpl.h | 48 +++
...ice_memoryservice_internal_VMemServiceImpl.c | 279 -------------
...ice_memoryservice_internal_VMemServiceImpl.h | 48 ---
...ervice.memory.VolatileMemoryAllocatorService | 1 +
...memoryservice.VolatileMemoryAllocatorService | 1 -
.../memory/internal/PMallocServiceImpl.java | 215 ++++++++++
.../internal/PMallocServiceImpl.java | 215 ----------
.../src/main/native/CMakeLists.txt | 2 +-
...service_memory_internal_PMallocServiceImpl.c | 378 +++++++++++++++++
...service_memory_internal_PMallocServiceImpl.h | 48 +++
..._memoryservice_internal_PMallocServiceImpl.c | 378 -----------------
..._memoryservice_internal_PMallocServiceImpl.h | 48 ---
...ice.memory.NonVolatileMemoryAllocatorService | 1 +
...oryservice.NonVolatileMemoryAllocatorService | 1 -
.../memory/internal/SysVMemServiceImpl.java | 201 +++++++++
.../internal/SysVMemServiceImpl.java | 201 ---------
.../src/main/native/CMakeLists.txt | 2 +-
...service_memory_internal_SysVMemServiceImpl.c | 238 +++++++++++
...service_memory_internal_SysVMemServiceImpl.h | 48 +++
..._memoryservice_internal_SysVMemServiceImpl.c | 238 -----------
..._memoryservice_internal_SysVMemServiceImpl.h | 48 ---
...ervice.memory.VolatileMemoryAllocatorService | 1 +
...memoryservice.VolatileMemoryAllocatorService | 1 -
.../mnemonic/query/memory/AttributeInfo.java | 62 ---
.../mnemonic/query/memory/EntityInfo.java | 50 ---
.../apache/mnemonic/query/memory/Queryable.java | 115 ------
.../apache/mnemonic/query/memory/ResultSet.java | 43 --
.../apache/mnemonic/query/memory/SortOrder.java | 35 --
.../src/test/resources/testng.xml | 2 +-
93 files changed, 4967 insertions(+), 4937 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-benches/mnemonic-sort-bench/src/main/java/org/apache/mnemonic/bench/DNCSTextFileSort.java
----------------------------------------------------------------------
diff --git a/mnemonic-benches/mnemonic-sort-bench/src/main/java/org/apache/mnemonic/bench/DNCSTextFileSort.java b/mnemonic-benches/mnemonic-sort-bench/src/main/java/org/apache/mnemonic/bench/DNCSTextFileSort.java
index 09f069e..1993d12 100644
--- a/mnemonic-benches/mnemonic-sort-bench/src/main/java/org/apache/mnemonic/bench/DNCSTextFileSort.java
+++ b/mnemonic-benches/mnemonic-sort-bench/src/main/java/org/apache/mnemonic/bench/DNCSTextFileSort.java
@@ -17,6 +17,15 @@
package org.apache.mnemonic.bench;
+import org.apache.mnemonic.DurableType;
+import org.apache.mnemonic.EntityFactoryProxy;
+import org.apache.mnemonic.Utils;
+import org.apache.mnemonic.VolatileMemAllocator;
+import org.apache.mnemonic.collections.DurableSinglyLinkedList;
+import org.apache.mnemonic.collections.DurableSinglyLinkedListFactory;
+import org.apache.mnemonic.service.computing.GeneralComputingService;
+import org.apache.mnemonic.service.computing.ValueInfo;
+
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
@@ -24,15 +33,6 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import org.apache.mnemonic.VolatileMemAllocator;
-import org.apache.mnemonic.EntityFactoryProxy;
-import org.apache.mnemonic.Utils;
-import org.apache.mnemonic.DurableType;
-import org.apache.mnemonic.collections.DurableSinglyLinkedList;
-import org.apache.mnemonic.collections.DurableSinglyLinkedListFactory;
-import org.apache.mnemonic.service.computingservice.GeneralComputingService;
-import org.apache.mnemonic.service.computingservice.ValueInfo;
-
public class DNCSTextFileSort implements TextFileSort {
private String uri = "";
private VolatileMemAllocator m_act = null;
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computing/internal/PrintServiceImpl.java
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computing/internal/PrintServiceImpl.java b/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computing/internal/PrintServiceImpl.java
new file mode 100644
index 0000000..dc9a968
--- /dev/null
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computing/internal/PrintServiceImpl.java
@@ -0,0 +1,60 @@
+/*
+ * 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.computing.internal;
+
+import org.apache.mnemonic.service.computing.GeneralComputingService;
+import org.apache.mnemonic.service.computing.ValueInfo;
+import org.flowcomputing.commons.primitives.NativeLibraryLoader;
+
+public class PrintServiceImpl implements GeneralComputingService {
+ static {
+ try {
+ NativeLibraryLoader.loadFromJar("utilitiescomputing");
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getServiceId() {
+ return "print";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public long[] perform(String mode, ValueInfo[] valinfos) {
+ long[] ret = null;
+ if (null != valinfos) {
+ ret = nperformPrint(valinfos);
+ }
+ return ret;
+ }
+
+ /**
+ * A native function to fulfill the action of print in native level.
+ * @param valinfos an array of value info, some of them could be set as NULL
+ * @return an array of handler returned by native level
+ */
+ protected native long[] nperformPrint(ValueInfo[] valinfos);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computing/internal/SortServiceImpl.java
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computing/internal/SortServiceImpl.java b/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computing/internal/SortServiceImpl.java
new file mode 100644
index 0000000..a35a74b
--- /dev/null
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computing/internal/SortServiceImpl.java
@@ -0,0 +1,66 @@
+/*
+ * 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.computing.internal;
+
+import org.apache.mnemonic.service.computing.GeneralComputingService;
+import org.apache.mnemonic.service.computing.ValueInfo;
+import org.flowcomputing.commons.primitives.NativeLibraryLoader;
+
+public class SortServiceImpl implements GeneralComputingService {
+ static {
+ try {
+ NativeLibraryLoader.loadFromJar("utilitiescomputing");
+ } catch (Exception e) {
+ throw new Error(e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getServiceId() {
+ return "sort";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public long[] perform(String mode, ValueInfo[] valinfos) {
+ long[] ret = null;
+ if (null != mode && null != valinfos) {
+ if ("tensor_bubble".equals(mode)) {
+ ret = nperformBubbleSort(valinfos);
+ } else if ("1dlong_bubble".equals(mode)) {
+ ret = nperform1DLongBubbleSort(valinfos);
+ }
+ }
+ return ret;
+ }
+
+ /**
+ * A native function to fulfill the action of print in native level.
+ * @param valinfos an array of value info, some of them could be set as NULL
+ * @return an array of handler returned by native level
+ */
+ protected native long[] nperformBubbleSort(ValueInfo[] valinfos);
+
+ protected native long[] nperform1DLongBubbleSort(ValueInfo[] valinfos);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computingservice/internal/PrintServiceImpl.java
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computingservice/internal/PrintServiceImpl.java b/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computingservice/internal/PrintServiceImpl.java
deleted file mode 100644
index ef82755..0000000
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computingservice/internal/PrintServiceImpl.java
+++ /dev/null
@@ -1,60 +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.service.computingservice.internal;
-
-import org.apache.mnemonic.service.computingservice.GeneralComputingService;
-import org.apache.mnemonic.service.computingservice.ValueInfo;
-import org.flowcomputing.commons.primitives.NativeLibraryLoader;
-
-public class PrintServiceImpl implements GeneralComputingService {
- static {
- try {
- NativeLibraryLoader.loadFromJar("utilitiescomputing");
- } catch (Exception e) {
- throw new Error(e);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getServiceId() {
- return "print";
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public long[] perform(String mode, ValueInfo[] valinfos) {
- long[] ret = null;
- if (null != valinfos) {
- ret = nperformPrint(valinfos);
- }
- return ret;
- }
-
- /**
- * A native function to fulfill the action of print in native level.
- * @param valinfos an array of value info, some of them could be set as NULL
- * @return an array of handler returned by native level
- */
- protected native long[] nperformPrint(ValueInfo[] valinfos);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computingservice/internal/SortServiceImpl.java
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computingservice/internal/SortServiceImpl.java b/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computingservice/internal/SortServiceImpl.java
deleted file mode 100644
index b866506..0000000
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/main/java/org/apache/mnemonic/service/computingservice/internal/SortServiceImpl.java
+++ /dev/null
@@ -1,66 +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.service.computingservice.internal;
-
-import org.apache.mnemonic.service.computingservice.GeneralComputingService;
-import org.apache.mnemonic.service.computingservice.ValueInfo;
-import org.flowcomputing.commons.primitives.NativeLibraryLoader;
-
-public class SortServiceImpl implements GeneralComputingService {
- static {
- try {
- NativeLibraryLoader.loadFromJar("utilitiescomputing");
- } catch (Exception e) {
- throw new Error(e);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getServiceId() {
- return "sort";
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public long[] perform(String mode, ValueInfo[] valinfos) {
- long[] ret = null;
- if (null != mode && null != valinfos) {
- if ("tensor_bubble".equals(mode)) {
- ret = nperformBubbleSort(valinfos);
- } else if ("1dlong_bubble".equals(mode)) {
- ret = nperform1DLongBubbleSort(valinfos);
- }
- }
- return ret;
- }
-
- /**
- * A native function to fulfill the action of print in native level.
- * @param valinfos an array of value info, some of them could be set as NULL
- * @return an array of handler returned by native level
- */
- protected native long[] nperformBubbleSort(ValueInfo[] valinfos);
-
- protected native long[] nperform1DLongBubbleSort(ValueInfo[] valinfos);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/CMakeLists.txt b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/CMakeLists.txt
index ccb878d..916ff10 100644
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/CMakeLists.txt
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/CMakeLists.txt
@@ -37,8 +37,8 @@ find_package(Threads REQUIRED)
include_directories(${CMAKE_THREAD_LIBS_INIT})
add_library(utilitiescomputing SHARED common.c
- org_apache_mnemonic_service_computingservice_internal_SortServiceImpl.c
- org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl.c)
+ org_apache_mnemonic_service_computing_internal_SortServiceImpl.c
+ org_apache_mnemonic_service_computing_internal_PrintServiceImpl.c)
target_include_directories(utilitiescomputing PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
include (InstallRequiredSystemLibraries)
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/common.c
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/common.c b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/common.c
index 1bf50d1..3091b1e 100644
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/common.c
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/common.c
@@ -76,7 +76,7 @@ struct NValueInfo *constructNValInfo(JNIEnv* env, jobject vinfoobj) {
if (0 == inited) {
inited = 1;
- vinfocls = (*env)->FindClass(env, "org/apache/mnemonic/service/computingservice/ValueInfo");
+ vinfocls = (*env)->FindClass(env, "org/apache/mnemonic/service/computing/ValueInfo");
dutenum = (*env)->FindClass(env, "org/apache/mnemonic/DurableType");
if (NULL != vinfocls && NULL != dutenum) {
handler_fid = (*env)->GetFieldID(env, vinfocls, "handler", "J");
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_PrintServiceImpl.c
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_PrintServiceImpl.c b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_PrintServiceImpl.c
new file mode 100644
index 0000000..0b0fb6c
--- /dev/null
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_PrintServiceImpl.c
@@ -0,0 +1,106 @@
+/**
+ * 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_computing_internal_PrintServiceImpl.h"
+
+/******************************************************************************
+ ** JNI implementations
+ *****************************************************************************/
+
+/**
+ * a customized handler as value handler.
+ * It handles would be used to iteratively callback for each value of a value matrix
+ */
+void valPrintHandler(JNIEnv* env, size_t dims[], size_t dimidx,
+ long *itmaddrs[], long *(* const nxtfitmaddrs)[], long (* const pendings)[],
+ void *addr, size_t sz, int dtype) {
+ size_t i;
+ if (0 == dims[dimidx]) {
+ printf("\n");
+ }
+ for (i = 0; i <= dimidx; ++i) {
+ printf("[%zu]", dims[i]);
+ }
+ printf(" <%p, %p> ", itmaddrs[dimidx], (*nxtfitmaddrs)[dimidx]);
+ switch(dtype) {
+ case DURABLE_BOOLEAN:
+ printf(" %s, ", (0 == *(char*)addr ? "T" : "F"));
+ break;
+ case DURABLE_CHARACTER:
+ printf(" %c, ", *(char*)addr);
+ break;
+ case DURABLE_BYTE:
+ printf(" %d, ", *(char*)addr);
+ break;
+ case DURABLE_SHORT:
+ printf(" %d, ", *(short*)addr);
+ break;
+ case DURABLE_INTEGER:
+ printf(" %d, ", *(int*)addr);
+ break;
+ case DURABLE_LONG:
+ printf(" %ld, ", *(long*)addr);
+ break;
+ case DURABLE_FLOAT:
+ printf(" %f, ", *(float*)addr);
+ break;
+ case DURABLE_DOUBLE:
+ printf(" %f, ", *(double*)addr);
+ break;
+ default:
+ printf(" (NA), ");
+ }
+}
+
+/**
+ * It is invoked by Java side computing service.
+ * a step of computation should be handle in a whole by this function.
+ * param. vinfos contains all relevant value matrixes for this computation.
+ * It could return a set of handlers as results or in-place update the data indicated by value matrixes.
+ */
+JNIEXPORT
+jlongArray JNICALL Java_org_apache_mnemonic_service_computing_internal_PrintServiceImpl_nperformPrint(JNIEnv* env,
+ jobject this, jobjectArray vinfos) {
+ jlongArray ret = NULL;
+ jsize retsz = 1;
+ jsize idx;
+ jlong nret[retsz];
+ for(idx = 0; idx < retsz; ++idx) {
+ nret[idx] = 0L;
+ }
+ size_t visz;
+ struct NValueInfo **nvinfos = constructNValueInfos(env, vinfos, &visz);
+ printNValueInfos(nvinfos, visz);
+ for(idx = 0; idx < visz; ++idx) {
+ printf("-- Value Matrix #%u --\n", idx);
+ if (NULL != nvinfos + idx) {
+ handleValueInfo(env, *(nvinfos + idx), valPrintHandler);
+ } else {
+ printf("NULL\n");
+ }
+ }
+
+ ret = constructJLongArray(env, nret, retsz);
+ destructNValueInfos(nvinfos, visz);
+ return ret;
+}
+
+/*
+__attribute__((destructor)) void fini(void) {
+}
+*/
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_PrintServiceImpl.h
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_PrintServiceImpl.h b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_PrintServiceImpl.h
new file mode 100644
index 0000000..85bad3c
--- /dev/null
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_PrintServiceImpl.h
@@ -0,0 +1,48 @@
+/**
+ * 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 PrintServiceImpl */
+
+#include "common.h"
+
+#ifndef _Included_org_apache_mnemonic_service_computing_internal_PrintServiceImpl
+#define _Included_org_apache_mnemonic_service_computing_internal_PrintServiceImpl
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: org_apache_mnemonic_service_computing_internal_PrintServiceImpl
+ * Method: jniInit
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_computing_internal_PrintServiceImpl_jniInit
+(JNIEnv *, jobject, jint, jint);
+
+/*
+ * Class: org_apache_mnemonic_service_computing_internal_PrintServiceImpl
+ * Method: jniTerm
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_memory_internal_PrintServiceImpl_jniTerm
+(JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_SortServiceImpl.c
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_SortServiceImpl.c b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_SortServiceImpl.c
new file mode 100644
index 0000000..862127f
--- /dev/null
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_SortServiceImpl.c
@@ -0,0 +1,249 @@
+/**
+ * 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_computing_internal_SortServiceImpl.h"
+
+/******************************************************************************
+ ** JNI implementations
+ *****************************************************************************/
+
+int compareLongValue(long val1, long val2) {
+ if (val1 == val2) {
+ return 0;
+ }
+ return val1 < val2 ? -1 : 1;
+}
+
+int compareDoubleValue(double val1, double val2) {
+ if (fabs(val1 - val2) <= FLT_EPSILON) {
+ return 0;
+ }
+ return val1 < val2 ? -1 : 1;
+}
+
+int compareValues(int dtype, void *val1ptr, void *val2ptr) {
+ int ret = 0;
+ if (NULL != val1ptr && NULL != val2ptr) {
+ switch(dtype) {
+ case DURABLE_BOOLEAN:
+ case DURABLE_CHARACTER:
+ case DURABLE_BYTE:
+ ret = memcmp(val1ptr, val2ptr, 1);
+ break;
+ case DURABLE_SHORT:
+ ret = compareLongValue(*(short*)val1ptr, *(short*)val2ptr);
+ break;
+ case DURABLE_INTEGER:
+ ret = compareLongValue(*(int*)val1ptr, *(int*)val2ptr);
+ break;
+ case DURABLE_LONG:
+ ret = compareLongValue(*(long*)val1ptr, *(long*)val2ptr);
+ break;
+ case DURABLE_FLOAT:
+ ret = compareDoubleValue(*(float*)val1ptr, *(float*)val2ptr);
+ break;
+ case DURABLE_DOUBLE:
+ ret = compareDoubleValue(*(double*)val1ptr, *(double*)val2ptr);
+ break;
+ }
+ }
+ return ret;
+}
+
+/**
+ * a customized handler as value handler.
+ * It handles would be used to iteratively callback for each value of a value matrix
+ */
+void valSimpleSortHandler(JNIEnv* env, size_t dims[], size_t dimidx,
+ long *itmaddrs[], long *(* const nxtfitmaddrs)[], long (* const pendings)[],
+ void *addr, size_t sz, int dtype) {
+ static long *hptr1 = NULL, *hptr2 = NULL;
+ static void *pvaladdr = NULL;
+ long *tmpptr = NULL;
+ long tmpval = 0L;
+ if (dimidx >= 0) {
+ if (NULL == pvaladdr) {
+ pvaladdr = addr;
+ hptr2 = itmaddrs[dimidx];
+ } else {
+ hptr1 = hptr2;
+ hptr2 = itmaddrs[dimidx];
+ if (compareValues(dtype, pvaladdr, addr) > 0) {
+ tmpptr = (*nxtfitmaddrs)[dimidx];
+ tmpval = *tmpptr;
+ *tmpptr = *hptr1;
+ *hptr1 = *hptr2;
+ *hptr2 = tmpval;
+ (*nxtfitmaddrs)[dimidx] = hptr2;
+ hptr2 = tmpptr;
+ ++(*pendings)[dimidx];
+ } else {
+ pvaladdr = addr;
+ }
+ }
+ if (0L == *(*nxtfitmaddrs)[dimidx]) {
+ pvaladdr = NULL;
+ }
+ }
+}
+
+/**
+ * It is invoked by Java side computing service.
+ * a step of computation should be handle in a whole by this function.
+ * param. vinfos contains all relevant value matrixes for this computation.
+ * It could return a set of handlers as results or in-place update the data indicated by value matrixes.
+ */
+JNIEXPORT
+jlongArray JNICALL Java_org_apache_mnemonic_service_computing_internal_SortServiceImpl_nperformBubbleSort(JNIEnv* env,
+ jobject this, jobjectArray vinfos) {
+ jlongArray ret = NULL;
+ jsize retsz = 1;
+ jsize idx;
+ size_t visz;
+ struct NValueInfo **nvinfos = constructNValueInfos(env, vinfos, &visz);
+ retsz = visz;
+ jlong nret[retsz];
+ for(idx = 0; idx < retsz; ++idx) {
+ nret[idx] = 0L;
+ }
+ printNValueInfos(nvinfos, visz);
+ for(idx = 0; idx < visz; ++idx) {
+ printf("-- Value Matrix #%u --\n", idx);
+ if (NULL != nvinfos + idx) {
+ nret[idx] = handleValueInfo(env, *(nvinfos + idx), valSimpleSortHandler);
+ } else {
+ printf("NULL\n");
+ }
+ }
+
+ ret = constructJLongArray(env, nret, retsz);
+ destructNValueInfos(nvinfos, visz);
+ return ret;
+}
+
+#define TO_E(nvi, p) addr_from_java(p)
+
+typedef struct {
+ long scan_count;
+ long swap_count;
+ long noswap_count;
+} SortInfo;
+
+long handle1DLongBubbleSort(JNIEnv* env, struct NValueInfo *nvinfo, SortInfo *sortinfo) {
+ if (NULL == nvinfo->frames || 0 >= nvinfo->framessz) {
+ return 0L;
+ }
+ register long *itmaddrs = NULL;
+ register long *nxtfitmaddrs = NULL;
+ register int pendings = 0;
+ register long hdls = 0;
+ hdls = nvinfo->handler;
+ itmaddrs = &nvinfo->handler;
+ register long *iatmp;
+ register long curoff = nvinfo->frames->nextoff;
+ register long curnloff = nvinfo->frames->nlvloff;
+// register long curnlsz = nvinfo->frames->nlvlsz;
+ register void *addr = NULL;
+ assert(-1L != curoff);
+ iatmp = itmaddrs;
+ register long *hptr1 = NULL, *hptr2 = NULL;
+ register void *pvaladdr = NULL;
+ register long *tmpptr = NULL;
+ register long tmpval = 0L;
+ register long cntscan = 0L, cntswap = 0L, cntnoswap = 0L;
+
+ if (0L == hdls) {
+ return 0L;
+ }
+
+ do {
+ ++cntscan;
+ pendings = 0;
+ pvaladdr = NULL;
+
+ addr = TO_E(nvinfo, hdls) + curnloff;
+ nxtfitmaddrs = (long*)(TO_E(nvinfo, hdls) + curoff);
+ pvaladdr = addr;
+ hptr2 = itmaddrs;
+
+ while (1) {
+ itmaddrs = nxtfitmaddrs;
+ hdls = *itmaddrs;
+ if (0L == hdls) {
+ break;
+ }
+ addr = TO_E(nvinfo, hdls) + curnloff;
+ nxtfitmaddrs = (long*)(TO_E(nvinfo, hdls) + curoff);
+
+ hptr1 = hptr2;
+ hptr2 = itmaddrs;
+ if (*(long*)pvaladdr > *(long*)addr) {
+ tmpptr = nxtfitmaddrs;
+ tmpval = *tmpptr;
+ *tmpptr = *hptr1;
+ *hptr1 = *hptr2;
+ *hptr2 = tmpval;
+ nxtfitmaddrs = hptr2;
+ hptr2 = tmpptr;
+ pendings = 1;
+ ++cntswap;
+ } else {
+ pvaladdr = addr;
+ ++cntnoswap;
+ }
+
+ }
+
+ itmaddrs = iatmp;
+ hdls = *iatmp;
+ } while (0 != pendings);
+
+ if (NULL != sortinfo) {
+ sortinfo->scan_count = cntscan;
+ sortinfo->swap_count = cntswap;
+ sortinfo->noswap_count = cntnoswap;
+ }
+ return nvinfo->handler;
+}
+
+JNIEXPORT
+jlongArray JNICALL Java_org_apache_mnemonic_service_computing_internal_SortServiceImpl_nperform1DLongBubbleSort(
+ JNIEnv* env, jobject this, jobjectArray vinfos) {
+ jlongArray ret = NULL;
+ jsize retsz = 1;
+ jsize idx;
+ size_t visz;
+ SortInfo sortinfo;
+ struct NValueInfo **nvinfos = constructNValueInfos(env, vinfos, &visz);
+ retsz = visz + 3;
+ jlong nret[retsz];
+ for(idx = 0; idx < retsz; ++idx) {
+ nret[idx] = 0L;
+ }
+ printNValueInfos(nvinfos, visz);
+ assert(1 == visz);
+
+ nret[0] = handle1DLongBubbleSort(env, *nvinfos, &sortinfo);
+ nret[1] = sortinfo.scan_count;
+ nret[2] = sortinfo.swap_count;
+ nret[3] = sortinfo.noswap_count;
+
+ ret = constructJLongArray(env, nret, retsz);
+ destructNValueInfos(nvinfos, visz);
+ return ret;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_SortServiceImpl.h
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_SortServiceImpl.h b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_SortServiceImpl.h
new file mode 100644
index 0000000..3e2fb3c
--- /dev/null
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computing_internal_SortServiceImpl.h
@@ -0,0 +1,48 @@
+/**
+ * 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 SortServiceImpl */
+
+#include "common.h"
+
+#ifndef _Included_org_apache_mnemonic_service_computing_internal_SortServiceImpl
+#define _Included_org_apache_mnemonic_service_computing_internal_SortServiceImpl
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: org_apache_mnemonic_service_computing_internal_SortServiceImpl
+ * Method: jniInit
+ * Signature: (II)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_computing_internal_SortServiceImpl_jniInit
+(JNIEnv *, jobject, jint, jint);
+
+/*
+ * Class: org_apache_mnemonic_service_computing_internal_SortServiceImpl
+ * Method: jniTerm
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_memory_internal_SortServiceImpl_jniTerm
+(JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl.c
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl.c b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl.c
deleted file mode 100644
index b1c687b..0000000
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl.c
+++ /dev/null
@@ -1,106 +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.
- */
-
-#include "org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl.h"
-
-/******************************************************************************
- ** JNI implementations
- *****************************************************************************/
-
-/**
- * a customized handler as value handler.
- * It handles would be used to iteratively callback for each value of a value matrix
- */
-void valPrintHandler(JNIEnv* env, size_t dims[], size_t dimidx,
- long *itmaddrs[], long *(* const nxtfitmaddrs)[], long (* const pendings)[],
- void *addr, size_t sz, int dtype) {
- size_t i;
- if (0 == dims[dimidx]) {
- printf("\n");
- }
- for (i = 0; i <= dimidx; ++i) {
- printf("[%zu]", dims[i]);
- }
- printf(" <%p, %p> ", itmaddrs[dimidx], (*nxtfitmaddrs)[dimidx]);
- switch(dtype) {
- case DURABLE_BOOLEAN:
- printf(" %s, ", (0 == *(char*)addr ? "T" : "F"));
- break;
- case DURABLE_CHARACTER:
- printf(" %c, ", *(char*)addr);
- break;
- case DURABLE_BYTE:
- printf(" %d, ", *(char*)addr);
- break;
- case DURABLE_SHORT:
- printf(" %d, ", *(short*)addr);
- break;
- case DURABLE_INTEGER:
- printf(" %d, ", *(int*)addr);
- break;
- case DURABLE_LONG:
- printf(" %ld, ", *(long*)addr);
- break;
- case DURABLE_FLOAT:
- printf(" %f, ", *(float*)addr);
- break;
- case DURABLE_DOUBLE:
- printf(" %f, ", *(double*)addr);
- break;
- default:
- printf(" (NA), ");
- }
-}
-
-/**
- * It is invoked by Java side computing service.
- * a step of computation should be handle in a whole by this function.
- * param. vinfos contains all relevant value matrixes for this computation.
- * It could return a set of handlers as results or in-place update the data indicated by value matrixes.
- */
-JNIEXPORT
-jlongArray JNICALL Java_org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl_nperformPrint(JNIEnv* env,
- jobject this, jobjectArray vinfos) {
- jlongArray ret = NULL;
- jsize retsz = 1;
- jsize idx;
- jlong nret[retsz];
- for(idx = 0; idx < retsz; ++idx) {
- nret[idx] = 0L;
- }
- size_t visz;
- struct NValueInfo **nvinfos = constructNValueInfos(env, vinfos, &visz);
- printNValueInfos(nvinfos, visz);
- for(idx = 0; idx < visz; ++idx) {
- printf("-- Value Matrix #%u --\n", idx);
- if (NULL != nvinfos + idx) {
- handleValueInfo(env, *(nvinfos + idx), valPrintHandler);
- } else {
- printf("NULL\n");
- }
- }
-
- ret = constructJLongArray(env, nret, retsz);
- destructNValueInfos(nvinfos, visz);
- return ret;
-}
-
-/*
-__attribute__((destructor)) void fini(void) {
-}
-*/
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl.h
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl.h b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl.h
deleted file mode 100644
index 7dc4e11..0000000
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl.h
+++ /dev/null
@@ -1,48 +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.
- */
-
-#include <jni.h>
-/* Header for class PrintServiceImpl */
-
-#include "common.h"
-
-#ifndef _Included_org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl
-#define _Included_org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
- * Class: org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl
- * Method: jniInit
- * Signature: (II)V
- */
-JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl_jniInit
-(JNIEnv *, jobject, jint, jint);
-
-/*
- * Class: org_apache_mnemonic_service_computingservice_internal_PrintServiceImpl
- * Method: jniTerm
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_memoryservice_internal_PrintServiceImpl_jniTerm
-(JNIEnv *, jobject);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_SortServiceImpl.c
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_SortServiceImpl.c b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_SortServiceImpl.c
deleted file mode 100644
index 6f84c6c..0000000
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_SortServiceImpl.c
+++ /dev/null
@@ -1,249 +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.
- */
-
-#include "org_apache_mnemonic_service_computingservice_internal_SortServiceImpl.h"
-
-/******************************************************************************
- ** JNI implementations
- *****************************************************************************/
-
-int compareLongValue(long val1, long val2) {
- if (val1 == val2) {
- return 0;
- }
- return val1 < val2 ? -1 : 1;
-}
-
-int compareDoubleValue(double val1, double val2) {
- if (fabs(val1 - val2) <= FLT_EPSILON) {
- return 0;
- }
- return val1 < val2 ? -1 : 1;
-}
-
-int compareValues(int dtype, void *val1ptr, void *val2ptr) {
- int ret = 0;
- if (NULL != val1ptr && NULL != val2ptr) {
- switch(dtype) {
- case DURABLE_BOOLEAN:
- case DURABLE_CHARACTER:
- case DURABLE_BYTE:
- ret = memcmp(val1ptr, val2ptr, 1);
- break;
- case DURABLE_SHORT:
- ret = compareLongValue(*(short*)val1ptr, *(short*)val2ptr);
- break;
- case DURABLE_INTEGER:
- ret = compareLongValue(*(int*)val1ptr, *(int*)val2ptr);
- break;
- case DURABLE_LONG:
- ret = compareLongValue(*(long*)val1ptr, *(long*)val2ptr);
- break;
- case DURABLE_FLOAT:
- ret = compareDoubleValue(*(float*)val1ptr, *(float*)val2ptr);
- break;
- case DURABLE_DOUBLE:
- ret = compareDoubleValue(*(double*)val1ptr, *(double*)val2ptr);
- break;
- }
- }
- return ret;
-}
-
-/**
- * a customized handler as value handler.
- * It handles would be used to iteratively callback for each value of a value matrix
- */
-void valSimpleSortHandler(JNIEnv* env, size_t dims[], size_t dimidx,
- long *itmaddrs[], long *(* const nxtfitmaddrs)[], long (* const pendings)[],
- void *addr, size_t sz, int dtype) {
- static long *hptr1 = NULL, *hptr2 = NULL;
- static void *pvaladdr = NULL;
- long *tmpptr = NULL;
- long tmpval = 0L;
- if (dimidx >= 0) {
- if (NULL == pvaladdr) {
- pvaladdr = addr;
- hptr2 = itmaddrs[dimidx];
- } else {
- hptr1 = hptr2;
- hptr2 = itmaddrs[dimidx];
- if (compareValues(dtype, pvaladdr, addr) > 0) {
- tmpptr = (*nxtfitmaddrs)[dimidx];
- tmpval = *tmpptr;
- *tmpptr = *hptr1;
- *hptr1 = *hptr2;
- *hptr2 = tmpval;
- (*nxtfitmaddrs)[dimidx] = hptr2;
- hptr2 = tmpptr;
- ++(*pendings)[dimidx];
- } else {
- pvaladdr = addr;
- }
- }
- if (0L == *(*nxtfitmaddrs)[dimidx]) {
- pvaladdr = NULL;
- }
- }
-}
-
-/**
- * It is invoked by Java side computing service.
- * a step of computation should be handle in a whole by this function.
- * param. vinfos contains all relevant value matrixes for this computation.
- * It could return a set of handlers as results or in-place update the data indicated by value matrixes.
- */
-JNIEXPORT
-jlongArray JNICALL Java_org_apache_mnemonic_service_computingservice_internal_SortServiceImpl_nperformBubbleSort(JNIEnv* env,
- jobject this, jobjectArray vinfos) {
- jlongArray ret = NULL;
- jsize retsz = 1;
- jsize idx;
- size_t visz;
- struct NValueInfo **nvinfos = constructNValueInfos(env, vinfos, &visz);
- retsz = visz;
- jlong nret[retsz];
- for(idx = 0; idx < retsz; ++idx) {
- nret[idx] = 0L;
- }
- printNValueInfos(nvinfos, visz);
- for(idx = 0; idx < visz; ++idx) {
- printf("-- Value Matrix #%u --\n", idx);
- if (NULL != nvinfos + idx) {
- nret[idx] = handleValueInfo(env, *(nvinfos + idx), valSimpleSortHandler);
- } else {
- printf("NULL\n");
- }
- }
-
- ret = constructJLongArray(env, nret, retsz);
- destructNValueInfos(nvinfos, visz);
- return ret;
-}
-
-#define TO_E(nvi, p) addr_from_java(p)
-
-typedef struct {
- long scan_count;
- long swap_count;
- long noswap_count;
-} SortInfo;
-
-long handle1DLongBubbleSort(JNIEnv* env, struct NValueInfo *nvinfo, SortInfo *sortinfo) {
- if (NULL == nvinfo->frames || 0 >= nvinfo->framessz) {
- return 0L;
- }
- register long *itmaddrs = NULL;
- register long *nxtfitmaddrs = NULL;
- register int pendings = 0;
- register long hdls = 0;
- hdls = nvinfo->handler;
- itmaddrs = &nvinfo->handler;
- register long *iatmp;
- register long curoff = nvinfo->frames->nextoff;
- register long curnloff = nvinfo->frames->nlvloff;
-// register long curnlsz = nvinfo->frames->nlvlsz;
- register void *addr = NULL;
- assert(-1L != curoff);
- iatmp = itmaddrs;
- register long *hptr1 = NULL, *hptr2 = NULL;
- register void *pvaladdr = NULL;
- register long *tmpptr = NULL;
- register long tmpval = 0L;
- register long cntscan = 0L, cntswap = 0L, cntnoswap = 0L;
-
- if (0L == hdls) {
- return 0L;
- }
-
- do {
- ++cntscan;
- pendings = 0;
- pvaladdr = NULL;
-
- addr = TO_E(nvinfo, hdls) + curnloff;
- nxtfitmaddrs = (long*)(TO_E(nvinfo, hdls) + curoff);
- pvaladdr = addr;
- hptr2 = itmaddrs;
-
- while (1) {
- itmaddrs = nxtfitmaddrs;
- hdls = *itmaddrs;
- if (0L == hdls) {
- break;
- }
- addr = TO_E(nvinfo, hdls) + curnloff;
- nxtfitmaddrs = (long*)(TO_E(nvinfo, hdls) + curoff);
-
- hptr1 = hptr2;
- hptr2 = itmaddrs;
- if (*(long*)pvaladdr > *(long*)addr) {
- tmpptr = nxtfitmaddrs;
- tmpval = *tmpptr;
- *tmpptr = *hptr1;
- *hptr1 = *hptr2;
- *hptr2 = tmpval;
- nxtfitmaddrs = hptr2;
- hptr2 = tmpptr;
- pendings = 1;
- ++cntswap;
- } else {
- pvaladdr = addr;
- ++cntnoswap;
- }
-
- }
-
- itmaddrs = iatmp;
- hdls = *iatmp;
- } while (0 != pendings);
-
- if (NULL != sortinfo) {
- sortinfo->scan_count = cntscan;
- sortinfo->swap_count = cntswap;
- sortinfo->noswap_count = cntnoswap;
- }
- return nvinfo->handler;
-}
-
-JNIEXPORT
-jlongArray JNICALL Java_org_apache_mnemonic_service_computingservice_internal_SortServiceImpl_nperform1DLongBubbleSort(
- JNIEnv* env, jobject this, jobjectArray vinfos) {
- jlongArray ret = NULL;
- jsize retsz = 1;
- jsize idx;
- size_t visz;
- SortInfo sortinfo;
- struct NValueInfo **nvinfos = constructNValueInfos(env, vinfos, &visz);
- retsz = visz + 3;
- jlong nret[retsz];
- for(idx = 0; idx < retsz; ++idx) {
- nret[idx] = 0L;
- }
- printNValueInfos(nvinfos, visz);
- assert(1 == visz);
-
- nret[0] = handle1DLongBubbleSort(env, *nvinfos, &sortinfo);
- nret[1] = sortinfo.scan_count;
- nret[2] = sortinfo.swap_count;
- nret[3] = sortinfo.noswap_count;
-
- ret = constructJLongArray(env, nret, retsz);
- destructNValueInfos(nvinfos, visz);
- return ret;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_SortServiceImpl.h
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_SortServiceImpl.h b/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_SortServiceImpl.h
deleted file mode 100644
index 9204c98..0000000
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/main/native/org_apache_mnemonic_service_computingservice_internal_SortServiceImpl.h
+++ /dev/null
@@ -1,48 +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.
- */
-
-#include <jni.h>
-/* Header for class SortServiceImpl */
-
-#include "common.h"
-
-#ifndef _Included_org_apache_mnemonic_service_computingservice_internal_SortServiceImpl
-#define _Included_org_apache_mnemonic_service_computingservice_internal_SortServiceImpl
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
- * Class: org_apache_mnemonic_service_computingservice_internal_SortServiceImpl
- * Method: jniInit
- * Signature: (II)V
- */
-JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_computingservice_internal_SortServiceImpl_jniInit
-(JNIEnv *, jobject, jint, jint);
-
-/*
- * Class: org_apache_mnemonic_service_computingservice_internal_SortServiceImpl
- * Method: jniTerm
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_org_apache_mnemonic_service_memoryservice_internal_SortServiceImpl_jniTerm
-(JNIEnv *, jobject);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.computing.GeneralComputingService
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.computing.GeneralComputingService b/mnemonic-computing-services/mnemonic-utilities-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.computing.GeneralComputingService
new file mode 100644
index 0000000..7c79d94
--- /dev/null
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.computing.GeneralComputingService
@@ -0,0 +1,2 @@
+org.apache.mnemonic.service.computing.internal.PrintServiceImpl
+org.apache.mnemonic.service.computing.internal.SortServiceImpl
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.computingservice.GeneralComputingService
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.computingservice.GeneralComputingService b/mnemonic-computing-services/mnemonic-utilities-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.computingservice.GeneralComputingService
deleted file mode 100644
index 9f9b4a3..0000000
--- a/mnemonic-computing-services/mnemonic-utilities-service/src/main/resources/META-INF/services/org.apache.mnemonic.service.computingservice.GeneralComputingService
+++ /dev/null
@@ -1,2 +0,0 @@
-org.apache.mnemonic.service.computingservice.internal.PrintServiceImpl
-org.apache.mnemonic.service.computingservice.internal.SortServiceImpl
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computing/DurableSinglyLinkedListNGPrintTest.java
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computing/DurableSinglyLinkedListNGPrintTest.java b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computing/DurableSinglyLinkedListNGPrintTest.java
new file mode 100644
index 0000000..dd5cc8d
--- /dev/null
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computing/DurableSinglyLinkedListNGPrintTest.java
@@ -0,0 +1,271 @@
+/*
+ * 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.computing;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.mnemonic.NonVolatileMemAllocator;
+import org.apache.mnemonic.RestorableAllocator;
+import org.apache.mnemonic.Durable;
+import org.apache.mnemonic.EntityFactoryProxy;
+import org.apache.mnemonic.Utils;
+import org.apache.mnemonic.DurableType;
+import org.apache.mnemonic.collections.DurableSinglyLinkedList;
+import org.apache.mnemonic.collections.DurableSinglyLinkedListFactory;
+import org.apache.mnemonic.ParameterHolder;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * A Test case suit, verify and demo the durable native computing services (DNCS) infra.
+ *
+ */
+
+public class DurableSinglyLinkedListNGPrintTest {
+ public static String uri = "./pobj_NodeValue_print.dat";
+ private long cKEYCAPACITY;
+ private Random m_rand;
+ private NonVolatileMemAllocator m_act;
+
+ @BeforeClass
+ public void setUp() throws IOException {
+ m_rand = Utils.createRandom();
+ Files.deleteIfExists(Paths.get(uri));
+ m_act = new NonVolatileMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 1024,
+ uri, true);
+ cKEYCAPACITY = m_act.handlerCapacity();
+ for (long i = 0; i < cKEYCAPACITY; ++i) {
+ m_act.setHandler(i, 0L);
+ }
+ }
+
+ @AfterClass
+ public void tearDown() {
+ m_act.close();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test(enabled = true)
+ public void testDurableSinglyLinkedListWithPerson() {
+
+ int elem_count = 10;
+
+ DurableType listgftypes[] = {DurableType.DURABLE};
+ EntityFactoryProxy listefproxies[] = {new EntityFactoryProxy() {
+ @Override
+ public <A extends RestorableAllocator<A>> Durable 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>> Durable restore(ParameterHolder<A> ph) {
+ return PersonFactory.restore(ph.getAllocator(),
+ ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getHandler(), ph.getAutoReclaim());
+ }
+ @Override
+ public <A extends RestorableAllocator<A>> Durable create(
+ A allocator, EntityFactoryProxy[] factoryproxys,
+ DurableType[] gfields, boolean autoreclaim) {
+ return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim);
+ }
+ @Override
+ public <A extends RestorableAllocator<A>> Durable create(ParameterHolder<A> ph) {
+ return PersonFactory.create(ph.getAllocator(),
+ ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getAutoReclaim());
+ }
+ } };
+
+ DurableSinglyLinkedList<Person<Long>> firstnv = DurableSinglyLinkedListFactory.create(m_act, listefproxies,
+ listgftypes, false);
+
+ DurableSinglyLinkedList<Person<Long>> nextnv = firstnv;
+
+ Person<Long> person = null;
+ long val;
+ DurableSinglyLinkedList<Person<Long>> newnv;
+ for (int i = 0; i < elem_count; ++i) {
+ 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);
+ if (i + 1 == elem_count) {
+ break;
+ }
+ newnv = DurableSinglyLinkedListFactory.create(m_act, listefproxies, listgftypes, false);
+ nextnv.setNext(newnv, false);
+ nextnv = newnv;
+ }
+
+ Person<Long> eval;
+ DurableSinglyLinkedList<Person<Long>> iternv = firstnv;
+ System.out.printf(" -- Stage 1 Generated---\n");
+ while (null != iternv) {
+ eval = iternv.getItem();
+ if (null != eval) {
+ eval.testOutputAge();
+ }
+ iternv = iternv.getNext();
+ }
+ System.out.printf("\n");
+
+ long handler = firstnv.getHandler();
+
+ DurableSinglyLinkedList<Person<Long>> firstnv2 = DurableSinglyLinkedListFactory.restore(m_act, listefproxies,
+ listgftypes, handler, false);
+
+ System.out.printf("--- Stage 2 Restored--- \n");
+ for (Person<Long> eval2 : firstnv2) {
+ if (null != eval2) {
+ eval2.testOutputAge();
+ }
+ }
+ System.out.printf("\n");
+
+ GeneralComputingService gcsvr = Utils.getGeneralComputingService("print");
+ ValueInfo vinfo = new ValueInfo();
+ List<long[][]> objstack = new ArrayList<long[][]>();
+ objstack.add(firstnv.getNativeFieldInfo());
+ objstack.add(person.getNativeFieldInfo());
+ long[][] fidinfostack = {{2L, 1L}, {0L, 1L}};
+ vinfo.handler = handler;
+ vinfo.transtable = m_act.getTranslateTable();
+ vinfo.dtype = DurableType.SHORT;
+ vinfo.frames = Utils.genNativeParamForm(objstack, fidinfostack);
+ ValueInfo[] vinfos = {vinfo};
+ gcsvr.perform(null, vinfos);
+
+ }
+
+ @Test(enabled = true)
+ public void testDurableSinglyLinkedListValue() {
+
+ int elem_count = 10;
+ long slotKeyId = 10;
+
+ DurableType[] elem_gftypes = {DurableType.DOUBLE};
+ EntityFactoryProxy[] elem_efproxies = null;
+
+ DurableType linkedgftypes[] = {DurableType.DURABLE, DurableType.DOUBLE};
+ EntityFactoryProxy linkedefproxies[] = {new EntityFactoryProxy() {
+ @Override
+ public <A extends RestorableAllocator<A>> Durable restore(A allocator, EntityFactoryProxy[] factoryproxys,
+ DurableType[] gfields, long phandler, boolean autoreclaim) {
+ Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields, factoryproxys, 1);
+ return DurableSinglyLinkedListFactory.restore(allocator, dpt.getRight(), dpt.getLeft(), phandler, autoreclaim);
+ }
+ @Override
+ public <A extends RestorableAllocator<A>> Durable restore(ParameterHolder<A> ph) {
+ Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(ph.getGenericTypes(),
+ ph.getEntityFactoryProxies(), 1);
+ return DurableSinglyLinkedListFactory.restore(ph.getAllocator(),
+ dpt.getRight(), dpt.getLeft(), ph.getHandler(), ph.getAutoReclaim());
+ }
+ @Override
+ public <A extends RestorableAllocator<A>> Durable create(A allocator, EntityFactoryProxy[] factoryproxys,
+ DurableType[] gfields, boolean autoreclaim) {
+ Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields, factoryproxys, 1);
+ return DurableSinglyLinkedListFactory.create(allocator, dpt.getRight(), dpt.getLeft(), autoreclaim);
+ }
+ @Override
+ public <A extends RestorableAllocator<A>> Durable create(ParameterHolder<A> ph) {
+ Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(ph.getGenericTypes(),
+ ph.getEntityFactoryProxies(), 1);
+ return DurableSinglyLinkedListFactory.create(ph.getAllocator(),
+ dpt.getRight(), dpt.getLeft(), ph.getAutoReclaim());
+ }
+ } };
+
+ DurableSinglyLinkedList<DurableSinglyLinkedList<Double>> nextnv = null, pre_nextnv = null;
+ DurableSinglyLinkedList<Double> elem = null, pre_elem = null, first_elem = null;
+
+ Long linkhandler = 0L;
+
+ System.out.printf(" --- Stage 1 Generated --- \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 = DurableSinglyLinkedListFactory.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 = DurableSinglyLinkedListFactory.create(m_act, linkedefproxies, linkedgftypes, false);
+ nextnv.setItem(first_elem, false);
+ if (null == pre_nextnv) {
+ linkhandler = nextnv.getHandler();
+ } 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);
+
+ DurableSinglyLinkedList<DurableSinglyLinkedList<Double>> linkedvals = DurableSinglyLinkedListFactory.restore(m_act,
+ linkedefproxies, linkedgftypes, handler, false);
+ Iterator<DurableSinglyLinkedList<Double>> iter = linkedvals.iterator();
+ Iterator<Double> elemiter = null;
+
+ System.out.printf(" --- Stage 2 Restored --- \n");
+ while (iter.hasNext()) {
+ elemiter = iter.next().iterator();
+ while (elemiter.hasNext()) {
+ System.out.printf("%f ", elemiter.next());
+ }
+ System.out.printf(" Fetched an item... \n");
+ }
+
+ GeneralComputingService gcsvr = Utils.getGeneralComputingService("print");
+ ValueInfo vinfo = new ValueInfo();
+ List<long[][]> objstack = new ArrayList<long[][]>();
+ objstack.add(linkedvals.getNativeFieldInfo());
+ objstack.add(linkedvals.getNativeFieldInfo());
+ long[][] fidinfostack = {{2L, 1L}, {2L, 1L}};
+ vinfo.handler = handler;
+ vinfo.transtable = m_act.getTranslateTable();
+ vinfo.dtype = DurableType.DOUBLE;
+ vinfo.frames = Utils.genNativeParamForm(objstack, fidinfostack);
+ ValueInfo[] vinfos = {vinfo};
+ gcsvr.perform(null, vinfos);
+
+ // Assert.assert, expected);(plist, plist2);
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computing/DurableSinglyLinkedListNGSortTest.java
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computing/DurableSinglyLinkedListNGSortTest.java b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computing/DurableSinglyLinkedListNGSortTest.java
new file mode 100644
index 0000000..77a6ccb
--- /dev/null
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computing/DurableSinglyLinkedListNGSortTest.java
@@ -0,0 +1,323 @@
+/*
+ * 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.computing;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.mnemonic.NonVolatileMemAllocator;
+import org.apache.mnemonic.RestorableAllocator;
+import org.apache.mnemonic.Durable;
+import org.apache.mnemonic.EntityFactoryProxy;
+import org.apache.mnemonic.Utils;
+import org.apache.mnemonic.DurableType;
+import org.apache.mnemonic.ParameterHolder;
+import org.apache.mnemonic.collections.DurableSinglyLinkedList;
+import org.apache.mnemonic.collections.DurableSinglyLinkedListFactory;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.testng.Assert;
+
+/**
+ * A Test case suit, verify and demo the durable native computing services (DNCS) infra.
+ *
+ */
+
+public class DurableSinglyLinkedListNGSortTest {
+ public static String uri = "./pobj_NodeValue_sorting.dat";
+ private long cKEYCAPACITY;
+ private Random m_rand;
+ private NonVolatileMemAllocator m_act;
+
+ @BeforeClass
+ public void setUp() throws IOException {
+ m_rand = Utils.createRandom();
+ Files.deleteIfExists(Paths.get(uri));
+ m_act = new NonVolatileMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmalloc"), 1024 * 1024 * 1024,
+ uri, true);
+ cKEYCAPACITY = m_act.handlerCapacity();
+ for (long i = 0; i < cKEYCAPACITY; ++i) {
+ m_act.setHandler(i, 0L);
+ }
+ }
+
+ @AfterClass
+ public void tearDown() {
+ m_act.close();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test(enabled = true)
+ public void testDurableSinglyLinkedListWithPerson() {
+
+ int elem_count = 20;
+
+ DurableType listgftypes[] = {DurableType.DURABLE};
+ EntityFactoryProxy listefproxies[] = {new EntityFactoryProxy() {
+ @Override
+ public <A extends RestorableAllocator<A>> Durable 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>> Durable restore(ParameterHolder<A> ph) {
+ return PersonFactory.restore(ph.getAllocator(),
+ ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getHandler(), ph.getAutoReclaim());
+ }
+ @Override
+ public <A extends RestorableAllocator<A>> Durable create(
+ A allocator, EntityFactoryProxy[] factoryproxys,
+ DurableType[] gfields, boolean autoreclaim) {
+ return PersonFactory.create(allocator, factoryproxys, gfields, autoreclaim);
+ }
+ @Override
+ public <A extends RestorableAllocator<A>> Durable create(ParameterHolder<A> ph) {
+ return PersonFactory.create(ph.getAllocator(),
+ ph.getEntityFactoryProxies(), ph.getGenericTypes(), ph.getAutoReclaim());
+ }
+ } };
+
+ DurableSinglyLinkedList<Person<Long>> firstnv = DurableSinglyLinkedListFactory.create(m_act, listefproxies,
+ listgftypes, false);
+
+ DurableSinglyLinkedList<Person<Long>> nextnv = firstnv;
+
+ Person<Long> person = null;
+ long val;
+ DurableSinglyLinkedList<Person<Long>> newnv;
+ for (int i = 0; i < elem_count; ++i) {
+ 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);
+ if (i + 1 == elem_count) {
+ break;
+ }
+ newnv = DurableSinglyLinkedListFactory.create(m_act, listefproxies, listgftypes, false);
+ nextnv.setNext(newnv, false);
+ nextnv = newnv;
+ }
+
+ Person<Long> eval;
+ DurableSinglyLinkedList<Person<Long>> iternv = firstnv;
+ System.out.printf(" --- Stage 1 Generated---\n");
+ long agesum1 = 0L;
+ while (null != iternv) {
+ eval = iternv.getItem();
+ Assert.assertNotNull(eval);
+ eval.testOutputAge();
+ agesum1 += eval.getAge();
+ iternv = iternv.getNext();
+ }
+ System.out.printf("\n");
+
+ long handler = firstnv.getHandler();
+
+ DurableSinglyLinkedList<Person<Long>> firstnv2 = DurableSinglyLinkedListFactory.restore(m_act, listefproxies,
+ listgftypes, handler, false);
+
+ System.out.printf("--- Stage 2 Restored--- \n");
+ long agesum2 = 0L;
+ for (Person<Long> eval2 : firstnv2) {
+ Assert.assertNotNull(eval2);
+ eval2.testOutputAge();
+ agesum2 += eval2.getAge();
+ }
+ System.out.printf("\n");
+ Assert.assertEquals(agesum1, agesum2);
+
+ GeneralComputingService gcsvr = Utils.getGeneralComputingService("sort");
+ ValueInfo vinfo = new ValueInfo();
+ List<long[][]> objstack = new ArrayList<long[][]>();
+ objstack.add(firstnv.getNativeFieldInfo());
+ objstack.add(person.getNativeFieldInfo());
+ long[][] fidinfostack = {{2L, 1L}, {0L, 1L}};
+ vinfo.handler = handler;
+ vinfo.transtable = m_act.getTranslateTable();
+ vinfo.dtype = DurableType.SHORT;
+ vinfo.frames = Utils.genNativeParamForm(objstack, fidinfostack);
+ ValueInfo[] vinfos = {vinfo};
+ long[] ret = gcsvr.perform("tensor_bubble", vinfos);
+
+ Assert.assertEquals(1, ret.length);
+ long handler2 = ret[0];
+ Assert.assertNotEquals(0L, handler2);
+
+ DurableSinglyLinkedList<Person<Long>> firstnv3 = DurableSinglyLinkedListFactory.restore(m_act, listefproxies,
+ listgftypes, handler2, false);
+
+ System.out.printf("--- Stage 3 Sorted--- \n");
+ long agesum3 = 0L;
+ int preage = -1;
+ for (Person<Long> eval3 : firstnv3) {
+ Assert.assertNotNull(eval3);
+ eval3.testOutputAge();
+ agesum3 += eval3.getAge();
+ if (preage >= 0) {
+ Assert.assertTrue(eval3.getAge() >= preage);
+ }
+ preage = eval3.getAge();
+ }
+ System.out.printf("\n");
+ Assert.assertEquals(agesum2, agesum3);
+ }
+
+ @Test(enabled = true)
+ public void testDurableSinglyLinkedListValue() {
+
+ int elem_count = 20;
+ long slotKeyId = 10;
+
+ DurableType[] elem_gftypes = {DurableType.DOUBLE};
+ EntityFactoryProxy[] elem_efproxies = null;
+
+ DurableType linkedgftypes[] = {DurableType.DURABLE, DurableType.DOUBLE};
+ EntityFactoryProxy linkedefproxies[] = {new EntityFactoryProxy() {
+ @Override
+ public <A extends RestorableAllocator<A>> Durable restore(A allocator, EntityFactoryProxy[] factoryproxys,
+ DurableType[] gfields, long phandler, boolean autoreclaim) {
+ Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields, factoryproxys, 1);
+ return DurableSinglyLinkedListFactory.restore(allocator, dpt.getRight(), dpt.getLeft(), phandler, autoreclaim);
+ }
+ @Override
+ public <A extends RestorableAllocator<A>> Durable restore(ParameterHolder<A> ph) {
+ Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(ph.getGenericTypes(),
+ ph.getEntityFactoryProxies(), 1);
+ return DurableSinglyLinkedListFactory.restore(ph.getAllocator(),
+ dpt.getRight(), dpt.getLeft(), ph.getHandler(), ph.getAutoReclaim());
+ }
+ @Override
+ public <A extends RestorableAllocator<A>> Durable create(A allocator, EntityFactoryProxy[] factoryproxys,
+ DurableType[] gfields, boolean autoreclaim) {
+ Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(gfields, factoryproxys, 1);
+ return DurableSinglyLinkedListFactory.create(allocator, dpt.getRight(), dpt.getLeft(), autoreclaim);
+ }
+ @Override
+ public <A extends RestorableAllocator<A>> Durable create(ParameterHolder<A> ph) {
+ Pair<DurableType[], EntityFactoryProxy[]> dpt = Utils.shiftDurableParams(ph.getGenericTypes(),
+ ph.getEntityFactoryProxies(), 1);
+ return DurableSinglyLinkedListFactory.create(ph.getAllocator(),
+ dpt.getRight(), dpt.getLeft(), ph.getAutoReclaim());
+ }
+ } };
+
+ DurableSinglyLinkedList<DurableSinglyLinkedList<Double>> nextnv = null, pre_nextnv = null;
+ DurableSinglyLinkedList<Double> elem = null, pre_elem = null, first_elem = null;
+
+ Long linkhandler = 0L;
+
+ System.out.printf(" --- Stage 1 Generated --- \n");
+
+ pre_nextnv = null;
+ Double val;
+ double valsum1 = 0.0;
+ for (int i = 0; i < elem_count; ++i) {
+ first_elem = null;
+ pre_elem = null;
+ for (int v = 0; v < 12; ++v) {
+ elem = DurableSinglyLinkedListFactory.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);
+ valsum1 += val;
+ }
+
+ nextnv = DurableSinglyLinkedListFactory.create(m_act, linkedefproxies, linkedgftypes, false);
+ nextnv.setItem(first_elem, false);
+ if (null == pre_nextnv) {
+ linkhandler = nextnv.getHandler();
+ } 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);
+
+ DurableSinglyLinkedList<DurableSinglyLinkedList<Double>> linkedvals = DurableSinglyLinkedListFactory.restore(m_act,
+ linkedefproxies, linkedgftypes, handler, false);
+ Iterator<DurableSinglyLinkedList<Double>> iter = linkedvals.iterator();
+ Iterator<Double> elemiter = null;
+
+ System.out.printf(" --- Stage 2 Restored --- \n");
+ double val2, valsum2 = 0.0;
+ while (iter.hasNext()) {
+ elemiter = iter.next().iterator();
+ while (elemiter.hasNext()) {
+ val2 = elemiter.next();
+ System.out.printf("%f ", val2);
+ valsum2 += val2;
+ }
+ System.out.printf(" Fetched an item... \n");
+ }
+ Assert.assertEquals(valsum1, valsum2, 0.0001);
+
+ GeneralComputingService gcsvr = Utils.getGeneralComputingService("sort");
+ ValueInfo vinfo = new ValueInfo();
+ List<long[][]> objstack = new ArrayList<long[][]>();
+ objstack.add(linkedvals.getNativeFieldInfo());
+ objstack.add(linkedvals.getNativeFieldInfo());
+ long[][] fidinfostack = {{2L, 1L}, {2L, 1L}};
+ vinfo.handler = handler;
+ vinfo.transtable = m_act.getTranslateTable();
+ vinfo.dtype = DurableType.DOUBLE;
+ vinfo.frames = Utils.genNativeParamForm(objstack, fidinfostack);
+ ValueInfo[] vinfos = {vinfo};
+ gcsvr.perform("tensor_bubble", vinfos);
+
+ // Assert.assert, expected);(plist, plist2);
+ DurableSinglyLinkedList<DurableSinglyLinkedList<Double>> linkedvals3 = DurableSinglyLinkedListFactory.restore(m_act,
+ linkedefproxies, linkedgftypes, handler, false);
+ Iterator<DurableSinglyLinkedList<Double>> iter3 = linkedvals3.iterator();
+ Iterator<Double> elemiter3 = null;
+
+ System.out.printf(" --- Stage 3 Sorted --- \n");
+ double val3, valsum3 = 0.0, preval3;
+ while (iter3.hasNext()) {
+ elemiter3 = iter3.next().iterator();
+ preval3 = 0.0;
+ while (elemiter3.hasNext()) {
+ val3 = elemiter3.next();
+ System.out.printf("%f ", val3);
+ valsum3 += val3;
+ if (preval3 != 0.0) {
+ Assert.assertTrue(val3 >= preval3);
+ }
+ preval3 = val3;
+ }
+ System.out.printf(" Fetched an item... \n");
+ }
+ Assert.assertEquals(valsum2, valsum3, 0.0001);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-mnemonic/blob/a4bb10eb/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computing/Person.java
----------------------------------------------------------------------
diff --git a/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computing/Person.java b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computing/Person.java
new file mode 100644
index 0000000..65e33ed
--- /dev/null
+++ b/mnemonic-computing-services/mnemonic-utilities-service/src/test/java/org/apache/mnemonic/service/computing/Person.java
@@ -0,0 +1,99 @@
+/*
+ * 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.computing;
+
+import org.apache.mnemonic.Durable;
+import org.apache.mnemonic.EntityFactoryProxy;
+import org.apache.mnemonic.DurableEntity;
+import org.apache.mnemonic.DurableGetter;
+import org.apache.mnemonic.DurableSetter;
+import org.apache.mnemonic.OutOfHybridMemory;
+import org.apache.mnemonic.RetrieveDurableEntityError;
+import org.apache.mnemonic.DurableType;
+import org.testng.annotations.Test;
+
+/**
+ * A simple generic object used for testing and demo.
+ *
+ */
+
+@DurableEntity
+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, DurableType[] gftypes) {
+
+ }
+
+ @Test
+ public void testOutput() throws RetrieveDurableEntityError {
+ System.out.printf("Person %s, Age: %d ( %s ) \n", getName(), getAge(),
+ null == getMother() ? "No Recorded Mother" : "Has Recorded Mother");
+ }
+
+ public void testOutputAge() throws RetrieveDurableEntityError {
+ System.out.printf("(Person %s, Age: %d) ", getName(), getAge());
+ }
+
+ public int compareTo(Person<E> anotherPerson) {
+ int ret = 0;
+ if (0 == ret) {
+ ret = ((Short)getAge()).compareTo(anotherPerson.getAge());
+ }
+ if (0 == ret) {
+ ret = getName().compareTo(anotherPerson.getName());
+ }
+ return ret;
+ }
+
+ @DurableGetter(Id = 1L)
+ public abstract short getAge();
+
+ @DurableSetter
+ public abstract void setAge(short age);
+
+ @DurableGetter(Id = 2L)
+ public abstract String getName() throws RetrieveDurableEntityError;
+
+ @DurableSetter
+ public abstract void setName(String name, boolean destroy)
+ throws OutOfHybridMemory, RetrieveDurableEntityError;
+
+ @DurableGetter(Id = 3L)
+ public abstract Person<E> getMother() throws RetrieveDurableEntityError;
+
+ @DurableSetter
+ public abstract void setMother(Person<E> mother, boolean destroy) throws RetrieveDurableEntityError;
+
+ @DurableGetter(Id = 4L)
+ public abstract Person<E> getFather() throws RetrieveDurableEntityError;
+
+ @DurableSetter
+ public abstract void setFather(Person<E> mother, boolean destroy) throws RetrieveDurableEntityError;
+}