Setup a callback called after {@link Channel} has been disconnected.

@param doOnDisconnected a consumer observing disconnected events

@return a new {@link TcpClient}
480174
public final TcpClient doOnDisconnected(Consumer<? super Connection> doOnDisconnected) {
		Objects.requireNonNull(doOnDisconnected, "doOnDisconnected");
		return new TcpClientDoOn(this, null, null, doOnDisconnected);
	}
1076783
function TcpConnect (socket) {
    this.count ++;    // increment client count inside this server
    socket.uid = "Socket://" + socket.remoteAddress +":" + socket.remotePort;
    socket.controller = this.controller;
    socket.adapter   = this.adapter;
    socket.controller.Debug(4, "N°:%d Server=[%s] Client: [%s]"
             ,this.count,this.uid,socket.uid);            
        
    // attach new device object to client socket
    socket.device = new TcpClient (socket);
    
    // notify adapter that it has a new client device connected
    if (socket.adapter.ClientConnect (socket) === -1) {
        try {socket.end();} catch(e){};
        return;
    }
  
    // send any received data to device parser
    socket.on(this.evtname, function(buffer) {
	    socket.controller.Debug(7, "%s Data=[%s]", socket.device.uid, buffer);
        // call adapter specific method to process messages
        socket.adapter.ParseBuffer(socket, buffer);
    });
    
    // On error close socket
    socket.on('error', function (err) {
        socket.controller.Debug(3, "%s ERROR=[%s]", socket.device.uid, err);
        this.adapter.ClientQuit(socket);
        try {socket.destroy();} catch(e){};
    });
        
    // Remove the device from gateway active device list and notify adapter for eventual cleanup
    socket.on('end', function () {
	socket.controller.Debug(4, "SockClient Quit devid=%s uid=%s", socket.device.devid, socket.device.uid);
        this.adapter.ClientQuit(socket);
    });
    
}
824884
@Override
    protected void setCommsConnection(CommsConnection cc) {
        if (tc.isEntryEnabled())
            SibTr.entry(this, tc, "setCommsConnection");

        // Retrieve Client Conversation State if necessary
        validateConversationState();

        sConState.setCommsConnection(cc);

        if (tc.isEntryEnabled())
            SibTr.exit(this, tc, "setCommsConnection");
    }
422679
public void addDisconnectInterceptor(DisconnectInterceptor<?> interceptor) {
		Class<?> serviceApiType = GenericTypeResolver.resolveTypeArgument(interceptor.getClass(), DisconnectInterceptor.class);
		disconnectInterceptors.add(serviceApiType, interceptor);
	}
973766
public static TcpClientTransport create(InetSocketAddress address) {
    Objects.requireNonNull(address, "address must not be null");

    TcpClient tcpClient = TcpClient.create().addressSupplier(() -> address);
    return create(tcpClient);
  }
138646
public TrmClientAttachReply createNewTrmClientAttachReply() throws MessageCreateFailedException {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(tc, "createNewTrmClientAttachReply");
    TrmClientAttachReply msg = null;
    try {
      msg = new TrmClientAttachReplyImpl();
    }
    catch (MessageDecodeFailedException e) {
      /* No need to FFDC this as JsMsgObject will already have done so */
      // No FFDC code needed
      throw new MessageCreateFailedException(e);
    }
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(tc, "createNewTrmClientAttachReply");
    return msg;
  }
746831
public static TcpClient<ByteBuf, ByteBuf> newClient(ConnectionProviderFactory<ByteBuf, ByteBuf> providerFactory,
                                                        Observable<Host> hostStream) {
        return TcpClientImpl.create(providerFactory, hostStream);
    }
1170748
public EpollSocketChannelConfig setTcpCork(boolean tcpCork) {
        try {
            ((EpollSocketChannel) channel).socket.setTcpCork(tcpCork);
            return this;
        } catch (IOException e) {
            throw new ChannelException(e);
        }
    }
705060
public final HttpClient doOnResponse(BiConsumer<? super HttpClientResponse, ? super Connection> doOnResponse) {
		Objects.requireNonNull(doOnResponse, "doOnResponse");
		return new HttpClientDoOn(this, null, null, doOnResponse, null);
	}
1022592
protected void connect() throws RpcException {
        if (_state.equals(State.CONNECTED)) {
            return;
        }

        final ChannelFuture oldChannelFuture = _channelFuture;

        if (LOG.isDebugEnabled()) {
            String logPrefix = _usePrivilegedPort ? "usePrivilegedPort " : "";
            LOG.debug("{}connecting to {}", logPrefix, getRemoteAddress());
        }
        _state = State.CONNECTING;

        if (_usePrivilegedPort) {
            _channel = bindToPrivilegedPort();
            _channelFuture = _channel.connect(getRemoteAddress());
        } else {
            _channelFuture = _clientBootstrap.connect();
            _channel = _channelFuture.getChannel();
        }

        NioSocketChannelConfig cfg = (NioSocketChannelConfig) _channel.getConfig();
        cfg.setWriteBufferHighWaterMark(MAX_SENDING_QUEUE_SIZE);

        _channelFuture.addListener(new ChannelFutureListener() {
            /* (non-Javadoc)
             * @see org.jboss.netty.channel.ChannelFutureListener#operationComplete(org.jboss.netty.channel.ChannelFuture)
             */
            public void operationComplete(ChannelFuture future) {
                if (_channelFuture.isSuccess()) {
                    _state = State.CONNECTED;
                    oldChannelFuture.setSuccess();
                } else {
                    _state = State.DISCONNECTED;
                    oldChannelFuture.cancel();
                }

            }
        });

    }
958311
public static Message buildDisconnected(String serverId) {
    Disconnected dis = Disconnected.newBuilder()
                                   .setServerId(serverId)
                                   .build();
    return Message.newBuilder().setType(MessageType.DISCONNECTED)
                               .setDisconnected(dis)
                               .build();
  }
124063
@Override
    protected Connection proxyConnection(Connection target, ConnectionCallback callback) {
        return new ConnectionDecorator(target, callback);
    }
1027720
protected Connection createStdOutConnection(Dsn dsn) {
        //CHECKSTYLE.OFF: RegexpSinglelineJava
        OutputStreamConnection stdOutConnection = new OutputStreamConnection(System.out);
        //CHECKSTYLE.ON: RegexpSinglelineJava
        stdOutConnection.setMarshaller(createMarshaller(dsn));
        return stdOutConnection;
    }
951613
public TCBeginRequest createBegin(Dialog d) {
        if (d == null) {
            throw new NullPointerException("Dialog is null");
        }
        TCBeginRequestImpl tcbr = new TCBeginRequestImpl();
        tcbr.setDialog(d);
        tcbr.setDestinationAddress(d.getRemoteAddress());
        tcbr.setOriginatingAddress(d.getLocalAddress());
        return tcbr;
    }
1171952
@SuppressWarnings("unchecked")
    protected <K, V, T extends RedisChannelHandler<K, V>> ConnectionFuture<T> initializeChannelAsync(
            ConnectionBuilder connectionBuilder) {

        Mono<SocketAddress> socketAddressSupplier = connectionBuilder.socketAddress();

        if (clientResources.eventExecutorGroup().isShuttingDown()) {
            throw new IllegalStateException("Cannot connect, Event executor group is terminated.");
        }

        CompletableFuture<SocketAddress> socketAddressFuture = new CompletableFuture<>();
        CompletableFuture<Channel> channelReadyFuture = new CompletableFuture<>();

        socketAddressSupplier.doOnError(socketAddressFuture::completeExceptionally).doOnNext(socketAddressFuture::complete)
                .subscribe(redisAddress -> {

                    if (channelReadyFuture.isCancelled()) {
                        return;
                    }
                    initializeChannelAsync0(connectionBuilder, channelReadyFuture, redisAddress);
                }, channelReadyFuture::completeExceptionally);

        return new DefaultConnectionFuture<>(socketAddressFuture, channelReadyFuture.thenApply(channel -> (T) connectionBuilder
                .connection()));
    }
517964
static Channel createNewInstance(String name, HFClient clientContext) throws InvalidArgumentException {
        return new Channel(name, clientContext);
    }
1271146
public BlockingMessage createBLO(int cic) {
        BlockingMessage msg = createBLO();
        CircuitIdentificationCode code = this.parameterFactory.createCircuitIdentificationCode();
        code.setCIC(cic);
        msg.setCircuitIdentificationCode(code);
        return msg;
    }