com.arangodb.shaded.vertx.core.WorkerExecutor Maven / Gradle / Ivy
/*
* Copyright (c) 2011-2019 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*/
package com.arangodb.shaded.vertx.core;
import com.arangodb.shaded.vertx.codegen.annotations.Nullable;
import com.arangodb.shaded.vertx.codegen.annotations.VertxGen;
import com.arangodb.shaded.vertx.core.metrics.Measured;
/**
* An executor for executing blocking code in Vert.x .
*
* It provides the same executeBlocking
operation than {@link com.arangodb.shaded.vertx.core.Context} and
* {@link com.arangodb.shaded.vertx.core.Vertx} but on a separate worker pool.
*
* @author Julien Viet
*/
@VertxGen
public interface WorkerExecutor extends Measured {
/**
* Safely execute some blocking code.
*
* Executes the blocking code in the handler {@code blockingCodeHandler} using a thread from the worker pool.
*
* When the code is complete the handler {@code resultHandler} will be called with the result on the original context
* (i.e. on the original event loop of the caller).
*
* A {@code Future} instance is passed into {@code blockingCodeHandler}. When the blocking code successfully completes,
* the handler should call the {@link Promise#complete} or {@link Promise#complete(Object)} method, or the {@link Promise#fail}
* method if it failed.
*
* In the {@code blockingCodeHandler} the current context remains the original context and therefore any task
* scheduled in the {@code blockingCodeHandler} will be executed on the this context and not on the worker thread.
*
* @param blockingCodeHandler handler representing the blocking code to run
* @param resultHandler handler that will be called when the blocking code is complete
* @param ordered if true then if executeBlocking is called several times on the same context, the executions
* for that context will be executed serially, not in parallel. if false then they will be no ordering
* guarantees
* @param the type of the result
*/
void executeBlocking(Handler> blockingCodeHandler, boolean ordered, Handler> resultHandler);
/**
* Like {@link #executeBlocking(Handler, boolean, Handler)} called with ordered = true.
*/
default void executeBlocking(Handler> blockingCodeHandler, Handler> resultHandler) {
executeBlocking(blockingCodeHandler, true, resultHandler);
}
/**
* Same as {@link #executeBlocking(Handler, boolean, Handler)} but with an {@code handler} called when the operation completes
*/
Future<@Nullable T> executeBlocking(Handler> blockingCodeHandler, boolean ordered);
/**
* Like {@link #executeBlocking(Handler, boolean, Handler)} called with ordered = true.
*/
default Future executeBlocking(Handler> blockingCodeHandler) {
return executeBlocking(blockingCodeHandler, true);
}
/**
* Close the executor.
*
* @param handler the completion handler
*/
void close(Handler> handler);
/**
* Like {@link #close(Handler)} but returns a {@code Future} of the asynchronous result
*/
Future close();
}