Class Runtime
java.lang.Object
com.github.kaktushose.jda.commands.dispatching.Runtime
- All Implemented Interfaces:
Closeable
,AutoCloseable
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 aBlockingQueue
in which jda events, belonging to this runtime, are put by theJDAEventListener
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 Summary
Modifier and TypeMethodDescriptionvoid
close()
@NotNull String
id()
instance
(InteractionDefinition definition) boolean
isClosed()
@NotNull KeyValueStore
void
queueEvent
(net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent event) static @NotNull Runtime
startNew
(String id, DispatchingContext dispatchingContext)
-
Method Details
-
startNew
-
id
-
queueEvent
public void queueEvent(net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent event) -
keyValueStore
-
instance
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
isClosed
public boolean isClosed()
-