当前位置: 首页>>代码示例>>Java>>正文


Java MessageHandler.Whole方法代码示例

本文整理汇总了Java中javax.websocket.MessageHandler.Whole方法的典型用法代码示例。如果您正苦于以下问题:Java MessageHandler.Whole方法的具体用法?Java MessageHandler.Whole怎么用?Java MessageHandler.Whole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.websocket.MessageHandler的用法示例。


在下文中一共展示了MessageHandler.Whole方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: WebsocketClient

import javax.websocket.MessageHandler; //导入方法依赖的package包/类
public WebsocketClient(String uri, final String sessionID, MessageHandler.Whole<String> messageHandler)
    throws IOException {

// add session ID so the request gets through LAMS security
Builder configBuilder = ClientEndpointConfig.Builder.create();
configBuilder.configurator(new Configurator() {
    @Override
    public void beforeRequest(Map<String, List<String>> headers) {
	headers.put("Cookie", Arrays.asList("JSESSIONID=" + sessionID));
    }
});
ClientEndpointConfig clientConfig = configBuilder.build();
this.websocketEndpoint = new WebsocketEndpoint(messageHandler);
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
try {
    container.connectToServer(websocketEndpoint, clientConfig, new URI(uri));
} catch (DeploymentException | URISyntaxException e) {
    throw new IOException("Error while connecting to websocket server", e);
}
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:WebsocketClient.java

示例2: onOpen

import javax.websocket.MessageHandler; //导入方法依赖的package包/类
@Override
public void onOpen(final Session session, EndpointConfig ec) {
    Log.log(Level.FINE,this, "onOpen called against room " + this.room.getRoomId());

    //send ack
    try{
        JsonObjectBuilder ack = Json.createObjectBuilder();
        JsonArrayBuilder versions = Json.createArrayBuilder();
        versions.add(1);
        ack.add("version", versions.build());
        String msg = "ack," + ack.build().toString();
        Log.log(Level.FINE, this, "ROOM(ack): sending to session {0} messsage {1}", session.getId(), msg);
        session.getBasicRemote().sendText(msg);
    }catch(IOException io){
        Log.log(Level.WARNING, this, "Error sending ack",io);
    }

    //session debug.
    debugDumpSessionInfo();

    // (lifecycle) Called when the connection is opened
    srrp.addSession(session);

    //add handler if needed, or use existing one.
    MessageHandler.Whole<String> handlerForSession = new SessionMessageHandler(session, this);
    MessageHandler.Whole<String> fromMap = handlersBySession.get(session);
    MessageHandler.Whole<String> chosen = fromMap != null ? fromMap : handlerForSession;
    handlersBySession.put(session, chosen);

    session.addMessageHandler(String.class, chosen);

    //session debug.
    Log.log(Level.FINE,this, "after opOpen room " + this.room.getRoomId());
    debugDumpSessionInfo();
}
 
开发者ID:gameontext,项目名称:gameon-room,代码行数:36,代码来源:RoomWS.java

示例3: doAddMessageHandler

import javax.websocket.MessageHandler; //导入方法依赖的package包/类
@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()));
            }
        }
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:60,代码来源:WsSession.java

示例4: getPongMessageHandler

import javax.websocket.MessageHandler; //导入方法依赖的package包/类
protected MessageHandler.Whole<PongMessage> getPongMessageHandler() {
    return pongMessageHandler;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:4,代码来源:WsSession.java

示例5: processDataControl

import javax.websocket.MessageHandler; //导入方法依赖的package包/类
private boolean processDataControl() throws IOException {
    TransformationResult tr = transformation.getMoreData(opCode, fin, rsv, controlBufferBinary);
    if (TransformationResult.UNDERFLOW.equals(tr)) {
        return false;
    }
    // Control messages have fixed message size so
    // TransformationResult.OVERFLOW is not possible here

    controlBufferBinary.flip();
    if (opCode == Constants.OPCODE_CLOSE) {
        open = false;
        String reason = null;
        int code = CloseCodes.NORMAL_CLOSURE.getCode();
        if (controlBufferBinary.remaining() == 1) {
            controlBufferBinary.clear();
            // Payload must be zero or greater than 2
            throw new WsIOException(new CloseReason(
                    CloseCodes.PROTOCOL_ERROR,
                    sm.getString("wsFrame.oneByteCloseCode")));
        }
        if (controlBufferBinary.remaining() > 1) {
            code = controlBufferBinary.getShort();
            if (controlBufferBinary.remaining() > 0) {
                CoderResult cr = utf8DecoderControl.decode(
                        controlBufferBinary, controlBufferText, true);
                if (cr.isError()) {
                    controlBufferBinary.clear();
                    controlBufferText.clear();
                    throw new WsIOException(new CloseReason(
                            CloseCodes.PROTOCOL_ERROR,
                            sm.getString("wsFrame.invalidUtf8Close")));
                }
                // There will be no overflow as the output buffer is big
                // enough. There will be no underflow as all the data is
                // passed to the decoder in a single call.
                controlBufferText.flip();
                reason = controlBufferText.toString();
            }
        }
        wsSession.onClose(new CloseReason(Util.getCloseCode(code), reason));
    } else if (opCode == Constants.OPCODE_PING) {
        if (wsSession.isOpen()) {
            wsSession.getBasicRemote().sendPong(controlBufferBinary);
        }
    } else if (opCode == Constants.OPCODE_PONG) {
        MessageHandler.Whole<PongMessage> mhPong =
                wsSession.getPongMessageHandler();
        if (mhPong != null) {
            try {
                mhPong.onMessage(new WsPongMessage(controlBufferBinary));
            } catch (Throwable t) {
                handleThrowableOnSend(t);
            } finally {
                controlBufferBinary.clear();
            }
        }
    } else {
        // Should have caught this earlier but just in case...
        controlBufferBinary.clear();
        throw new WsIOException(new CloseReason(
                CloseCodes.PROTOCOL_ERROR,
                sm.getString("wsFrame.invalidOpCode",
                        Integer.valueOf(opCode))));
    }
    controlBufferBinary.clear();
    newFrame();
    return true;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:69,代码来源:WsFrameBase.java

示例6: WebsocketEndpoint

import javax.websocket.MessageHandler; //导入方法依赖的package包/类
WebsocketEndpoint(MessageHandler.Whole<String> messageHandler) {
this.messageHandler = messageHandler;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:4,代码来源:WebsocketClient.java

示例7: doAddMessageHandler

import javax.websocket.MessageHandler; //导入方法依赖的package包/类
@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()));
		}
		}
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:53,代码来源:WsSession.java

示例8: getPongMessageHandler

import javax.websocket.MessageHandler; //导入方法依赖的package包/类
protected MessageHandler.Whole<PongMessage> getPongMessageHandler() {
	return pongMessageHandler;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:4,代码来源:WsSession.java

示例9: processDataControl

import javax.websocket.MessageHandler; //导入方法依赖的package包/类
private boolean processDataControl() throws IOException {
	TransformationResult tr = transformation.getMoreData(opCode, fin, rsv, controlBufferBinary);
	if (TransformationResult.UNDERFLOW.equals(tr)) {
		return false;
	}
	// Control messages have fixed message size so
	// TransformationResult.OVERFLOW is not possible here

	controlBufferBinary.flip();
	if (opCode == Constants.OPCODE_CLOSE) {
		open = false;
		String reason = null;
		int code = CloseCodes.NORMAL_CLOSURE.getCode();
		if (controlBufferBinary.remaining() == 1) {
			controlBufferBinary.clear();
			// Payload must be zero or greater than 2
			throw new WsIOException(
					new CloseReason(CloseCodes.PROTOCOL_ERROR, sm.getString("wsFrame.oneByteCloseCode")));
		}
		if (controlBufferBinary.remaining() > 1) {
			code = controlBufferBinary.getShort();
			if (controlBufferBinary.remaining() > 0) {
				CoderResult cr = utf8DecoderControl.decode(controlBufferBinary, controlBufferText, true);
				if (cr.isError()) {
					controlBufferBinary.clear();
					controlBufferText.clear();
					throw new WsIOException(
							new CloseReason(CloseCodes.PROTOCOL_ERROR, sm.getString("wsFrame.invalidUtf8Close")));
				}
				// There will be no overflow as the output buffer is big
				// enough. There will be no underflow as all the data is
				// passed to the decoder in a single call.
				controlBufferText.flip();
				reason = controlBufferText.toString();
			}
		}
		wsSession.onClose(new CloseReason(Util.getCloseCode(code), reason));
	} else if (opCode == Constants.OPCODE_PING) {
		if (wsSession.isOpen()) {
			wsSession.getBasicRemote().sendPong(controlBufferBinary);
		}
	} else if (opCode == Constants.OPCODE_PONG) {
		MessageHandler.Whole<PongMessage> mhPong = wsSession.getPongMessageHandler();
		if (mhPong != null) {
			try {
				mhPong.onMessage(new WsPongMessage(controlBufferBinary));
			} catch (Throwable t) {
				handleThrowableOnSend(t);
			} finally {
				controlBufferBinary.clear();
			}
		}
	} else {
		// Should have caught this earlier but just in case...
		controlBufferBinary.clear();
		throw new WsIOException(new CloseReason(CloseCodes.PROTOCOL_ERROR,
				sm.getString("wsFrame.invalidOpCode", Integer.valueOf(opCode))));
	}
	controlBufferBinary.clear();
	newFrame();
	return true;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:63,代码来源:WsFrameBase.java

示例10: addMessageHandler

import javax.websocket.MessageHandler; //导入方法依赖的package包/类
@Override
public <T> void addMessageHandler(Class<T> clazz, MessageHandler.Whole<T> handler) {
    throw new UnsupportedOperationException("Method is not supported");
}
 
开发者ID:wso2,项目名称:carbon-transports,代码行数:5,代码来源:WebSocketSessionAdapter.java

示例11: addMessageHandler

import javax.websocket.MessageHandler; //导入方法依赖的package包/类
public void addMessageHandler(MessageHandler.Whole<String> handler) {
    this.session.addMessageHandler(handler);
}
 
开发者ID:dejanpaler,项目名称:edit-2015,代码行数:4,代码来源:BrickClient.java

示例12: addMessageHandler

import javax.websocket.MessageHandler; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void addMessageHandler(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(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()));
            }
        }
    }
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:62,代码来源:WsSession.java

示例13: processDataControl

import javax.websocket.MessageHandler; //导入方法依赖的package包/类
private boolean processDataControl() throws IOException {
    if (!appendPayloadToMessage(controlBufferBinary)) {
        return false;
    }
    controlBufferBinary.flip();
    if (opCode == Constants.OPCODE_CLOSE) {
        open = false;
        String reason = null;
        int code = CloseCodes.NORMAL_CLOSURE.getCode();
        if (controlBufferBinary.remaining() == 1) {
            controlBufferBinary.clear();
            // Payload must be zero or greater than 2
            throw new WsIOException(new CloseReason(
                    CloseCodes.PROTOCOL_ERROR,
                    sm.getString("wsFrame.oneByteCloseCode")));
        }
        if (controlBufferBinary.remaining() > 1) {
            code = controlBufferBinary.getShort();
            if (controlBufferBinary.remaining() > 0) {
                CoderResult cr = utf8DecoderControl.decode(
                        controlBufferBinary, controlBufferText, true);
                if (cr.isError()) {
                    controlBufferBinary.clear();
                    controlBufferText.clear();
                    throw new WsIOException(new CloseReason(
                            CloseCodes.PROTOCOL_ERROR,
                            sm.getString("wsFrame.invalidUtf8Close")));
                }
                // There will be no overflow as the output buffer is big
                // enough. There will be no underflow as all the data is
                // passed to the decoder in a single call.
                controlBufferText.flip();
                reason = controlBufferText.toString();
            }
        }
        wsSession.onClose(new CloseReason(Util.getCloseCode(code), reason));
    } else if (opCode == Constants.OPCODE_PING) {
        if (wsSession.isOpen()) {
            wsSession.getBasicRemote().sendPong(controlBufferBinary);
        }
    } else if (opCode == Constants.OPCODE_PONG) {
        MessageHandler.Whole<PongMessage> mhPong =
                wsSession.getPongMessageHandler();
        if (mhPong != null) {
            try {
                mhPong.onMessage(new WsPongMessage(controlBufferBinary));
            } catch (Throwable t) {
                handleThrowableOnSend(t);
            } finally {
                controlBufferBinary.clear();
            }
        }
    } else {
        // Should have caught this earlier but just in case...
        controlBufferBinary.clear();
        throw new WsIOException(new CloseReason(
                CloseCodes.PROTOCOL_ERROR,
                sm.getString("wsFrame.invalidOpCode",
                        Integer.valueOf(opCode))));
    }
    controlBufferBinary.clear();
    newFrame();
    return true;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:65,代码来源:WsFrameBase.java

示例14: createTextHandler

import javax.websocket.MessageHandler; //导入方法依赖的package包/类
static public MessageHandler.Whole<String> createTextHandler(final MessageHandler.Whole proxy) {
    return new MessageHandler.Whole<String>() {
        public void onMessage(String msg) {
            proxy.onMessage(msg);
        }};
}
 
开发者ID:projectodd,项目名称:wunderboss,代码行数:7,代码来源:WebsocketUtil.java

示例15: createBinaryHandler

import javax.websocket.MessageHandler; //导入方法依赖的package包/类
static public MessageHandler.Whole<byte[]> createBinaryHandler(final MessageHandler.Whole proxy) {
    return new MessageHandler.Whole<byte[]>() {
        public void onMessage(byte[] msg) {
            proxy.onMessage(msg);
        }};
}
 
开发者ID:projectodd,项目名称:wunderboss,代码行数:7,代码来源:WebsocketUtil.java


注:本文中的javax.websocket.MessageHandler.Whole方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。