All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.linecorp.armeria.common.RequestContextAwareCompletableFuture Maven / Gradle / Ivy

Go to download

Asynchronous HTTP/2 RPC/REST client/server library built on top of Java 8, Netty, Thrift and GRPC (armeria-shaded)

There is a newer version: 0.75.0
Show newest version
/*
 * Copyright 2017 LINE Corporation
 *
 * LINE Corporation licenses this file to you 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:
 *
 *   https://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.
 */

package com.linecorp.armeria.common;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Executor;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;

final class RequestContextAwareCompletableFuture extends CompletableFuture {

    private final RequestContext ctx;

    RequestContextAwareCompletableFuture(RequestContext requestContext) {
        ctx = requestContext;
    }

    @Override
    public  CompletableFuture thenApply(Function fn) {
        return ctx.makeContextAware(super.thenApply(ctx.makeContextAware(fn)));
    }

    @Override
    public  CompletableFuture thenApplyAsync(Function fn) {
        return ctx.makeContextAware(super.thenApplyAsync(ctx.makeContextAware(fn)));
    }

    @Override
    public  CompletableFuture thenApplyAsync(Function fn, Executor executor) {
        return ctx.makeContextAware(super.thenApplyAsync(ctx.makeContextAware(fn), executor));
    }

    @Override
    public CompletableFuture thenAccept(Consumer action) {
        return ctx.makeContextAware(super.thenAccept(ctx.makeContextAware(action)));
    }

    @Override
    public CompletableFuture thenAcceptAsync(Consumer action) {
        return ctx.makeContextAware(super.thenAcceptAsync(ctx.makeContextAware(action)));
    }

    @Override
    public CompletableFuture thenAcceptAsync(Consumer action, Executor executor) {
        return ctx.makeContextAware(super.thenAcceptAsync(ctx.makeContextAware(action), executor));
    }

    @Override
    public CompletableFuture thenRun(Runnable action) {
        return ctx.makeContextAware(super.thenRun(ctx.makeContextAware(action)));
    }

    @Override
    public CompletableFuture thenRunAsync(Runnable action) {
        return ctx.makeContextAware(super.thenRunAsync(ctx.makeContextAware(action)));
    }

    @Override
    public CompletableFuture thenRunAsync(Runnable action, Executor executor) {
        return ctx.makeContextAware(super.thenRunAsync(ctx.makeContextAware(action), executor));
    }

    @Override
    public  CompletableFuture thenCombine(CompletionStage other,
                                                  BiFunction fn) {
        return ctx.makeContextAware(super.thenCombine(other, ctx.makeContextAware(fn)));
    }

    @Override
    public  CompletableFuture thenCombineAsync(CompletionStage other,
                                                       BiFunction fn) {
        return ctx.makeContextAware(super.thenCombineAsync(other, ctx.makeContextAware(fn)));
    }

    @Override
    public  CompletableFuture thenCombineAsync(CompletionStage other,
                                                       BiFunction fn,
                                                       Executor executor) {
        return ctx.makeContextAware(super.thenCombineAsync(other, ctx.makeContextAware(fn), executor));
    }

    @Override
    public  CompletableFuture thenAcceptBoth(CompletionStage other,
                                                      BiConsumer action) {
        return ctx.makeContextAware(super.thenAcceptBoth(other, ctx.makeContextAware(action)));
    }

    @Override
    public  CompletableFuture thenAcceptBothAsync(CompletionStage other,
                                                           BiConsumer action) {
        return ctx.makeContextAware(super.thenAcceptBothAsync(other, ctx.makeContextAware(action)));
    }

    @Override
    public  CompletableFuture thenAcceptBothAsync(CompletionStage other,
                                                           BiConsumer action,
                                                           Executor executor) {
        return ctx.makeContextAware(super.thenAcceptBothAsync(other, ctx.makeContextAware(action), executor));
    }

    @Override
    public CompletableFuture runAfterBoth(CompletionStage other,
                                                Runnable action) {
        return ctx.makeContextAware(super.runAfterBoth(other, ctx.makeContextAware(action)));
    }

    @Override
    public CompletableFuture runAfterBothAsync(CompletionStage other,
                                                     Runnable action) {
        return ctx.makeContextAware(super.runAfterBothAsync(other, ctx.makeContextAware(action)));
    }

    @Override
    public CompletableFuture runAfterBothAsync(CompletionStage other,
                                                     Runnable action,
                                                     Executor executor) {
        return ctx.makeContextAware(super.runAfterBothAsync(other, ctx.makeContextAware(action), executor));
    }

    @Override
    public  CompletableFuture applyToEither(CompletionStage other,
                                                  Function fn) {
        return ctx.makeContextAware(super.applyToEither(other, ctx.makeContextAware(fn)));
    }

    @Override
    public  CompletableFuture applyToEitherAsync(CompletionStage other,
                                                       Function fn) {
        return ctx.makeContextAware(super.applyToEitherAsync(other, ctx.makeContextAware(fn)));
    }

    @Override
    public  CompletableFuture applyToEitherAsync(CompletionStage other,
                                                       Function fn,
                                                       Executor executor) {
        return ctx.makeContextAware(super.applyToEitherAsync(other, ctx.makeContextAware(fn), executor));
    }

    @Override
    public CompletableFuture acceptEither(CompletionStage other,
                                                Consumer action) {
        return ctx.makeContextAware(super.acceptEither(other, ctx.makeContextAware(action)));
    }

    @Override
    public CompletableFuture acceptEitherAsync(CompletionStage other,
                                                     Consumer action) {
        return ctx.makeContextAware(super.acceptEitherAsync(other, ctx.makeContextAware(action)));
    }

    @Override
    public CompletableFuture acceptEitherAsync(CompletionStage other,
                                                     Consumer action,
                                                     Executor executor) {
        return ctx.makeContextAware(super.acceptEitherAsync(other, ctx.makeContextAware(action), executor));
    }

    @Override
    public CompletableFuture runAfterEither(CompletionStage other,
                                                  Runnable action) {
        return ctx.makeContextAware(super.runAfterEither(other, ctx.makeContextAware(action)));
    }

    @Override
    public CompletableFuture runAfterEitherAsync(CompletionStage other,
                                                       Runnable action) {
        return ctx.makeContextAware(super.runAfterEitherAsync(other, ctx.makeContextAware(action)));
    }

    @Override
    public CompletableFuture runAfterEitherAsync(CompletionStage other,
                                                       Runnable action,
                                                       Executor executor) {
        return ctx.makeContextAware(super.runAfterEitherAsync(other, ctx.makeContextAware(action), executor));
    }

    @Override
    public  CompletableFuture thenCompose(Function> fn) {
        return ctx.makeContextAware(super.thenCompose(ctx.makeContextAware(fn)));
    }

    @Override
    public  CompletableFuture thenComposeAsync(Function> fn) {
        return ctx.makeContextAware(super.thenComposeAsync(ctx.makeContextAware(fn)));
    }

    @Override
    public  CompletableFuture thenComposeAsync(Function> fn,
                                                     Executor executor) {
        return ctx.makeContextAware(super.thenComposeAsync(ctx.makeContextAware(fn), executor));
    }

    @Override
    public CompletableFuture whenComplete(BiConsumer action) {
        return ctx.makeContextAware(super.whenComplete(ctx.makeContextAware(action)));
    }

    @Override
    public CompletableFuture whenCompleteAsync(BiConsumer action) {
        return ctx.makeContextAware(super.whenCompleteAsync(ctx.makeContextAware(action)));
    }

    @Override
    public CompletableFuture whenCompleteAsync(BiConsumer action,
                                                  Executor executor) {
        return ctx.makeContextAware(super.whenCompleteAsync(ctx.makeContextAware(action), executor));
    }

    @Override
    public  CompletableFuture handle(BiFunction fn) {
        return ctx.makeContextAware(super.handle(ctx.makeContextAware(fn)));
    }

    @Override
    public  CompletableFuture handleAsync(BiFunction fn) {
        return ctx.makeContextAware(super.handleAsync(ctx.makeContextAware(fn)));
    }

    @Override
    public  CompletableFuture handleAsync(BiFunction fn,
                                                Executor executor) {
        return ctx.makeContextAware(super.handleAsync(ctx.makeContextAware(fn), executor));
    }

    @Override
    public CompletableFuture exceptionally(Function fn) {
        return ctx.makeContextAware(super.exceptionally(ctx.makeContextAware(fn)));
    }
}