Search in sources :

Example 1 with Promise

use of scala.concurrent.impl.Promise in project flink by apache.

the class AkkaRpcActor method sendAsyncResponse.

private void sendAsyncResponse(CompletableFuture<?> asyncResponse, String methodName) {
    final ActorRef sender = getSender();
    Promise.DefaultPromise<Object> promise = new Promise.DefaultPromise<>();
    FutureUtils.assertNoException(asyncResponse.handle((value, throwable) -> {
        if (throwable != null) {
            promise.failure(throwable);
        } else {
            if (isRemoteSender(sender)) {
                Either<AkkaRpcSerializedValue, AkkaRpcException> serializedResult = serializeRemoteResultAndVerifySize(value, methodName);
                if (serializedResult.isLeft()) {
                    promise.success(serializedResult.left());
                } else {
                    promise.failure(serializedResult.right());
                }
            } else {
                promise.success(new Status.Success(value));
            }
        }
        // consume the provided throwable
        return null;
    }));
    Patterns.pipe(promise.future(), getContext().dispatcher()).to(sender);
}
Also used : RunAsync(org.apache.flink.runtime.rpc.messages.RunAsync) Either(org.apache.flink.types.Either) RpcEndpoint(org.apache.flink.runtime.rpc.RpcEndpoint) LoggerFactory(org.slf4j.LoggerFactory) ClassLoadingUtils.runWithContextClassLoader(org.apache.flink.runtime.concurrent.akka.ClassLoadingUtils.runWithContextClassLoader) MainThreadValidatorUtil(org.apache.flink.runtime.rpc.MainThreadValidatorUtil) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RpcConnectionException(org.apache.flink.runtime.rpc.exceptions.RpcConnectionException) ExceptionUtils(org.apache.flink.util.ExceptionUtils) Callable(java.util.concurrent.Callable) CompletableFuture(java.util.concurrent.CompletableFuture) AkkaHandshakeException(org.apache.flink.runtime.rpc.akka.exceptions.AkkaHandshakeException) LocalRpcInvocation(org.apache.flink.runtime.rpc.messages.LocalRpcInvocation) RemoteHandshakeMessage(org.apache.flink.runtime.rpc.messages.RemoteHandshakeMessage) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) RpcGateway(org.apache.flink.runtime.rpc.RpcGateway) ActorRef(akka.actor.ActorRef) Patterns(akka.pattern.Patterns) Promise(scala.concurrent.impl.Promise) Preconditions.checkNotNull(org.apache.flink.util.Preconditions.checkNotNull) Nonnull(javax.annotation.Nonnull) Method(java.lang.reflect.Method) Nullable(javax.annotation.Nullable) CallAsync(org.apache.flink.runtime.rpc.messages.CallAsync) Logger(org.slf4j.Logger) FiniteDuration(scala.concurrent.duration.FiniteDuration) AkkaUnknownMessageException(org.apache.flink.runtime.rpc.akka.exceptions.AkkaUnknownMessageException) HandshakeSuccessMessage(org.apache.flink.runtime.rpc.messages.HandshakeSuccessMessage) IOException(java.io.IOException) Preconditions(org.apache.flink.util.Preconditions) AkkaRpcException(org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException) AkkaRpcInvalidStateException(org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcInvalidStateException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TimeUnit(java.util.concurrent.TimeUnit) Status(akka.actor.Status) Preconditions.checkArgument(org.apache.flink.util.Preconditions.checkArgument) RpcInvocation(org.apache.flink.runtime.rpc.messages.RpcInvocation) AbstractActor(akka.actor.AbstractActor) ReceiveBuilder(akka.japi.pf.ReceiveBuilder) Promise(scala.concurrent.impl.Promise) ActorRef(akka.actor.ActorRef) Either(org.apache.flink.types.Either)

Aggregations

AbstractActor (akka.actor.AbstractActor)1 ActorRef (akka.actor.ActorRef)1 Status (akka.actor.Status)1 ReceiveBuilder (akka.japi.pf.ReceiveBuilder)1 Patterns (akka.pattern.Patterns)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Callable (java.util.concurrent.Callable)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 ClassLoadingUtils.runWithContextClassLoader (org.apache.flink.runtime.concurrent.akka.ClassLoadingUtils.runWithContextClassLoader)1 MainThreadValidatorUtil (org.apache.flink.runtime.rpc.MainThreadValidatorUtil)1 RpcEndpoint (org.apache.flink.runtime.rpc.RpcEndpoint)1 RpcGateway (org.apache.flink.runtime.rpc.RpcGateway)1 AkkaHandshakeException (org.apache.flink.runtime.rpc.akka.exceptions.AkkaHandshakeException)1 AkkaRpcException (org.apache.flink.runtime.rpc.akka.exceptions.AkkaRpcException)1