Class Scheduler

java.lang.Object
org.mockserver.scheduler.Scheduler

public class Scheduler extends Object
Author:
jamesdbloom
  • Constructor Details

  • Method Details

    • getExecutorService

      public ScheduledExecutorService 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

      public void submitAsync(Runnable command, Delay... delays)
    • schedule

      public void schedule(Runnable command, boolean synchronous, Delay... delays)
    • scheduleLocalCallback

      public void scheduleLocalCallback(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.

      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=true path) the body runs INLINE after any delay, exactly as the equivalent schedule(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

      public void submit(Runnable command)
    • submit

      public void submit(Runnable command, boolean synchronous)
    • submit

      public void submit(HttpForwardActionResult future, Runnable command, boolean synchronous, Predicate<Throwable> logException)
    • submit

      public void submit(CompletableFuture<BinaryMessage> future, Runnable command, boolean synchronous)
    • submit

      public void submit(HttpForwardActionResult future, BiConsumer<HttpResponse,Throwable> consumer, boolean synchronous)