Java Code Examples for javax.websocket.MessageHandler#Partial

The following examples show how to use javax.websocket.MessageHandler#Partial . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WsFrameBase.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void sendMessageBinary(ByteBuffer msg, boolean last) throws WsIOException {
    if (binaryMsgHandler instanceof WrappedMessageHandler) {
        long maxMessageSize = ((WrappedMessageHandler) binaryMsgHandler).getMaxMessageSize();
        if (maxMessageSize > -1 && msg.remaining() > maxMessageSize) {
            throw new WsIOException(new CloseReason(CloseCodes.TOO_BIG,
                    sm.getString("wsFrame.messageTooBig",
                            Long.valueOf(msg.remaining()),
                            Long.valueOf(maxMessageSize))));
        }
    }
    try {
        if (binaryMsgHandler instanceof MessageHandler.Partial<?>) {
            ((MessageHandler.Partial<ByteBuffer>) binaryMsgHandler).onMessage(msg, last);
        } else {
            // Caller ensures last == true if this branch is used
            ((MessageHandler.Whole<ByteBuffer>) binaryMsgHandler).onMessage(msg);
        }
    } catch (Throwable t) {
        handleThrowableOnSend(t);
    }
}
 
Example 2
Source File: WsFrameBase.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void sendMessageBinary(ByteBuffer msg, boolean last)
        throws WsIOException {
    if (binaryMsgHandler instanceof WrappedMessageHandler) {
        long maxMessageSize =
                ((WrappedMessageHandler) binaryMsgHandler).getMaxMessageSize();
        if (maxMessageSize > -1 && msg.remaining() > maxMessageSize) {
            throw new WsIOException(new CloseReason(CloseCodes.TOO_BIG,
                    sm.getString("wsFrame.messageTooBig",
                            Long.valueOf(msg.remaining()),
                            Long.valueOf(maxMessageSize))));
        }
    }
    try {
        if (binaryMsgHandler instanceof MessageHandler.Partial<?>) {
            ((MessageHandler.Partial<ByteBuffer>) binaryMsgHandler).onMessage(msg, last);
        } else {
            // Caller ensures last == true if this branch is used
            ((MessageHandler.Whole<ByteBuffer>) binaryMsgHandler).onMessage(msg);
        }
    } catch(Throwable t) {
        handleThrowableOnSend(t);
    }
}
 
Example 3
Source File: WsFrameBase.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void sendMessageBinary(ByteBuffer msg, boolean last)
        throws WsIOException {
    if (binaryMsgHandler instanceof WrappedMessageHandler) {
        long maxMessageSize =
                ((WrappedMessageHandler) binaryMsgHandler).getMaxMessageSize();
        if (maxMessageSize > -1 && msg.remaining() > maxMessageSize) {
            throw new WsIOException(new CloseReason(CloseCodes.TOO_BIG,
                    sm.getString("wsFrame.messageTooBig",
                            Long.valueOf(msg.remaining()),
                            Long.valueOf(maxMessageSize))));
        }
    }
    try {
        if (binaryMsgHandler instanceof MessageHandler.Partial<?>) {
            ((MessageHandler.Partial<ByteBuffer>) binaryMsgHandler).onMessage(msg, last);
        } else {
            // Caller ensures last == true if this branch is used
            ((MessageHandler.Whole<ByteBuffer>) binaryMsgHandler).onMessage(msg);
        }
    } catch(Throwable t) {
        handleThrowableOnSend(t);
    }
}
 
Example 4
Source File: WsFrameBase.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected void sendMessageText(boolean last) throws WsIOException {
    if (textMsgHandler instanceof WrappedMessageHandler) {
        long maxMessageSize = ((WrappedMessageHandler) textMsgHandler).getMaxMessageSize();
        if (maxMessageSize > -1 && messageBufferText.remaining() > maxMessageSize) {
            throw new WsIOException(new CloseReason(CloseCodes.TOO_BIG,
                    sm.getString("wsFrame.messageTooBig",
                            Long.valueOf(messageBufferText.remaining()),
                            Long.valueOf(maxMessageSize))));
        }
    }

    try {
        if (textMsgHandler instanceof MessageHandler.Partial<?>) {
            ((MessageHandler.Partial<String>) textMsgHandler)
                    .onMessage(messageBufferText.toString(), last);
        } else {
            // Caller ensures last == true if this branch is used
            ((MessageHandler.Whole<String>) textMsgHandler)
                    .onMessage(messageBufferText.toString());
        }
    } catch (Throwable t) {
        handleThrowableOnSend(t);
    } finally {
        messageBufferText.clear();
    }
}
 
Example 5
Source File: WsFrameBase.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private boolean usePartial() {
    if (Util.isControl(opCode)) {
        return false;
    } else if (textMessage) {
        return textMsgHandler instanceof MessageHandler.Partial;
    } else {
        // Must be binary
        return binaryMsgHandler instanceof MessageHandler.Partial;
    }
}
 
Example 6
Source File: WsFrameBase.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void sendMessageText(boolean last) throws WsIOException {
    if (textMsgHandler instanceof WrappedMessageHandler) {
        long maxMessageSize =
                ((WrappedMessageHandler) textMsgHandler).getMaxMessageSize();
        if (maxMessageSize > -1 &&
                messageBufferText.remaining() > maxMessageSize) {
            throw new WsIOException(new CloseReason(CloseCodes.TOO_BIG,
                    sm.getString("wsFrame.messageTooBig",
                            Long.valueOf(messageBufferText.remaining()),
                            Long.valueOf(maxMessageSize))));
        }
    }

    try {
        if (textMsgHandler instanceof MessageHandler.Partial<?>) {
            ((MessageHandler.Partial<String>) textMsgHandler).onMessage(
                    messageBufferText.toString(), last);
        } else {
            // Caller ensures last == true if this branch is used
            ((MessageHandler.Whole<String>) textMsgHandler).onMessage(
                    messageBufferText.toString());
        }
    } catch (Throwable t) {
        handleThrowableOnSend(t);
    } finally {
        messageBufferText.clear();
    }
}
 
Example 7
Source File: WsFrameBase.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private boolean usePartial() {
    if (Util.isControl(opCode)) {
        return false;
    } else if (textMessage) {
        return textMsgHandler instanceof MessageHandler.Partial<?>;
    } else {
        // Must be binary
        return binaryMsgHandler instanceof MessageHandler.Partial<?>;
    }
}
 
Example 8
Source File: WsFrameBase.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void sendMessageText(boolean last) throws WsIOException {
    if (textMsgHandler instanceof WrappedMessageHandler) {
        long maxMessageSize =
                ((WrappedMessageHandler) textMsgHandler).getMaxMessageSize();
        if (maxMessageSize > -1 &&
                messageBufferText.remaining() > maxMessageSize) {
            throw new WsIOException(new CloseReason(CloseCodes.TOO_BIG,
                    sm.getString("wsFrame.messageTooBig",
                            Long.valueOf(messageBufferText.remaining()),
                            Long.valueOf(maxMessageSize))));
        }
    }

    try {
        if (textMsgHandler instanceof MessageHandler.Partial<?>) {
            ((MessageHandler.Partial<String>) textMsgHandler).onMessage(
                    messageBufferText.toString(), last);
        } else {
            // Caller ensures last == true if this branch is used
            ((MessageHandler.Whole<String>) textMsgHandler).onMessage(
                    messageBufferText.toString());
        }
    } catch (Throwable t) {
        handleThrowableOnSend(t);
    } finally {
        messageBufferText.clear();
    }
}
 
Example 9
Source File: WsFrameBase.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private boolean usePartial() {
    if (Util.isControl(opCode)) {
        return false;
    } else if (textMessage) {
        return textMsgHandler instanceof MessageHandler.Partial<?>;
    } else {
        // Must be binary
        return binaryMsgHandler instanceof MessageHandler.Partial<?>;
    }
}
 
Example 10
Source File: UndertowSession.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@Override
public <T> void addMessageHandler(Class<T> clazz, MessageHandler.Partial<T> handler) {
    frameHandler.addHandler(clazz, handler);
}
 
Example 11
Source File: MCRWebCLIResourceSockets.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <T> void addMessageHandler(Class<T> clazz, MessageHandler.Partial<T> handler) {
    delegate.addMessageHandler(clazz, handler);
}