Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A616567126 GPT WEB JAVA DiscordInstanceImpl

From Leeroopedia
Knowledge Sources
Domains Distributed_Systems, Task_Queueing, Concurrency
Last Updated 2026-10-13 00:00 GMT

Overview

Concrete tool for managing a single Discord account's task queue with a dedicated thread pool, WSS connection, and Discord API service, provided by the Spring framework.

Description

The DiscordInstanceImpl class implements the DiscordInstance interface and represents one Discord account. Each instance has:

  • A ThreadPoolTaskExecutor with configurable core/max pool size and queue capacity
  • A UserWebSocketStarter for Discord WSS connection
  • A DiscordServiceImpl for Discord REST API calls
  • A CopyOnWriteArrayList of running tasks and a synchronized Future map

The submitTask(task, discordSubmit) method saves the task to the store, submits it to the thread pool, and returns immediately. The thread pool executes executeTask(), which calls the Discord API, waits for status updates, and notifies on each change.

Usage

Import this class when you need to:

  • Submit tasks to a specific Discord account's execution queue
  • Understand per-account thread pool configuration
  • Handle task lifecycle (submit, execute, exit, saveAndNotify)

Code Reference

Source Location

  • Repository: GPT-WEB-JAVA
  • File: src/main/java/com/intelligent/bot/api/midjourney/loadbalancer/DiscordInstanceImpl.java

Signature

public class DiscordInstanceImpl implements DiscordInstance {
    public DiscordInstanceImpl(DiscordAccount account, UserWebSocketStarter socketStarter,
                                RestTemplate restTemplate, TaskStoreService taskStoreService,
                                NotifyService notifyService, Map<String, String> paramsMap);

    public synchronized B<Void> submitTask(Task task, Callable<B<Void>> discordSubmit);
    public void exitTask(Task task);
    public B<Void> imagine(String prompt, String nonce);
    public B<Void> upscale(String messageId, int index, String messageHash, int messageFlags, String nonce);
    public B<Void> variation(String messageId, int index, String messageHash, int messageFlags, String nonce);
    public B<Void> describe(String finalFileName, String nonce);
    public B<Void> blend(List<String> finalFileNames, BlendDimensions dimensions, String nonce);
    public B<String> upload(String fileName, DataUrl dataUrl);
}

Import

import com.intelligent.bot.api.midjourney.loadbalancer.DiscordInstanceImpl;

I/O Contract

Inputs

Name Type Required Description
task Task Yes Task entity with ID, prompt, nonce
discordSubmit Callable<B<Void>> Yes Lambda that calls the Discord API

Outputs

Name Type Description
submitTask returns B<Void> Success, or "排队中,前面还有N个任务" if queued

Usage Examples

Submitting an Imagine Task

instance.submitTask(task, () -> {
    return instance.imagine(task.getPromptEn(), task.getNonce());
});
// Task saved to store, submitted to thread pool
// executeTask calls imagine(), waits for WSS response

Task Rejection

// If queue is full, RejectedExecutionException is caught:
// taskStoreService.delete(task.getId());
// return B.finalBuild("队列已满,请稍后尝试");

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment