public WsCloseFilter(WebSocketWireProtocol wsVersion, Properties configuration, Logger logger, ScheduledExecutorService scheduler) { this.sentCloseFrame = new AtomicBoolean(false); this.receivedCloseFrame = new AtomicBoolean(false); this.timedOut = new AtomicBoolean(false); this.logger = logger; assert scheduler != null; this.scheduler = scheduler; // Check the configuration for the timeout to use this.closeTimeout = getCloseTimeout(configuration); }
if (codecRequired && WsCloseFilter.neededForProtocolVersion(wsVersion)) { if (logger.isTraceEnabled()) { logger.trace(String.format("Adding CLOSE frame filter for WS protocol version %s for session %s", wsVersion, session)); filterChain.addLast(WsAcceptor.CLOSE_FILTER, new WsCloseFilter(wsVersion, configuration, logger, scheduler));
@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); }