You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by al...@apache.org on 2021/07/01 19:35:39 UTC

[ignite] branch ignite-2.11 updated: IGNITE-14510 Documentation: java thin client continuous queries - Fixes #9214.

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

alexpl pushed a commit to branch ignite-2.11
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/ignite-2.11 by this push:
     new aeb2c3f  IGNITE-14510 Documentation: java thin client continuous queries - Fixes #9214.
aeb2c3f is described below

commit aeb2c3f3cd6854a089de9bac4eed0158a29de4bf
Author: Aleksey Plekhanov <pl...@gmail.com>
AuthorDate: Thu Jul 1 22:23:10 2021 +0300

    IGNITE-14510 Documentation: java thin client continuous queries - Fixes #9214.
    
    Signed-off-by: Aleksey Plekhanov <pl...@gmail.com>
    (cherry picked from commit 85be7e04deba2b27a99d9425aa3b5855e3dc3fa0)
---
 docs/_docs/code-snippets/java/pom.xml              |  2 +-
 .../org/apache/ignite/snippets/JavaThinClient.java | 44 ++++++++++++++++++++--
 docs/_docs/thin-client-comparison.csv              |  3 +-
 docs/_docs/thin-clients/java-thin-client.adoc      | 23 +++++++++++
 4 files changed, 66 insertions(+), 6 deletions(-)

diff --git a/docs/_docs/code-snippets/java/pom.xml b/docs/_docs/code-snippets/java/pom.xml
index 4589866..78a85b2b 100644
--- a/docs/_docs/code-snippets/java/pom.xml
+++ b/docs/_docs/code-snippets/java/pom.xml
@@ -24,7 +24,7 @@
 	<version>1.0.0-SNAPSHOT</version>
 	<properties>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-		<ignite.version>2.9.0-SNAPSHOT</ignite.version>
+		<ignite.version>2.11.0-SNAPSHOT</ignite.version>
 	</properties>
 	<dependencies>
 		<dependency>
diff --git a/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/JavaThinClient.java b/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/JavaThinClient.java
index 42b6873..d3ba1c5 100644
--- a/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/JavaThinClient.java
+++ b/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/JavaThinClient.java
@@ -21,9 +21,10 @@ import java.util.Map;
 import java.util.UUID;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
-
 import javax.cache.Cache;
-
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryListenerException;
+import javax.cache.event.CacheEntryUpdatedListener;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteBinary;
 import org.apache.ignite.Ignition;
@@ -31,21 +32,25 @@ import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.cache.CacheAtomicityMode;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.query.ContinuousQuery;
 import org.apache.ignite.cache.query.FieldsQueryCursor;
 import org.apache.ignite.cache.query.Query;
 import org.apache.ignite.cache.query.QueryCursor;
 import org.apache.ignite.cache.query.ScanQuery;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.client.ClientAddressFinder;
 import org.apache.ignite.client.ClientAuthenticationException;
 import org.apache.ignite.client.ClientCache;
 import org.apache.ignite.client.ClientCacheConfiguration;
 import org.apache.ignite.client.ClientCluster;
 import org.apache.ignite.client.ClientClusterGroup;
 import org.apache.ignite.client.ClientConnectionException;
+import org.apache.ignite.client.ClientDisconnectListener;
 import org.apache.ignite.client.ClientException;
 import org.apache.ignite.client.ClientTransaction;
 import org.apache.ignite.client.ClientTransactions;
 import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.client.IgniteClientFuture;
 import org.apache.ignite.client.SslMode;
 import org.apache.ignite.client.SslProtocol;
 import org.apache.ignite.cluster.ClusterState;
@@ -244,6 +249,7 @@ public class JavaThinClient {
     }
 
     public static final String KEYSTORE = "keystore/client.jks";
+
     public static final String TRUSTSTORE = "keystore/trust.jks";
 
     @Test
@@ -318,7 +324,6 @@ public class JavaThinClient {
         // end::results-to-map[]
     }
 
-
     void veiwsystemview() {
         //tag::system-views[]
         ClientConfiguration cfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
@@ -360,6 +365,10 @@ public class JavaThinClient {
         //end::partition-awareness[]
     }
 
+    private String[] fetchServerAddresses() {
+        return null;
+    }
+
     void clientAddressFinder() throws Exception {
         //tag::client-address-finder[]
         ClientAddressFinder finder = () -> {
@@ -369,7 +378,7 @@ public class JavaThinClient {
         };
 
         ClientConfiguration cfg = new ClientConfiguration()
-            .setAddressFinder(finder)
+            .setAddressesFinder(finder)
             .setPartitionAwarenessEnabled(true);
 
         try (IgniteClient client = Ignition.startClient(cfg)) {
@@ -452,6 +461,33 @@ public class JavaThinClient {
         //end::async-api[]
     }
 
+    void continuousQueries() throws Exception {
+        ClientConfiguration clientCfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
+
+        try (IgniteClient client = Ignition.startClient(clientCfg)) {
+            //tag::continuous-queries[]
+            ClientCache<Integer, String> cache = client.getOrCreateCache("myCache");
+
+            ContinuousQuery<Integer, String> query = new ContinuousQuery<>();
+
+            query.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {
+                @Override public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> events)
+                    throws CacheEntryListenerException {
+                    // react to the update events here
+                }
+            });
+
+            ClientDisconnectListener disconnectListener = new ClientDisconnectListener() {
+                @Override public void onDisconnected(Exception reason) {
+                    // react to the disconnect event here
+                }
+            };
+
+            cache.query(query, disconnectListener);
+            //end::continuous-queries[]
+        }
+    }
+
     private static class MyTask {
     }
 
diff --git a/docs/_docs/thin-client-comparison.csv b/docs/_docs/thin-client-comparison.csv
index 2325183..bf5eb80 100644
--- a/docs/_docs/thin-client-comparison.csv
+++ b/docs/_docs/thin-client-comparison.csv
@@ -13,4 +13,5 @@ Cluster API,{yes},{yes},No,No,No,No
 Compute,{yes},{yes},No,No,No,No
 Service invocation,{yes},{yes},No,No,No,No
 Server Discovery,No,{yes},No,No,No,No
-Server Discovery in Kubernetes,{yes},No,No,No,No,No
\ No newline at end of file
+Server Discovery in Kubernetes,{yes},No,No,No,No,No
+Continuous queries,{yes},{yes},No,No,No,No
\ No newline at end of file
diff --git a/docs/_docs/thin-clients/java-thin-client.adoc b/docs/_docs/thin-clients/java-thin-client.adoc
index 5aadb23..b71d15a 100644
--- a/docs/_docs/thin-clients/java-thin-client.adoc
+++ b/docs/_docs/thin-clients/java-thin-client.adoc
@@ -197,6 +197,29 @@ include::{sourceCodeFile}[tag=binary-example,indent=0]
 
 Refer to the link:key-value-api/binary-objects[Working with Binary Objects] page for detailed information.
 
+=== Cache Entry Listening
+
+When a cache is modified (an entry is inserted, updated, deleted, or expired), an event can be sent to notify the client.
+To listen to these events, you can use one of the following approaches:
+
+* Continuous queries
+* Cache `registerCacheEntryListener` methods
+
+Both approaches require a local listener to be provided, which is triggered on every cache modification event.
+
+For both approaches you can also specify a remote filter to narrow down the range of entries that are monitored for updates. This filter is executed for each updated entry on the server-side and evaluates whether the event should be propagated to the client's local listener.
+
+NOTE: The classes of the remote filter factory must be available on the server nodes of the cluster.
+
+Refer to the link:key-value-api/continuous-queries[thick client continuous queries] page for more information about continuous queries.
+
+In case of connection to server failure, a thin client cannot silently reconnect with guarantees that no events are lost, so continuous queries and registered cache event listeners are closed after the server disconnection. There are also several methods with the additional parameter: disconnect listener. This listener allows to catch server disconnection events and react appropriately.
+
+[source, java]
+-------------------------------------------------------------------------------
+include::{sourceCodeFile}[tag=continuous-queries,indent=0]
+-------------------------------------------------------------------------------
+
 == Executing SQL Statements
 
 The Java thin client provides a SQL API to execute SQL statements. SQL statements are declared using the `SqlFieldsQuery` objects and executed through the `IgniteClient.query(SqlFieldsQuery)` method.