@Test public void shouldSimplyForwardEventWhenConnectIsCalledWithNonInetSocketAddress() throws Exception { ChannelStateEvent event = new DownstreamChannelStateEvent( channel, new DefaultChannelFuture(channel, false), ChannelState.CONNECTED, new LocalAddress(LocalAddress.EPHEMERAL) ); handler.connectRequested(ctx, event); verify(ctx).sendDownstream(refEq(event)); }
@Override public void connectRequested(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception { if (!(e.getValue() instanceof InetSocketAddress)) { super.connectRequested(ctx, e); return; } final InetSocketAddress originalAddress = (InetSocketAddress) e.getValue(); if (!originalAddress.isUnresolved()) { super.connectRequested(ctx, e); return; } ListenableFuture<InetSocketAddress> resolvedFuture = resolveService.submit(new Callable<InetSocketAddress>() { @Override public InetSocketAddress call() throws Exception { return resolvedAddressProvider.createResolved(originalAddress); } }); Futures.addCallback(resolvedFuture, new FutureCallback<InetSocketAddress>() { @Override public void onSuccess(InetSocketAddress resolvedAddress) { try { DownstreamChannelStateEvent forwardedEvent = new DownstreamChannelStateEvent(e.getChannel(), e.getFuture(), e.getState(), resolvedAddress); AddressResolverHandler.super.connectRequested(ctx, forwardedEvent); } catch (Exception cause) { failConnect(cause); } } @Override public void onFailure(Throwable cause) { failConnect(cause); } private void failConnect(Throwable cause) { LOGGER.warn("fail connect to unresolved address:{}", originalAddress, cause); Channels.fireExceptionCaughtLater(ctx, cause); } }); }
AddressResolverHandler extends SimpleChannelDownstreamHandler { @Override public void connectRequested(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception { if (!(e.getValue() instanceof InetSocketAddress)) { super.connectRequested(ctx, e); return; } final InetSocketAddress originalAddress = (InetSocketAddress) e.getValue(); if (!originalAddress.isUnresolved()) { super.connectRequested(ctx, e); return; } ListenableFuture<InetSocketAddress> resolvedFuture = resolveService.submit(new Callable<InetSocketAddress>() { @Override public InetSocketAddress call() throws Exception { return resolvedAddressProvider.createResolved(originalAddress); } }); Futures.addCallback(resolvedFuture, new FutureCallback<InetSocketAddress>() { @Override public void onSuccess(InetSocketAddress resolvedAddress) { try { DownstreamChannelStateEvent forwardedEvent = new DownstreamChannelStateEvent(e.getChannel(), e.getFuture(), e.getState(), resolvedAddress); AddressResolverHandler.super.connectRequested(ctx, forwardedEvent); } catch (Exception cause) { failConnect(cause); } } @Override public void onFailure(Throwable cause) { failConnect(cause); } private void failConnect(Throwable cause) { LOGGER.warn("fail connect to unresolved address:{}", originalAddress, cause); Channels.fireExceptionCaughtLater(ctx, cause); } }); } }
AddressResolverHandler extends SimpleChannelDownstreamHandler { @Override public void connectRequested(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception { if (!(e.getValue() instanceof InetSocketAddress)) { super.connectRequested(ctx, e); return; } final InetSocketAddress originalAddress = (InetSocketAddress) e.getValue(); if (!originalAddress.isUnresolved()) { super.connectRequested(ctx, e); return; } ListenableFuture<InetSocketAddress> resolvedFuture = resolveService.submit(new Callable<InetSocketAddress>() { @Override public InetSocketAddress call() throws Exception { return resolvedAddressProvider.createResolved(originalAddress); } }); Futures.addCallback(resolvedFuture, new FutureCallback<InetSocketAddress>() { @Override public void onSuccess(InetSocketAddress resolvedAddress) { try { DownstreamChannelStateEvent forwardedEvent = new DownstreamChannelStateEvent(e.getChannel(), e.getFuture(), e.getState(), resolvedAddress); AddressResolverHandler.super.connectRequested(ctx, forwardedEvent); } catch (Exception cause) { failConnect(cause); } } @Override public void onFailure(Throwable cause) { failConnect(cause); } private void failConnect(Throwable cause) { LOGGER.warn("fail connect to unresolved address:{}", originalAddress, cause); Channels.fireExceptionCaughtLater(ctx, cause); } }); } AddressResolverHandler(ListeningExecutorService resolveService);   AddressResolverHandler(ListeningExecutorService resolveService, ResolvedAddressProvider resolvedAddressProvider); }
AddressResolverHandler extends SimpleChannelDownstreamHandler { @Override public void connectRequested(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception { if (!(e.getValue() instanceof InetSocketAddress)) { super.connectRequested(ctx, e); return; } final InetSocketAddress originalAddress = (InetSocketAddress) e.getValue(); if (!originalAddress.isUnresolved()) { super.connectRequested(ctx, e); return; } ListenableFuture<InetSocketAddress> resolvedFuture = resolveService.submit(new Callable<InetSocketAddress>() { @Override public InetSocketAddress call() throws Exception { return resolvedAddressProvider.createResolved(originalAddress); } }); Futures.addCallback(resolvedFuture, new FutureCallback<InetSocketAddress>() { @Override public void onSuccess(InetSocketAddress resolvedAddress) { try { DownstreamChannelStateEvent forwardedEvent = new DownstreamChannelStateEvent(e.getChannel(), e.getFuture(), e.getState(), resolvedAddress); AddressResolverHandler.super.connectRequested(ctx, forwardedEvent); } catch (Exception cause) { failConnect(cause); } } @Override public void onFailure(Throwable cause) { failConnect(cause); } private void failConnect(Throwable cause) { LOGGER.warn("fail connect to unresolved address:{}", originalAddress, cause); Channels.fireExceptionCaughtLater(ctx, cause); } }); } AddressResolverHandler(ListeningExecutorService resolveService);   AddressResolverHandler(ListeningExecutorService resolveService, ResolvedAddressProvider resolvedAddressProvider); @Override void connectRequested(final ChannelHandlerContext ctx, final ChannelStateEvent e); }
AddressResolverHandler extends SimpleChannelDownstreamHandler { @Override public void connectRequested(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception { if (!(e.getValue() instanceof InetSocketAddress)) { super.connectRequested(ctx, e); return; } final InetSocketAddress originalAddress = (InetSocketAddress) e.getValue(); if (!originalAddress.isUnresolved()) { super.connectRequested(ctx, e); return; } ListenableFuture<InetSocketAddress> resolvedFuture = resolveService.submit(new Callable<InetSocketAddress>() { @Override public InetSocketAddress call() throws Exception { return resolvedAddressProvider.createResolved(originalAddress); } }); Futures.addCallback(resolvedFuture, new FutureCallback<InetSocketAddress>() { @Override public void onSuccess(InetSocketAddress resolvedAddress) { try { DownstreamChannelStateEvent forwardedEvent = new DownstreamChannelStateEvent(e.getChannel(), e.getFuture(), e.getState(), resolvedAddress); AddressResolverHandler.super.connectRequested(ctx, forwardedEvent); } catch (Exception cause) { failConnect(cause); } } @Override public void onFailure(Throwable cause) { failConnect(cause); } private void failConnect(Throwable cause) { LOGGER.warn("fail connect to unresolved address:{}", originalAddress, cause); Channels.fireExceptionCaughtLater(ctx, cause); } }); } AddressResolverHandler(ListeningExecutorService resolveService);   AddressResolverHandler(ListeningExecutorService resolveService, ResolvedAddressProvider resolvedAddressProvider); @Override void connectRequested(final ChannelHandlerContext ctx, final ChannelStateEvent e);  }