package eu.mikroskeem.utils.etcdconnector; import mousio.etcd4j.EtcdClient; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.List; import java.util.function.Function; public interface EtcdConnector { /** * Closes Etcd4j client * * @throws IOException Thrown by Etcd4j */ void close() throws IOException; /** * Gets etcd key value * * @param path Key path * @return Key value */ @Nullable String getKey(@NotNull String path); /** * Gets etcd key value and sets default, * if key isn't defined * * @param path Key path * @param defaultValue Value to set if key is nonexistent * @return Key value */ @Nullable String getKey(@NotNull String path, @NotNull String defaultValue); /** * Gets etcd directory contents and returns it as * List of String * * @param path directory path * @return directory contents */ @Nullable List getDir(@NotNull String path); /** * Sets etcd key value * * @param path key path * @param value key value * @return whether write succeeded or not */ boolean putKey(@NotNull String path, @NotNull String value); /** * Sets etcd key value with TTL * * @param path key path * @param value key value * @param ttl key ttl (seconds) * @return whether write succeeded or not */ boolean putKey(@NotNull String path, @NotNull String value, @NotNull Integer ttl); /** * Deletes etcd key * * @param path key path * @return whether delete succeeded or not */ boolean deleteKey(@NotNull String path); /** * Waits for key change * * Deprecated: it is broken, literally * * @param path Key path * @param callback Callback to run */ @Deprecated void waitKey(@NotNull String path, @NotNull Function callback); /** * Get client instance * * @return Etcd client instance */ EtcdClient getClient(); }