org.jooq.impl.ExecutorProviderCompletionStage Maven / Gradle / Ivy
/**
* Copyright (c) 2009-2016, Data Geekery GmbH (http://www.datageekery.com)
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.impl;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Executor;
import java.util.concurrent.ForkJoinPool;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import org.jooq.ExecutorProvider;
/**
* A {@link CompletionStage} that defaults to an {@link ExecutorProvider} for
* all async methods that do not have an explicit {@link Executor}.
*
* In jOOQ, the {@link ExecutorProvider} SPI is used for all types of
* asynchronous tasks. It overrides standard {@link CompletableFuture} behaviour
* in case users prefer not to use the {@link ForkJoinPool#commonPool()}.
*
* @author Lukas Eder
*/
final class ExecutorProviderCompletionStage implements CompletionStage {
private final CompletionStage delegate;
private final ExecutorProvider provider;
static final ExecutorProviderCompletionStage of(CompletionStage delegate, ExecutorProvider provider) {
return new ExecutorProviderCompletionStage<>(delegate, provider);
}
ExecutorProviderCompletionStage(CompletionStage delegate, ExecutorProvider provider) {
this.delegate = delegate;
this.provider = provider;
}
@Override
public final CompletionStage thenApply(Function fn) {
return of(delegate.thenApply(fn), provider);
}
@Override
public final CompletionStage thenApplyAsync(Function fn) {
return of(delegate.thenApplyAsync(fn, provider.provide()), provider);
}
@Override
public final CompletionStage thenApplyAsync(Function fn, Executor executor) {
return of(delegate.thenApplyAsync(fn, executor), provider);
}
@Override
public final CompletionStage thenAccept(Consumer action) {
return of(delegate.thenAccept(action), provider);
}
@Override
public final CompletionStage thenAcceptAsync(Consumer action) {
return of(delegate.thenAcceptAsync(action, provider.provide()), provider);
}
@Override
public final CompletionStage thenAcceptAsync(Consumer action, Executor executor) {
return of(delegate.thenAcceptAsync(action, executor), provider);
}
@Override
public final CompletionStage thenRun(Runnable action) {
return of(delegate.thenRun(action), provider);
}
@Override
public final CompletionStage thenRunAsync(Runnable action) {
return of(delegate.thenRunAsync(action, provider.provide()), provider);
}
@Override
public final CompletionStage thenRunAsync(Runnable action, Executor executor) {
return of(delegate.thenRunAsync(action, executor), provider);
}
@Override
public final CompletionStage thenCombine(CompletionStage other, BiFunction fn) {
return of(delegate.thenCombine(other, fn), provider);
}
@Override
public final CompletionStage thenCombineAsync(CompletionStage other, BiFunction fn) {
return of(delegate.thenCombineAsync(other, fn, provider.provide()), provider);
}
@Override
public final CompletionStage thenCombineAsync(CompletionStage other, BiFunction fn, Executor executor) {
return of(delegate.thenCombineAsync(other, fn, executor), provider);
}
@Override
public final CompletionStage thenAcceptBoth(CompletionStage other, BiConsumer action) {
return of(delegate.thenAcceptBoth(other, action), provider);
}
@Override
public final CompletionStage thenAcceptBothAsync(CompletionStage other, BiConsumer action) {
return of(delegate.thenAcceptBothAsync(other, action, provider.provide()), provider);
}
@Override
public final CompletionStage thenAcceptBothAsync(CompletionStage other, BiConsumer action, Executor executor) {
return of(delegate.thenAcceptBothAsync(other, action, executor), provider);
}
@Override
public final CompletionStage runAfterBoth(CompletionStage other, Runnable action) {
return of(delegate.runAfterBoth(other, action), provider);
}
@Override
public final CompletionStage runAfterBothAsync(CompletionStage other, Runnable action) {
return of(delegate.runAfterBothAsync(other, action, provider.provide()), provider);
}
@Override
public final CompletionStage runAfterBothAsync(CompletionStage other, Runnable action, Executor executor) {
return of(delegate.runAfterBothAsync(other, action, executor), provider);
}
@Override
public final CompletionStage applyToEither(CompletionStage other, Function fn) {
return of(delegate.applyToEither(other, fn), provider);
}
@Override
public final CompletionStage applyToEitherAsync(CompletionStage other, Function fn) {
return of(delegate.applyToEitherAsync(other, fn, provider.provide()), provider);
}
@Override
public final CompletionStage applyToEitherAsync(CompletionStage other, Function fn, Executor executor) {
return of(delegate.applyToEitherAsync(other, fn, executor), provider);
}
@Override
public final CompletionStage acceptEither(CompletionStage other, Consumer action) {
return of(delegate.acceptEither(other, action), provider);
}
@Override
public final CompletionStage acceptEitherAsync(CompletionStage other, Consumer action) {
return of(delegate.acceptEitherAsync(other, action, provider.provide()), provider);
}
@Override
public final CompletionStage acceptEitherAsync(CompletionStage other, Consumer action, Executor executor) {
return of(delegate.acceptEitherAsync(other, action, executor), provider);
}
@Override
public final CompletionStage runAfterEither(CompletionStage other, Runnable action) {
return of(delegate.runAfterEither(other, action), provider);
}
@Override
public final CompletionStage runAfterEitherAsync(CompletionStage other, Runnable action) {
return of(delegate.runAfterEitherAsync(other, action, provider.provide()), provider);
}
@Override
public final CompletionStage runAfterEitherAsync(CompletionStage other, Runnable action, Executor executor) {
return of(delegate.runAfterEitherAsync(other, action, executor), provider);
}
@Override
public final CompletionStage thenCompose(Function> fn) {
return of(delegate.thenCompose(fn), provider);
}
@Override
public final CompletionStage thenComposeAsync(Function> fn) {
return of(delegate.thenComposeAsync(fn, provider.provide()), provider);
}
@Override
public final CompletionStage thenComposeAsync(Function> fn,
Executor executor) {
return of(delegate.thenComposeAsync(fn, executor), provider);
}
@Override
public final CompletionStage exceptionally(Function fn) {
return of(delegate.exceptionally(fn), provider);
}
@Override
public final CompletionStage whenComplete(BiConsumer action) {
return of(delegate.whenComplete(action), provider);
}
@Override
public final CompletionStage whenCompleteAsync(BiConsumer action) {
return of(delegate.whenCompleteAsync(action, provider.provide()), provider);
}
@Override
public final CompletionStage whenCompleteAsync(BiConsumer action, Executor executor) {
return of(delegate.whenCompleteAsync(action, executor), provider);
}
@Override
public final CompletionStage handle(BiFunction fn) {
return of(delegate.handle(fn), provider);
}
@Override
public final CompletionStage handleAsync(BiFunction fn) {
return of(delegate.handleAsync(fn, provider.provide()), provider);
}
@Override
public final CompletionStage handleAsync(BiFunction fn, Executor executor) {
return of(delegate.handleAsync(fn, executor), provider);
}
@Override
public final CompletableFuture toCompletableFuture() {
return delegate.toCompletableFuture();
}
}