-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mutiny 1.6.0 upgrade and capture Vert.x contexts across all Mutiny sc…
…hedulers Fixes #25818 This is part of a coordinated fix across Quarkus and Mutiny where scheduler wrapping would cause Vert.x context propagation not to be done. Some changes have been adapted from the draft code from @luneo7 in the discussions of: - #26242 - #25818 See the matching changes in Mutiny: smallrye/smallrye-mutiny#955
- Loading branch information
Showing
8 changed files
with
364 additions
and
16 deletions.
There are no files selected for viewing
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
71 changes: 71 additions & 0 deletions
71
...ny/runtime/src/main/java/io/quarkus/mutiny/runtime/ContextualRunnableScheduledFuture.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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.quarkus.mutiny.runtime; | ||
|
||
import java.util.concurrent.Delayed; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.RunnableScheduledFuture; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import org.jboss.threads.ContextHandler; | ||
|
||
class ContextualRunnableScheduledFuture<V> implements RunnableScheduledFuture<V> { | ||
private final RunnableScheduledFuture<V> runnable; | ||
private final Object context; | ||
private final ContextHandler<Object> contextHandler; | ||
|
||
public ContextualRunnableScheduledFuture(ContextHandler<Object> contextHandler, Object context, | ||
RunnableScheduledFuture<V> runnable) { | ||
this.contextHandler = contextHandler; | ||
this.context = context; | ||
this.runnable = runnable; | ||
} | ||
|
||
@Override | ||
public boolean isPeriodic() { | ||
return runnable.isPeriodic(); | ||
} | ||
|
||
@Override | ||
public long getDelay(TimeUnit unit) { | ||
return runnable.getDelay(unit); | ||
} | ||
|
||
@Override | ||
public int compareTo(Delayed o) { | ||
return runnable.compareTo(o); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
if (contextHandler != null) { | ||
contextHandler.runWith(runnable, context); | ||
} else { | ||
runnable.run(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean cancel(boolean mayInterruptIfRunning) { | ||
return runnable.cancel(mayInterruptIfRunning); | ||
} | ||
|
||
@Override | ||
public boolean isCancelled() { | ||
return runnable.isCancelled(); | ||
} | ||
|
||
@Override | ||
public boolean isDone() { | ||
return runnable.isDone(); | ||
} | ||
|
||
@Override | ||
public V get() throws InterruptedException, ExecutionException { | ||
return runnable.get(); | ||
} | ||
|
||
@Override | ||
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { | ||
return runnable.get(timeout, unit); | ||
} | ||
} |
131 changes: 121 additions & 10 deletions
131
extensions/mutiny/runtime/src/main/java/io/quarkus/mutiny/runtime/MutinyInfrastructure.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
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
24 changes: 24 additions & 0 deletions
24
...tiny/src/main/java/io/quarkus/it/resteasy/mutiny/regression/bug25818/BlockingService.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.quarkus.it.resteasy.mutiny.regression.bug25818; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import io.vertx.core.Context; | ||
import io.vertx.core.Vertx; | ||
|
||
@ApplicationScoped | ||
public class BlockingService { | ||
|
||
public String getBlocking() { | ||
try { | ||
Thread.sleep(250); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
Context context = Vertx.currentContext(); | ||
if (context == null) { | ||
return "~~ context is null ~~"; | ||
} else { | ||
return "hello-" + context.getLocal("hello-target"); | ||
} | ||
} | ||
} |
Oops, something went wrong.