How to handle Apache Curator Distributed Lock loss of connection
<p>Say I have two distributed process running the following code that uses zookeeper and curator for a shared lock:</p>

<pre><code>public static void main(String[] args) throws Exception {
    CuratorFramework client = CuratorFrameworkFactory.newClient("localhost:2181", new ExponentialBackoffRetry(500, 2));
    client.start();
    InterProcessMutex lock = new InterProcessMutex(client, "/12345");

    System.out.println("before acquire");
    lock.acquire();
    System.out.println("lock has been acquired");
    //do some things that need to be done in an atomic fashion
    lock.release();
    System.out.println("after release");
}
</code></pre>

<p>Where the "do some things" comment represents multiple statements that need to be done by only one process at a time. e.g. multiple writes into various databases.</p>

<p>This all seems fine until one of the java process loses the connection with zookeeper after it has acquired a lock. </p>

<p>According to the documentation:</p>

<blockquote>
  <p>It is strongly recommended that you add a ConnectionStateListener and
  watch for SUSPENDED and LOST state changes. If a SUSPENDED state is
  reported you cannot be certain that you still hold the lock unless you
  subsequently receive a RECONNECTED state. If a LOST state is reported
  it is certain that you no longer hold the lock.</p>
</blockquote>

<p>If I understand this correctly, at any point after acquiring a lock I might receive a notification that the lock has been lost, due to a network issue, at which point some other process may have acquired the lock. If that is true there is no guarantee that after acquiring the lock you are the only process that has the lock. My precious statements that must only be executed by one process at a time might be interleaved with another process. </p>

<p>Have I misunderstood the above? If so please clarify what it means. If I have not misunderstood the above how is a curator lock useful if it cannot guarantee exclusive access?</p>