Distributed Concurrency

> Primitives for distributed concurrency

DistributedLock

The DistributedLock resources provides an asynchronous API similar to that of the JDK’s Lock.

To create a DistributedLock, use the Atomix#getLock(String) method:

atomix.getLock("foo").thenAccept(lock -> {
  // Do something with the lock
});

The DistributedLock API is asynchronous and returns CompletableFuture for all methods:

lock.lock().thenRun(() -> {
  // Do some stuff and then...
  lock.unlock();
});

To block and wait for the lock to be acquired instead, call join() or get() on the returned CompletableFutures:

lock.lock().join();

// Do some stuff

lock.unlock().join();