Class StatusReply<T>
- Type Parameters:
T- the type of value a successful reply would have
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 classScala API for creating and pattern matching an error responsestatic final classCarrier exception used for textual error descriptions.static classstatic classScala 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 Ackbooleanstatic <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.static <T> StatusReply<T>fromCallable(Callable<T> callable) Java API: Convert the result of aCallableinto aStatusReply.static <T> StatusReply<T>fromCallableKeepException(Callable<T> callable) Java API: Convert the result of aCallableinto aStatusReply, keeping the original exception in case of failure.static <T> StatusReply<T>fromTry(scala.util.Try<T> status) Scala API: Turn aTryinto a status reply.static <T> StatusReply<T>fromTryKeepException(scala.util.Try<T> status) Scala API: Turn aTryinto a status reply, keeping the original exception.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 throwninthashCode()booleanisError()booleanstatic <T> StatusReply<T>success(T value) Java API: Create a successful reply containingvaluetoString()
-
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-built serializers for arbitrary exceptions.
-
fromTry
Scala API: Turn aTryinto a status reply.Transforms exceptions into status reply errors containing just the exception message string. This makes it safe for use with remote actors since Pekko includes built-in serializers for text-based error messages, unlike arbitrary exception types.
See
fromTryKeepException(scala.util.Try<T>)for passing the exception along as is.- Since:
- 2.0.0
-
fromTryKeepException
Scala API: Turn aTryinto a status reply, keeping the original exception.Unlike
fromTry(scala.util.Try<T>), this preserves the full exception object. This is useful when callers need to match on exception types, but requires that serializers are configured for the exception types used when communicating with remote actors.Prefer
fromTry(scala.util.Try<T>)(string-based errors) 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.Also note that Pekko does not contain pre-built serializers for arbitrary exceptions.
- Since:
- 2.0.0
-
fromCallable
Java API: Convert the result of aCallableinto aStatusReply.If the callable completes successfully, wraps the result in a successful reply. If it throws an exception, converts the exception message to an error reply (discarding the original exception type, making it safe for remote serialization).
This is the Java-friendly equivalent of
fromTry(scala.util.Try<T>).- Since:
- 2.0.0
-
fromCallableKeepException
Java API: Convert the result of aCallableinto aStatusReply, keeping the original exception in case of failure.Unlike
fromCallable(java.util.concurrent.Callable<T>), this preserves the full exception object. This is useful when callers need to match on exception types, but requires that serializers are configured for the exception types used when communicating with remote actors.This is the Java-friendly equivalent of
fromTryKeepException(scala.util.Try<T>).- Since:
- 2.0.0
-
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
-