You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@curator.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2015/09/07 01:11:45 UTC
[jira] [Commented] (CURATOR-259) Add try-with-resources class for
Curator locks
[ https://issues.apache.org/jira/browse/CURATOR-259?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14733166#comment-14733166 ]
ASF GitHub Bot commented on CURATOR-259:
----------------------------------------
Github user cammckenzie commented on the pull request:
https://github.com/apache/curator/pull/103#issuecomment-138134924
Looks good to me.
> Add try-with-resources class for Curator locks
> ----------------------------------------------
>
> Key: CURATOR-259
> URL: https://issues.apache.org/jira/browse/CURATOR-259
> Project: Apache Curator
> Issue Type: New Feature
> Components: Recipes
> Reporter: Jordan Zimmerman
> Assignee: Jordan Zimmerman
> Priority: Minor
> Fix For: 3.0.0
>
>
> For Java7+, try-with-resources makes using locks safer. Curator should have a utility for this. Something like:
> {code}
> public class SafeLock implements AutoCloseable {
> private final InterProcessLock lock;
> private final boolean acquired;
> public SafeLock(InterProcessLock lock, long timeout, TimeUnit unit) {
> this.lock = lock;
> acquired = lock.acquire(timeout, unit);
> }
> public void close() throws Exception {
> if ( acquired ) {
> lock.release();
> }
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)