org.springframework.web.socket.PingMessage Java Examples

The following examples show how to use org.springframework.web.socket.PingMessage. 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: SessionMonitor.java    From devicehive-java-server with Apache License 2.0 7 votes vote down vote up
@Scheduled(cron = "0/30 * * * * *")
public synchronized void ping() {
    try {
        for (WebSocketSession session : sessionMap.values()) {
            if (session.isOpen()) {
                logger.debug("Pinging session {}", session.getId());
                session.sendMessage(new PingMessage());
            } else {
                logger.debug("Session {} is closed.", session.getId());
                sessionMap.remove(session.getId());
            }
        }
    } catch (IOException e) {
        logger.error("Exception while ping session");
    }
}
 
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: 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 #4
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 #5
Source File: StandardWebSocketSession.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected void sendPingMessage(PingMessage message) throws IOException {
	getNativeSession().getBasicRemote().sendPing(message.getPayload());
}
 
Example #6
Source File: JettyWebSocketSession.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
protected void sendPingMessage(PingMessage message) throws IOException {
	getRemoteEndpoint().sendPing(message.getPayload());
}
 
Example #7
Source File: StandardWebSocketSession.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected void sendPingMessage(PingMessage message) throws IOException {
	getNativeSession().getBasicRemote().sendPing(message.getPayload());
}
 
Example #8
Source File: JettyWebSocketSession.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
protected void sendPingMessage(PingMessage message) throws IOException {
	getRemoteEndpoint().sendPing(message.getPayload());
}
 
Example #9
Source File: StandardWebSocketSession.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected void sendPingMessage(PingMessage message) throws IOException {
	getNativeSession().getBasicRemote().sendPing(message.getPayload());
}
 
Example #10
Source File: JettyWebSocketSession.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected void sendPingMessage(PingMessage message) throws IOException {
	getNativeSession().getRemote().sendPing(message.getPayload());
}
 
Example #11
Source File: AbstractWebSocketSession.java    From spring-analysis-note with MIT License votes vote down vote up
protected abstract void sendPingMessage(PingMessage message) throws IOException; 
Example #12
Source File: AbstractWebSocketSession.java    From java-technology-stack with MIT License votes vote down vote up
protected abstract void sendPingMessage(PingMessage message) throws IOException; 
Example #13
Source File: AbstractWebSocketSession.java    From spring4-understanding with Apache License 2.0 votes vote down vote up
protected abstract void sendPingMessage(PingMessage message) throws IOException;