Interface AsyncResult<T>

Type Parameters:
T - value type
All Known Implementing Classes:
AsyncResultImpl

public interface AsyncResult<T>

Utility that combines the value, the ZooKeeper result code and the exception in one object allowing you to not worry about exceptional completions. i.e. the CompletionStage returned by of(AsyncStage) always completes successfully with an AsyncResult object.

All three possible results from a ZooKeeper method are encapsulated in this object. If the ZooKeeper method succeeds, the internal value will be set. If there was a standard ZooKeeper error code (KeeperException.Code.NODEEXISTS, etc.), that code is set and the value is null. If there was a general exception, that exception is set, the value will be null and the code will be KeeperException.Code.SYSTEMERROR.

  • Method Details

    • of

      static <T> CompletionStage<AsyncResult<T>> of(AsyncStage<T> stage)
      Return a new stage that wraps an async stage into a result-style completion stage. The returned CompletionStage will always complete successfully.
      Type Parameters:
      T - value type
      Parameters:
      stage - the stage to wrap
      Returns:
      completion stage that resolves to a result
    • getRawValue

      T getRawValue()
      Returns the raw result of the ZooKeeper method or null
      Returns:
      result or null
    • getValue

      Optional<T> getValue()
      An optional wrapper around the ZooKeeper method result
      Returns:
      wrapped result
    • getCode

      org.apache.zookeeper.KeeperException.Code getCode()
      Return the ZooKeeper result code. If the method was successful, KeeperException.Code.OK is returned. If there was a general exception KeeperException.Code.SYSTEMERROR is returned.
      Returns:
      result code
    • getRawException

      Throwable getRawException()
      Return any general exception or null
      Returns:
      exception or null
    • getException

      Optional<Throwable> getException()
      An optional wrapper around any general exception
      Returns:
      wrapped exception
    • checkException

      void checkException()
      If there was a general exception (but not a KeeperException) a RuntimeException is thrown that wraps the exception. Otherwise, the method returns without any action being performed.
    • checkError

      void checkError()
      If there was a general exception or a KeeperException a RuntimeException is thrown that wraps the exception. Otherwise, the method returns without any action being performed.