T
- value typepublic 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
.
Modifier and Type | Method and Description |
---|---|
void |
checkError()
If there was a general exception or a
KeeperException
a RuntimeException is thrown that wraps the exception. |
void |
checkException()
If there was a general exception (but not a
KeeperException )
a RuntimeException is thrown that wraps the exception. |
org.apache.zookeeper.KeeperException.Code |
getCode()
Return the ZooKeeper result code.
|
Optional<Throwable> |
getException()
An optional wrapper around any general exception
|
Throwable |
getRawException()
Return any general exception or
null |
T |
getRawValue()
Returns the raw result of the ZooKeeper method or
null |
Optional<T> |
getValue()
An optional wrapper around the ZooKeeper method result
|
static <T> CompletionStage<AsyncResult<T>> |
of(AsyncStage<T> stage)
Return a new stage that wraps an async stage into a result-style completion stage.
|
static <T> CompletionStage<AsyncResult<T>> of(AsyncStage<T> stage)
T
- value typestage
- the stage to wrapT getRawValue()
null
null
Optional<T> getValue()
org.apache.zookeeper.KeeperException.Code getCode()
KeeperException.Code.OK
is returned. If there was a general
exception KeeperException.Code.SYSTEMERROR
is returned.Throwable getRawException()
null
null
Optional<Throwable> getException()
void checkException()
KeeperException
)
a RuntimeException
is thrown that wraps the exception. Otherwise, the method returns
without any action being performed.void checkError()
KeeperException
a RuntimeException
is thrown that wraps the exception. Otherwise, the method returns
without any action being performed.Copyright © 2011–2023 The Apache Software Foundation. All rights reserved.