Uploaded image for project: 'Apache Curator'
  1. Apache Curator
  2. CURATOR-259

Add try-with-resources class for Curator locks

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 3.0.0
    • Recipes
    • None

    Description

      For Java7+, try-with-resources makes using locks safer. Curator should have a utility for this. Something like:

      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();
            }
         }
      }
      

      Attachments

        Issue Links

          Activity

            People

              randgalt Jordan Zimmerman
              randgalt Jordan Zimmerman
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: