Java Code Examples for com.sedmelluq.discord.lavaplayer.tools.ExceptionTools#rethrowErrors()

The following examples show how to use com.sedmelluq.discord.lavaplayer.tools.ExceptionTools#rethrowErrors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserContextAudioPlayerManager.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
private Callable<Void> createItemLoader(final String identifier, final AudioLoadResultHandler resultHandler, boolean isPatron) {
    return () -> {
        final boolean[] reported = new boolean[1];

        try {
            if (!checkSourcesForItem(new AudioReference(identifier, null), resultHandler, reported, isPatron)) {
                log.debug("No matches for track with identifier {}.", identifier);
                resultHandler.noMatches();
            }
        } catch (Throwable throwable) {
            if (reported[0]) {
                log.warn("Load result handler for {} threw an exception", identifier, throwable);
            } else {
                dispatchItemLoadFailure(identifier, resultHandler, throwable);
            }

            ExceptionTools.rethrowErrors(throwable);
        }

        return null;
    };
}
 
Example 2
Source File: DefaultAudioPlayerManager.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
private Callable<Void> createItemLoader(final String identifier, final AudioLoadResultHandler resultHandler) {
  return () -> {
    boolean[] reported = new boolean[1];

    try {
      if (!checkSourcesForItem(new AudioReference(identifier, null), resultHandler, reported)) {
        log.debug("No matches for track with identifier {}.", identifier);
        resultHandler.noMatches();
      }
    } catch (Throwable throwable) {
      if (reported[0]) {
        log.warn("Load result handler for {} threw an exception", identifier, throwable);
      } else {
        dispatchItemLoadFailure(identifier, resultHandler, throwable);
      }

      ExceptionTools.rethrowErrors(throwable);
    }

    return null;
  };
}
 
Example 3
Source File: HttpInterface.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the given query using the client and context stored in this instance.
 *
 * @param request The request to execute.
 * @return Closeable response from the server.
 * @throws IOException On network error.
 */
public CloseableHttpResponse execute(HttpUriRequest request) throws IOException {
  boolean isRepeated = false;

  while (true) {
    filter.onRequest(context, request, isRepeated);

    try {
      CloseableHttpResponse response = client.execute(request, context);
      lastRequest = request;

      if (!filter.onRequestResponse(context, request, response)) {
        return response;
      }
    } catch (Throwable e) {
      if (!filter.onRequestException(context, request, e)) {
        if (e instanceof Error) {
          throw (Error) e;
        } else if (e instanceof RuntimeException) {
          throw (RuntimeException) e;
        } else //noinspection ConstantConditions
          if (e instanceof IOException) {
          throw (IOException) e;
        } else {
          throw new RuntimeException(e);
        }
      } else {
        ExceptionTools.rethrowErrors(e);
      }
    }

    isRepeated = true;
  }
}
 
Example 4
Source File: RemoteAudioTrackExecutor.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TrackStateListener listener) {
  try {
    hasStarted = true;
    activeListener = listener;
    remoteNodeManager.startPlaying(this);
  } catch (Throwable throwable) {
    listener.onTrackException(track, ExceptionTools.wrapUnfriendlyExceptions(
        "An error occurred when trying to start track remotely.", FriendlyException.Severity.FAULT, throwable));

    ExceptionTools.rethrowErrors(throwable);
  }
}
 
Example 5
Source File: RemoteNodeProcessor.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
private boolean handleResponseBody(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 instanceof TrackStartResponseMessage) {
        handleTrackStartResponse((TrackStartResponseMessage) message);
      } else if (message instanceof TrackFrameDataMessage) {
        handleTrackFrameData((TrackFrameDataMessage) message);
      } else if (message instanceof TrackExceptionMessage) {
        handleTrackException((TrackExceptionMessage) message);
      } else if (message instanceof NodeStatisticsMessage) {
        handleNodeStatistics((NodeStatisticsMessage) message);
      }
    }
  } catch (InterruptedException interruption) {
    log.error("Node {} processing thread was interrupted.", nodeAddress);
    Thread.currentThread().interrupt();
    return false;
  } catch (Throwable e) {
    log.error("Error when processing response from node {}.", nodeAddress, e);
    ExceptionTools.rethrowErrors(e);
  } finally {
    tickBuilder.responseSize = countingStream.getCount();
  }

  return true;
}
 
Example 6
Source File: LocalAudioTrackExecutor.java    From lavaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(TrackStateListener listener) {
  InterruptedException interrupt = null;

  if (Thread.interrupted()) {
    log.debug("Cleared a stray interrupt.");
  }

  if (playingThread.compareAndSet(null, Thread.currentThread())) {
    log.debug("Starting to play track {} locally with listener {}", audioTrack.getInfo().identifier, listener);

    state.set(AudioTrackState.LOADING);

    try {
      audioTrack.process(this);

      log.debug("Playing track {} finished or was stopped.", audioTrack.getIdentifier());
    } catch (Throwable e) {
      // Temporarily clear the interrupted status so it would not disrupt listener methods.
      interrupt = findInterrupt(e);

      if (interrupt != null && checkStopped()) {
        log.debug("Track {} was interrupted outside of execution loop.", audioTrack.getIdentifier());
      } else {
        frameBuffer.setTerminateOnEmpty();

        FriendlyException exception = ExceptionTools.wrapUnfriendlyExceptions("Something broke when playing the track.", FAULT, e);
        ExceptionTools.log(log, exception, "playback of " + audioTrack.getIdentifier());

        trackException = exception;
        listener.onTrackException(audioTrack, exception);

        ExceptionTools.rethrowErrors(e);
      }
    } finally {
      synchronized (actionSynchronizer) {
        interrupt = interrupt != null ? interrupt : findInterrupt(null);

        playingThread.compareAndSet(Thread.currentThread(), null);

        markerTracker.trigger(ENDED);
        state.set(AudioTrackState.FINISHED);
      }

      if (interrupt != null) {
        Thread.currentThread().interrupt();
      }
    }
  } else {
    log.warn("Tried to start an already playing track {}", audioTrack.getIdentifier());
  }
}