// Create an Atomix instance from a HOCON configuration file Atomix atomix = new Atomix("atomix.conf"); // Start the instance atomix.start().join(); // Get or create an AtomicValue AtomicValue<String> value = atomix.getAtomicValue("value"); // Set the value value.set("Hello world!"); // Print the current value System.out.println(value.get());

// Create an Atomix instance from a HOCON configuration file Atomix atomix = new Atomix("atomix.conf"); // Start the instance atomix.start().join(); // Get or create an AtomicCounter AtomicCounter counter = atomix.getAtomicCounter("my-counter"); // Increment the counter long value = counter.incrementAndGet(); // Reset the counter value counter.set(0);

// Create an Atomix instance from a HOCON configuration file Atomix atomix = new Atomix("atomix.conf"); // Start the instance atomix.start().join(); // Create a cached AtomicMap AtomicMap<String, String> map = atomix.atomicMapBuilder("my-map") .withCacheEnabled() .withCacheSize(100) .build(); // Set a value in the map map.put("foo", "Hello world!"); // Read a value from the map Versioned<String> value = map.get("foo"); // Update the value using an optimistic lock while (!map.put("foo", "Hello world again!", value.version())) { Thread.sleep(10); }

// Create an Atomix instance from a HOCON configuration file Atomix atomix = new Atomix("atomix.conf"); // Start the instance atomix.start().join(); // Get or create a multimap AtomicMultimap<String, String> multimap = atomix.getAtomicMultimap("my-multimap"); // Add a value to a key multimap.put("foo", "Hello world!"); // Get the values associated with a key Versioned<Collection<String>> values = multimap.get("foo");

// Create an Atomix instance from a HOCON configuration file Atomix atomix = new Atomix("atomix.conf"); // Start the instance atomix.start().join(); // Create a cached distributed set DistributedSet<String> set = atomix.setBuilder("my-set") .withCacheEnabled() .withCacheSize(100) .build(); // Add a value to the set set.add("foo"); // Check a value in the set if (set.contains("foo")) { ... }

// Create an Atomix instance from a HOCON configuration file Atomix atomix = new Atomix("atomix.conf"); // Start the instance atomix.start().join(); // Get or create a distributed list DistributedList<String> list = atomix.getList("my-list"); // Add a value to the list list.add("foo"); // Get a value from the list String foo = list.get(0); // Stream all values in the list list.stream().forEach(value -> { ... });

// Create an Atomix instance from a HOCON configuration file Atomix atomix = new Atomix("atomix.conf"); // Start the instance atomix.start().join(); // Get or create a distributed queue DistributedList<String> queue = atomix.getQueue("my-queue"); // Add a value to the queue queue.offer("foo"); // Get a value from the queue String next = queue.poll(); // Stream all values in the queue queue.stream().forEach(value -> { ... });

// Create an Atomix instance from a HOCON configuration file Atomix atomix = new Atomix("atomix.conf"); // Start the instance atomix.start().join();

// Create an Atomix instance from a HOCON configuration file Atomix atomix = new Atomix("atomix.conf"); // Start the instance atomix.start().join();

// Create an Atomix instance from a HOCON configuration file Atomix atomix = new Atomix("atomix.conf"); // Start the instance atomix.start().join(); // Get or create a distributed lock DistributedLock lock = atomix.getLock("my-lock"); // Acquire the lock lock.lock(); // Perform some functions and then release the lock try { ... } finally { lock.unlock(); } // Attempt to acquire the lock until a timeout lock.lock(Duration.ofSeconds(5));

// Create an Atomix instance from a HOCON configuration file Atomix atomix = new Atomix("atomix.conf"); // Start the instance atomix.start().join(); // Get or create a distributed semaphore DistributedSemaphore semaphore = atomix.getSemaphore("my-semaphore"); // Acquire the semaphore semaphore.acquire(); try { ... } finally { semaphore.release(); } // Acquire the lock lock.lock(); // Perform some functions and then release the lock try { ... } finally { lock.unlock(); } // Attempt to acquire the lock until a timeout lock.lock(Duration.ofSeconds(5));

// Create an Atomix instance from a HOCON configuration file Atomix atomix = new Atomix("atomix.conf"); // Start the instance atomix.start().join(); // Get or create a leader election LeaderElection<MemberId> election = atomix.getLeaderElection("my-election"); // Enter the election Leadership<MemberId> leadership = election.run(atomix.membershipService().getLocalMember().id()); // Check if the current node is the leader if (leadership.leader().equals(atomix.membershipService().getLocalMember().id())) { System.out.println("I am the leader!"); } // Listen for changes in leadership election.addListener(event -> { if (event.newLeadership().leader().equals(atomix.membershipService().getLocalMember().id())) { System.out.println("I am the leader!"); } });

// Create an Atomix instance from a HOCON configuration file Atomix atomix = new Atomix("atomix.conf"); // Start the instance atomix.start().join(); // Get a list of members in the cluster Collection<Node> nodes = atomix.getMembershipService().getNodes(); // Listen for members joining/leaving the cluster atomix.getMembershipService().addListener(event -> { switch (event.type()) { case MEMBER_ADDED: System.out.println(event.subject().id() + " joined the cluster"); break; case MEMBER_REMOVED: System.out.println(event.subject().id() + " left the cluster"); break; } });