Search in sources :

Example 1 with RunAsync

use of org.apache.flink.runtime.rpc.akka.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) {
    if (runAsync.getRunnable() == null) {
        LOG.warn("Received a {} message with an empty runnable field. This indicates " + "that this message has been serialized prior to sending the message. The " + "{} is only supported with local communication.", runAsync.getClass().getName(), runAsync.getClass().getName());
    } else if (runAsync.getDelay() == 0) {
        // run immediately
        try {
            runAsync.getRunnable().run();
        } 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(runAsync.getDelay(), TimeUnit.MILLISECONDS);
        RunAsync message = new RunAsync(runAsync.getRunnable(), 0);
        getContext().system().scheduler().scheduleOnce(delay, getSelf(), message, getContext().dispatcher(), ActorRef.noSender());
    }
}
Also used : FiniteDuration(scala.concurrent.duration.FiniteDuration) RunAsync(org.apache.flink.runtime.rpc.akka.messages.RunAsync)

Example 2 with RunAsync

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

the class AkkaInvocationHandler method scheduleRunAsync.

@Override
public void scheduleRunAsync(Runnable runnable, long delay) {
    checkNotNull(runnable, "runnable");
    checkArgument(delay >= 0, "delay must be zero or greater");
    if (isLocal) {
        rpcEndpoint.tell(new RunAsync(runnable, delay), ActorRef.noSender());
    } 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.akka.messages.RunAsync)

Aggregations

RunAsync (org.apache.flink.runtime.rpc.akka.messages.RunAsync)2 FiniteDuration (scala.concurrent.duration.FiniteDuration)1