public static void addIfFeatureEnabled(IoFilterChain filterChain, String filterName, long inactivityTimeoutIn, Logger logger) { addIfFeatureEnabled(filterChain, filterName, inactivityTimeoutIn, null, logger); }
public static void addIfFeatureEnabled(IoFilterChain filterChain, String filterName, long inactivityTimeoutIn, IoSessionEx wsSession, Logger logger) { long inactivityTimeout = getInactivityTimeoutMillis(inactivityTimeoutIn, logger); if (inactivityTimeout > 0) { filterChain.addLast(filterName, new WsCheckAliveFilter(inactivityTimeout, wsSession, logger)); if (logger.isDebugEnabled()) { logger.debug(String.format("Configured WebSocket inactivity timeout (ws.inactivity.timeout) is %d milliseconds", inactivityTimeout)); } } }
@Override public void onPostAdd(IoFilterChain filterChain, String name, NextFilter nextFilter) throws Exception { init(filterChain); }
WsCheckAliveFilter.addIfFeatureEnabled(filterChain, CHECK_ALIVE_FILTER, localAddress.getOption(INACTIVITY_TIMEOUT), logger); WsCheckAliveFilter.moveIfFeatureEnabled(parent.getFilterChain(), filterChain, CHECK_ALIVE_FILTER, localAddress.getOption(INACTIVITY_TIMEOUT), logger);
private void schedulePing(IoSessionEx session) { nextAction = NextAction.PING; setReadIdleTimeInMillis(session, pingDelay); }
private void init(IoFilterChain filterChain) { IoSessionEx session = (IoSessionEx)filterChain.getSession(); schedulePing(session); }
@Override protected void init() { // Fail gateway startup if the obsolete system property "org.kaazing.gateway.transport.ws.INACTIVITY_TIMEOUT" // from JMS Edition release 3.5.3 is used (KG-7125) WsCheckAliveFilter.validateSystemProperties(configuration, logger); super.init(); }
break; case PING: writePing(nextFilter, session);
private void writePing(NextFilter nextFilter, IoSessionEx session) throws Exception { WsPingMessage emptyPing = new WsPingMessage(); setReadIdleTimeInMillis(session, maxExpectedRtt); nextAction = NextAction.PONG; if (logger.isTraceEnabled()) { logger.trace(String.format("Writing %s at time %d", emptyPing, System.currentTimeMillis())); } pingSentTime = System.currentTimeMillis(); session.write(emptyPing); }
AbstractWsBridgeSession.LAST_ROUND_TRIP_LATENCY_TIMESTAMP.set(session, pingSentTime); schedulePing(session); return; default:
private void addSession0(IoSessionEx wsebSession) { if (ALREADY_TRACKED.get(wsebSession, false)) { // Expected for downstream reconnects return; } IoSessionEx transportSession = ((WsebSession)wsebSession).getTransportSession(); ALREADY_TRACKED.set(wsebSession, true); idleTracker.addSession(transportSession); WsCheckAliveFilter.addIfFeatureEnabled(transportSession.getFilterChain(), CHECK_ALIVE_FILTER, ((WsebSession) wsebSession).getLocalAddress().getOption(INACTIVITY_TIMEOUT), wsebSession, logger); }
public static void updateExtensions(IoFilterChain filterChain) { WsCheckAliveFilter filter = (WsCheckAliveFilter) filterChain.get(WsCheckAliveFilter.class); if (filter != null) { filter.init(filterChain); } }
@Override public void addBridgeFilters(IoFilterChain filterChain) { IoSession session = filterChain.getSession(); Encoding encoding = (Encoding) session.getAttribute(ENCODING_KEY); filterChain.addLast(CODEC_FILTER, codec); if (encoding != null) { switch (encoding) { case BASE64: // add framing before encoding filterChain.addLast(BASE64_FILTER, base64); break; case TEXT: // add framing before encoding filterChain.addLast(TEXT_FILTER, text); break; default: break; } } // We speak a new enough version of the WebSocket protocol that // we need to conform to the proper CLOSE semantics. filterChain.addLast(WsAcceptor.CLOSE_FILTER, new WsCloseFilter(WebSocketWireProtocol.RFC_6455, configuration, logger, scheduler)); // post-upgrade filter is added before WebSocket codec filter // where the type of this filter chain is still IoBuffer filterChain.addBefore(CODEC_FILTER, POST_UPGRADE_FILTER, postUpgrade); // (KG-7391) Use ping and pong to detect and close dead connections, if ws inactivity timeout is active final ResourceAddress connectAddress = (ResourceAddress) session.removeAttribute(WSN_CONNECT_ADDRESS_KEY); WsCheckAliveFilter.addIfFeatureEnabled(filterChain, WsnAcceptor.CHECK_ALIVE_FILTER, connectAddress.getOption(WsResourceAddress.INACTIVITY_TIMEOUT), logger); }