public void Waiting(IThreadState state)
        {
            if (ShouldNotifyDistributor())
            {
                _bus.Send(new WorkerThreadAvailableCommand
                {
                    Identifier        = _identifier,
                    InboxWorkQueueUri = _configuration.Inbox.WorkQueue.Uri.ToString(),
                    ManagedThreadId   = Thread.CurrentThread.ManagedThreadId,
                    DateSent          = DateTime.Now
                },
                          c => c.WithRecipient(_configuration.Worker.DistributorControlInboxWorkQueue));

                if (_log.IsVerboseEnabled)
                {
                    _log.Verbose(string.Format(EsbResources.DebugWorkerAvailable,
                                               _identifier,
                                               _configuration.Inbox.WorkQueue.Uri.Secured(),
                                               _configuration.Worker.DistributorControlInboxWorkQueue.Uri.Secured()));
                }

                _nextNotificationDate = DateTime.Now.AddSeconds(_configuration.Worker.ThreadAvailableNotificationIntervalSeconds);
            }

            _threadActivity.Waiting(state);
        }
예제 #2
0
        public void Should_be_able_to_have_the_thread_wait()
        {
            var activity = new ThreadActivity(new[]
            {
                TimeSpan.FromMilliseconds(250),
                TimeSpan.FromMilliseconds(500)
            });

            var start = DateTime.Now;
            var token = new CancellationToken(false);

            activity.Waiting(token);

            Assert.IsTrue((DateTime.Now - start).TotalMilliseconds >= 250);

            activity.Waiting(token);

            Assert.IsTrue((DateTime.Now - start).TotalMilliseconds >= 750);
        }
예제 #3
0
        public void Should_be_able_to_have_the_thread_wait()
        {
            var activity = new ThreadActivity(new[]
            {
                TimeSpan.FromMilliseconds(250),
                TimeSpan.FromMilliseconds(500)
            });

            var start = DateTime.Now;

            var mockState = new Mock <IThreadState>();

            mockState.Setup(mock => mock.Active).Returns(true);

            activity.Waiting(mockState.Object);

            Assert.IsTrue((DateTime.Now - start).TotalMilliseconds >= 250);

            activity.Waiting(mockState.Object);

            Assert.IsTrue((DateTime.Now - start).TotalMilliseconds >= 750);
        }
예제 #4
0
        public void Should_be_able_to_have_the_thread_wait()
        {
            var activity = new ThreadActivity(new[]
                                                  {
                                                      TimeSpan.FromMilliseconds(250),
                                                      TimeSpan.FromMilliseconds(500)
                                                  });

            var start = DateTime.Now;

            var mockState = new Mock<IActiveState>();

            mockState.Setup(mock => mock.Active).Returns(true);

            activity.Waiting(mockState.Object);

            Assert.IsTrue((DateTime.Now - start).TotalMilliseconds >= 250);

            activity.Waiting(mockState.Object);

            Assert.IsTrue((DateTime.Now - start).TotalMilliseconds >= 750);
        }