forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#35072 from michalvavrik/feature/security…
…-run-blocking-tasks-from-duplicated-ctx Run blocking security tasks from Vert.x duplicated context
- Loading branch information
Showing
13 changed files
with
139 additions
and
127 deletions.
There are no files selected for viewing
53 changes: 23 additions & 30 deletions
53
extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/BlockingTaskRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,36 @@ | ||
package io.quarkus.oidc.runtime; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.oidc.OidcRequestContext; | ||
import io.quarkus.runtime.BlockingOperationControl; | ||
import io.quarkus.runtime.ExecutorRecorder; | ||
import io.quarkus.security.spi.runtime.BlockingSecurityExecutor; | ||
import io.smallrye.mutiny.Uni; | ||
import io.smallrye.mutiny.subscription.UniEmitter; | ||
|
||
public class BlockingTaskRunner<T> implements OidcRequestContext<T> { | ||
public Uni<T> runBlocking(Supplier<T> function) { | ||
return Uni.createFrom().deferred(new Supplier<Uni<? extends T>>() { | ||
|
||
private final BlockingSecurityExecutor blockingExecutor; | ||
|
||
public BlockingTaskRunner() { | ||
this.blockingExecutor = new BlockingSecurityExecutor() { | ||
|
||
private volatile BlockingSecurityExecutor delegate = null; | ||
|
||
@Override | ||
public Uni<T> get() { | ||
if (BlockingOperationControl.isBlockingAllowed()) { | ||
try { | ||
return Uni.createFrom().item(function.get()); | ||
} catch (Throwable t) { | ||
return Uni.createFrom().failure(t); | ||
} | ||
} else { | ||
return Uni.createFrom().emitter(new Consumer<UniEmitter<? super T>>() { | ||
@Override | ||
public void accept(UniEmitter<? super T> uniEmitter) { | ||
ExecutorRecorder.getCurrent().execute(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
uniEmitter.complete(function.get()); | ||
} catch (Throwable t) { | ||
uniEmitter.fail(t); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
public <O> Uni<O> executeBlocking(Supplier<? extends O> supplier) { | ||
if (delegate == null) { | ||
delegate = Arc.container().select(BlockingSecurityExecutor.class).get(); | ||
} | ||
return delegate.executeBlocking(supplier); | ||
} | ||
}); | ||
}; | ||
} | ||
|
||
public BlockingTaskRunner(BlockingSecurityExecutor blockingExecutor) { | ||
this.blockingExecutor = blockingExecutor; | ||
} | ||
|
||
public Uni<T> runBlocking(Supplier<T> function) { | ||
return blockingExecutor.executeBlocking(function); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.