/// <summary> /// Send the specified exception as an event to the active state listener. </summary> /// <param name="exception"> Exception to send </param> public virtual void dispatchException(FriendlyException exception) { TrackStateListener currentListener = activeListener; ExceptionTools.log(log, exception, track.Identifier); if (currentListener != null) { trackException = exception; currentListener.onTrackException(track, exception); } }
public void execute(TrackStateListener listener) { try { hasStarted = true; activeListener = listener; remoteNodeManager.startPlaying(this); } catch (Exception throwable) { listener.onTrackException(track, ExceptionTools.wrapUnfriendlyExceptions("An error occurred when trying to start track remotely.", FriendlyException.Severity.FAULT, throwable)); ExceptionTools.rethrowErrors(throwable); } }
private bool handleResponseBody(Discord.Audio.Streams.InputStream inputStream, TickBuilder tickBuilder) { CountingInputStream countingStream = new CountingInputStream(inputStream); DataInputStream input = new DataInputStream(countingStream); RemoteMessage message; try { while ((message = mapper.decode(input)) != null) { if (message is TrackStartResponseMessage) { handleTrackStartResponse((TrackStartResponseMessage)message); } else if (message is TrackFrameDataMessage) { handleTrackFrameData((TrackFrameDataMessage)message); } else if (message is TrackExceptionMessage) { handleTrackException((TrackExceptionMessage)message); } else if (message is NodeStatisticsMessage) { handleNodeStatistics((NodeStatisticsMessage)message); } } } catch (InterruptedException) { log.LogError("Node {} processing thread was interrupted.", nodeAddress); System.Threading.Thread.CurrentThread.Interrupt(); return(false); } catch (System.Exception e) { log.LogError("Error when processing response from node {}.", nodeAddress, e); ExceptionTools.rethrowErrors(e); } finally { tickBuilder.responseSize = countingStream.Count; } return(true); }
public void run() { if (closed || !threadRunning.compareAndSet(false, true)) { log.LogDebug("Not running node processor for {}, thread already active.", nodeAddress); return; } log.LogDebug("Trying to connect to node {}.", nodeAddress); connectionState.set(ConnectionState.PENDING.id()); try { using (HttpInterface httpInterface = httpInterfaceManager.Interface) { RingBufferMath timingAverage = new RingBufferMath(10, @in => Math.Pow(@in, 5.0), @out => Math.Pow(@out, 0.2)); while (processOneTick(httpInterface, timingAverage)) { aliveTickCounter = System.Math.Max(1, aliveTickCounter + 1); lastAliveTime = DateTimeHelperClass.CurrentUnixTimeMillis(); } } } catch (InterruptedException) { log.LogInformation("Node {} processing was stopped.", nodeAddress); System.Threading.Thread.CurrentThread.Interrupt(); } catch (IOException e) { if (aliveTickCounter > 0) { log.LogError("Node {} went offline with exception.", nodeAddress, e); } else { log.LogDebug("Retry, node {} is still offline.", nodeAddress); } } catch (System.Exception e) { log.LogError("Node {} appears offline due to unexpected exception.", nodeAddress, e); ExceptionTools.rethrowErrors(e); } finally { processHealthCheck(true); connectionState.set(ConnectionState.OFFLINE.id()); aliveTickCounter = System.Math.Min(-1, aliveTickCounter - 1); threadRunning.set(false); if (!closed) { long delay = ScheduleDelay; if (aliveTickCounter == -1) { log.LogInformation("Node {} loop ended, retry scheduled in {}.", nodeAddress, delay); } scheduledExecutor.schedule(this, delay, TimeUnit.MILLISECONDS); } else { log.LogInformation("Node {} loop ended, node was removed.", nodeAddress); } } }