Search in sources :

Example 1 with MessageInputStream

use of org.eclipse.jetty.websocket.common.message.MessageInputStream in project jetty.project by eclipse.

the class JsrAnnotatedEventDriver method onBinaryFrame.

/**
     * Entry point for all incoming binary frames.
     */
@Override
public void onBinaryFrame(ByteBuffer buffer, boolean fin) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("onBinaryFrame({}, {})", BufferUtil.toDetailString(buffer), fin);
        LOG.debug("events.onBinary={}", events.hasBinary());
        LOG.debug("events.onBinaryStream={}", events.hasBinaryStream());
    }
    boolean handled = false;
    if (events.hasBinary()) {
        handled = true;
        if (activeMessage == null) {
            if (events.isBinaryPartialSupported()) {
                // Partial Message Support (does not use messageAppender)
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Partial Binary Message: fin={}", fin);
                }
                activeMessage = new BinaryPartialOnMessage(this);
            } else {
                // Whole Message Support
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Whole Binary Message");
                }
                activeMessage = new SimpleBinaryMessage(this);
            }
        }
    }
    if (events.hasBinaryStream()) {
        handled = true;
        // Streaming Message Support
        if (activeMessage == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Binary Message InputStream");
            }
            final MessageInputStream stream = new MessageInputStream();
            activeMessage = stream;
            // Always dispatch streaming read to another thread.
            dispatch(new Runnable() {

                @Override
                public void run() {
                    try {
                        events.callBinaryStream(jsrsession.getAsyncRemote(), websocket, stream);
                    } catch (Throwable e) {
                        onFatalError(e);
                    }
                }
            });
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("handled = {}", handled);
    }
    // Process any active MessageAppender
    if (handled && (activeMessage != null)) {
        appendMessage(buffer, fin);
    }
}
Also used : MessageInputStream(org.eclipse.jetty.websocket.common.message.MessageInputStream) SimpleBinaryMessage(org.eclipse.jetty.websocket.common.message.SimpleBinaryMessage) BinaryPartialOnMessage(org.eclipse.jetty.websocket.jsr356.messages.BinaryPartialOnMessage)

Example 2 with MessageInputStream

use of org.eclipse.jetty.websocket.common.message.MessageInputStream in project jetty.project by eclipse.

the class JsrAnnotatedEventDriver method onTextFrame.

/**
     * Entry point for all incoming text frames.
     */
@Override
public void onTextFrame(ByteBuffer buffer, boolean fin) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("onTextFrame({}, {})", BufferUtil.toDetailString(buffer), fin);
        LOG.debug("events.hasText={}", events.hasText());
        LOG.debug("events.hasTextStream={}", events.hasTextStream());
    }
    boolean handled = false;
    if (events.hasText()) {
        handled = true;
        if (activeMessage == null) {
            if (events.isTextPartialSupported()) {
                // Partial Message Support
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Partial Text Message: fin={}", fin);
                }
                activeMessage = new TextPartialOnMessage(this);
            } else {
                // Whole Message Support
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Whole Text Message");
                }
                activeMessage = new SimpleTextMessage(this);
            }
        }
    }
    if (events.hasTextStream()) {
        handled = true;
        // Streaming Message Support
        if (activeMessage == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Text Message Writer");
            }
            final MessageReader stream = new MessageReader(new MessageInputStream());
            activeMessage = stream;
            // Always dispatch streaming read to another thread.
            dispatch(new Runnable() {

                @Override
                public void run() {
                    try {
                        events.callTextStream(jsrsession.getAsyncRemote(), websocket, stream);
                    } catch (Throwable e) {
                        onFatalError(e);
                    }
                }
            });
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("handled = {}", handled);
    }
    // Process any active MessageAppender
    if (handled && (activeMessage != null)) {
        appendMessage(buffer, fin);
    }
}
Also used : MessageInputStream(org.eclipse.jetty.websocket.common.message.MessageInputStream) SimpleTextMessage(org.eclipse.jetty.websocket.common.message.SimpleTextMessage) TextPartialOnMessage(org.eclipse.jetty.websocket.jsr356.messages.TextPartialOnMessage) MessageReader(org.eclipse.jetty.websocket.common.message.MessageReader)

Example 3 with MessageInputStream

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

use of org.eclipse.jetty.websocket.common.message.MessageInputStream in project jetty.project by eclipse.

the class JettyAnnotatedEventDriver method onTextFrame.

@Override
public void onTextFrame(ByteBuffer buffer, boolean fin) throws IOException {
    if (events.onText == null) {
        // not interested in text events
        return;
    }
    if (activeMessage == null) {
        if (events.onText.isStreaming()) {
            activeMessage = new MessageReader(new MessageInputStream());
            final MessageAppender msg = activeMessage;
            dispatch(new Runnable() {

                @Override
                public void run() {
                    try {
                        events.onText.call(websocket, session, msg);
                    } catch (Throwable t) {
                        // dispatched calls need to be reported
                        onError(t);
                    }
                }
            });
        } else {
            activeMessage = new SimpleTextMessage(this);
        }
    }
    appendMessage(buffer, fin);
}
Also used : MessageInputStream(org.eclipse.jetty.websocket.common.message.MessageInputStream) SimpleTextMessage(org.eclipse.jetty.websocket.common.message.SimpleTextMessage) MessageReader(org.eclipse.jetty.websocket.common.message.MessageReader) MessageAppender(org.eclipse.jetty.websocket.common.message.MessageAppender)

Example 5 with MessageInputStream

use of org.eclipse.jetty.websocket.common.message.MessageInputStream in project jetty.project by eclipse.

the class JettyAnnotatedEventDriver method onBinaryFrame.

@Override
public void onBinaryFrame(ByteBuffer buffer, boolean fin) throws IOException {
    if (events.onBinary == null) {
        // not interested in binary events
        return;
    }
    if (activeMessage == null) {
        if (events.onBinary.isStreaming()) {
            activeMessage = new MessageInputStream();
            final MessageAppender msg = activeMessage;
            dispatch(new Runnable() {

                @Override
                public void run() {
                    try {
                        events.onBinary.call(websocket, session, msg);
                    } catch (Throwable t) {
                        // dispatched calls need to be reported
                        onError(t);
                    }
                }
            });
        } else {
            activeMessage = new SimpleBinaryMessage(this);
        }
    }
    appendMessage(buffer, fin);
}
Also used : MessageInputStream(org.eclipse.jetty.websocket.common.message.MessageInputStream) SimpleBinaryMessage(org.eclipse.jetty.websocket.common.message.SimpleBinaryMessage) MessageAppender(org.eclipse.jetty.websocket.common.message.MessageAppender)

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