org.springframework.web.socket.PongMessage Java Examples

The following examples show how to use org.springframework.web.socket.PongMessage. 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: AbstractWebSocketSession.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public final void sendMessage(WebSocketMessage<?> message) throws IOException {

	checkNativeSessionInitialized();
	Assert.isTrue(isOpen(), "Cannot send message after connection closed.");

	if (logger.isTraceEnabled()) {
		logger.trace("Sending " + message + ", " + this);
	}

	if (message instanceof TextMessage) {
		sendTextMessage((TextMessage) message);
	}
	else if (message instanceof BinaryMessage) {
		sendBinaryMessage((BinaryMessage) message);
	}
	else if (message instanceof PingMessage) {
		sendPingMessage((PingMessage) message);
	}
	else if (message instanceof PongMessage) {
		sendPongMessage((PongMessage) message);
	}
	else {
		throw new IllegalStateException("Unexpected WebSocketMessage type: " + message);
	}
}
 
Example #2
Source File: AbstractWebSocketSession.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public final void sendMessage(WebSocketMessage<?> message) throws IOException {
	checkNativeSessionInitialized();

	if (logger.isTraceEnabled()) {
		logger.trace("Sending " + message + ", " + this);
	}

	if (message instanceof TextMessage) {
		sendTextMessage((TextMessage) message);
	}
	else if (message instanceof BinaryMessage) {
		sendBinaryMessage((BinaryMessage) message);
	}
	else if (message instanceof PingMessage) {
		sendPingMessage((PingMessage) message);
	}
	else if (message instanceof PongMessage) {
		sendPongMessage((PongMessage) message);
	}
	else {
		throw new IllegalStateException("Unexpected WebSocketMessage type: " + message);
	}
}
 
Example #3
Source File: AbstractWebSocketHandler.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
	if (message instanceof TextMessage) {
		handleTextMessage(session, (TextMessage) message);
	}
	else if (message instanceof BinaryMessage) {
		handleBinaryMessage(session, (BinaryMessage) message);
	}
	else if (message instanceof PongMessage) {
		handlePongMessage(session, (PongMessage) message);
	}
	else {
		throw new IllegalStateException("Unexpected WebSocket message type: " + message);
	}
}
 
Example #4
Source File: JettyWebSocketHandlerAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@OnWebSocketFrame
public void onWebSocketFrame(Frame frame) {
	if (OpCode.PONG == frame.getOpCode()) {
		ByteBuffer payload = frame.getPayload() != null ? frame.getPayload() : EMPTY_PAYLOAD;
		PongMessage message = new PongMessage(payload);
		try {
			this.webSocketHandler.handleMessage(this.wsSession, message);
		}
		catch (Throwable ex) {
			ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
		}
	}
}
 
Example #5
Source File: StandardWebSocketHandlerAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void handlePongMessage(javax.websocket.Session session, ByteBuffer payload) {
	PongMessage pongMessage = new PongMessage(payload);
	try {
		this.handler.handleMessage(this.wsSession, pongMessage);
	}
	catch (Throwable ex) {
		ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
	}
}
 
Example #6
Source File: AbstractWebSocketHandler.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
	if (message instanceof TextMessage) {
		handleTextMessage(session, (TextMessage) message);
	}
	else if (message instanceof BinaryMessage) {
		handleBinaryMessage(session, (BinaryMessage) message);
	}
	else if (message instanceof PongMessage) {
		handlePongMessage(session, (PongMessage) message);
	}
	else {
		throw new IllegalStateException("Unexpected WebSocket message type: " + message);
	}
}
 
Example #7
Source File: WebSocketServerHandler.java    From redtorch with MIT License 5 votes vote down vote up
@Override
protected void handlePongMessage(WebSocketSession session, PongMessage message) throws Exception {
	int nodeId = (int) session.getAttributes().get(RtConstant.KEY_NODE_ID);
	if (session.getAttributes().get(WebSocketConstant.KEY_AUTHED) == null || !(boolean) session.getAttributes().get(WebSocketConstant.KEY_AUTHED)) {
		logger.error("接收PONE消息,丢弃,会话尚未得到验证,节点ID:{},会话ID:{}", nodeId, session.getId());
		return;
	}
	Long pingTimestamp = message.getPayload().asLongBuffer().get();
	sessionIdPingStartTimeMap.remove(session.getId());
	logger.info("收到PONG,节点ID:{},会话ID:{},延时{}ms", nodeId, session.getId(), System.currentTimeMillis() - pingTimestamp);
}
 
Example #8
Source File: JettyWebSocketHandlerAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
@OnWebSocketFrame
public void onWebSocketFrame(Frame frame) {
	if (OpCode.PONG == frame.getOpCode()) {
		ByteBuffer payload = frame.getPayload() != null ? frame.getPayload() : EMPTY_PAYLOAD;
		PongMessage message = new PongMessage(payload);
		try {
			this.webSocketHandler.handleMessage(this.wsSession, message);
		}
		catch (Throwable ex) {
			ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
		}
	}
}
 
Example #9
Source File: StandardWebSocketHandlerAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void handlePongMessage(javax.websocket.Session session, ByteBuffer payload) {
	PongMessage pongMessage = new PongMessage(payload);
	try {
		this.handler.handleMessage(this.wsSession, pongMessage);
	}
	catch (Throwable ex) {
		ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
	}
}
 
Example #10
Source File: AbstractWebSocketHandler.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
	if (message instanceof TextMessage) {
		handleTextMessage(session, (TextMessage) message);
	}
	else if (message instanceof BinaryMessage) {
		handleBinaryMessage(session, (BinaryMessage) message);
	}
	else if (message instanceof PongMessage) {
		handlePongMessage(session, (PongMessage) message);
	}
	else {
		throw new IllegalStateException("Unexpected WebSocket message type: " + message);
	}
}
 
Example #11
Source File: AbstractWebSocketSession.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public final void sendMessage(WebSocketMessage<?> message) throws IOException {
	checkNativeSessionInitialized();

	if (logger.isTraceEnabled()) {
		logger.trace("Sending " + message + ", " + this);
	}

	if (message instanceof TextMessage) {
		sendTextMessage((TextMessage) message);
	}
	else if (message instanceof BinaryMessage) {
		sendBinaryMessage((BinaryMessage) message);
	}
	else if (message instanceof PingMessage) {
		sendPingMessage((PingMessage) message);
	}
	else if (message instanceof PongMessage) {
		sendPongMessage((PongMessage) message);
	}
	else {
		throw new IllegalStateException("Unexpected WebSocketMessage type: " + message);
	}
}
 
Example #12
Source File: StandardWebSocketHandlerAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void handlePongMessage(javax.websocket.Session session, ByteBuffer payload) {
	PongMessage pongMessage = new PongMessage(payload);
	try {
		this.handler.handleMessage(this.wsSession, pongMessage);
	}
	catch (Throwable ex) {
		ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
	}
}
 
Example #13
Source File: JettyWebSocketHandlerAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@OnWebSocketFrame
public void onWebSocketFrame(Frame frame) {
	if (OpCode.PONG == frame.getOpCode()) {
		ByteBuffer payload = frame.getPayload() != null ? frame.getPayload() : EMPTY_PAYLOAD;
		PongMessage message = new PongMessage(payload);
		try {
			this.webSocketHandler.handleMessage(this.wsSession, message);
		}
		catch (Throwable ex) {
			ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
		}
	}
}
 
Example #14
Source File: DeviceHiveWebSocketHandler.java    From devicehive-java-server with Apache License 2.0 4 votes vote down vote up
@Override
protected void handlePongMessage(WebSocketSession session, PongMessage message) throws Exception {
    logger.debug("Pong received for session {}", session.getId());
}
 
Example #15
Source File: BrokerStomp.java    From WeEvent with Apache License 2.0 4 votes vote down vote up
@Override
protected void handlePongMessage(WebSocketSession session, PongMessage message) throws Exception {
    log.debug("handle pong message, {}", session.getId());

    super.handlePongMessage(session, message);
}
 
Example #16
Source File: WebSocketStompClientTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void handleWebSocketMessagePong() throws Exception {
	connect().handleMessage(this.webSocketSession, new PongMessage());
	verifyNoMoreInteractions(this.stompSession);
}
 
Example #17
Source File: OfframpWebSocketHandler.java    From data-highway with Apache License 2.0 4 votes vote down vote up
@Override
protected void handlePongMessage(WebSocketSession session, PongMessage message) throws Exception {
  log.debug("Road: {}, stream: {}, sessionId: {} - Received Unsolicited Pong", roadName, streamName, sessionId);
}
 
Example #18
Source File: JettyWebSocketSession.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected void sendPongMessage(PongMessage message) throws IOException {
	getNativeSession().getRemote().sendPong(message.getPayload());
}
 
Example #19
Source File: AbstractWebSocketHandler.java    From spring-analysis-note with MIT License 4 votes vote down vote up
protected void handlePongMessage(WebSocketSession session, PongMessage message) throws Exception {
}
 
Example #20
Source File: StandardWebSocketSession.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected void sendPongMessage(PongMessage message) throws IOException {
	getNativeSession().getBasicRemote().sendPong(message.getPayload());
}
 
Example #21
Source File: StandardWebSocketSession.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected void sendPongMessage(PongMessage message) throws IOException {
	getNativeSession().getBasicRemote().sendPong(message.getPayload());
}
 
Example #22
Source File: AbstractWebSocketHandler.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
protected void handlePongMessage(WebSocketSession session, PongMessage message) throws Exception {
}
 
Example #23
Source File: MetricWsHandler.java    From artemis with Apache License 2.0 4 votes vote down vote up
@Override
protected void handlePongMessage(final WebSocketSession session, final PongMessage message) throws Exception {
}
 
Example #24
Source File: WebSocketStompClientTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void handleWebSocketMessagePong() throws Exception {
	connect().handleMessage(this.webSocketSession, new PongMessage());
	verifyNoMoreInteractions(this.stompSession);
}
 
Example #25
Source File: JettyWebSocketSession.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected void sendPongMessage(PongMessage message) throws IOException {
	getRemoteEndpoint().sendPong(message.getPayload());
}
 
Example #26
Source File: JettyWebSocketSession.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected void sendPongMessage(PongMessage message) throws IOException {
	getRemoteEndpoint().sendPong(message.getPayload());
}
 
Example #27
Source File: StandardWebSocketSession.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected void sendPongMessage(PongMessage message) throws IOException {
	getNativeSession().getBasicRemote().sendPong(message.getPayload());
}
 
Example #28
Source File: AbstractWebSocketHandler.java    From java-technology-stack with MIT License 4 votes vote down vote up
protected void handlePongMessage(WebSocketSession session, PongMessage message) throws Exception {
}
 
Example #29
Source File: WebSocketStompClientTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void handleWebSocketMessagePong() throws Exception {
	connect().handleMessage(this.webSocketSession, new PongMessage());
	verifyNoMoreInteractions(this.stompSession);
}
 
Example #30
Source File: WebSocketMqtt.java    From WeEvent with Apache License 2.0 4 votes vote down vote up
@Override
protected void handlePongMessage(WebSocketSession session, PongMessage message) throws Exception {
    log.debug("handle pong message, {}", session.getId());

    super.handlePongMessage(session, message);
}