javax.websocket.MessageHandler.Whole Java Examples

The following examples show how to use javax.websocket.MessageHandler.Whole. 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: WsSession.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public <T> void addMessageHandler(Class<T> clazz, Whole<T> handler)
        throws IllegalStateException {
    doAddMessageHandler(clazz, handler);
}
 
Example #2
Source File: WsSession.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void doAddMessageHandler(Class<?> target, MessageHandler listener) {
    checkState();

    // Message handlers that require decoders may map to text messages,
    // binary messages, both or neither.

    // The frame processing code expects binary message handlers to
    // accept ByteBuffer

    // Use the POJO message handler wrappers as they are designed to wrap
    // arbitrary objects with MessageHandlers and can wrap MessageHandlers
    // just as easily.

    Set<MessageHandlerResult> mhResults = Util.getMessageHandlers(target, listener,
            endpointConfig, this);

    for (MessageHandlerResult mhResult : mhResults) {
        switch (mhResult.getType()) {
        case TEXT: {
            if (textMessageHandler != null) {
                throw new IllegalStateException(sm.getString("wsSession.duplicateHandlerText"));
            }
            textMessageHandler = mhResult.getHandler();
            break;
        }
        case BINARY: {
            if (binaryMessageHandler != null) {
                throw new IllegalStateException(
                        sm.getString("wsSession.duplicateHandlerBinary"));
            }
            binaryMessageHandler = mhResult.getHandler();
            break;
        }
        case PONG: {
            if (pongMessageHandler != null) {
                throw new IllegalStateException(sm.getString("wsSession.duplicateHandlerPong"));
            }
            MessageHandler handler = mhResult.getHandler();
            if (handler instanceof MessageHandler.Whole<?>) {
                pongMessageHandler = (MessageHandler.Whole<PongMessage>) handler;
            } else {
                throw new IllegalStateException(
                        sm.getString("wsSession.invalidHandlerTypePong"));
            }

            break;
        }
        default: {
            throw new IllegalArgumentException(
                    sm.getString("wsSession.unknownHandlerType", listener, mhResult.getType()));
        }
        }
    }
}
 
Example #3
Source File: WsSession.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
protected MessageHandler.Whole<PongMessage> getPongMessageHandler() {
    return pongMessageHandler;
}
 
Example #4
Source File: WsSession.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public <T> void addMessageHandler(Class<T> clazz, Whole<T> handler)
        throws IllegalStateException {
    doAddMessageHandler(clazz, handler);
}
 
Example #5
Source File: WsSession.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void doAddMessageHandler(Class<?> target, MessageHandler listener) {
    checkState();

    // Message handlers that require decoders may map to text messages,
    // binary messages, both or neither.

    // The frame processing code expects binary message handlers to
    // accept ByteBuffer

    // Use the POJO message handler wrappers as they are designed to wrap
    // arbitrary objects with MessageHandlers and can wrap MessageHandlers
    // just as easily.

    Set<MessageHandlerResult> mhResults =
            Util.getMessageHandlers(target, listener, endpointConfig, this);

    for (MessageHandlerResult mhResult : mhResults) {
        switch (mhResult.getType()) {
            case TEXT: {
                if (textMessageHandler != null) {
                    throw new IllegalStateException(
                            sm.getString("wsSession.duplicateHandlerText"));
                }
                textMessageHandler = mhResult.getHandler();
                break;
            }
            case BINARY: {
                if (binaryMessageHandler != null) {
                    throw new IllegalStateException(
                            sm.getString("wsSession.duplicateHandlerBinary"));
                }
                binaryMessageHandler = mhResult.getHandler();
                break;
            }
            case PONG: {
                if (pongMessageHandler != null) {
                    throw new IllegalStateException(
                            sm.getString("wsSession.duplicateHandlerPong"));
                }
                MessageHandler handler = mhResult.getHandler();
                if (handler instanceof MessageHandler.Whole<?>) {
                    pongMessageHandler =
                            (MessageHandler.Whole<PongMessage>) handler;
                } else {
                    throw new IllegalStateException(
                            sm.getString("wsSession.invalidHandlerTypePong"));
                }

                break;
            }
            default: {
                throw new IllegalArgumentException(sm.getString(
                        "wsSession.unknownHandlerType", listener,
                        mhResult.getType()));
            }
        }
    }
}
 
Example #6
Source File: WsSession.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
protected MessageHandler.Whole<PongMessage> getPongMessageHandler() {
    return pongMessageHandler;
}
 
Example #7
Source File: WsSession.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public <T> void addMessageHandler(Class<T> clazz, Whole<T> handler)
        throws IllegalStateException {
    doAddMessageHandler(clazz, handler);
}
 
Example #8
Source File: WsSession.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void doAddMessageHandler(Class<?> target, MessageHandler listener) {
    checkState();

    // Message handlers that require decoders may map to text messages,
    // binary messages, both or neither.

    // The frame processing code expects binary message handlers to
    // accept ByteBuffer

    // Use the POJO message handler wrappers as they are designed to wrap
    // arbitrary objects with MessageHandlers and can wrap MessageHandlers
    // just as easily.

    Set<MessageHandlerResult> mhResults =
            Util.getMessageHandlers(target, listener, endpointConfig, this);

    for (MessageHandlerResult mhResult : mhResults) {
        switch (mhResult.getType()) {
            case TEXT: {
                if (textMessageHandler != null) {
                    throw new IllegalStateException(
                            sm.getString("wsSession.duplicateHandlerText"));
                }
                textMessageHandler = mhResult.getHandler();
                break;
            }
            case BINARY: {
                if (binaryMessageHandler != null) {
                    throw new IllegalStateException(
                            sm.getString("wsSession.duplicateHandlerBinary"));
                }
                binaryMessageHandler = mhResult.getHandler();
                break;
            }
            case PONG: {
                if (pongMessageHandler != null) {
                    throw new IllegalStateException(
                            sm.getString("wsSession.duplicateHandlerPong"));
                }
                MessageHandler handler = mhResult.getHandler();
                if (handler instanceof MessageHandler.Whole<?>) {
                    pongMessageHandler =
                            (MessageHandler.Whole<PongMessage>) handler;
                } else {
                    throw new IllegalStateException(
                            sm.getString("wsSession.invalidHandlerTypePong"));
                }

                break;
            }
            default: {
                throw new IllegalArgumentException(sm.getString(
                        "wsSession.unknownHandlerType", listener,
                        mhResult.getType()));
            }
        }
    }
}
 
Example #9
Source File: WsSession.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
protected MessageHandler.Whole<PongMessage> getPongMessageHandler() {
    return pongMessageHandler;
}