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

client: add AutoCloseable #244

Merged
merged 1 commit into from
Sep 30, 2017
Merged

Conversation

ScienJus
Copy link
Contributor

for #239

I think Client , CloseableClient and Watcher should extends AutoCloseable.

but i can't make sure it's necessary for KeepAlive and KeepAliveListener, because i don't know how to use them.


/**
* closes this watcher and all its resources.
**/
@Override
void close();
Copy link
Collaborator

Choose a reason for hiding this comment

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

AutoCloseable::close() throws an exception, I do not think we should change the signature

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the point is whether to throw out exception on Watch#close, so far it’s prohibited.

We uses AutoCloseable just for try-with-resource, it should not be a constraint.

Copy link
Collaborator

Choose a reason for hiding this comment

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

so lgtm :)

/**
* close the client and release its resources.
*/
@Override
default void close() {
// noop
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as before

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;

import java.util.Arrays;
Copy link
Member

Choose a reason for hiding this comment

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

why move imports around?

@@ -26,6 +24,8 @@
import org.junit.Test;
import org.junit.rules.Timeout;

import static org.assertj.core.api.Assertions.assertThat;
Copy link
Member

Choose a reason for hiding this comment

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

prefer not move imports order

@@ -48,11 +48,12 @@
/**
* Interface of Watcher.
*/
interface Watcher {
interface Watcher extends AutoCloseable {
Copy link
Member

Choose a reason for hiding this comment

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

why extends not implement the AutoCloseable?

if we @Override the close() from AutoCloseable, how come our close() doesn't throw Exception?

Copy link
Contributor Author

@ScienJus ScienJus Sep 30, 2017

Choose a reason for hiding this comment

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

  1. Interface can only extends another interface. not implement.

  2. The overriding method can throw those checked exceptions, which have less scope than the exception(s) declared in the overridden method.

Copy link
Member

Choose a reason for hiding this comment

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

now i understand what you were doing. pretty cool java trick.

@fanminshi
Copy link
Member

lgtm

@fanminshi fanminshi merged commit a085a3c into etcd-io:master Sep 30, 2017
@fanminshi fanminshi added this to the 0.0.2 milestone Sep 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants