This is an automated email from the ASF dual-hosted git repository.

bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 3931c78  GEODE-4337: cpp example, function execution (#382)
3931c78 is described below

commit 3931c786df64e030b4f13297a5367dc1692d43c1
Author: Blake Bender <[email protected]>
AuthorDate: Thu Oct 25 15:34:22 2018 -0700

    GEODE-4337: cpp example, function execution (#382)
    
    Co-authored-by: Matthew Reddington <[email protected]>
---
 examples/cpp/CMakeLists.txt                        |   3 +
 examples/cpp/CMakeLists.txt.in                     |   1 +
 examples/cpp/function-execution/README.md          | 207 +++++++++++++++++++++
 examples/cpp/function-execution/main.cpp           | 184 ++++++++++++++++++
 .../startserver.sh}                                |  25 ++-
 .../stopserver.sh}                                 |  24 ++-
 tests/javaobject/CMakeLists.txt                    |  10 +-
 7 files changed, 437 insertions(+), 17 deletions(-)

diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt
index 5b4efd5..8ab76e9 100644
--- a/examples/cpp/CMakeLists.txt
+++ b/examples/cpp/CMakeLists.txt
@@ -62,6 +62,9 @@ add_example(NAME pdxserializer
 add_example(NAME put-get-remove
     SOURCE main.cpp)
 
+add_example(NAME function-execution
+    SOURCE main.cpp)
+
 add_example(NAME remotequery
     SOURCE main.cpp Order.cpp Order.hpp)
 
diff --git a/examples/cpp/CMakeLists.txt.in b/examples/cpp/CMakeLists.txt.in
index e176810..a1854c0 100644
--- a/examples/cpp/CMakeLists.txt.in
+++ b/examples/cpp/CMakeLists.txt.in
@@ -22,4 +22,5 @@ add_subdirectory(dataserializable)
 add_subdirectory(pdxserializable)
 add_subdirectory(pdxserializer)
 add_subdirectory(put-get-remove)
+add_subdirectory(function-execution)
 add_subdirectory(remotequery)
diff --git a/examples/cpp/function-execution/README.md 
b/examples/cpp/function-execution/README.md
new file mode 100644
index 0000000..394b23c
--- /dev/null
+++ b/examples/cpp/function-execution/README.md
@@ -0,0 +1,207 @@
+# Function-execution example
+This is a very simple example showing how to execute a function on the server. 
 
+It creates a `Cache` using the `CacheFactory`, configures a `Pool` with a 
+`PoolFactory`, and configures a `Region` with a `RegionFactory`.  The 
+startserver script deploys a jar file with several custom functions in it, and 
+the example app executes those functions and prints out the result set(s).
+
+## Prerequisites
+* An installation of Apache Geode.
+* Apache Geode Native, built and installed.
+* Apache Geode Native examples, built and installed.
+* A `GEODE_HOME` environment variable set to the location of the Apache Geode 
installation.
+* `GEODE_HOME/bin` in the execution path.
+
+## Running
+1. Set the current directory to the `function-execution` directory in your 
example workspace.
+
+  ```
+  $ cd workspace/examples/cpp/function-execution
+  ```
+
+1. Run the `startserver.sh` script to start the Geode server, create a region, 
and populate the region with sample data.
+
+  ```
+  $ sh ./startserver.sh
+  /Users/user/geode/bin/gfsh
+
+  (1) Executing - start locator --name=locator
+  ...
+  (2) Executing - start server --name=server
+  ...
+(3) Executing - create region --name=example_userinfo --type=PARTITION
+
+  Member | Status
+  ------ | ----------------------------------------------
+  server | Region "/partition_region" created on "the-server"
+  ```
+(1) Executing - start locator --name=locator
+
+...
+Locator in /nc_install/examples/cpp/function-execution/locator on 
10.118.33.178[10334] as locator is currently online.
+Process ID: 63773
+Uptime: 2 seconds
+Geode Version: 1.6.0
+Java Version: 1.8.0_162
+Log File: /nc_install/examples/cpp/function-execution/locator/locator.log
+JVM Arguments: -Dgemfire.enable-cluster-configuration=true 
-Dgemfire.load-cluster-configuration-from-dir=false 
-Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true 
-Dsun.rmi.dgc.server.gcInterval=9223372036854775806
+Class-Path: 
/apache-geode-1.6.0/lib/geode-core-1.6.0.jar:/apache-geode-1.6.0/lib/geode-dependencies.jar
+
+Successfully connected to: JMX Manager [host=10.118.33.178, port=1099]
+
+Cluster configuration service is up and running.
+
+
+(2) Executing - deploy --jar=../../javaobject.jar
+
+
+
+(3) Executing - start server --name=the-server --server-port=40404
+
+....
+Server in /nc_install/examples/cpp/function-execution/the-server on 
10.118.33.178[40404] as the-server is currently online.
+Process ID: 63778
+Uptime: 5 seconds
+Geode Version: 1.6.0
+Java Version: 1.8.0_162
+Log File: /nc_install/examples/cpp/function-execution/the-server/the-server.log
+JVM Arguments: -Dgemfire.default.locators=10.118.33.178[10334] 
-Dgemfire.start-dev-rest-api=false -Dgemfire.use-cluster-configuration=true 
-XX:OnOutOfMemoryError=kill -KILL %p 
-Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true 
-Dsun.rmi.dgc.server.gcInterval=9223372036854775806
+Class-Path: 
/apache-geode-1.6.0/lib/geode-core-1.6.0.jar:/apache-geode-1.6.0/lib/geode-dependencies.jar
+
+
+(4) Executing - create region --name=partition_region --type=PARTITION
+
+  Member   | Status
+---------- | --------------------------------------------------
+the-server | Region "/partition_region" created on "the-server"
+
+
+(5) Executing - start server --name=the-second-server --server-port=50505
+
+....
+Server in /nc_install/examples/cpp/function-execution/the-second-server on 
10.118.33.178[50505] as the-second-server is currently online.
+Process ID: 63779
+Uptime: 4 seconds
+Geode Version: 1.6.0
+Java Version: 1.8.0_162
+Log File: 
/nc_install/examples/cpp/function-execution/the-second-server/the-second-server.log
+JVM Arguments: -Dgemfire.default.locators=10.118.33.178[10334] 
-Dgemfire.start-dev-rest-api=false -Dgemfire.use-cluster-configuration=true 
-XX:OnOutOfMemoryError=kill -KILL %p 
-Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true 
-Dsun.rmi.dgc.server.gcInterval=9223372036854775806
+Class-Path: 
/apache-geode-1.6.0/lib/geode-core-1.6.0.jar:/apache-geode-1.6.0/lib/geode-dependencies.jar
+1. Execute `function-execution`:
+
+  ```
+
+  $./function-execution 
+Created CacheFactory
+Created the Region
+test data independent function with result on one server
+get: result count = 17
+get result[0]=VALUE--1
+get result[1]=VALUE--3
+get result[2]=VALUE--5
+get result[3]=VALUE--7
+get result[4]=VALUE--9
+get result[5]=VALUE--11
+get result[6]=VALUE--13
+get result[7]=VALUE--15
+get result[8]=VALUE--17
+get result[9]=VALUE--19
+get result[10]=VALUE--21
+get result[11]=VALUE--23
+get result[12]=VALUE--25
+get result[13]=VALUE--27
+get result[14]=VALUE--29
+get result[15]=VALUE--31
+get result[16]=VALUE--33
+test data independent function without result on one server
+test data independent function with result on all servers
+get: result count = 34
+get result[0]=KEY--1
+get result[1]=KEY--3
+get result[2]=KEY--5
+get result[3]=KEY--7
+get result[4]=KEY--9
+get result[5]=KEY--11
+get result[6]=KEY--13
+get result[7]=KEY--15
+get result[8]=VALUE--17
+get result[9]=VALUE--19
+get result[10]=VALUE--21
+get result[11]=VALUE--23
+get result[12]=VALUE--25
+get result[13]=VALUE--27
+get result[14]=VALUE--29
+get result[15]=VALUE--31
+get result[16]=VALUE--33
+get result[17]=KEY--1
+get result[18]=KEY--3
+get result[19]=KEY--5
+get result[20]=KEY--7
+get result[21]=KEY--9
+get result[22]=KEY--11
+get result[23]=KEY--13
+get result[24]=KEY--15
+get result[25]=KEY--17
+get result[26]=KEY--19
+get result[27]=KEY--21
+get result[28]=KEY--23
+get result[29]=KEY--25
+get result[30]=KEY--27
+get result[31]=KEY--29
+get result[32]=KEY--31
+get result[33]=KEY--33
+test data independent function without result on all servers
+test data dependent function with result
+Execute on Region: result count = 4
+Execute on Region: result count = 34
+Execute on Region: result[0]=KEY--11
+Execute on Region: result[1]=KEY--5
+Execute on Region: result[2]=KEY--17
+Execute on Region: result[3]=KEY--27
+Execute on Region: result[4]=KEY--9
+Execute on Region: result[5]=KEY--29
+Execute on Region: result[6]=KEY--13
+Execute on Region: result[7]=KEY--23
+Execute on Region: result[8]=KEY--15
+Execute on Region: result[9]=KEY--11
+Execute on Region: result[10]=KEY--5
+Execute on Region: result[11]=KEY--17
+Execute on Region: result[12]=KEY--27
+Execute on Region: result[13]=KEY--9
+Execute on Region: result[14]=KEY--29
+Execute on Region: result[15]=KEY--13
+Execute on Region: result[16]=KEY--23
+Execute on Region: result[17]=KEY--15
+Execute on Region: result[18]=KEY--31
+Execute on Region: result[19]=KEY--1
+Execute on Region: result[20]=KEY--33
+Execute on Region: result[21]=KEY--21
+Execute on Region: result[22]=KEY--3
+Execute on Region: result[23]=KEY--7
+Execute on Region: result[24]=KEY--19
+Execute on Region: result[25]=KEY--25
+Execute on Region: result[26]=KEY--31
+Execute on Region: result[27]=KEY--1
+Execute on Region: result[28]=KEY--33
+Execute on Region: result[29]=KEY--21
+Execute on Region: result[30]=KEY--3
+Execute on Region: result[31]=KEY--7
+Execute on Region: result[32]=KEY--19
+Execute on Region: result[33]=KEY--25
+test data dependent function without result
+Closed the Geode Cache  
+```
+
+1. Stop the server
+
+  ```
+  $ sh ./stopserver.sh
+  /Users/user/geode/bin/gfsh
+  (1) Executing - connect
+  ...
+  (2) Executing - stop server --name=server
+  ...
+  (3) Executing - stop locator --name=locator
+  ....
+  ```
+
diff --git a/examples/cpp/function-execution/main.cpp 
b/examples/cpp/function-execution/main.cpp
new file mode 100644
index 0000000..1b0ae81
--- /dev/null
+++ b/examples/cpp/function-execution/main.cpp
@@ -0,0 +1,184 @@
+/*
+ * 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.
+ */
+
+/*
+ * The Execute Function QuickStart Example.
+ *
+ * This example takes the following steps:
+ *
+ * 1. Create a Geode Cache.
+ * 2. Create the example Region Programmatically.
+ * 3. Populate some objects on the Region.
+ * 4. Create Execute Objects
+ * 5. Execute Functions
+ * 6. Close the Cache.
+ *
+ */
+#include <iostream>
+#include <memory>
+
+#include <geode/CacheFactory.hpp>
+#include <geode/PoolManager.hpp>
+#include <geode/RegionFactory.hpp>
+#include <geode/RegionShortcut.hpp>
+#include <geode/FunctionService.hpp>
+#include <geode/CacheableString.hpp>
+
+// Use the "geode" namespace.
+using namespace apache::geode::client;
+
+const auto getFuncIName = std::string("MultiGetFunctionI");
+const auto putFuncIName = std::string("MultiPutFunctionI");
+const auto getFuncName = std::string("MultiGetFunction");
+
+const int EXAMPLE_ITEM_COUNT = 34;
+
+// The Execute Function QuickStart example.
+int main(int argc, char** argv) {
+  try {
+    // Create CacheFactory using the settings from the geode.properties file by
+    // default.
+    auto cache = CacheFactory()
+        .set("log-level", "none")
+        .create();
+
+    std::cout << "Created CacheFactory\n";
+
+    auto pool = cache.getPoolManager()
+        .createFactory()
+        .setSubscriptionEnabled(true)
+        .addServer("localhost", 50505)
+        .addServer("localhost", 40404);
+        .create("pool");
+
+    // Create the example Region Programmatically
+    auto regionFactory = cache.createRegionFactory(RegionShortcut::PROXY);
+    auto regPtr0 = 
regionFactory.setPoolName("pool").create("partition_region");
+
+    std::cout << "Created the Region\n";
+
+    regPtr0->registerAllKeys();
+    char buf[128];
+
+    auto resultList = CacheableVector::create();
+    for (int i = 0; i < EXAMPLE_ITEM_COUNT; i++) {
+      sprintf(buf, "VALUE--%d", i);
+      auto value(CacheableString::create(buf));
+
+      sprintf(buf, "KEY--%d", i);
+      auto key = CacheableKey::create(buf);
+      regPtr0->put(key, value);
+    }
+
+    auto routingObj = CacheableVector::create();
+    for (int i = 1; i < EXAMPLE_ITEM_COUNT; i+=2) {
+      sprintf(buf, "KEY--%d", i);
+      auto key = CacheableKey::create(buf);
+      routingObj->push_back(key);
+    }
+
+    std::cout << "test data independent function with result on one server\n";
+    auto exc = FunctionService::onServer(regPtr0->getRegionService());
+    if(auto executeFunctionResult = 
exc.withArgs(routingObj).execute(getFuncIName)->getResult()) {
+      for (auto &arrayList: *executeFunctionResult) {
+        for (auto &cachedString: 
*std::dynamic_pointer_cast<CacheableArrayList>(arrayList)) {
+          resultList->push_back(cachedString);
+        }
+      }
+      sprintf(buf, "get: result count = %lu\n", resultList->size());
+      std::cout << buf;
+      int i = 0;
+      for (auto &cachedString: *resultList) {
+        sprintf(
+            buf, "get result[%d]=%s\n", i,
+            
std::dynamic_pointer_cast<CacheableString>(cachedString)->value().c_str());
+        std::cout << buf;
+        ++i;
+      }
+    } else {
+      std::cout << "get executeFunctionResult is NULL\n";
+    }
+
+    std::cout << "test data independent function without result on one 
server\n";
+
+    exc.withArgs(routingObj).execute(putFuncIName, 
std::chrono::milliseconds(15));
+
+    std::cout << "test data independent function with result on all servers\n";
+
+    exc = FunctionService::onServers(regPtr0->getRegionService());
+    if(auto executeFunctionResult = 
exc.withArgs(routingObj).execute(getFuncIName)->getResult()) {
+      resultList->clear();
+      for (auto &arrayList: *executeFunctionResult) {
+        for (auto &cachedString: 
*std::dynamic_pointer_cast<CacheableArrayList>(arrayList)) {
+          resultList->push_back(cachedString);
+        }
+      }
+      sprintf(buf, "get: result count = %lu\n", resultList->size());
+      std::cout << buf;
+      int i = 0;
+      for (auto &cachedString: *resultList) {
+        sprintf(
+            buf, "get result[%d]=%s\n", i,
+            
std::dynamic_pointer_cast<CacheableString>(cachedString)->value().c_str());
+        std::cout << buf;
+        ++i;
+      }
+    } else {
+      std::cout << "get executeFunctionResult is NULL\n";
+    }
+
+
+    std::cout << "test data independent function without result on all 
servers\n";
+    exc.withArgs(routingObj).execute(putFuncIName, 
std::chrono::milliseconds(15));
+    std::cout << "test data dependent function with result\n";
+
+    auto args = CacheableBoolean::create(1);
+    exc = FunctionService::onRegion(regPtr0);
+    if(auto executeFunctionResult = exc.withFilter(routingObj)
+        .withArgs(args)
+        .execute(getFuncName)
+        ->getResult()) {
+      resultList->clear();
+      std::cout << "Execute on Region: result count = " << 
executeFunctionResult->size() << '\n';
+      for (auto &arrayList: *executeFunctionResult) {
+        for (auto &cachedString: 
*std::dynamic_pointer_cast<CacheableArrayList>(arrayList)) {
+          resultList->push_back(cachedString);
+        }
+      }
+      sprintf(buf, "Execute on Region: result count = %lu\n", 
resultList->size());
+      std::cout << buf;
+      int i = 0;
+      for (auto &cachedString: *resultList) {
+        sprintf(
+            buf, "Execute on Region: result[%d]=%s\n", i,
+            
std::dynamic_pointer_cast<CacheableString>(cachedString)->value().c_str());
+        std::cout << buf;
+        ++i;
+      }
+    } else {
+      std::cout << "execute on region: executeFunctionResult is NULL\n";
+    }
+
+    return 0;
+  }
+    // An exception should not occur
+  catch (const Exception& geodeExcp) {
+    std::cerr << "Function Execution Geode Exception: " << 
geodeExcp.getMessage() << '\n';
+
+    return 1;
+  }
+}
diff --git a/examples/cpp/CMakeLists.txt.in 
b/examples/cpp/function-execution/startserver.sh
old mode 100644
new mode 100755
similarity index 57%
copy from examples/cpp/CMakeLists.txt.in
copy to examples/cpp/function-execution/startserver.sh
index e176810..24e2a9f
--- a/examples/cpp/CMakeLists.txt.in
+++ b/examples/cpp/function-execution/startserver.sh
@@ -1,3 +1,5 @@
+#!/bin/env bash
+
 # 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.
@@ -13,13 +15,20 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-cmake_minimum_required(VERSION 3.10)
+GFSH_PATH=""
+which gfsh 2> /dev/null
+
+if [ $? -eq 0 ]; then
+    GFSH_PATH="gfsh"
+else
+    if [ "$GEODE_HOME" == "" ]; then
+        echo "Could not find gfsh. Please set the GEODE_HOME path."
+        echo "e.g. export GEODE_HOME=<path to Geode>"
+    else
+        GFSH_PATH=$GEODE_HOME/bin/gfsh
+    fi
+fi
+
+$GFSH_PATH  -e "start locator --name=locator" -e "deploy 
--jar=../../javaobject.jar" -e "start server --name=the-server 
--server-port=40404"  -e "create region --name=partition_region 
--type=PARTITION" -e "start server --name=the-second-server --server-port=50505"
 
-project(@[email protected] LANGUAGES NONE)
 
-add_subdirectory(continuousquery)
-add_subdirectory(dataserializable)
-add_subdirectory(pdxserializable)
-add_subdirectory(pdxserializer)
-add_subdirectory(put-get-remove)
-add_subdirectory(remotequery)
diff --git a/examples/cpp/CMakeLists.txt.in 
b/examples/cpp/function-execution/stopserver.sh
old mode 100644
new mode 100755
similarity index 67%
copy from examples/cpp/CMakeLists.txt.in
copy to examples/cpp/function-execution/stopserver.sh
index e176810..7891cf6
--- a/examples/cpp/CMakeLists.txt.in
+++ b/examples/cpp/function-execution/stopserver.sh
@@ -1,3 +1,5 @@
+#!/bin/env bash
+
 # 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.
@@ -13,13 +15,19 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-cmake_minimum_required(VERSION 3.10)
+GFSH_PATH=""
+which gfsh 2> /dev/null
+
+if [ $? -eq 0 ]; then
+    GFSH_PATH="gfsh"
+else
+    if [ "$GEODE_HOME" == "" ]; then
+        echo "Could not find gfsh. Please set the GEODE_HOME path."
+        echo "e.g. export GEODE_HOME=<path to Geode>"
+    else
+        GFSH_PATH=$GEODE_HOME/bin/gfsh
+    fi
+fi
 
-project(@[email protected] LANGUAGES NONE)
+$GFSH_PATH -e "connect" -e "shutdown --include-locators=true"
 
-add_subdirectory(continuousquery)
-add_subdirectory(dataserializable)
-add_subdirectory(pdxserializable)
-add_subdirectory(pdxserializer)
-add_subdirectory(put-get-remove)
-add_subdirectory(remotequery)
diff --git a/tests/javaobject/CMakeLists.txt b/tests/javaobject/CMakeLists.txt
index 3f3a595..a6f61fd 100644
--- a/tests/javaobject/CMakeLists.txt
+++ b/tests/javaobject/CMakeLists.txt
@@ -22,7 +22,15 @@ include(UseJava)
 
 file(GLOB_RECURSE SOURCES "*.java")
 
-
 add_jar(javaobject ${SOURCES}
   INCLUDE_JARS ${Geode_CLASSPATH}
 )
+
+set(EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/javaobject.jar)
+
+install(DIRECTORY ${COMMON_INCLUDE_DIR} DESTINATION .)
+install(FILES
+        ${EXPORT_FILE_NAME}
+        DESTINATION examples/
+        )
+

Reply via email to