@Override public void run() { TyrusSession session = TyrusSession.this; if (session.isOpen() && session.getHeartbeatInterval() > 0) { try { session.getBasicRemote().sendPong(null); } catch (IOException e) { LOGGER.log(Level.FINE, "Pong could not have been sent " + e.getMessage()); } } else { cancelHeartBeatTask(); } } }
@Override public void run() { TyrusSession session = TyrusSession.this; if (session.isOpen() && session.getHeartbeatInterval() > 0) { try { session.getBasicRemote().sendPong(null); } catch (IOException e) { LOGGER.log(Level.FINE, "Pong could not have been sent " + e.getMessage()); } } else { cancelHeartBeatTask(); } } }
/** * Called by the provider when the web socket connection * has an incoming ping message from the given remote endpoint. * <p> * The endpoint needs to respond as soon as possible (see the websocket RFC). * No involvement from application layer, there is no ping listener. * * @param socket {@link TyrusWebSocket} who sent the message. * @param bytes the message. */ void onPing(TyrusWebSocket socket, ByteBuffer bytes) { TyrusSession session = getSession(socket); if (session == null) { LOGGER.log(Level.FINE, "Ping received on already closed connection."); return; } session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Received ping message"); session.restartIdleTimeoutExecutor(); try { session.getBasicRemote().sendPong(bytes); } catch (IOException e) { // do nothing. // we might consider calling onError, but there should be better defined exception. } }
/** * Called by the provider when the web socket connection * has an incoming ping message from the given remote endpoint. * <p> * The endpoint needs to respond as soon as possible (see the websocket RFC). * No involvement from application layer, there is no ping listener. * * @param socket {@link TyrusWebSocket} who sent the message. * @param bytes the message. */ void onPing(TyrusWebSocket socket, ByteBuffer bytes) { TyrusSession session = getSession(socket); if (session == null) { LOGGER.log(Level.FINE, "Ping received on already closed connection."); return; } session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Received ping message"); session.restartIdleTimeoutExecutor(); try { session.getBasicRemote().sendPong(bytes); } catch (IOException e) { // do nothing. // we might consider calling onError, but there should be better defined exception. } }