Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AutoCloseable interface to RiakClient #683

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/main/java/com/basho/riak/client/api/RiakClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.lang.AutoCloseable;

/**
* <script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
Expand Down Expand Up @@ -158,7 +159,7 @@
* @author Sergey Galkin <srggal at gmail dot com>
* @since 2.0
*/
public class RiakClient
public class RiakClient implements AutoCloseable
{
private final RiakCluster cluster;

Expand Down Expand Up @@ -416,6 +417,18 @@ public Future<Boolean> shutdown()
return cluster.shutdown();
}


/**
* Implementation of the AutoCloseable-Inteface.
* <p>
* The Client will be automatically shut down when used with try-with-resource statement
* </p>
*/
@Override
public void close(){
this.shutdown();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shutdown method returns Future, therefore to respect AutoCloseable it might be better to call as follows:

this.shutdown().get();

}

/**
* Get the RiakCluster being used by this client.
* <p>
Expand Down