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

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


The following commit(s) were added to refs/heads/develop by this push:
     new f0d604c  GEODE-8751: geode compression example (#106)
f0d604c is described below

commit f0d604ceb66c42b667157ce57473ea339ba06ecd
Author: Ashish Choudhary <aashish.choudha...@gmail.com>
AuthorDate: Mon Jan 4 11:37:59 2021 +0530

    GEODE-8751: geode compression example (#106)
---
 README.md                                          |  2 +-
 compression/README.md                              | 42 +++++++++++++++
 compression/scripts/start.gfsh                     | 25 +++++++++
 compression/scripts/stop.gfsh                      | 18 +++++++
 .../apache/geode_examples/compression/Example.java | 62 ++++++++++++++++++++++
 settings.gradle                                    |  1 +
 6 files changed, 149 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 9046cf3..53c796c 100644
--- a/README.md
+++ b/README.md
@@ -98,7 +98,7 @@ tutorial.
 *  Delta propagation
 *  Network partition detection
 *  D-lock
-*  Compression
+*  [Compression](compression/README.md)
 *  Resource manager
 *  PDX Advanced
 
diff --git a/compression/README.md b/compression/README.md
new file mode 100644
index 0000000..cf757bd
--- /dev/null
+++ b/compression/README.md
@@ -0,0 +1,42 @@
+<!--
+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.
+-->
+
+# Geode Compression example
+
+This is a simple example that demonstrates enabling Compression in a
+replicated region. The Default compression algorithm included with Geode is 
Snappy. Additionally, you can specify your own compressor algorithm as well by 
implementing `org.apache.geode.compression.Compression` Interface. For enabling 
compression on a Geode region you can follow the official 
[document](https://geode.apache.org/docs/guide/113/managing/region_compression.html#topic_inm_whc_gl).
+
+This example assumes you have installed Java and Geode.
+
+## Steps
+
+1. From the `geode-examples/compression` directory, build the example and
+   run unit tests
+
+        $ ../gradlew build
+
+2. Next start the locator, two servers and create replicated region 
`example-region` with `compression` enabled.
+
+        $ gfsh run --file=scripts/start.gfsh
+
+3. Run the example to create and get entries using Geode Java Client from the 
region
+
+        $ ../gradlew run
+        
+4. Shut down the system:
+
+        $ gfsh run --file=scripts/stop.gfsh
diff --git a/compression/scripts/start.gfsh b/compression/scripts/start.gfsh
new file mode 100644
index 0000000..aa0ed5f
--- /dev/null
+++ b/compression/scripts/start.gfsh
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+start locator --name=locator --bind-address=127.0.0.1
+
+start server --name=server1 --locators=127.0.0.1[10334] --server-port=0
+start server --name=server2 --locators=127.0.0.1[10334] --server-port=0
+
+create region --name=example-region --type=REPLICATE 
--compressor=org.apache.geode.compression.SnappyCompressor
+
+list members
+describe region --name=example-region
diff --git a/compression/scripts/stop.gfsh b/compression/scripts/stop.gfsh
new file mode 100644
index 0000000..9281b31
--- /dev/null
+++ b/compression/scripts/stop.gfsh
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+connect --locator=127.0.0.1[10334]
+shutdown --include-locators=true
\ No newline at end of file
diff --git 
a/compression/src/main/java/org/apache/geode_examples/compression/Example.java 
b/compression/src/main/java/org/apache/geode_examples/compression/Example.java
new file mode 100644
index 0000000..d498ecd
--- /dev/null
+++ 
b/compression/src/main/java/org/apache/geode_examples/compression/Example.java
@@ -0,0 +1,62 @@
+/*
+ * 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.geode_examples.compression;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.IntStream;
+
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.client.*;
+
+public class Example {
+  private final Region<Integer, String> region;
+  private static final String POOL_NAME = "client-pool";
+
+  public Example(Region<Integer, String> region) {
+    this.region = region;
+  }
+
+  public static void main(String[] args) {
+    ClientCache cache = new ClientCacheFactory().set("log-level", 
"WARN").create();
+    // connect to the locator using default port 10334
+    PoolFactory poolFactory = PoolManager.createFactory();
+    poolFactory.addLocator("127.0.0.1", 10334);
+    poolFactory.create(POOL_NAME);
+
+    // create a local region that matches the server region
+    Region<Integer, String> region =
+        cache.<Integer, 
String>createClientRegionFactory(ClientRegionShortcut.PROXY)
+            .setPoolName(POOL_NAME).create("example-region");
+
+    Example example = new Example(region);
+    example.putValues(10);
+    example.printValues(example.getValues());
+
+    cache.close();
+  }
+
+  Set<Integer> getValues() {
+    return new HashSet<>(region.keySetOnServer());
+  }
+
+  void putValues(int upperLimit) {
+    IntStream.rangeClosed(1, upperLimit).forEach(i -> region.put(i, "value" + 
i));
+  }
+
+  void printValues(Set<Integer> values) {
+    values.forEach(key -> System.out.println(String.format("%d:%s", key, 
region.get(key))));
+  }
+}
diff --git a/settings.gradle b/settings.gradle
index 3296793..7a681e3 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -41,6 +41,7 @@ include 'jdbc'
 include 'sessionState'
 include 'colocation'
 include 'micrometerMetrics'
+include 'compression'
 
 // Logic for defining a custom Geode clone for integration with this project
 // Define `-PgeodeCompositeDirectory` to your geode root, default `../geode`

Reply via email to