Class Runtime

java.lang.Object
com.github.kaktushose.jda.commands.dispatching.Runtime
All Implemented Interfaces:
Closeable, AutoCloseable

@Internal public final class Runtime extends Object implements Closeable

A Runtime delegates the jda events to their corresponding EventHandler and manages the used virtual threads.

A new Runtime is created each time an SlashCommandInteractionEvent, GenericContextInteractionEvent or CommandAutoCompleteInteractionEvent is provided by jda or if an interaction is marked as 'independent'. Runtimes are executed in parallel, but events are processed sequentially by each runtime. Every EventHandler called by this Runtime is executed in its own virtual thread, isolated from the runtime one.

Implementation Note:
Each Runtime is based on a BlockingQueue in which jda events, belonging to this runtime, are put by the JDAEventListener running on the jda event thread. Each runtime than has its own virtual thread that takes events from this queue and executes them sequentially but each in its own (sub) virtual thread. Therefore, the virtual thread in which the user code will be called, only exists for the lifespan of one "interaction" and cannot interfere with other interactions on the same or other runtimes.
  • Method Details

    • startNew

      @NotNull public static @NotNull Runtime startNew(String id, DispatchingContext dispatchingContext)
    • id

      @NotNull public @NotNull String id()
    • queueEvent

      public void queueEvent(net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent event)
    • keyValueStore

      @NotNull public @NotNull KeyValueStore keyValueStore()
    • instance

      public Object instance(InteractionDefinition definition)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • isClosed

      public boolean isClosed()