Package org.apache.pekko.pattern
Class StatusReply<T>
java.lang.Object
org.apache.pekko.pattern.StatusReply<T>
- Type Parameters:
T
- the type of value a successful reply would have
Generic top-level message type for replies that signal failure or success. Convenient to use together with the
askWithStatus
ask variants.
Create using the factory methods success(T)
and error(java.lang.String)
.
Pekko contains predefined serializers for the wrapper type and the textual error messages.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Scala API for creating and pattern matching an error responsestatic final class
Carrier exception used for textual error descriptions.static class
static class
Scala API for creation and pattern matching a successful response. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StatusReply<Done>
ack()
Java API: A general purpose message for using as an Ackstatic StatusReply<Done>
Ack()
Scala API: A general purpose message for using as an Ackboolean
static <T> StatusReply<T>
Java API: Create an status response with a error message describing why the request was failed or denied.static <T> StatusReply<T>
Java API: Create an error response with a user definedThrowable
.getError()
Java API: returns the exception if the reply is a failure, or throws an exception if not.getValue()
Java API: in the case of a successful reply returns the value, if the reply was not successful the exception the failure was created with is thrownint
hashCode()
boolean
isError()
boolean
static <T> StatusReply<T>
success
(T value) Java API: Create a successful reply containingvalue
toString()
-
Constructor Details
-
StatusReply
public StatusReply()
-
-
Method Details
-
Ack
Scala API: A general purpose message for using as an Ack -
ack
Java API: A general purpose message for using as an Ack -
success
Java API: Create a successful reply containingvalue
-
error
Java API: Create an status response with a error message describing why the request was failed or denied. -
error
Java API: Create an error response with a user definedThrowable
.Prefer the string based error response over this one when possible to avoid tightly coupled logic across actors and passing internal failure details on to callers that can not do much to handle them.
For cases where types are needed to identify errors and behave differently enumerating them with a specific set of response messages may be a better alternative to encoding them as generic exceptions.
Also note that Pekko does not contain pre-build serializers for arbitrary exceptions.
-
getValue
Java API: in the case of a successful reply returns the value, if the reply was not successful the exception the failure was created with is thrown -
getError
Java API: returns the exception if the reply is a failure, or throws an exception if not. -
isError
public boolean isError() -
isSuccess
public boolean isSuccess() -
equals
-
hashCode
public int hashCode() -
toString
-