예제 #1
0
        public void Stop(Boolean setToFaulted)
        {
            _logger.InfoFormat("CommitPollingClient {0}: Stop called, set to faulted {1}", _id, setToFaulted);
            if (Status == CommitPollingClientStatus.Polling)
            {
                if (_innerClient == null)
                {
                    throw new JarvisFrameworkEngineException($"CommitPollingClient {_id}: Cannot stop polling client because you forget to call Configure First");
                }

                if (Status != CommitPollingClientStatus.Polling)
                {
                    _logger.WarnFormat($"CommitPollingClient {0}: Cannot stop poller poller is in unstoppable status: {1}", _id, Status);
                    return;
                }

                _innerClient.Stop();
                CloseEverything();
                Status = setToFaulted ?
                         CommitPollingClientStatus.Faulted :
                         CommitPollingClientStatus.Stopped;
            }
            else
            {
                _logger.WarnFormat("CommitPollingClient {0}: Stop called but it was not started", _id);
            }
        }
예제 #2
0
 public async Task ShutdownAsync()
 {
     if (_pollingClient != null)
     {
         await _pollingClient.Stop().ConfigureAwait(false);
     }
 }
예제 #3
0
        public async Task polling_client_should_not_miss_data(int parallelism, bool autopolling)
        {
            _logger.LogDebug("Starting with {Parallelism} workers and Autopolling {Autopolling}", parallelism, autopolling);

            var sequenceChecker = new StrictSequenceChecker($"Workers {parallelism} autopolling {autopolling}");
            var poller          = new PollingClient(Store, 0, sequenceChecker, this.LoggerFactory)
            {
                PollingIntervalMilliseconds = 0,
                HoleDetectionTimeout        = 1000
            };

            if (autopolling)
            {
                poller.Start();
                _logger.LogDebug("Started Polling");
            }

            const int range = 1000;

            var producer = new ActionBlock <int>(async i =>
            {
                await Store.AppendAsync("p", i, "demo", "op#" + i).ConfigureAwait(false);
            }, new ExecutionDataflowBlockOptions()
            {
                MaxDegreeOfParallelism = parallelism
            });

            _logger.LogDebug("Started pushing data: {elements} elements", range);

            foreach (var i in Enumerable.Range(1, range))
            {
                Assert.True(await producer.SendAsync(i).ConfigureAwait(false));
            }

            producer.Complete();
            await producer.Completion.ConfigureAwait(false);

            _logger.LogDebug("Data pushed");

            if (autopolling)
            {
                _logger.LogDebug("Stopping poller");
                await poller.Stop();

                _logger.LogDebug("Poller stopped");
            }

            // read to end
            _logger.LogDebug("Polling to end");
            var timeout = new CancellationTokenSource(60000);
            await poller.Poll(timeout.Token).ConfigureAwait(false);

            _logger.LogDebug("Polling to end - done");

            Assert.True(poller.Position == sequenceChecker.Position, "Sequence " + sequenceChecker.Position + " != Position " + poller.Position);
            Assert.True(range == poller.Position, "Poller @" + poller.Position);
            Assert.True(range == sequenceChecker.Position, "Sequence @" + sequenceChecker.Position);
        }
예제 #4
0
        /// <summary>
        /// Create a poller, start the poller and return starting position of the poller.
        /// </summary>
        /// <param name="poller"></param>
        /// <param name="pollerId"></param>
        /// <returns></returns>
        private Int64 CreatePollerAndStart(ref PollingClient poller, Int32 pollerId, Func <AtomicDispatchChunk, Task <Boolean> > dispatchToTplFunction)
        {
            if (poller != null)
            {
                poller.Stop();
            }
            var startingPosition = TryGetStartingPoint(pollerId);

            Logger.InfoFormat("AtomicProjectionEngine: Starting poller id {0} from position {1}", pollerId, startingPosition);
            var subscription = new JarvisFrameworkLambdaSubscription(c => dispatchToTplFunction(new AtomicDispatchChunk(pollerId, c)));

            poller = new PollingClient(_persistence, startingPosition, subscription, _nStoreLoggerFactory);
            poller.Start();
            return(startingPosition);
        }
예제 #5
0
        /// <summary>
        /// Create a poller, start the poller and return starting position of the poller.
        /// </summary>
        /// <param name="poller"></param>
        /// <param name="pollerId"></param>
        /// <returns></returns>
        private Int64 CreatePollerAndStart(ref PollingClient poller, Int32 pollerId, Func <AtomicDispatchChunk, Task <Boolean> > dispatchToTplFunction)
        {
            if (poller != null)
            {
                poller.Stop();
            }
            //The default value to start is zero, it is a situation that should never happen, if it happens this poller has no projection to dispatch.
            var startingPosition = TryGetStartingPoint(pollerId, 0);

            Logger.InfoFormat("AtomicProjectionEngine: Starting poller id {0} from position {1}", pollerId, startingPosition);
            var subscription = new JarvisFrameworkLambdaSubscription(c => dispatchToTplFunction(new AtomicDispatchChunk(pollerId, c)));

            poller = new PollingClient(_persistence, startingPosition, subscription, _nStoreLoggerFactory);
            poller.Start();
            return(startingPosition);
        }
예제 #6
0
 public void Dispose()
 {
     _poller.Stop().GetAwaiter().GetResult();
 }
예제 #7
0
 public void Stop()
 {
     _pollingClient.Stop();
 }