示例#1
0
        public EpidemicBroadcastServiceImpl(
            ILogger logger,
            EpidemicBroadcastServiceOption options,
            IStopwatchProvider stopwatchProvider,
            GossiperImpl gossiperImpl,
            Func <IReadOnlyList <string> > memberListProvider,
            Func <string, Gossiper.GossiperClient> gossiperClientFactory,
            EventHandler <RumorReceivedEventArgs> onRumorReceived)
        {
            this.logger                = logger;
            this.options               = options;
            this.stopwatchProvider     = stopwatchProvider;
            this.gossiperImpl          = gossiperImpl;
            this.memberListProvider    = memberListProvider;
            this.gossiperClientFactory = gossiperClientFactory;
            this.onRumorReceived       = onRumorReceived;

            gossiperImpl.OnPull += PassivePullRumors;
            gossiperImpl.OnPush += PassivePushRumors;

            backgroundTaskCancellationTokenSource = new CancellationTokenSource();
            backgroundTask = Task.Factory.StartNew(
                () => RunBackgroundTaskAsync(backgroundTaskCancellationTokenSource.Token).GetAwaiter().GetResult(),
                backgroundTaskCancellationTokenSource.Token,
                TaskCreationOptions.LongRunning,
                TaskScheduler.Current);
        }
        public EpidemicBroadcastService(
            ILogger <EpidemicBroadcastService> logger,
            IOptions <EpidemicBroadcastServiceOption> options,
            IStopwatchProvider stopwatchProvider)
        {
            this.logger            = logger;
            this.options           = options.Value;
            this.stopwatchProvider = stopwatchProvider;

            gossiperImpl = new GossiperImpl();
        }