Search in sources :

Example 1 with BinaryPartialMessage

use of org.eclipse.jetty.websocket.jsr356.messages.BinaryPartialMessage in project jetty.project by eclipse.

the class JsrEndpointEventDriver method onBinaryFrame.

@Override
public void onBinaryFrame(ByteBuffer buffer, boolean fin) throws IOException {
    if (activeMessage == null) {
        final MessageHandlerWrapper wrapper = jsrsession.getMessageHandlerWrapper(MessageType.BINARY);
        if (wrapper == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("No BINARY MessageHandler declared");
            }
            return;
        }
        if (wrapper.wantsPartialMessages()) {
            activeMessage = new BinaryPartialMessage(wrapper);
        } else if (wrapper.wantsStreams()) {
            final MessageInputStream stream = new MessageInputStream();
            activeMessage = stream;
            dispatch(new Runnable() {

                @SuppressWarnings("unchecked")
                @Override
                public void run() {
                    MessageHandler.Whole<InputStream> handler = (Whole<InputStream>) wrapper.getHandler();
                    handler.onMessage(stream);
                }
            });
        } else {
            activeMessage = new BinaryWholeMessage(this, wrapper);
        }
    }
    activeMessage.appendFrame(buffer, fin);
    if (fin) {
        activeMessage.messageComplete();
        activeMessage = null;
    }
}
Also used : MessageHandlerWrapper(org.eclipse.jetty.websocket.jsr356.MessageHandlerWrapper) BinaryWholeMessage(org.eclipse.jetty.websocket.jsr356.messages.BinaryWholeMessage) MessageInputStream(org.eclipse.jetty.websocket.common.message.MessageInputStream) MessageHandler(javax.websocket.MessageHandler) BinaryPartialMessage(org.eclipse.jetty.websocket.jsr356.messages.BinaryPartialMessage) MessageInputStream(org.eclipse.jetty.websocket.common.message.MessageInputStream) InputStream(java.io.InputStream) Whole(javax.websocket.MessageHandler.Whole)

Aggregations

InputStream (java.io.InputStream)1 MessageHandler (javax.websocket.MessageHandler)1 Whole (javax.websocket.MessageHandler.Whole)1 MessageInputStream (org.eclipse.jetty.websocket.common.message.MessageInputStream)1 MessageHandlerWrapper (org.eclipse.jetty.websocket.jsr356.MessageHandlerWrapper)1 BinaryPartialMessage (org.eclipse.jetty.websocket.jsr356.messages.BinaryPartialMessage)1 BinaryWholeMessage (org.eclipse.jetty.websocket.jsr356.messages.BinaryWholeMessage)1