From 8e1082511c7cea17e78a6a756f60cb459fff5c66 Mon Sep 17 00:00:00 2001 From: "Oliver A. Tazl" Date: Mon, 31 Oct 2016 13:33:22 +0100 Subject: [PATCH 1/2] Added AutoCloseable interface to RiakClient --- .../com/basho/riak/client/api/RiakClient.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/basho/riak/client/api/RiakClient.java b/src/main/java/com/basho/riak/client/api/RiakClient.java index 114c31b38..8b556a69a 100644 --- a/src/main/java/com/basho/riak/client/api/RiakClient.java +++ b/src/main/java/com/basho/riak/client/api/RiakClient.java @@ -31,6 +31,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.lang.AutoCloseable; /** * @@ -158,7 +159,7 @@ * @author Sergey Galkin * @since 2.0 */ -public class RiakClient +public class RiakClient implements AutoCloseable { private final RiakCluster cluster; @@ -416,6 +417,18 @@ public Future shutdown() return cluster.shutdown(); } + + /** + * Implementation of the AutoCloseable-Inteface. + *

+ * The Client will be automatically shut down when used with try-with-resource statement + *

+ */ + @Override + public void close(){ + this.shutdown(); + } + /** * Get the RiakCluster being used by this client. *

From 80a5c77020f1641be7b3e8b70c3cf9f2da5bf70d Mon Sep 17 00:00:00 2001 From: "Oliver A. Tazl" Date: Mon, 31 Oct 2016 15:35:52 +0100 Subject: [PATCH 2/2] Added FutureHandling and Exceptions to close() --- src/main/java/com/basho/riak/client/api/RiakClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/basho/riak/client/api/RiakClient.java b/src/main/java/com/basho/riak/client/api/RiakClient.java index 8b556a69a..d5ff3ac54 100644 --- a/src/main/java/com/basho/riak/client/api/RiakClient.java +++ b/src/main/java/com/basho/riak/client/api/RiakClient.java @@ -425,8 +425,8 @@ public Future shutdown() *

*/ @Override - public void close(){ - this.shutdown(); + public void close() throws ExecutionException, InterruptedException { + this.shutdown().get(); } /**