Search in sources :

Example 1 with RemoteMessage

use of com.sedmelluq.discord.lavaplayer.remote.message.RemoteMessage in project lavaplayer by sedmelluq.

the class NodeController method handeTick.

@RequestMapping("/tick")
public void handeTick(HttpServletRequest request, HttpServletResponse response) throws IOException {
    DataInputStream input = new DataInputStream(request.getInputStream());
    DataOutputStream output = new DataOutputStream(response.getOutputStream());
    MessageOutput messageOutput = new MessageOutput(mapper, output);
    RemoteMessage message;
    while ((message = mapper.decode(input)) != null) {
        messageHandlerRegistry.processMessage(message, messageOutput);
    }
    messageOutput.send(statisticsManager.getStatistics());
    mapper.endOutput(output);
}
Also used : RemoteMessage(com.sedmelluq.discord.lavaplayer.remote.message.RemoteMessage) MessageOutput(com.sedmelluq.discord.lavaplayer.node.message.MessageOutput) DataOutputStream(java.io.DataOutputStream) DataInputStream(java.io.DataInputStream) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with RemoteMessage

use of com.sedmelluq.discord.lavaplayer.remote.message.RemoteMessage in project lavaplayer by sedmelluq.

the class RemoteNodeProcessor method handleResponseBody.

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;
}
Also used : RemoteMessage(com.sedmelluq.discord.lavaplayer.remote.message.RemoteMessage) TrackExceptionMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackExceptionMessage) TrackStartResponseMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackStartResponseMessage) CountingInputStream(org.apache.commons.io.input.CountingInputStream) DataInputStream(java.io.DataInputStream) TrackFrameDataMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameDataMessage) NodeStatisticsMessage(com.sedmelluq.discord.lavaplayer.remote.message.NodeStatisticsMessage)

Example 3 with RemoteMessage

use of com.sedmelluq.discord.lavaplayer.remote.message.RemoteMessage in project lavaplayer by sedmelluq.

the class RemoteNodeProcessor method buildRequestBody.

private byte[] buildRequestBody() throws IOException {
    ByteArrayOutputStream outputBytes = new ByteArrayOutputStream();
    DataOutputStream output = new DataOutputStream(outputBytes);
    List<RemoteMessage> messages = new ArrayList<>();
    int queuedCount = queuedMessages.drainTo(messages);
    if (queuedCount > 0) {
        log.debug("Including {} queued messages in the request to {}.", queuedCount, nodeAddress);
    }
    for (RemoteAudioTrackExecutor executor : playingTracks.values()) {
        long pendingSeek = executor.getPendingSeek();
        AudioFrameBuffer buffer = executor.getAudioBuffer();
        int neededFrames = pendingSeek == -1 ? buffer.getRemainingCapacity() : buffer.getFullCapacity();
        messages.add(new TrackFrameRequestMessage(executor.getExecutorId(), neededFrames, executor.getVolume(), pendingSeek));
    }
    for (RemoteMessage message : messages) {
        mapper.encode(output, message);
    }
    mapper.endOutput(output);
    return outputBytes.toByteArray();
}
Also used : RemoteMessage(com.sedmelluq.discord.lavaplayer.remote.message.RemoteMessage) DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TrackFrameRequestMessage(com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameRequestMessage) AudioFrameBuffer(com.sedmelluq.discord.lavaplayer.track.playback.AudioFrameBuffer)

Aggregations

RemoteMessage (com.sedmelluq.discord.lavaplayer.remote.message.RemoteMessage)3 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 MessageOutput (com.sedmelluq.discord.lavaplayer.node.message.MessageOutput)1 NodeStatisticsMessage (com.sedmelluq.discord.lavaplayer.remote.message.NodeStatisticsMessage)1 TrackExceptionMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackExceptionMessage)1 TrackFrameDataMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameDataMessage)1 TrackFrameRequestMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackFrameRequestMessage)1 TrackStartResponseMessage (com.sedmelluq.discord.lavaplayer.remote.message.TrackStartResponseMessage)1 AudioFrameBuffer (com.sedmelluq.discord.lavaplayer.track.playback.AudioFrameBuffer)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 CountingInputStream (org.apache.commons.io.input.CountingInputStream)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1