private <T extends ConnectFuture> IoSessionInitializer<ConnectFuture> createParentInitializer(final ResourceAddress connectAddress, final ConnectFuture httpConnectFuture, HttpConnectSessionFactory httpSessionFactory) { // initialize parent session before connection attempt return (parent, future) -> { HTTP_SESSION_FACTORY_KEY.set(parent, httpSessionFactory); HTTP_CONNECT_FUTURE_KEY.set(parent, httpConnectFuture); }; }
@Override public void set(Object state) { DECODING_STATE.set(session, state); } }
@Override public void initializeSession(IoSession session, T future) { SslAcceptor.SSL_RESOURCE_ADDRESS.set(session, connectAddress); if (parentInitializer != null) { parentInitializer.initializeSession(session, future); } } };
protected <T extends ConnectFuture> void connectUsingExistingTransport(final ConnectFuture connectFuture, IoSession transportSession, HttpConnectSessionFactory httpSessionFactory) { HTTP_SESSION_FACTORY_KEY.set(transportSession, httpSessionFactory); HTTP_CONNECT_FUTURE_KEY.set(transportSession, connectFuture); try { bridgeHandler.sessionOpened(transportSession); } catch (Exception e) { connectFuture.setException(e); } }
@Override public void initializeSession(IoSession session, T future) { SslAcceptor.SSL_RESOURCE_ADDRESS.set(session, address); if (parentInitializer != null) { parentInitializer.initializeSession(session, future); } } };
private void setLocalAddressFromSocketAddress(final IoSession session, final String transportName, String nextProtocol) { SocketAddress socketAddress = session.getLocalAddress(); if (socketAddress instanceof InetSocketAddress) { InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; ResourceAddress resourceAddress = newResourceAddress(inetSocketAddress, transportName, nextProtocol); LOCAL_ADDRESS.set(session, resourceAddress); } else if (socketAddress instanceof NamedPipeAddress) { NamedPipeAddress namedPipeAddress = (NamedPipeAddress) socketAddress; ResourceAddress resourceAddress = newResourceAddress(namedPipeAddress, transportName, nextProtocol); LOCAL_ADDRESS.set(session, resourceAddress); } }
private void setLocalAddressFromSocketAddress(final IoSession session, final String transportName) { SocketAddress socketAddress = session.getLocalAddress(); if (socketAddress instanceof InetSocketAddress) { InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; ResourceAddress resourceAddress = newResourceAddress(inetSocketAddress, transportName); LOCAL_ADDRESS.set(session, resourceAddress); } else if (socketAddress instanceof NamedPipeAddress) { NamedPipeAddress namedPipeAddress = (NamedPipeAddress) socketAddress; ResourceAddress resourceAddress = newResourceAddress(namedPipeAddress, "pipe"); LOCAL_ADDRESS.set(session, resourceAddress); } }
@Override public void initializeSession(IoSession session, F future) { REMOTE_ADDRESS.set(session, remoteAddress); setLocalAddressFromSocketAddress(session, getTransportName(), nextProtocol); if (initializer != null) { initializer.initializeSession(session, future); } } });
@Override public void initializeSession(IoSession session, T future) { if ( theCreateInitializer != null ) { theCreateInitializer.initializeSession(session, future); } // Store the next over-the-top of-websocket protocols the server supports for this address on session. SUPPORTED_PROTOCOLS.set(session, address.getOption(WsResourceAddress.SUPPORTED_PROTOCOLS)); } };
@Override protected void doSessionCreated(IoSessionEx session) throws Exception { HTTPXE_SPEC_KEY.set(session, httpxeSpecCompliant); IoFilterChain filterChain = session.getFilterChain(); addBridgeFilters(filterChain); }
@Override protected void doSessionOpened(IoSessionEx session) throws Exception { IoFilterChain filterChain = session.getFilterChain(); addBridgeFilters(filterChain); // defer creation of WsnSession until WebSocket handshake completed Callable<WsnSession> sessionFactory = WSN_SESSION_FACTORY_KEY.remove(session); WsnSession wsnSession = sessionFactory.call(); SESSION_KEY.set(session, wsnSession); }
@Override protected void doSessionOpened(HttpSession session) throws Exception { // TODO session.get[Ready]Future().addListener(...) to check // response status / headers IoFilterChain filterChain = session.getFilterChain(); addBridgeFilters(filterChain); SseSession sseSession = SSE_SESSION_KEY.get(session); if (sseSession == null) { Callable<SseSession> sessionFactory = SSE_SESSION_FACTORY_KEY.remove(session); SseSession newSseSession = sessionFactory.call(); SSE_SESSION_KEY.set(session, newSseSession); } }
@Override public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception { // create SslSession SslSession sslSession = unsecureBridgeHandler.createSslSession((IoSessionEx) session); SESSION_KEY.set(session, sslSession); session.getFilterChain().remove(this); super.messageReceived(nextFilter, session, message); } }
@Override public void initializeSession(IoSession session, F future) { // connectors don't need lookup so set this directly on the session session.setAttribute(BridgeConnectHandler.DELEGATE_KEY, handler); REMOTE_ADDRESS.set(session, remoteAddress); setLocalAddressFromSocketAddress(session, getTransportName(), nextProtocol); if (initializer != null) { initializer.initializeSession(session, future); } } });
@Override protected void doSessionOpened(final HttpConnectSession createSession) throws Exception { Callable<WsebSession> sessionFactory = WSE_SESSION_FACTORY_KEY.remove(createSession); final WsebSession wsebSession = sessionFactory.call(); // clean up session idle tracker wsebSession.getCloseFuture().addListener(new IoFutureListener<CloseFuture>() { @Override public void operationComplete(CloseFuture future) { currentSessionIdleTracker.get().removeSession(wsebSession); // handle exception during create response createSession.close(false); } }); // store created session to process during session close, or exception WSE_SESSION_KEY.set(createSession, wsebSession); WSE_CONNECT_FUTURE_KEY.remove(createSession); }
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); }
@Override public void initializeSession(IoSession connectSession, ConnectFuture future) { if (acceptSession.isClosing()) { connectSession.close(true); } else { BridgeSession.NEXT_PROTOCOL_KEY.set(connectSession, nextProtocol); // guarantee strongly-typed buffers; this is the connect-side where // the service is the client of the broker. initFilterChain(connectSession, true); // hook in any ProxyServiceExtensions here and give them a chance // to initialize the accept side of the proxy connection for (ProxyServiceExtensionSpi extension : extensions) { extension.initConnectSession(connectSession, getServiceContext().getProperties()); } } } });
@Override protected void doMessageReceived(HttpConnectSession createSession, Object message) throws Exception { // Handle fragmentation of response body IoBufferEx in = (IoBufferEx) message; IoBufferEx buf = CREATE_RESPONSE_KEY.get(createSession); if (buf == null) { IoBufferAllocatorEx<?> allocator = createSession.getBufferAllocator(); buf = allocator.wrap(allocator.allocate(in.remaining())).setAutoExpander(allocator); CREATE_RESPONSE_KEY.set(createSession, buf); } buf.put(in); }
@Override protected void doSessionOpened(IoSessionEx session) throws Exception { IoFilterChain filterChain = session.getFilterChain(); addBridgeFilters(filterChain); HttpConnectSessionFactory sessionFactory = HTTP_SESSION_FACTORY_KEY.remove(session); DefaultHttpSession httpSession = sessionFactory.get(session); HTTP_SESSION_KEY.set(session, httpSession); DefaultConnectFuture connectFuture = (DefaultConnectFuture) HTTP_CONNECT_FUTURE_KEY.remove(session); if (!connectFuture.isDone()) { // needed for http redirect as there will be a new connect on the wire connectFuture.setValue(httpSession); } }
@Override protected void doMessageReceived(HttpSession createSession, Object message) throws Exception { // Handle fragmentation of response body IoBufferEx in = (IoBufferEx) message; IoBufferEx buf = CREATE_RESPONSE_KEY.get(createSession); if (buf == null) { IoBufferAllocatorEx<?> allocator = createSession.getBufferAllocator(); ByteBuffer nioBuf = allocator.allocate(in.remaining()); buf = allocator.wrap(nioBuf).setAutoExpander(allocator); CREATE_RESPONSE_KEY.set(createSession, buf); } buf.put(in); }