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.
Capture context across all scheduler methods
Adapted from the draft code from @luneo7 in the discussions of - quarkusio#26242 - quarkusio#25818
- Loading branch information
Showing
6 changed files
with
147 additions
and
7 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
67 changes: 67 additions & 0 deletions
67
...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,67 @@ | ||
package io.quarkus.mutiny.runtime; | ||
|
||
import java.util.concurrent.*; | ||
|
||
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); | ||
} | ||
} |
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