@Override public void bind(ResourceAddress address, IoHandler handler, BridgeSessionInitializer<?> initializer) { if (acceptor != null) { try { acceptor.bind(address, handler, initializer); } catch (RuntimeException re) { // Catch this RuntimeException and add a bit more information // to its message (cf KG-1462) throw new RuntimeException(String.format("Error binding to %s: %s", address.getResource(), re.getMessage()), re); } } }
@Override public final void unbind(ResourceAddress address) { if (acceptor != null) { acceptor.unbind(address).awaitUninterruptibly(); } }
@Override protected IoHandler getHandler(IoSession session, boolean throwIfNull) throws Exception { IoHandler handler = DELEGATE_KEY.get(session); if (handler == null) { ResourceAddress localAddress = LOCAL_ADDRESS.get(session); // If there is an exception in sessionCreated(), it may not set up LOCAL_ADDRESS // and hence localAddress could be null. So return null in this case when // exceptionCaught()/sessionClosed() looks up the handler. handler = localAddress == null ? null : acceptor.getHandler(localAddress); if (handler != null) { DELEGATE_KEY.set(session, handler); } else if (throwIfNull) { throw new Exception("No handler found for: " + localAddress); } } return handler; } }
acceptor.bind(transportAddress, bridgeHandler, wrapperInitializer); IoHandler existingHandler = acceptor.getHandler(failedAddress); if (existingHandler == secureBridgeHandler) { throw new RuntimeException(
@Override public void dispose() { if (acceptor != null) { acceptor.dispose(); } if (connector != null) { connector.dispose(); } }
private void bindCookiesHandler(ResourceAddress address) { final ResourceAddress cookiesAddress = createCookiesAddress(address); BridgeAcceptor cookiesAcceptor = bridgeServiceFactory.newBridgeAcceptor(cookiesAddress); cookiesAcceptor.bind(cookiesAddress, cookiesHandler, null); }
private void bindApiPath(ResourceAddress address) { ResourceAddress apiAddress = createApiAddress(address); bridgeServiceFactory.newBridgeAcceptor(apiAddress).bind(apiAddress, WsAcceptor.API_PATH_HANDLER, null); }
private UnbindFuture unbindCookiesHandler(ResourceAddress address) { final ResourceAddress cookiesAddress = createCookiesAddress(address); BridgeAcceptor cookiesAcceptor = bridgeServiceFactory.newBridgeAcceptor(cookiesAddress); return cookiesAcceptor.unbind(cookiesAddress); }
private void bindInternal(final ResourceAddress address, final IoHandler handler, final Transport transport, final IoSessionInitializer<ConnectFuture> sessionInitializer, final BridgeSessionInitializer<ConnectFuture> bridgeSessionInitializer) { BridgeAcceptor acceptor = transport.getAcceptor(address); try { acceptor.bind(address, handler, new BridgeSessionInitializer<ConnectFuture>() { @Override public BridgeSessionInitializer<ConnectFuture> getParentInitializer(Protocol protocol) { return (bridgeSessionInitializer != null) ? bridgeSessionInitializer.getParentInitializer(protocol) : null; } @Override public void initializeSession(IoSession session, ConnectFuture future) { sessionInitializer.initializeSession(session, future); if (bridgeSessionInitializer != null) { bridgeSessionInitializer.initializeSession(session, future); } } }); } catch (RuntimeException re) { // Catch this RuntimeException and add a bit more information // to its message (cf KG-1462) throw new RuntimeException(String.format("Error binding to %s: %s", address.getResource(), re.getMessage()), re); } }
@Override protected UnbindFuture unbindInternal(ResourceAddress address, IoHandler handler, BridgeSessionInitializer<? extends IoFuture> initializer) { final ResourceAddress transportBindAddress = address.getTransport(); final BridgeAcceptor transportAcceptor = bridgeServiceFactory.newBridgeAcceptor(transportBindAddress); return transportAcceptor.unbind(transportBindAddress); }
private void bindApiPath(ResourceAddress address) { ResourceAddress apiHttpAddress = createApiHttpAddress(address.getTransport()); bridgeServiceFactory.newBridgeAcceptor(apiHttpAddress).bind(apiHttpAddress, WsAcceptor.API_PATH_HANDLER, null); ResourceAddress apiHttpxeAddress = address.getTransport().getOption(ALTERNATE); if (apiHttpxeAddress != null) { apiHttpxeAddress = createApiHttpxeAddress(apiHttpxeAddress); bridgeServiceFactory.newBridgeAcceptor(apiHttpxeAddress).bind(apiHttpxeAddress, WsAcceptor.API_PATH_HANDLER, null); } }
private void unbindApiPath(ResourceAddress address) { ResourceAddress apiAddress = createApiAddress(address); bridgeServiceFactory.newBridgeAcceptor(apiAddress).unbind(apiAddress); }
@Override public void bind(ResourceAddress address, IoHandler handler, BridgeSessionInitializer<? extends IoFuture> initializer) { // bind only address with matching scheme URI location = address.getResource(); String schemeName = location.getScheme(); if (!canBind(schemeName)) { throw new IllegalArgumentException(format("Unexpected scheme \"%s\" for URI: %s", schemeName, location)); } // note: ignore BIND_ALTERNATE (used by delegate acceptors) do { BridgeAcceptor bridgeAcceptor = selectWsAcceptor(address); if ( bridgeAcceptor != null ) { bridgeAcceptor.bind(address, handler, initializer); } else { if (logger.isDebugEnabled()) { String format = "No bridge acceptor found for address '%s'. Is the %s transport enabled?"; logger.warn(format(format, address.getExternalURI(), URIUtils.getScheme(address.getExternalURI()))); } } address = address.getOption(ALTERNATE); } while (address != null); }
private UnbindFuture unbindCreateAddress(final ResourceAddress address) { // bind the create URL accessed using HTTP transport ResourceAddress wsrCreateAddress = createWsrCreateAddress(address); BridgeAcceptor createAcceptor = bridgeServiceFactory.newBridgeAcceptor(wsrCreateAddress); return createAcceptor.unbind(wsrCreateAddress); }
@Override protected <T extends IoFuture> void bindInternal(final ResourceAddress address, IoHandler handler, final BridgeSessionInitializer<T> initializer) { if (logger.isTraceEnabled()) { logger.trace(format("binding: '%s' %s", address.getExternalURI(), address.getOption(NEXT_PROTOCOL))); } // // Bind the transport of the address. // final ResourceAddress transportAddress = address.getTransport(); final URI transportURI = transportAddress.getResource(); final Protocol transportProtocol = bridgeServiceFactory.getTransportFactory().getProtocol(transportURI.getScheme()); final BridgeSessionInitializer<T> sessionInitializer = (initializer != null) ? initializer.getParentInitializer(transportProtocol) : null; BridgeAcceptor acceptor = bridgeServiceFactory.newBridgeAcceptor(transportAddress); acceptor.bind(transportAddress, bridgeHandler, sessionInitializer); }
@Override protected UnbindFuture unbindInternal(ResourceAddress address, IoHandler handler, BridgeSessionInitializer<? extends IoFuture> initializer) { if (logger.isTraceEnabled()) { logger.trace(format("unbinding: '%s' %s", address.getExternalURI(), address.getOption(NEXT_PROTOCOL))); } ResourceAddress transport = address.getTransport(); BridgeAcceptor acceptor = bridgeServiceFactory.newBridgeAcceptor(transport); return acceptor.unbind(transport); }
if (transport != null) { BridgeAcceptor acceptor = bridgeServiceFactory.newBridgeAcceptor(transport); acceptor.bind(transport, handler, initializer);
@Override public UnbindFuture unbind(ResourceAddress address) { UnbindFuture future = DefaultUnbindFuture.succeededFuture(); // note: ignore BIND_ALTERNATE (used by delegate acceptors) do { BridgeAcceptor bridgeAcceptor = selectWsAcceptor(address); if ( bridgeAcceptor == null ) { if (logger.isTraceEnabled()) { logger.trace(format("The acceptor for %s is not enabled.", address.getExternalURI())); } } else { future = combineFutures(future, bridgeAcceptor.unbind(address)); } address = address.getOption(ALTERNATE); } while (address != null); return future; }
private <T extends IoFuture> void bindCreateAddress(final ResourceAddress address, BridgeSessionInitializer<T> initializer) { // bind the create URL accessed using HTTP transport ResourceAddress wsrCreateAddress = createWsrCreateAddress(address); BridgeAcceptor createAcceptor = bridgeServiceFactory.newBridgeAcceptor(wsrCreateAddress); final BridgeSessionInitializer<T> theCreateInitializer = (initializer != null) ? initializer.getParentInitializer(HttpProtocol.HTTP) : null; BridgeSessionInitializer<T> wrapperInitializer = new BridgeSessionInitializerAdapter<T>() { @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)); } }; createAcceptor.bind(wsrCreateAddress, selectCreateHandler(wsrCreateAddress), wrapperInitializer); }