Search in sources :

Example 1 with SimpleTextMessage

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

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

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

the class JettyListenerEventDriver method onTextFrame.

@Override
public void onTextFrame(ByteBuffer buffer, boolean fin) throws IOException {
    if (listener instanceof WebSocketListener) {
        if (activeMessage == null) {
            activeMessage = new SimpleTextMessage(this);
        }
        appendMessage(buffer, fin);
    }
    if (listener instanceof WebSocketPartialListener) {
        if (utf8Partial == null) {
            utf8Partial = new Utf8PartialBuilder();
        }
        String partial = utf8Partial.toPartialString(buffer);
        ((WebSocketPartialListener) listener).onWebSocketPartialText(partial, fin);
        if (fin) {
            partial = null;
        }
    }
}
Also used : WebSocketListener(org.eclipse.jetty.websocket.api.WebSocketListener) SimpleTextMessage(org.eclipse.jetty.websocket.common.message.SimpleTextMessage) Utf8PartialBuilder(org.eclipse.jetty.websocket.common.util.Utf8PartialBuilder) WebSocketPartialListener(org.eclipse.jetty.websocket.api.WebSocketPartialListener)

Aggregations

SimpleTextMessage (org.eclipse.jetty.websocket.common.message.SimpleTextMessage)3 MessageInputStream (org.eclipse.jetty.websocket.common.message.MessageInputStream)2 MessageReader (org.eclipse.jetty.websocket.common.message.MessageReader)2 WebSocketListener (org.eclipse.jetty.websocket.api.WebSocketListener)1 WebSocketPartialListener (org.eclipse.jetty.websocket.api.WebSocketPartialListener)1 MessageAppender (org.eclipse.jetty.websocket.common.message.MessageAppender)1 Utf8PartialBuilder (org.eclipse.jetty.websocket.common.util.Utf8PartialBuilder)1 TextPartialOnMessage (org.eclipse.jetty.websocket.jsr356.messages.TextPartialOnMessage)1