Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
                }
            }
        }