Build a {@link ChannelBindException}

@param bootstrap a netty bootstrap
@param cause a root cause

@return a new {@link ChannelBindException}
426394
public static ChannelBindException fail(AbstractBootstrap<?, ?> bootstrap, @Nullable Throwable cause) {
		Objects.requireNonNull(bootstrap, "bootstrap");
		if (cause instanceof java.net.BindException ||
				// With epoll/kqueue transport it is
				// io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
				(cause instanceof IOException && cause.getMessage() != null &&
						cause.getMessage().contains("Address already in use"))) {
			cause = null;
		}
		if (!(bootstrap.config().localAddress() instanceof InetSocketAddress)) {
			return new ChannelBindException(bootstrap.config().localAddress().toString(), -1, cause);
		}
		InetSocketAddress address = (InetSocketAddress)bootstrap.config().localAddress();

		return new ChannelBindException(address.getHostString(), address.getPort(), cause);
	}
476013
@Override
    public Channel openChannel() throws IOException, IllegalStateException {
        assertOpen();
        try {
            return this.bootstrap.clone().register().sync().channel();
        } catch (Exception e) {
            throw new IOException("Could not open channel.", e);
        }
    }
1358043
private void fireConnectionClosedOnError(
            final Throwable cause) {
        assertUnlocked();

        BOSHClientConnEvent event = null;
        for (BOSHClientConnListener listener : connListeners) {
            if (event == null) {
                event = BOSHClientConnEvent
                        .createConnectionClosedOnErrorEvent(
                        this, pendingRequestAcks, cause);
            }
            try {
                listener.connectionEvent(event);
            } catch (Exception ex) {
                LOG.log(Level.WARNING, UNHANDLED, ex);
            }
        }
    }
671699
private CompletableFuture<Void> bind(ServerBootstrap bootstrap) {
    CompletableFuture<Void> future = new CompletableFuture<>();
    int port = config.getPort() != null ? config.getPort() : returnAddress.port();
    if (config.getInterfaces().isEmpty()) {
      bind(bootstrap, Lists.newArrayList("0.0.0.0").iterator(), port, future);
    } else {
      bind(bootstrap, config.getInterfaces().iterator(), port, future);
    }
    return future;
  }
517964
static Channel createNewInstance(String name, HFClient clientContext) throws InvalidArgumentException {
        return new Channel(name, clientContext);
    }
927734
static InstallException create(RepositoryException e, Throwable cause, RestRepositoryConnectionProxy proxy, boolean defaultRepo) {

        if (proxy != null && cause instanceof UnknownHostException)
            return create(Messages.INSTALL_KERNEL_MESSAGES.getLogMessage("ERROR_TOOL_UNKNOWN_PROXY_HOST", proxy.getProxyURL().getHost()), e);
        else if (cause instanceof ConnectException && cause.getMessage() != null && cause.getMessage().contains("Connection refused") && proxy != null)
            return create(Messages.INSTALL_KERNEL_MESSAGES.getLogMessage("ERROR_TOOL_INCORRECT_PROXY_PORT", String.valueOf(proxy.getProxyURL().getPort())),
                          e);
        else if (isCertPathBuilderException(cause))
            return create(Messages.INSTALL_KERNEL_MESSAGES.getLogMessage(defaultRepo ? "ERROR_FAILED_TO_CONNECT_CAUSED_BY_CERT" : "ERROR_FAILED_TO_CONNECT_REPOS_CAUSED_BY_CERT"),
                          e, InstallException.RUNTIME_EXCEPTION);
        else
            return create(Messages.INSTALL_KERNEL_MESSAGES.getLogMessage(defaultRepo ? "ERROR_FAILED_TO_CONNECT" : "ERROR_FAILED_TO_CONNECT_REPOS"),
                          e, InstallException.RUNTIME_EXCEPTION);
    }
680324
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
        Throwable cause = e.getCause();

        // do not print exception if it is BindException.
        // we are trying to search available port below 1024. It is not good to
        // print a flood
        // of error logs during the searching.
        if (cause instanceof java.net.BindException) {
            return;
        }

        LOG.error("Exception on connection to " + getRemoteAddress(), e.getCause());

        // close the channel unless we are connecting and it is
        // NotYetConnectedException
        if (!((cause instanceof NotYetConnectedException)
                && _connection.getConnectionState().equals(Connection.State.CONNECTING))) {
            ctx.getChannel().close();
        }
    }
1077758
private Bootstrap getNettyBootstrap() {
        Bootstrap b = new Bootstrap();
        b.group(group)
         .channel(Epoll.isAvailable() ? EpollSocketChannel.class : NioSocketChannel.class)
         .option(ChannelOption.TCP_NODELAY, true);
        return b;
    }
382684
@Override
    public void openChannel(FutureCallback<Channel> callback) throws IllegalStateException {
        assertOpen();

        ChannelFuture future = this.bootstrap.clone().register();
        future.addListener(new NetworkManagerChannelFutureCallback(callback));
    }
600176
public static QueryException fromThrowable(Throwable cause) {
    return (cause instanceof QueryException)
                   ? (QueryException) cause
                   : new QueryException(cause);
  }
93440
public ConnectionlessBootstrap bootStrapUdpClient()
            throws HttpRequestCreateException {

        ConnectionlessBootstrap udpClient = null;
        try {

            // Configure the client.
            udpClient = new ConnectionlessBootstrap(udpMeta.getChannelFactory());

            udpClient.setPipeline(new UdpPipelineFactory(
                    TcpUdpSshPingResourceStore.getInstance().getTimer(), this)
                    .getPipeline());

        } catch (Exception t) {
            throw new TcpUdpRequestCreateException(
                    "Error in creating request in udp worker. "
                            + " If udpClient is null. Then fail to create.", t);
        }

        return udpClient;

    }
569162
public VirtualConnection createConnection() throws ChannelException, ChainException {
        OutboundVirtualConnectionImpl vc = new OutboundVirtualConnectionImpl();
        if (getChain().getState() != RuntimeState.STARTED) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Starting outbound chain, " + getName());
            }
            this.cf.startChainInternal(getChain().getChainData());
            // Reset the reference to the new outboundChain.
            this.outboundChain = this.cf.getRunningChain(getName());
            // Handle issues where the refCount may have gone negative due
            // to too many VCF.destroy calls from the same VCF.
            if (getRefCount() <= 0) {
                this.refCount = 1;
            }
        }
        ConnectionLink[] links = new ConnectionLink[chans.length];
        links[0] = chans[0].getConnectionLink(vc);
        for (int i = 1; i < chans.length; i++) {
            try {
                links[i] = chans[i].getConnectionLink(vc);
            } catch (Exception e) {
                FFDCFilter.processException(e, getClass().getName() + ".createConnection", "125", new Object[] { this, chans[i] });
                // Channel implementation had an error.
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Error getting conn link from " + chans[i].getName() + ", " + e.getMessage());
                }
                throw new ChannelException(e.getMessage());
            }
            links[i - 1].setDeviceLink(links[i]);
            links[i].setApplicationCallback(links[i - 1]);
        }
        // do the single cast here instead of many times later
        vc.setConnectionLink((OutboundConnectionLink) links[0]);
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Putting name of chain into vc statemap: " + getName());
        }
        // Set the name of the chain into the statemap of the vc.
        // (Currently used on Z in XMEM channel)
        vc.getStateMap().put("ChainName", getName());

        return vc;
    }
479674
public static void connectionObserver(AbstractBootstrap<?, ?> b,
			ConnectionObserver connectionObserver) {
		Objects.requireNonNull(b, "bootstrap");
		Objects.requireNonNull(connectionObserver, "connectionObserver");
		b.option(OBSERVER_OPTION, connectionObserver);
	}
37800
@Override
    public synchronized ServerBootstrap newServerBootstrap() throws Exception {

        ServerSocketChannelFactory serverChannelFactory = this.serverChannelFactory;

        if (serverChannelFactory == null) {
            Executor bossExecutor = executorServiceFactory.newExecutorService("boss.server");
            NioServerBossPool bossPool = new NioServerBossPool(bossExecutor, 1);
            Executor workerExecutor = executorServiceFactory.newExecutorService("worker.server");
            NioWorkerPool workerPool = new NioWorkerPool(workerExecutor, 1);
            serverChannelFactory = new NioServerSocketChannelFactory(bossPool, workerPool);

            // unshared
            channelFactories.add(serverChannelFactory);
        }

        return new ServerBootstrap(serverChannelFactory) {

            @Override
            public ChannelFuture bindAsync(SocketAddress localAddress) {
                return super.bindAsync(toInetSocketAddress(localAddress));
            }

        };
    }
1182931
public Future<Void> start(final int port) {
        final ChannelFuture channelFuture = this.bootstrap.bind(port);
        this.allChannels.add(channelFuture.channel());

        return channelFuture;
    }
489512
public ClientBootstrap bootStrapTcpClient()
            throws HttpRequestCreateException {

        ClientBootstrap tcpClient = null;
        try {

            // Configure the client.
            tcpClient = new ClientBootstrap(tcpMeta.getChannelFactory());

            // Configure the pipeline factory.
            tcpClient.setPipelineFactory(new MyPipelineFactory(TcpUdpSshPingResourceStore.getInstance().getTimer(),
                    this, tcpMeta.getTcpIdleTimeoutSec())
            );

            tcpClient.setOption("connectTimeoutMillis",
                    tcpMeta.getTcpConnectTimeoutMillis());
            tcpClient.setOption("tcpNoDelay", true);
          // tcpClient.setOption("keepAlive", true);

        } catch (Exception t) {
            throw new TcpUdpRequestCreateException(
                    "Error in creating request in Tcpworker. "
                            + " If tcpClient is null. Then fail to create.", t);
        }

        return tcpClient;

    }
1365404
private ServerBootstrap createBootstrap(final ChannelGroup channelGroup) throws Exception {
    EventLoopGroup bossGroup = new NioEventLoopGroup(bossThreadPoolSize,
                                                     createDaemonThreadFactory(serviceName + "-boss-thread-%d"));
    EventLoopGroup workerGroup = new NioEventLoopGroup(workerThreadPoolSize,
                                                       createDaemonThreadFactory(serviceName + "-worker-thread-%d"));
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap
      .group(bossGroup, workerGroup)
      .channel(NioServerSocketChannel.class)
      .childHandler(new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
          channelGroup.add(ch);

          ChannelPipeline pipeline = ch.pipeline();
          if (sslHandlerFactory != null) {
            // Add SSLHandler if SSL is enabled
            pipeline.addLast("ssl", sslHandlerFactory.create(ch.alloc()));
          }
          pipeline.addLast("codec", new HttpServerCodec());
          pipeline.addLast("compressor", new HttpContentCompressor());
          pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
          pipeline.addLast("keepAlive", new HttpServerKeepAliveHandler());
          pipeline.addLast("router", new RequestRouter(resourceHandler, httpChunkLimit, sslHandlerFactory != null));
          if (eventExecutorGroup == null) {
            pipeline.addLast("dispatcher", new HttpDispatcher());
          } else {
            pipeline.addLast(eventExecutorGroup, "dispatcher", new HttpDispatcher());
          }

          if (pipelineModifier != null) {
            pipelineModifier.modify(pipeline);
          }
        }
      });

    for (Map.Entry<ChannelOption, Object> entry : channelConfigs.entrySet()) {
      bootstrap.option(entry.getKey(), entry.getValue());
    }
    for (Map.Entry<ChannelOption, Object> entry : childChannelConfigs.entrySet()) {
      bootstrap.childOption(entry.getKey(), entry.getValue());
    }

    return bootstrap;
  }