[ 
https://issues.apache.org/jira/browse/GEODE-4119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16311946#comment-16311946
 ] 

ASF GitHub Bot commented on GEODE-4119:
---------------------------------------

PivotalSarge closed pull request #41: GEODE-4119: Add an example of eviction.
URL: https://github.com/apache/geode-examples/pull/41
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/README.md b/README.md
index e77194b..5be09cf 100644
--- a/README.md
+++ b/README.md
@@ -74,7 +74,7 @@ tutorial.
 *  [Async Event Queues & Async Event Listeners](async/README.md)
 *  Continuous Querying
 *  Transactions
-*  Eviction
+*  [Eviction](eviction/README.md)
 *  Expiration
 *  Overflow
 *  Security
diff --git a/eviction/README.md b/eviction/README.md
new file mode 100644
index 0000000..9606434
--- /dev/null
+++ b/eviction/README.md
@@ -0,0 +1,53 @@
+<!--
+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 Eviction Example
+
+This is a simple example that demonstrates eviction of entries from a region. 
This allows control
+over the system resources consumed by any given region.
+
+A region is a collection of entries which are tuples of key and value. Each 
entry requires memory
+for the key object, the value object, and some overhead. Regions that contain 
a large number of
+entries, entries of a large size, or both can consume enough system resources 
to impact overall
+system performance, even for other regions.
+
+A region can have eviction enabled to enforce an upper limit on either the 
total number of entries
+_or_ the total amount of memory consumed by the entries. The region will then 
ensure the specified
+limits on its in-memory resource consumption. When an operation would exceed 
those limits, the
+region will take an action to assure that the limits will not be exceeded 
after the operation
+completes. The region can either destroy one or more entries or overflow one 
or more entries to disk.
+
+This example assumes you have installed Java and Geode.
+
+## Steps
+
+1. From the `geode-examples/eviction` directory, build the example and
+   run unit tests.
+
+        $ ../gradlew build
+
+2. Next start a locator, start a server, and create a region.
+
+        $ gfsh run --file=scripts/start.gfsh
+
+3. Run the example to demonstrate eviction.
+
+        $ ../gradlew run
+
+4. Shut down the system.
+
+        $ gfsh run --file=scripts/stop.gfsh
diff --git a/eviction/scripts/start.gfsh b/eviction/scripts/start.gfsh
new file mode 100755
index 0000000..163aae9
--- /dev/null
+++ b/eviction/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 
--classpath=../build/classes/main
+start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 
--classpath=../build/classes/main
+list members
+
+create region --name=example-region --type=REPLICATE --skip-if-exists=true \
+    --eviction-entry-count=10 --eviction-action=local-destroy
+describe region --name=example-region
diff --git a/eviction/scripts/stop.gfsh b/eviction/scripts/stop.gfsh
new file mode 100755
index 0000000..15cd93c
--- /dev/null
+++ b/eviction/scripts/stop.gfsh
@@ -0,0 +1,19 @@
+#
+# 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
diff --git 
a/eviction/src/main/java/org/apache/geode_examples/eviction/Example.java 
b/eviction/src/main/java/org/apache/geode_examples/eviction/Example.java
new file mode 100644
index 0000000..b83dfbb
--- /dev/null
+++ b/eviction/src/main/java/org/apache/geode_examples/eviction/Example.java
@@ -0,0 +1,72 @@
+/*
+ * 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.eviction;
+
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.client.ClientCache;
+import org.apache.geode.cache.client.ClientCacheFactory;
+import org.apache.geode.cache.client.ClientRegionFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Random;
+import java.util.Set;
+import java.util.stream.IntStream;
+
+public class Example {
+  public static final int ITERATIONS = 20;
+
+  public static void main(String[] args) {
+    // connect to the locator using default port 10334
+    ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 
10334)
+        .set("log-level", "WARN").create();
+
+    Example example = new Example();
+
+    // create a local region that matches the server region
+    ClientRegionFactory<Integer, String> clientRegionFactory =
+        cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
+    Region<Integer, String> region = 
clientRegionFactory.create("example-region");
+
+    example.putEntries(region);
+    cache.close();
+  }
+
+  private Collection<Integer> generateIntegers() {
+    IntStream stream = new Random().ints(0, ITERATIONS);
+    Iterator<Integer> iterator = stream.iterator();
+    Set<Integer> integers = new LinkedHashSet<>();
+    while (iterator.hasNext() && integers.size() < ITERATIONS) {
+      integers.add(iterator.next());
+    }
+    return integers;
+  }
+
+  public void putEntries(Region<Integer, String> region) {
+    Collection<Integer> integers = generateIntegers();
+    Iterator<Integer> iterator = integers.iterator();
+
+    int created = 0;
+    while (iterator.hasNext()) {
+      Integer integer = iterator.next();
+      region.put(integer, integer.toString());
+      System.out.println("Added value for " + integer + "; the region now has "
+          + region.sizeOnServer() + " entries.");
+      ++created;
+    }
+  }
+}
diff --git a/settings.gradle b/settings.gradle
index e43f7f8..d0760e3 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -29,3 +29,4 @@ include 'writer'
 include 'listener'
 include 'async'
 include 'luceneSpatial'
+include 'eviction'


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Create new geode-example about eviction
> ---------------------------------------
>
>                 Key: GEODE-4119
>                 URL: https://issues.apache.org/jira/browse/GEODE-4119
>             Project: Geode
>          Issue Type: New Feature
>          Components: examples
>            Reporter: Michael Dodge
>            Assignee: Michael Dodge
>
> Create a new example that demonstrates eviction.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to