Search in sources :

Example 1 with SimpleBinaryMessage

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

use of org.eclipse.jetty.websocket.common.message.SimpleBinaryMessage 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)2 SimpleBinaryMessage (org.eclipse.jetty.websocket.common.message.SimpleBinaryMessage)2 MessageAppender (org.eclipse.jetty.websocket.common.message.MessageAppender)1 BinaryPartialOnMessage (org.eclipse.jetty.websocket.jsr356.messages.BinaryPartialOnMessage)1