Module io.jooby
Package io.jooby

Enum Class ExecutionMode

All Implemented Interfaces:
Serializable, Comparable<ExecutionMode>, Constable

public enum ExecutionMode extends Enum<ExecutionMode>
Execution mode.
Author:
edgar
  • Enum Constant Details

    • EVENT_LOOP

      public static final ExecutionMode EVENT_LOOP
      Execute route handler in the event loop thread (non-blocking). Handler must never block.

      Examples:

      
       {
         mode(EVENT_LOOP);
      
         get("/non-blocking", ctx -> "I'm running on event-loop thread (no blocking allowed)");
      
         // Dispatch to worker thread, blocking routes
         dispatch(() -> {
      
           get("/blocking", ctx -> {
             // remote call: service, database, etc..
             return "Safe to block";
           });
         });
       }
       
    • WORKER

      public static final ExecutionMode WORKER
      Execute handler in a worker/io thread (blocking). Handler is allowed to block.

      Examples:

      
       {
      
         mode(WORKER);
      
         get("/worker", ctx -> {
           // remote call: another service, database, etc..
           return "Safe to block";
         });
       }
      
       
    • DEFAULT

      public static final ExecutionMode DEFAULT
      Default execution mode.

      Automatically choose between EVENT_LOOP and WORKER.

      If route handler returns a `reactive` type, then Jooby run the route handler in the event-loop thread. Otherwise, run the handler in the worker thread.

      A reactive type is one of:

      - CompletableFuture. - A reactive stream Publisher - Rx types: Observable, Flowable, Single, Maybe, etc.. - Reactor types: Flux and Mono.

      Examples:

      
       {
      
         get("/non-blocking", ctx -> {
           return CompletableFuture.supplyAsync(() -> {
             return "I'm non-blocking";
           });
         });
      
         get("/blocking", ctx -> {
           return "I'm blocking";
         });
       }
       
  • Method Details

    • values

      public static ExecutionMode[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static ExecutionMode valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null