Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor: improve variable naming and log message
  • Loading branch information
christolis committed Oct 29, 2024
commit 0287536f19bbf2bcb63b76df5c2872cfe54f69d1
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public class DynamicVoiceListener extends VoiceReceiverAdapter {
private final Map<String, AtomicBoolean> activeQueuesMap = new HashMap<>();

/** Boolean to track if events from all queues should be handled at a slower rate. */
private final AtomicBoolean slowmode = new AtomicBoolean(false);
private final AtomicBoolean voiceActivityCongestion = new AtomicBoolean(false);
private final Executor eventQueueExecutor =
CompletableFuture.delayedExecutor(1L, TimeUnit.SECONDS);
private static final int SLOWMODE_THRESHOLD = 5;
private static final int CONGESTION_THRESHOLD = 5;

/**
* Initializes a new {@link DynamicVoiceListener} with the specified configuration.
Expand Down Expand Up @@ -97,14 +97,18 @@ private void insertEventToQueue(GuildVoiceUpdateEvent event, String channelTopic
}

eventQueue.add(event);
slowmode.set(eventQueue.size() >= SLOWMODE_THRESHOLD);
voiceActivityCongestion.set(eventQueue.size() >= CONGESTION_THRESHOLD);

if (activeQueuesMap.get(channelTopic).get()) {
return;
}

if (slowmode.get()) {
logger.info("Running with slowmode");
if (voiceActivityCongestion.get()) {
final String logMessage = String.format(
"Congestion detected in the event queue of voice channel '%s', responding to event %s asynchronously.",
channelTopic, event);

logger.info(logMessage);
CompletableFuture.runAsync(() -> processEventFromQueue(channelTopic),
eventQueueExecutor);
return;
Expand Down
Loading