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

Add try-with-resources support for Entry class #550

Merged
merged 1 commit into from
Mar 8, 2019

Conversation

sczyh30
Copy link
Member

@sczyh30 sczyh30 commented Mar 6, 2019

Describe what this PR does / why we need it

Since 1.5.0 the min JDK version will be 1.7. We added try-with-resources support for Entry class so that it's easier to use Sentinel's API like this:

try (Entry entry = SphU.entry("someResource")) {
    // Your own logic here.
} catch (BlockException ex) {
    // Your logic for handling rejection here.
}

Does this pull request fix one issue?

Resolves #233

Describe how you did it

The Entry class now implements JDK's AutoCloseable interface so it supports try-with-resources (close method adapts to exit)

Describe how to verify it

Run the test cases.

Special notes for reviews

NONE

- `Entry` class now implements `AutoCloseable` so it supports try-with-resources (`close` method adapts to `exit`)

Signed-off-by: Eric Zhao <[email protected]>
@sczyh30 sczyh30 added the to-review To review label Mar 6, 2019
@sczyh30 sczyh30 added this to the 1.5.0 milestone Mar 6, 2019
Copy link
Contributor

@CarpenterLee CarpenterLee left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

consider easier APIs (as extensions, maybe) to use Entry
2 participants