Package org.apache.curator.x.async
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 Summary
Modifier and TypeMethodDescriptionvoid
If there was a general exception or aKeeperException
aRuntimeException
is thrown that wraps the exception.void
If there was a general exception (but not aKeeperException
) aRuntimeException
is thrown that wraps the exception.org.apache.zookeeper.KeeperException.Code
getCode()
Return the ZooKeeper result code.An optional wrapper around any general exceptionReturn any general exception ornull
Returns the raw result of the ZooKeeper method ornull
getValue()
An optional wrapper around the ZooKeeper method resultstatic <T> CompletionStage
<AsyncResult<T>> of
(AsyncStage<T> stage) Return a new stage that wraps an async stage into a result-style completion stage.
-
Method Details
-
of
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 ornull
- Returns:
- result or
null
-
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 exceptionKeeperException.Code.SYSTEMERROR
is returned.- Returns:
- result code
-
getRawException
Throwable getRawException()Return any general exception ornull
- Returns:
- exception or
null
-
getException
An optional wrapper around any general exception- Returns:
- wrapped exception
-
checkException
void checkException()If there was a general exception (but not aKeeperException
) aRuntimeException
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 aKeeperException
aRuntimeException
is thrown that wraps the exception. Otherwise, the method returns without any action being performed.
-