當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。