示例#1
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);
                        });
                    }
                });
            }
        }
示例#2
0
        public override void Run()
        {
            if (!MoveToRunningState())
            {
                return;
            }

            try
            {
                _monitor.startedDownloadingSnapshot();
                _applicationProcess.pauseApplier(OPERATION_NAME);
                while (_keepRunning && !_downloader.downloadSnapshot(_addressProvider))
                {
                    Thread.Sleep(_timeout.Millis);
                    _timeout.increment();
                }
            }
            catch (InterruptedException)
            {
                Thread.CurrentThread.Interrupt();
                _log.warn("Persistent snapshot downloader was interrupted");
            }
            catch (DatabaseShutdownException e)
            {
                _log.warn("Store copy aborted due to shut down", e);
            }
            catch (Exception e)
            {
                _log.error("Unrecoverable error during store copy", e);
                _dbHealth.get().panic(e);
            }
            finally
            {
                _applicationProcess.resumeApplier(OPERATION_NAME);
                _monitor.downloadSnapshotComplete();
                _state = State.Completed;
            }
        }