Files
netneutrality/docs/threading.md
T
anthorob 4cf7c47645 Remove Lavaplayer and migrate to Lavalink
Replaced the bot's audio handling system by removing Lavaplayer dependencies and migrating to a Lavalink v4 node. Updated `MusicManager`, `TrackScheduler`, and related classes to utilize the `LavalinkClient`. Refactored playlist and track loading logic, task integrations, and event dispatch to integrate with the remote node. Deprecated the custom Udio source, preserving references for a future plugin port. Documented configuration and deployment details for the new audio architecture.
2026-09-23 15:08:06 -04:00

2.3 KiB

Threading & Scheduling

Package: me.bobert.netneutrality.platform.concurrency

This subsystem centralizes asynchronous execution and recurring jobs.

Classes

Class Responsibility
ThreadManager Static registry of ExecutorService instances shared across the bot.
BaseThreadFactory Custom ThreadFactory giving threads meaningful names and an uncaught-exception handler.
ScheduledTaskManager Schedules and cancels recurring scheduled tasks.

ThreadManager

  • getScheduledExecutor() — a ScheduledThreadPool sized to the number of CPU cores.
  • getExecutor(name) — returns (and caches) a named thread pool for ad-hoc async work.
  • shutdownExecutor() — shuts the executors down cleanly; called from App.shutdown().

BaseThreadFactory

Names created threads (e.g. web-api-1) so they are identifiable in logs and stack dumps, and installs an ExecutorException as the thread's UncaughtExceptionHandler so crashes on worker threads are still routed through LogHandler. It is used both by ThreadManager and by the Web API server pool.

ScheduledTaskManager

Coordinates ScheduledTask instances (discovered reflectively at startup by TaskManager.init()):

  • schedule(ScheduledTask task) — schedules the task at a fixed delay/interval derived from its TimeFrame (minutely / hourly / daily / custom), using the shared scheduled executor.
  • cancelAll() — cancels every scheduled task; called first in App.shutdown().

The existing scheduled tasks are MusicManagerCleanup, MusicPlayerAutoDisconnect (which reads the bot's gateway voice state rather than JDA's audio manager, see music.md), and TaskCleanup (see the task catalog).

Direction of travel: the scheduled-task abstraction is intended to eventually replace ad-hoc threads created via ThreadManager, giving a single, uniform way to express recurring background work. It is still evolving (see tasks.md §3.4).