/java-sdk

Java Client SDK for Stateful.co

Primary LanguageJavaOtherNOASSERTION

EO principles respected here DevOps By Rultor.com We recommend IntelliJ IDEA

mvn Maven Central Javadoc

This is Java SDK for Stateful.

The JavaDoc is here.

First, register an account at Stateful. Then, you can create a counter and increment it:

import co.stateful.Counter;
import co.stateful.Counters;
import co.stateful.Sttc;
import co.stateful.RtSttc;
import com.jcabi.urn.URN;
public class Main {
  public static void main(String... args) {
    Sttc sttc = new RtSttc(
      new URN("urn:github:526301"),
      "9FF3-41E0-73FB-F900"
    );
    String name = "test-123";
    Counters counters = sttc.counters();
    Counter counter = counters.create(name);
    long value = counter.incrementAndGet(1L);
    System.out.println("new value: " + value);
    counters.delete(name);
  }
}

Here is how you can use a lock:

Locks locks = sttc.locks();
Lock lock = locks.get("test-lock");
new Atomic(lock).call(
  new Callable<Void>() {
    @Override
    public void call() {
      // perfectly synchronized code
      return null;
    }
  }
);