use of net.dv8tion.jda.internal.audio.ConnectionRequest in project JDA by DV8FromTheWorld.
the class WebSocketSendingThread method run.
@Override
public void run() {
// Make sure that we don't send any packets before sending auth info.
if (!client.sentAuthInfo) {
scheduleIdle();
return;
}
ConnectionRequest audioRequest = null;
DataObject chunkRequest = null;
try {
api.setContext();
attemptedToSend = false;
needRateLimit = false;
// We do this outside of the lock because otherwise we could potentially deadlock here
audioRequest = client.getNextAudioConnectRequest();
if (!queueLock.tryLock() && !queueLock.tryLock(10, TimeUnit.SECONDS)) {
scheduleNext();
return;
}
chunkRequest = chunkQueue.peek();
if (chunkRequest != null)
handleChunkSync(chunkRequest);
else if (audioRequest != null)
handleAudioRequest(audioRequest);
else
handleNormalRequest();
} catch (InterruptedException ignored) {
LOG.debug("Main WS send thread interrupted. Most likely JDA is disconnecting the websocket.");
return;
} catch (Throwable ex) {
// Log error
LOG.error("Encountered error in gateway worker", ex);
if (!attemptedToSend) {
// Try to remove the failed request
if (chunkRequest != null)
client.chunkSyncQueue.remove(chunkRequest);
else if (audioRequest != null)
client.removeAudioConnection(audioRequest.getGuildIdLong());
}
// Rethrow if error to kill thread
if (ex instanceof Error)
throw (Error) ex;
} finally {
// on any exception that might cause this lock to not release
client.maybeUnlock();
}
scheduleNext();
}
Aggregations