Esempio n. 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private boolean canConnect() throws InterruptedException
        private bool CanConnect()
        {
            ListenSocketAddress socketAddress = _server.address();
            ChannelFuture       channelFuture = _bootstrap.connect(socketAddress.Hostname, socketAddress.Port);

            _channel = channelFuture.channel();
            return(channelFuture.await().Success);
        }
Esempio n. 2
0
        private void TryConnect()
        {
            lock (this)
            {
                if (_disposed)
                {
                    return;
                }
                else if (_fChannel != null && !_fChannel.Done)
                {
                    return;
                }

                _fChannel = _bootstrap.connect(_destination.socketAddress());
                _channel  = _fChannel.channel();

                _fChannel.addListener((ChannelFuture f) =>
                {
                    if (!f.Success)
                    {
                        long millis = _connectionBackoff.Millis;
                        _cappedLogger.warn("Failed to connect to: " + _destination.socketAddress() + ". Retrying in " + millis + " ms");
                        f.channel().eventLoop().schedule(this.tryConnect, millis, MILLISECONDS);
                        _connectionBackoff.increment();
                    }
                    else
                    {
                        _log.info("Connected: " + f.channel());
                        f.channel().closeFuture().addListener(closed =>
                        {
                            _log.warn(string.Format("Lost connection to: {0} ({1})", _destination, _channel.remoteAddress()));
                            _connectionBackoff = _connectionBackoffStrategy.newTimeout();
                            f.channel().eventLoop().schedule(this.tryConnect, 0, MILLISECONDS);
                        });
                    }
                });
            }
        }