Search in sources :

Example 6 with MessageInputStream

use of org.eclipse.jetty.websocket.common.message.MessageInputStream 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

MessageInputStream (org.eclipse.jetty.websocket.common.message.MessageInputStream)6 MessageReader (org.eclipse.jetty.websocket.common.message.MessageReader)3 MessageHandler (javax.websocket.MessageHandler)2 Whole (javax.websocket.MessageHandler.Whole)2 MessageAppender (org.eclipse.jetty.websocket.common.message.MessageAppender)2 SimpleBinaryMessage (org.eclipse.jetty.websocket.common.message.SimpleBinaryMessage)2 SimpleTextMessage (org.eclipse.jetty.websocket.common.message.SimpleTextMessage)2 MessageHandlerWrapper (org.eclipse.jetty.websocket.jsr356.MessageHandlerWrapper)2 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 BinaryPartialMessage (org.eclipse.jetty.websocket.jsr356.messages.BinaryPartialMessage)1 BinaryPartialOnMessage (org.eclipse.jetty.websocket.jsr356.messages.BinaryPartialOnMessage)1 BinaryWholeMessage (org.eclipse.jetty.websocket.jsr356.messages.BinaryWholeMessage)1 TextPartialMessage (org.eclipse.jetty.websocket.jsr356.messages.TextPartialMessage)1 TextPartialOnMessage (org.eclipse.jetty.websocket.jsr356.messages.TextPartialOnMessage)1 TextWholeMessage (org.eclipse.jetty.websocket.jsr356.messages.TextWholeMessage)1