Search in sources :

Example 1 with RunAsync

use of org.apache.flink.runtime.rpc.messages.RunAsync in project flink by apache.

the class AkkaRpcActor method handleRunAsync.

/**
 * Handle asynchronous {@link Runnable}. This method simply executes the given {@link Runnable}
 * in the context of the actor thread.
 *
 * @param runAsync Run async message
 */
private void handleRunAsync(RunAsync runAsync) {
    final long timeToRun = runAsync.getTimeNanos();
    final long delayNanos;
    if (timeToRun == 0 || (delayNanos = timeToRun - System.nanoTime()) <= 0) {
        // run immediately
        try {
            runWithContextClassLoader(() -> runAsync.getRunnable().run(), flinkClassLoader);
        } catch (Throwable t) {
            log.error("Caught exception while executing runnable in main thread.", t);
            ExceptionUtils.rethrowIfFatalErrorOrOOM(t);
        }
    } else {
        // schedule for later. send a new message after the delay, which will then be
        // immediately executed
        FiniteDuration delay = new FiniteDuration(delayNanos, TimeUnit.NANOSECONDS);
        RunAsync message = new RunAsync(runAsync.getRunnable(), timeToRun);
        final Object envelopedSelfMessage = envelopeSelfMessage(message);
        getContext().system().scheduler().scheduleOnce(delay, getSelf(), envelopedSelfMessage, getContext().dispatcher(), ActorRef.noSender());
    }
}
Also used : FiniteDuration(scala.concurrent.duration.FiniteDuration) RunAsync(org.apache.flink.runtime.rpc.messages.RunAsync)

Example 2 with RunAsync

use of org.apache.flink.runtime.rpc.messages.RunAsync in project flink by apache.

the class AkkaRpcActor method handleRpcMessage.

protected void handleRpcMessage(Object message) {
    if (message instanceof RunAsync) {
        handleRunAsync((RunAsync) message);
    } else if (message instanceof CallAsync) {
        handleCallAsync((CallAsync) message);
    } else if (message instanceof RpcInvocation) {
        handleRpcInvocation((RpcInvocation) message);
    } else {
        log.warn("Received message of unknown type {} with value {}. Dropping this message!", message.getClass().getName(), message);
        sendErrorIfSender(new AkkaUnknownMessageException("Received unknown message " + message + " of type " + message.getClass().getSimpleName() + '.'));
    }
}
Also used : LocalRpcInvocation(org.apache.flink.runtime.rpc.messages.LocalRpcInvocation) RpcInvocation(org.apache.flink.runtime.rpc.messages.RpcInvocation) AkkaUnknownMessageException(org.apache.flink.runtime.rpc.akka.exceptions.AkkaUnknownMessageException) RunAsync(org.apache.flink.runtime.rpc.messages.RunAsync) CallAsync(org.apache.flink.runtime.rpc.messages.CallAsync)

Example 3 with RunAsync

use of org.apache.flink.runtime.rpc.messages.RunAsync in project flink by apache.

the class AkkaInvocationHandler method scheduleRunAsync.

@Override
public void scheduleRunAsync(Runnable runnable, long delayMillis) {
    checkNotNull(runnable, "runnable");
    checkArgument(delayMillis >= 0, "delay must be zero or greater");
    if (isLocal) {
        long atTimeNanos = delayMillis == 0 ? 0 : System.nanoTime() + (delayMillis * 1_000_000);
        tell(new RunAsync(runnable, atTimeNanos));
    } else {
        throw new RuntimeException("Trying to send a Runnable to a remote actor at " + rpcEndpoint.path() + ". This is not supported.");
    }
}
Also used : RunAsync(org.apache.flink.runtime.rpc.messages.RunAsync)

Aggregations

RunAsync (org.apache.flink.runtime.rpc.messages.RunAsync)3 AkkaUnknownMessageException (org.apache.flink.runtime.rpc.akka.exceptions.AkkaUnknownMessageException)1 CallAsync (org.apache.flink.runtime.rpc.messages.CallAsync)1 LocalRpcInvocation (org.apache.flink.runtime.rpc.messages.LocalRpcInvocation)1 RpcInvocation (org.apache.flink.runtime.rpc.messages.RpcInvocation)1 FiniteDuration (scala.concurrent.duration.FiniteDuration)1