Class Scheduler
- Author:
- jamesdbloom
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionScheduler(Configuration configuration, MockServerLogger mockServerLogger) Scheduler(Configuration configuration, MockServerLogger mockServerLogger, boolean synchronous) -
Method Summary
Modifier and TypeMethodDescriptionReturns the underlying executor service for use with CompletableFuture async continuations (e.g. thenAcceptAsync).voidvoidscheduleLocalCallback(Runnable command, boolean synchronous, Delay... delays) Dispatch a LOCAL (in-JVM) object/class callback so that — in asynchronous (Netty) mode — its potentially-BLOCKING body never runs on the server worker event loop and never consumes the bounded scheduler pool.voidshutdown()voidvoidvoidsubmit(CompletableFuture<BinaryMessage> future, Runnable command, boolean synchronous) voidsubmit(HttpForwardActionResult future, Runnable command, boolean synchronous, Predicate<Throwable> logException) voidsubmit(HttpForwardActionResult future, BiConsumer<HttpResponse, Throwable> consumer, boolean synchronous) voidsubmitAsync(Runnable command, Delay... delays)
-
Constructor Details
-
Scheduler
-
Scheduler
public Scheduler(Configuration configuration, MockServerLogger mockServerLogger, boolean synchronous)
-
-
Method Details
-
getExecutorService
Returns the underlying executor service for use with CompletableFuture async continuations (e.g. thenAcceptAsync). Returns null in synchronous mode — callers must handle that case (run inline). -
shutdown
public void shutdown() -
submitAsync
-
schedule
-
scheduleLocalCallback
Dispatch a LOCAL (in-JVM) object/class callback so that — in asynchronous (Netty) mode — its potentially-BLOCKING body never runs on the server worker event loop and never consumes the bounded scheduler pool.In asynchronous mode the callback is run on the dedicated, unbounded
localCallbackExecutor(see its field javadoc): this both moves the blocking loopback off the worker thread (so the loopback's reply can be read on a now-free worker) and guarantees a recursively-triggered inner local callback always gets its own thread, so the only failure mode is a BOUNDED wait, never a pool-exhaustion deadlock. An optional delay is honoured on the shared scheduled executor first (it only occupies a timer thread until it fires), after which the body hops to the cached pool.In synchronous mode (WAR/servlet, or the unit-test
synchronous=truepath) the body runs INLINE after any delay, exactly as the equivalentschedule(java.lang.Runnable, boolean, org.mockserver.model.Delay...)call would, so the response is written before the caller returns and blocking-model deployments keep their semantics unchanged.Whatever thread the body ends up on, it runs through
run(Runnable, Integer)with the captured loop-prevention port restored, so response routing/HttpState.getPort()behave identically to the existing scheduler paths. -
submit
-
submit
-
submit
public void submit(HttpForwardActionResult future, Runnable command, boolean synchronous, Predicate<Throwable> logException) -
submit
-
submit
public void submit(HttpForwardActionResult future, BiConsumer<HttpResponse, Throwable> consumer, boolean synchronous)
-