geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From upthewatersp...@apache.org
Subject [geode-examples] branch develop updated: GEODE-3724: Add a new geode-example about and async event listeners. (#23)
Date Thu, 19 Oct 2017 23:38:02 GMT
This is an automated email from the ASF dual-hosted git repository.

upthewaterspout 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 14d2999  GEODE-3724: Add a new geode-example about and async event listeners. (#23)
14d2999 is described below

commit 14d2999a80f1f27cb3c7c327fd849208f740339d
Author: Michael "Sarge" Dodge <mdodge@pivotal.io>
AuthorDate: Thu Oct 19 16:38:00 2017 -0700

    GEODE-3724: Add a new geode-example about and async event listeners. (#23)
    
    Added a new example of using a async event listener to spellcheck entries and write to
a different region.
---
 README.md                                          |  2 +-
 async/README.md                                    | 52 +++++++++++++++
 async/scripts/start.gfsh                           | 39 +++++++++++
 async/scripts/stop.gfsh                            | 22 +++++++
 .../org/apache/geode/examples/async/Example.java   | 76 ++++++++++++++++++++++
 .../examples/async/ExampleAsyncEventListener.java  | 71 ++++++++++++++++++++
 .../geode/examples/async/LevenshteinDistance.java  | 36 ++++++++++
 .../async/ExampleAsyncEventListenerTest.java       | 47 +++++++++++++
 .../apache/geode/examples/async/ExampleTest.java   | 44 +++++++++++++
 .../examples/async/LevenshteinDistanceTest.java    | 41 ++++++++++++
 build.gradle                                       |  4 ++
 settings.gradle                                    |  1 +
 .../org/geode/examples/util/TestAsyncEvent.java    | 73 +++++++++++++++++++++
 13 files changed, 507 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index bf0cdbd..d0a097d 100644
--- a/README.md
+++ b/README.md
@@ -71,7 +71,7 @@ tutorial.
 *  [Cache Loader](loader/README.md)
 *  [Cache Writer](writer/README.md)
 *  [Cache Listeners](listener/README.md)
-*  Async Event Queues & Async Event Listeners
+*  [Async Event Queues & Async Event Listeners](async/README.md)
 *  Continuous Querying
 *  Transactions
 *  Eviction
diff --git a/async/README.md b/async/README.md
new file mode 100644
index 0000000..32964bf
--- /dev/null
+++ b/async/README.md
@@ -0,0 +1,52 @@
+<!--
+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 Asynchronous Event Queues & Listeners Example
+
+This is a simple example that demonstrates asynchronous event queues and listeners.
+
+An asynchronous event queue is an ordered collection of events that occurred on a region,
e.g., create a new entry, update an existing entry. An asynchronous event listener has its
method invoked from time to time with batches of events that have occurred previously. The
method invocation occurs inside the JVM of the server and can _not_ affect the operation on
the region.
+
+In this example, an asynchronous event queue is created for the region of incoming words.
An asynchronous event listener is specified for that asynchronous event queue. Whenever the
`processEvents` method is invoked on the listener, it uses the Levenshtein distance for each
word to perform simplistic spell-checking. The proposed revision is the put in the outgoing
region. A cache listener is installed that captures all of the creation events for the outgoing
region and displays the propo [...]
+
+This example assumes you have installed Java and Geode.
+
+## Steps
+
+1. From the `geode-examples/async` directory, build the example, and
+   run unit tests.
+
+        $ ../gradlew build
+
+2. Next start a locator, start two servers, create two regions, and deploy the asynchronous
event listener.
+
+        $ gfsh run --file=scripts/start.gfsh
+
+3. Run the example to put entries into the incoming region and get entries from the outgoing
region.
+
+        $ ../gradlew run
+
+4. Notice the output.
+
+        that -> that
+        teh -> the
+        wil -> will
+        i -> I
+
+5. Shut down the system.
+
+        $ gfsh run --file=scripts/stop.gfsh
diff --git a/async/scripts/start.gfsh b/async/scripts/start.gfsh
new file mode 100644
index 0000000..78c16e9
--- /dev/null
+++ b/async/scripts/start.gfsh
@@ -0,0 +1,39 @@
+#
+# 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
+
+deploy --jar=build/libs/async.jar
+list functions
+
+create async-event-queue --id=example-async-event-queue \
+  --parallel=false \
+  --enable-batch-conflation=false \
+  --batch-size=1 \
+  --batch-time-interval=0 \
+  --listener=org.apache.geode.examples.async.ExampleAsyncEventListener
+list async-event-queues
+
+create region --name=incoming-region --type=REPLICATE --async-event-queue-id=example-async-event-queue
+create region --name=outgoing-region --type=REPLICATE
+
+list members
+describe region --name=incoming-region
+describe region --name=outgoing-region
diff --git a/async/scripts/stop.gfsh b/async/scripts/stop.gfsh
new file mode 100644
index 0000000..9e81298
--- /dev/null
+++ b/async/scripts/stop.gfsh
@@ -0,0 +1,22 @@
+#
+# 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]
+destroy region --name=outgoing-region
+destroy region --name=incoming-region
+undeploy --jar=build/libs/async.jar
+shutdown --include-locators=true
diff --git a/async/src/main/java/org/apache/geode/examples/async/Example.java b/async/src/main/java/org/apache/geode/examples/async/Example.java
new file mode 100644
index 0000000..3855372
--- /dev/null
+++ b/async/src/main/java/org/apache/geode/examples/async/Example.java
@@ -0,0 +1,76 @@
+/*
+ * 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.async;
+
+import java.util.Arrays;
+import java.util.List;
+
+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 org.apache.geode.cache.client.PoolManager;
+
+public class Example {
+  public static final String INCOMING_REGION_NAME = "incoming-region";
+  public static final String OUTGOING_REGION_NAME = "outgoing-region";
+
+  public static void main(String[] args) {
+    // connect to the locator using default port 10334
+    ClientCache cache = new ClientCacheFactory().set("log-level", "WARN").create();
+
+    final String poolName = "subscriptionPool";
+    PoolManager.createFactory().addLocator("127.0.0.1", 10334).setSubscriptionEnabled(true)
+        .create(poolName);
+
+    // create a local region that matches the server region
+    final ClientRegionFactory<Integer, String> incomingRegionFactory =
+        cache.<Integer, String>createClientRegionFactory(ClientRegionShortcut.PROXY);
+    Region<Integer, String> incomingRegion =
+        incomingRegionFactory.setPoolName(poolName).create(INCOMING_REGION_NAME);
+
+    // create another local region that matches the server region
+    final ClientRegionFactory<String, String> outgoingRegionFactory =
+        cache.<String, String>createClientRegionFactory(ClientRegionShortcut.PROXY);
+    Region<String, String> outgoingRegion =
+        outgoingRegionFactory.setPoolName(poolName).create(OUTGOING_REGION_NAME);
+
+    new Example().checkWords(incomingRegion, outgoingRegion,
+        Arrays.asList(new String[] {"that", "teh", "wil", "i'"}));
+    cache.close();
+  }
+
+  public void checkWords(Region<Integer, String> incomingRegion,
+      Region<String, String> outgoingRegion, List<String> words) {
+    int key = 0;
+    for (String word : words) {
+      incomingRegion.put(key++, word);
+    }
+
+    // Give the process a chance to work.
+    while (outgoingRegion.sizeOnServer() < words.size()) {
+      try {
+        Thread.sleep(500);
+      } catch (InterruptedException ie) {
+        // NOP
+      }
+    }
+
+    for (String candidate : outgoingRegion.keySetOnServer()) {
+      System.out.println(candidate + " -> " + outgoingRegion.get(candidate));
+    }
+  }
+}
diff --git a/async/src/main/java/org/apache/geode/examples/async/ExampleAsyncEventListener.java
b/async/src/main/java/org/apache/geode/examples/async/ExampleAsyncEventListener.java
new file mode 100644
index 0000000..2af0809
--- /dev/null
+++ b/async/src/main/java/org/apache/geode/examples/async/ExampleAsyncEventListener.java
@@ -0,0 +1,71 @@
+/*
+ * 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.async;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.asyncqueue.AsyncEvent;
+import org.apache.geode.cache.asyncqueue.AsyncEventListener;
+
+public class ExampleAsyncEventListener implements AsyncEventListener {
+  private final String[] words =
+      {"the", "be", "to", "of", "and", "I", "a", "in", "that", "have", "it", "for", "not",
"on",
+          "with", "he", "as", "you", "do", "at", "this", "but", "his", "by", "from", "they",
"we",
+          "say", "her", "she", "or", "an", "will", "my", "one", "all", "would", "there",
"their",
+          "what", "so", "up", "out", "if", "about", "who", "get", "which", "go", "me"};
+
+  private final LevenshteinDistance distance = new LevenshteinDistance();
+
+  public String spellCheck(String candidate) {
+    int index = -1;
+    int shortest = Integer.MAX_VALUE;
+    for (int i = 0; i < words.length; ++i) {
+      final String word = words[i];
+      final int score = distance.calculate(word, candidate);
+      if (score < shortest) {
+        index = i;
+        shortest = score;
+      }
+    }
+    if (0 <= index) {
+      return words[index];
+    }
+    return candidate;
+  }
+
+  @Override
+  public boolean processEvents(List<AsyncEvent> events) {
+    final ExecutorService exService = Executors.newSingleThreadExecutor();
+    for (AsyncEvent<Integer, String> event : events) {
+      final String oldValue = event.getDeserializedValue();
+      final String newValue = spellCheck(oldValue);
+      exService.submit(() -> {
+        Cache cache = (Cache) event.getRegion().getRegionService();
+        Region<String, String> region = cache.getRegion(Example.OUTGOING_REGION_NAME);
+        region.put(oldValue, newValue);
+      });
+    }
+    return true;
+  }
+
+  @Override
+  public void close() {
+    // NOP
+  }
+}
diff --git a/async/src/main/java/org/apache/geode/examples/async/LevenshteinDistance.java
b/async/src/main/java/org/apache/geode/examples/async/LevenshteinDistance.java
new file mode 100644
index 0000000..7d75698
--- /dev/null
+++ b/async/src/main/java/org/apache/geode/examples/async/LevenshteinDistance.java
@@ -0,0 +1,36 @@
+/*
+ * 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.async;
+
+/**
+ * The Levenshtein distance is a measure of the difference between two strings of characters.
It can
+ * be useful in determining when two strings are very much alike, e.g., a transposed character.
+ * While not as powerful as other techniques, one use is simple spell-checking.
+ */
+public class LevenshteinDistance {
+  public int calculate(String first, String second) {
+    if (first == null || first.isEmpty())
+      return (second == null ? 0 : second.length());
+    if (second == null || second.isEmpty())
+      return (first == null ? 0 : first.length());
+
+    final String firstPrime = first.substring(0, first.length() - 1);
+    final String secondPrime = second.substring(0, second.length() - 1);
+    final int cost =
+        ((first.charAt(first.length() - 1) == second.charAt(second.length() - 1)) ? 0 : 1);
+    return Math.min(Math.min(calculate(firstPrime, second) + 1, calculate(first, secondPrime)
+ 1),
+        calculate(firstPrime, secondPrime) + cost);
+  }
+}
diff --git a/async/src/test/java/org/apache/geode/examples/async/ExampleAsyncEventListenerTest.java
b/async/src/test/java/org/apache/geode/examples/async/ExampleAsyncEventListenerTest.java
new file mode 100644
index 0000000..49b12ea
--- /dev/null
+++ b/async/src/test/java/org/apache/geode/examples/async/ExampleAsyncEventListenerTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.async;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.geode.examples.util.TestAsyncEvent;
+import org.junit.Test;
+
+import org.apache.geode.cache.Operation;
+import org.apache.geode.cache.asyncqueue.AsyncEvent;
+
+public class ExampleAsyncEventListenerTest {
+  @Test
+  public void testAfterCreate() {
+    ExampleAsyncEventListener listener = new ExampleAsyncEventListener();
+    List<AsyncEvent> events = new LinkedList<AsyncEvent>();
+    events.add(new TestAsyncEvent<Integer, String>(null, Operation.CREATE, 1, "teh"));
+    events.add(new TestAsyncEvent<Integer, String>(null, Operation.CREATE, 2, "wil"));
+    events.add(new TestAsyncEvent<Integer, String>(null, Operation.CREATE, 3, "i"));
+    assertEquals(true, listener.processEvents(events));
+  }
+
+  @Test
+  public void testSpellCheck() {
+    ExampleAsyncEventListener listener = new ExampleAsyncEventListener();
+    assertEquals("that", listener.spellCheck("that"));
+    assertEquals("the", listener.spellCheck("teh"));
+    assertEquals("will", listener.spellCheck("wil"));
+    assertEquals("I", listener.spellCheck("i"));
+  }
+}
diff --git a/async/src/test/java/org/apache/geode/examples/async/ExampleTest.java b/async/src/test/java/org/apache/geode/examples/async/ExampleTest.java
new file mode 100644
index 0000000..834c318
--- /dev/null
+++ b/async/src/test/java/org/apache/geode/examples/async/ExampleTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.async;
+
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.geode.cache.Region;
+
+import org.geode.examples.util.Mocks;
+import org.junit.Test;
+
+public class ExampleTest {
+  @Test
+  public void testExample() throws Exception {
+    Example example = new Example();
+
+    Region<String, String> outgoingRegion = Mocks.region(Example.OUTGOING_REGION_NAME);
+    Region<Integer, String> incomingRegion = Mocks.region(Example.INCOMING_REGION_NAME);
+
+    final List<String> words = Arrays.asList(new String[] {"that", "teh"});
+    when(outgoingRegion.sizeOnServer()).thenReturn(words.size());
+    example.checkWords(incomingRegion, outgoingRegion, words);
+
+    verify(incomingRegion).put(eq(0), eq(words.get(0)));
+    verify(incomingRegion).put(eq(1), eq(words.get(1)));
+  }
+}
diff --git a/async/src/test/java/org/apache/geode/examples/async/LevenshteinDistanceTest.java
b/async/src/test/java/org/apache/geode/examples/async/LevenshteinDistanceTest.java
new file mode 100644
index 0000000..fa8d19d
--- /dev/null
+++ b/async/src/test/java/org/apache/geode/examples/async/LevenshteinDistanceTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.async;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class LevenshteinDistanceTest {
+  @Test
+  public void testCalculate() throws Exception {
+    LevenshteinDistance distance = new LevenshteinDistance();
+    assertEquals(0, distance.calculate(null, null));
+    assertEquals(0, distance.calculate(null, ""));
+    assertEquals(0, distance.calculate("", null));
+    assertEquals(0, distance.calculate("", ""));
+    assertEquals(3, distance.calculate(null, "foo"));
+    assertEquals(3, distance.calculate("foo", null));
+    assertEquals(3, distance.calculate("", "foo"));
+    assertEquals(3, distance.calculate("foo", ""));
+    assertEquals(3, distance.calculate("foo", "bar"));
+    assertEquals(2, distance.calculate("foo", "ofo"));
+    assertEquals(2, distance.calculate("foo", "oof"));
+    assertEquals(1, distance.calculate("the", "th"));
+    assertEquals(1, distance.calculate("the", "he"));
+    assertEquals(2, distance.calculate("the", "teh"));
+    assertEquals(2, distance.calculate("project", "porject"));
+  }
+}
diff --git a/build.gradle b/build.gradle
index e6844e3..1b2d368 100644
--- a/build.gradle
+++ b/build.gradle
@@ -105,6 +105,10 @@ subprojects {
   jar {
     archiveName "${baseName}.${extension}"
   }
+
+  jar {
+    archiveName "${baseName}.${extension}"
+  }
   
   task cleanServer {
     doLast {
diff --git a/settings.gradle b/settings.gradle
index 6d0d478..de9db34 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -26,3 +26,4 @@ include 'functions'
 include 'persistence'
 include 'writer'
 include 'listener'
+include 'async'
diff --git a/src/test/java/org/geode/examples/util/TestAsyncEvent.java b/src/test/java/org/geode/examples/util/TestAsyncEvent.java
new file mode 100644
index 0000000..1efe693
--- /dev/null
+++ b/src/test/java/org/geode/examples/util/TestAsyncEvent.java
@@ -0,0 +1,73 @@
+/*
+ * 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.geode.examples.util;
+
+import org.apache.geode.cache.Operation;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.asyncqueue.AsyncEvent;
+import org.apache.geode.cache.wan.EventSequenceID;
+
+public class TestAsyncEvent<K, V> implements AsyncEvent<K, V> {
+  private final Region region;
+  private final Operation operation;
+  private final K key;
+  private final V value;
+
+  public TestAsyncEvent(Region region, Operation operation, K key, V value) {
+    this.region = region;
+    this.operation = operation;
+    this.key = key;
+    this.value = value;
+  }
+  @Override
+  public boolean getPossibleDuplicate() {
+    return false;
+  }
+
+  @Override
+  public EventSequenceID getEventSequenceID() {
+    return null;
+  }
+
+  @Override
+  public Region<K, V> getRegion() {
+    return region;
+  }
+
+  @Override
+  public Operation getOperation() {
+    return operation;
+  }
+
+  @Override
+  public Object getCallbackArgument() {
+    return null;
+  }
+
+  @Override
+  public K getKey() {
+    return key;
+  }
+
+  @Override
+  public V getDeserializedValue() {
+    return value;
+  }
+
+  @Override
+  public byte[] getSerializedValue() {
+    return new byte[0];
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <commits@geode.apache.org>'].

Mime
View raw message