コード例 #1
0
ファイル: NyxBorg.cs プロジェクト: ycdivfx/nyx
        /// <summary>
        ///     Protected default construtor for creating a new id.
        /// </summary>
        public NyxBorg(
            ILogger <NyxBorg> logger,
            IConfigManager config,
            PluginManager plugman)
        {
            NodeId  = Guid.NewGuid().ToString("N");
            _config = config;
            _logger = logger;
            _config.WhenConfigChanges.ObserveOn(ThreadPoolScheduler.Instance).Subscribe(LoadConfig);
            _plugman = plugman;

            _messageLoopToken  = _messageLoopCancelation.Token;
            _serverCancelToken = _serverCancelationSource.Token;

            _disposables.Add(_messageSendResetEvent);
            _disposables.Add(_serverEvent);
            _disposables.Add(_messageLoopCancelation);
            _disposables.Add(_serverCancelationSource);

            LoadConfig(null);
            Heartbeat.CreateInstance(_lastHubIp, _port);
            //_heartbeat = new Heartbeat(_context, _lastHubIp, _port.ToString());
            ConnectionStatusStream = Observable.Create <ConnectionStatus>(o =>
            {
                _logger.Debug("Hearbeat restarted.");
                Heartbeat.Instance.Init();
                return(Heartbeat.Instance.ConnectionStatusStream.Subscribe(o));
            }).Repeat().Publish().RefCount();

            _disposables.Add(ConnectionStatusStream
                             .ObserveOn(ThreadPoolScheduler.Instance)
                             .Subscribe(x => _hubOnline = x.HasFlag(ConnectionStatus.Online)));

            _disposables.Add(NyxMessageStream.Subscribe(x =>
            {
                if (TotalInMessages == long.MaxValue)
                {
                    TotalInMessages = 0;
                }
                TotalInMessages++;
            }));

            _disposables.Add(OutMessageStream.Subscribe(x =>
            {
                if (TotalInMessages == long.MaxValue)
                {
                    TotalOutMessages = 0;
                }
                TotalOutMessages++;
            }));
        }