-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61c2043
commit b273fa6
Showing
10 changed files
with
155 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Runtime Concept | ||
|
||
## Overview | ||
|
||
One of the core concepts in JDA-Commands is the so-called `Runtime`. It will be mentioned frequently here and in the | ||
[Javadocs](https://kaktushose.github.io/jda-commands/javadocs/latest/). A `Runtime` delegates the JDA events to their | ||
corresponding `EventHandlers` and manages the used virtual threads. | ||
|
||
A new `Runtime` is created each time a: | ||
|
||
- [`SlashCommandInteractionEvent`](https://javadoc.io/doc/net.dv8tion/JDA/latest/net/dv8tion/jda/api/events/interaction/command/SlashCommandInteractionEvent.html) | ||
- [`GenericContextInteractionEvent`](https://javadoc.io/doc/net.dv8tion/JDA/latest/net/dv8tion/jda/api/events/interaction/command/GenericContextInteractionEvent.html) | ||
- [`CommandAutoCompleteInteractionEvent`](https://javadoc.io/doc/net.dv8tion/JDA/latest/net/dv8tion/jda/api/events/interaction/command/CommandAutoCompleteInteractionEvent.html) | ||
|
||
is provided by JDA or if an interaction is marked as [*independent*](#components). | ||
|
||
Runtimes are executed in parallel, but events are processed sequentially by each `Runtime`. | ||
Every `EventHandler` called by a `Runtime` is executed in its own virtual thread, isolated from the runtime one. | ||
|
||
See [`Lifetime`](#Lifetime) for | ||
details when a `Runtime` will close. | ||
|
||
## Threading Model | ||
|
||
JDA-Commands will listen for incoming events on the `JDA MainWS-ReadThread`. It will then create a new `Runtime` | ||
or use an existing one, depending on the type of event _(see the flowchart below for details)._ The incoming event is | ||
then passed to the corresponding `Runtime`. | ||
|
||
Each `Runtime` will run in its own virtual thread, called `JDAC Runtime-Thread <UUID>`. The `Runtime` will wait for new | ||
incoming events and then delegate them to the correct `EventHandler`. For instance, a | ||
[`SlashCommandInteractionEvent`](https://javadoc.io/doc/net.dv8tion/JDA/latest/net/dv8tion/jda/api/events/interaction/command/SlashCommandInteractionEvent.html) | ||
will be passed to the `SlashCommandHandler`. | ||
|
||
The `EventHandler` will _again_ run in its own virtual thread, named `JDAC EventHandler-Thread <UUID>`, isolated from | ||
the runtime one. Other incoming events are only executed when the previous one has finished. | ||
|
||
!!! tip "Blocking Methods" | ||
Because each event has its own virtual thread, you can call blocking methods like JDAs `RestAction#complete` safely | ||
without blocking the `JDA MainWS-ReadThread`. | ||
|
||
![Runtime Flowchart](../assets/runtime.png) | ||
|
||
## Lifetime | ||
|
||
By default, JDA-Commands will handle the lifetime of Runtimes for you. Every `Runtime` will be closed **15 minutes** | ||
after its creation. This time span is oriented towards the lifespan of the | ||
[`InteractionHook`](https://javadoc.io/doc/net.dv8tion/JDA/latest/net/dv8tion/jda/api/interactions/InteractionHook.html). | ||
|
||
### Explicit | ||
|
||
You can disable the default behaviour by setting the | ||
[`ExpirationStrategy`](https://kaktushose.github.io/jda-commands/javadocs/latest/jda.commands/com/github/kaktushose/jda/commands/dispatching/expiration/ExpirationStrategy.html) to | ||
[`EXPLICIT`](https://kaktushose.github.io/jda-commands/javadocs/latest/jda.commands/com/github/kaktushose/jda/commands/dispatching/expiration/ExpirationStrategy.Explicit.html). | ||
|
||
|
||
```java title="Main.java" | ||
JDACommands.builder(jda, Main.class) | ||
.expirationStrategy(ExpirationStrategy.EXPLICIT) | ||
.start(); | ||
``` | ||
|
||
This will prevent any `Runtime` from closing until [`closeRuntime`](https://kaktushose.github.io/jda-commands/javadocs/latest/jda.commands/com/github/kaktushose/jda/commands/dispatching/events/Event.html#closeRuntime()) | ||
is explicitly called. | ||
|
||
!!! example | ||
```java title="GreetCommand.java" hl_lines="4" | ||
@SlashCommand("greet") | ||
public void onCommand(CommandEvent event) { | ||
event.reply("Hello World!"); | ||
event.closeRuntime(); | ||
} | ||
``` | ||
|
||
### Inactivity | ||
You can also adjust the time frame until a `Runtime` gets closed. | ||
|
||
!!! example | ||
```java title="Main.java" hl_lines="2" | ||
JDACommands.builder(jda, Main.class) | ||
.expirationStrategy(new ExpirationStrategy.Inactivity(20))//(1)! | ||
.start(); | ||
``` | ||
|
||
1. Note: the duration is always passed as minutes. | ||
|
||
## Components and Modals | ||
|
||
### Runtime-bound | ||
|
||
By default, Buttons, SelectMenus and Modals are `runtime-bound`. This means that any incoming event will use the same | ||
`Runtime` as the interaction that replied with them. | ||
|
||
However, this also means that they cannot be executed anymore after the `Runtime` is closed. JDA-Commands will handle | ||
that case and remove the component in question. It will also send an ephemeral reply to the user, saying that the | ||
component is no longer available. | ||
|
||
|
||
### Independent | ||
|
||
!!! info | ||
Modals cannot be independent because they always need a parent interaction that triggers them! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mkdocs-material | ||
mkdocs-open-in-new-tab |