Skip to content

Commit

Permalink
implement few MCF.*Async methods, MSES.copy
Browse files Browse the repository at this point in the history
Specifically MCF.thenApplyAsync, thenCombineAsync, applyToEitherAsync,
MSES.cop
  • Loading branch information
aubi authored and breakponchito committed May 13, 2022
1 parent 81bb0b5 commit 18eff7a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.enterprise.concurrent;

import java.util.ArrayList;
Expand Down Expand Up @@ -452,12 +451,24 @@ public <U> CompletionStage<U> completedStage(U value) {

@Override
public <T> CompletableFuture<T> copy(CompletableFuture<T> future) {
return ManagedCompletableFuture.copy(future, this);
return copyInternal(future);
}

@Override
public <T> CompletionStage<T> copy(CompletionStage<T> stage) {
return ManagedCompletableFuture.copy(stage,this);
return copyInternal(stage);
}

private <T> CompletableFuture<T> copyInternal(CompletionStage<T> future) {
ManagedCompletableFuture managedFuture = new ManagedCompletableFuture(this);
future.whenComplete((result, exception) -> {
if (exception == null) {
managedFuture.complete(result);
} else {
managedFuture.completeExceptionally(exception);
}
});
return managedFuture;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ public <U> CompletionStage<U> completedStage(U value) {

@Override
public <T> CompletableFuture<T> copy(CompletableFuture<T> future) {
return ManagedCompletableFuture.copy(future, this);
return executor.copy(future);
}

@Override
public <T> CompletionStage<T> copy(CompletionStage<T> stage) {
return ManagedCompletableFuture.copy(stage, this);
public <T> CompletionStage<T> copy(CompletionStage<T> completionStage) {
return executor.copy(completionStage);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public <U> CompletableFuture<U> thenApplyAsync(Function<? super T, ? extends U>

@Override
public <U> CompletableFuture<U> thenApplyAsync(Function<? super T, ? extends U> fn, Executor executor) {
return super.thenApplyAsync(fn, executor);
return super.thenApplyAsync(this.executor.getContextService().contextualFunction(fn), executor);
}

@Override
Expand All @@ -106,7 +106,7 @@ public <U, V> CompletableFuture<V> thenCombineAsync(CompletionStage<? extends U>

@Override
public <U, V> CompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T, ? super U, ? extends V> fn, Executor executor) {
return super.thenCombineAsync(other, fn, executor);
return super.thenCombineAsync(other, this.executor.getContextService().contextualFunction(fn), executor);
}

@Override
Expand All @@ -120,6 +120,17 @@ public <U, V> CompletableFuture<V> thenCombine(CompletionStage<? extends U> othe
return super.thenCombine(other, executor.getContextService().contextualFunction(fn));
}

@Override
public <U> CompletableFuture<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T, U> fn) {
return applyToEitherAsync(other, fn, executor);
}

@Override
public <U> CompletableFuture<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T, U> fn, Executor executor) {
return super.applyToEitherAsync(other, this.executor.getContextService().contextualFunction(fn), executor); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/OverriddenMethodBody
}


public static <U> CompletableFuture<U> completedFuture(U value, ManagedExecutorService executor) {
ManagedCompletableFuture<U> future = new ManagedCompletableFuture<>(executor);
future.complete(value);
Expand All @@ -132,14 +143,6 @@ public static <U> CompletionStage<U> completedStage(U value, ManagedExecutorServ
return (CompletionStage<U>) future;
}

public static <T> CompletableFuture<T> copy(CompletableFuture<T> future, ManagedExecutorService executor) {
return future.copy();
}

public static <T> CompletionStage<T> copy(CompletionStage<T> stage, ManagedExecutorService executor) {
return stage.thenApply(Function.identity());
}

public static <U> CompletableFuture<U> failedFuture(Throwable ex, ManagedExecutorService executor) {
return executor.failedFuture(ex);
}
Expand Down

0 comments on commit 18eff7a

Please sign in to comment.