You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@curator.apache.org by "Jordan Zimmerman (JIRA)" <ji...@apache.org> on 2015/09/05 23:22:45 UTC
[jira] [Created] (CURATOR-259) Add try-with-resources class for
Curator locks
Jordan Zimmerman created CURATOR-259:
----------------------------------------
Summary: 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: Improvement
Components: Recipes
Reporter: Jordan Zimmerman
Priority: Minor
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);
}
void close() throws Exception {
if ( acquired ) {
lock.release();
}
}
}
{code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)