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#38478 from mkouba/issue-16833
Vertx: use NoopShutdownExecutorService and DevModeExecutorService
- Loading branch information
Showing
9 changed files
with
250 additions
and
47 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
87 changes: 87 additions & 0 deletions
87
core/runtime/src/main/java/io/quarkus/runtime/util/ForwardingExecutorService.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,87 @@ | ||
package io.quarkus.runtime.util; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
/** | ||
* Forwards all method calls to the executor service returned from the {@link #delegate()} method. Only non-default methods | ||
* declared on the {@link ExecutorService} interface are forwarded. | ||
*/ | ||
public abstract class ForwardingExecutorService implements ExecutorService { | ||
|
||
protected abstract ExecutorService delegate(); | ||
|
||
@Override | ||
public void execute(Runnable command) { | ||
delegate().execute(command); | ||
} | ||
|
||
@Override | ||
public void shutdown() { | ||
delegate().shutdown(); | ||
} | ||
|
||
@Override | ||
public List<Runnable> shutdownNow() { | ||
return delegate().shutdownNow(); | ||
} | ||
|
||
@Override | ||
public boolean isShutdown() { | ||
return delegate().isShutdown(); | ||
} | ||
|
||
@Override | ||
public boolean isTerminated() { | ||
return delegate().isTerminated(); | ||
} | ||
|
||
@Override | ||
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { | ||
return delegate().awaitTermination(timeout, unit); | ||
} | ||
|
||
@Override | ||
public <T> Future<T> submit(Callable<T> task) { | ||
return delegate().submit(task); | ||
} | ||
|
||
@Override | ||
public <T> Future<T> submit(Runnable task, T result) { | ||
return delegate().submit(task, result); | ||
} | ||
|
||
@Override | ||
public Future<?> submit(Runnable task) { | ||
return delegate().submit(task); | ||
} | ||
|
||
@Override | ||
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException { | ||
return delegate().invokeAll(tasks); | ||
} | ||
|
||
@Override | ||
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) | ||
throws InterruptedException { | ||
return delegate().invokeAll(tasks, timeout, unit); | ||
} | ||
|
||
@Override | ||
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException { | ||
return delegate().invokeAny(tasks); | ||
} | ||
|
||
@Override | ||
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) | ||
throws InterruptedException, ExecutionException, TimeoutException { | ||
return delegate().invokeAny(tasks, 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
44 changes: 44 additions & 0 deletions
44
...ons/vertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/DevModeExecutorService.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,44 @@ | ||
package io.quarkus.vertx.core.runtime; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.function.Supplier; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkus.runtime.util.ForwardingExecutorService; | ||
|
||
/** | ||
* This executor is only used in the dev mode as the Vertx worker thread pool. | ||
* <p> | ||
* The underlying executor can be shut down and then replaced with a new re-initialized executor. | ||
*/ | ||
class DevModeExecutorService extends ForwardingExecutorService { | ||
|
||
private static final Logger LOG = Logger.getLogger(DevModeExecutorService.class); | ||
|
||
private final Supplier<ExecutorService> initializer; | ||
private volatile ExecutorService executor; | ||
|
||
DevModeExecutorService(Supplier<ExecutorService> initializer) { | ||
this.initializer = initializer; | ||
this.executor = initializer.get(); | ||
} | ||
|
||
@Override | ||
protected ExecutorService delegate() { | ||
return executor; | ||
} | ||
|
||
/** | ||
* Shutdown the underlying executor and then initialize a new one. | ||
*/ | ||
void reinit() { | ||
ExecutorService oldExecutor = this.executor; | ||
if (oldExecutor != null) { | ||
oldExecutor.shutdownNow(); | ||
} | ||
this.executor = initializer.get(); | ||
LOG.debug("Dev mode executor re-initialized"); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...ertx/runtime/src/main/java/io/quarkus/vertx/core/runtime/NoopShutdownExecutorService.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,39 @@ | ||
package io.quarkus.vertx.core.runtime; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkus.runtime.util.ForwardingExecutorService; | ||
|
||
/** | ||
* This executor is only used in the prod mode as the Vertx worker thread pool. | ||
*/ | ||
class NoopShutdownExecutorService extends ForwardingExecutorService { | ||
|
||
private static final Logger LOG = Logger.getLogger(NoopShutdownExecutorService.class); | ||
|
||
private final ExecutorService delegate; | ||
|
||
NoopShutdownExecutorService(ExecutorService delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
protected ExecutorService delegate() { | ||
return delegate; | ||
} | ||
|
||
@Override | ||
public void shutdown() { | ||
LOG.debug("shutdown() deliberately not delegated"); | ||
} | ||
|
||
@Override | ||
public List<Runnable> shutdownNow() { | ||
LOG.debug("shutdownNow() deliberately not delegated"); | ||
return List.of(); | ||
} | ||
|
||
} |
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.