Search in sources :

Example 1 with Whole

use of javax.websocket.MessageHandler.Whole in project jetty.project by eclipse.

the class JsrEndpointEventDriver method onTextFrame.

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

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

Example 2 with Whole

use of javax.websocket.MessageHandler.Whole 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)

Example 3 with Whole

use of javax.websocket.MessageHandler.Whole in project jetty.project by eclipse.

the class JsrEndpointEventDriver method onPongMessage.

private void onPongMessage(ByteBuffer buffer) {
    final MessageHandlerWrapper wrapper = jsrsession.getMessageHandlerWrapper(MessageType.PONG);
    if (wrapper == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("No PONG MessageHandler declared");
        }
        return;
    }
    ByteBuffer pongBuf = null;
    if (BufferUtil.isEmpty(buffer)) {
        pongBuf = BufferUtil.EMPTY_BUFFER;
    } else {
        pongBuf = ByteBuffer.allocate(buffer.remaining());
        BufferUtil.put(buffer, pongBuf);
        BufferUtil.flipToFlush(pongBuf, 0);
    }
    @SuppressWarnings("unchecked") Whole<PongMessage> pongHandler = (Whole<PongMessage>) wrapper.getHandler();
    pongHandler.onMessage(new JsrPongMessage(pongBuf));
}
Also used : MessageHandlerWrapper(org.eclipse.jetty.websocket.jsr356.MessageHandlerWrapper) PongMessage(javax.websocket.PongMessage) JsrPongMessage(org.eclipse.jetty.websocket.jsr356.JsrPongMessage) ByteBuffer(java.nio.ByteBuffer) Whole(javax.websocket.MessageHandler.Whole) JsrPongMessage(org.eclipse.jetty.websocket.jsr356.JsrPongMessage)

Aggregations

Whole (javax.websocket.MessageHandler.Whole)3 MessageHandlerWrapper (org.eclipse.jetty.websocket.jsr356.MessageHandlerWrapper)3 MessageHandler (javax.websocket.MessageHandler)2 MessageInputStream (org.eclipse.jetty.websocket.common.message.MessageInputStream)2 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 ByteBuffer (java.nio.ByteBuffer)1 PongMessage (javax.websocket.PongMessage)1 MessageReader (org.eclipse.jetty.websocket.common.message.MessageReader)1 JsrPongMessage (org.eclipse.jetty.websocket.jsr356.JsrPongMessage)1 BinaryPartialMessage (org.eclipse.jetty.websocket.jsr356.messages.BinaryPartialMessage)1 BinaryWholeMessage (org.eclipse.jetty.websocket.jsr356.messages.BinaryWholeMessage)1 TextPartialMessage (org.eclipse.jetty.websocket.jsr356.messages.TextPartialMessage)1 TextWholeMessage (org.eclipse.jetty.websocket.jsr356.messages.TextWholeMessage)1