SessionControllerAdapter
public interface SessionController
JDA
instances.
The SessionControllerAdapter
provides
a default implementation that can be extended and overridden.
Global REST Ratelimit
The global REST ratelimit is not bound to a single session and should be
handled on all JDA instances. This controller will receive updates of this ratelimit through setGlobalRatelimit(long)
and should report the last ratelimit information it received through getGlobalRatelimit()
.
Gateway Provider
This provider can be used to change the gateway retrieval (using cache, http, or static) and
allows to set a custom gateway endpoint. Use carefully.
JDABuilder
JDABuilder builder = new JDABuilder(AccountType.BOT).setToken(BOT_TOKEN);
builder.setSessionController(new SessionControllerAdapter() {
@Override
public void appendSession(SessionConnectNode node) {
System.out.println("[SessionController] Adding SessionConnectNode to Queue!");
super.appendSession(node);
}
});
builder.addEventListener(myListener);
for (int i = 0; i < 10; i++) {
builder.useSharding(i, 10).buildAsync();
}
Using ShardManager
DefaultShardManagerBuilder builder = new DefaultShardManagerBuilder();
builder.setToken(BOT_TOKEN);
builder.setSessionController(new SessionControllerAdapter() {
@Override
public Pair<String, Integer> getGatewayBot(JDA api) {
return Pair.of(getGateway(), 10);
}
});
builder.addEventListener(myListener);
builder.build();
Modifier and Type | Interface | Description |
---|---|---|
static interface |
SessionController.SessionConnectNode |
Represents a WebSocketClient request to start a session.
|
Modifier and Type | Field | Description |
---|---|---|
static int |
IDENTIFY_DELAY |
The default delay (in seconds) to wait between running
SessionConnectNodes |
Modifier and Type | Method | Description |
---|---|---|
void |
appendSession(SessionController.SessionConnectNode node) |
Called by
WebSocketClient when
a WebSocket should be started. |
java.lang.String |
getGateway(JDA api) |
Called by
WebSocketClient
when a new session starts (Connecting, Reconnecting). |
net.dv8tion.jda.core.utils.tuple.Pair<java.lang.String,java.lang.Integer> |
getGatewayBot(JDA api) |
Called by
DefaultShardManager
when a new shards is starting. |
long |
getGlobalRatelimit() |
Provides the cross-session global REST ratelimit it received through
setGlobalRatelimit(long) . |
void |
removeSession(SessionController.SessionConnectNode node) |
Called by
WebSocketClient when
a JDA session has been shutdown. |
void |
setGlobalRatelimit(long ratelimit) |
Called by the
RateLimiter if the global rest ratelimit
has changed. |
static final int IDENTIFY_DELAY
SessionConnectNodes
void appendSession(SessionController.SessionConnectNode node)
WebSocketClient
when
a WebSocket should be started. (Connecting and Reconnecting)
IDENTIFY_DELAY
.node
- The SessionConnectNode
void removeSession(SessionController.SessionConnectNode node)
WebSocketClient
when
a JDA session has been shutdown.
SessionConnectNode.run(boolean)
will be a no-op and does not contribute to the IDENTIFY_DELAY
.node
- The SessionConnectNode
to remove from the queue.long getGlobalRatelimit()
setGlobalRatelimit(long)
.void setGlobalRatelimit(long ratelimit)
RateLimiter
if the global rest ratelimit
has changed.ratelimit
- The new global ratelimitjava.lang.String getGateway(JDA api)
WebSocketClient
when a new session starts (Connecting, Reconnecting).
api
- The current JDA instance (used for RestActions and ShardInfo)net.dv8tion.jda.core.utils.tuple.Pair<java.lang.String,java.lang.Integer> getGatewayBot(JDA api)
DefaultShardManager
when a new shards is starting.
Pair
with (gateway, shardTotal)
.api
- The current JDA instance (used for RestActions and ShardInfo)getGateway(net.dv8tion.jda.core.JDA)