Package com.styra.opa
Class OPAResult
java.lang.Object
com.styra.opa.OPAResult
This class encapsulates a result of a previous OPA request for deferred
access. It may contain an exception, a value, or both. This is intended for
usage patterns where multiple requests are made, and only later does the
caller want to inspect which of them succeeded or failed, and what their
values may have been.
This abstraction is a little unclean - typically it is preferred to throw
exceptions, not pass them around as values. However, problems with the
HTTP requests often generate exceptions, and those can be challenging to
deal with when dispatching many requests at once.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> T
get()
Attempt to retrieve the value stored in this result, throwing the stored exception if one is present.<T> T
get
(com.fasterxml.jackson.core.type.TypeReference<T> toValueType) <T> T
get
(com.fasterxml.jackson.databind.JavaType toValueType) <T> T
Retrieves the deferred exception, if any.getValue()
Retrieves the deferred value if one is present.boolean
success()
Returns true if and only if this result contains a non-null value AND ta null exception.
-
Constructor Details
-
OPAResult
-
OPAResult
-
-
Method Details
-
get
Attempt to retrieve the value stored in this result, throwing the stored exception if one is present. NOTE: this can make it look like the exception came from this class, but that's not true, it was simply smuggling a deferred exception from somewhere else inside of it. OPAException usually wraps some other, lower-level exception - consider inspecting that to determine the true source of error.- Throws:
OPAException
-
get
- Throws:
OPAException
-
get
- Throws:
OPAException
-
get
- Throws:
OPAException
-
success
public boolean success()Returns true if and only if this result contains a non-null value AND ta null exception. In other words, if this method returns true, then get() is guaranteed not to throw an exception or return null. -
getValue
Retrieves the deferred value if one is present. Does not attempt to re-throw a stored exception even if one is present. -
getException
Retrieves the deferred exception, if any.
-