protected void FireServiceRemoveEvent(DiscoveryEvent data)
 {
     if (serviceRemoveHandler != null && started.Value)
     {
         // Have the listener process the event async so that
         // he does not block this thread since we are doing time sensitive
         // processing of events.
         executor.QueueUserWorkItem(ServiceRemoveCallback, data);
     }
 }
        public void TestAllTasksCompleteAfterException()
        {
            ThreadPoolExecutor executor = new ThreadPoolExecutor();

            Assert.IsNotNull(executor);
            Assert.IsFalse(executor.IsShutdown);

            executor.QueueUserWorkItem(TaskThatThrowsAnException);

            for (int i = 0; i < JOB_COUNT; ++i)
            {
                executor.QueueUserWorkItem(TaskThatCountsDown);
            }

            Assert.IsTrue(this.doneLatch.await(TimeSpan.FromMilliseconds(30 * 1000)));

            executor.Shutdown();
            Assert.IsTrue(executor.IsShutdown);
        }
        public void TestThatShutdownPurgesTasks()
        {
            ThreadPoolExecutor executor = new ThreadPoolExecutor();

            Assert.IsNotNull(executor);
            Assert.IsFalse(executor.IsShutdown);

            executor.QueueUserWorkItem(TaskThatSleeps);

            for (int i = 0; i < JOB_COUNT; ++i)
            {
                executor.QueueUserWorkItem(TaskThatIncrementsCount);
            }

            Thread.Sleep(100);

            executor.Shutdown();
            Assert.AreEqual(0, count);
            Assert.IsTrue(executor.IsShutdown);
        }
示例#4
0
        internal void OnAsyncException(Exception error)
        {
            if (!this.closed.Value && !this.closing.Value)
            {
                if (this.ExceptionListener != null)
                {
                    if (!(error is NMSException))
                    {
                        error = NMSExceptionSupport.Create(error);
                    }
                    NMSException e = (NMSException)error;

                    // Called in another thread so that processing can continue
                    // here, ensures no lock contention.
                    executor.QueueUserWorkItem(AsyncCallExceptionListener, e);
                }
                else
                {
                    Tracer.Debug("Async exception with no exception listener: " + error);
                }
            }
        }
示例#5
0
        public void TestIsTerminated()
        {
            ThreadPoolExecutor executor = new ThreadPoolExecutor();

            Assert.IsNotNull(executor);
            Assert.IsFalse(executor.IsShutdown);
            Assert.IsFalse(executor.IsTerminated);

            executor.QueueUserWorkItem(TaskThatSleeps);
            executor.Shutdown();

            JoinPool(executor);
            Assert.IsTrue(executor.IsTerminated);
        }
示例#6
0
        private void OnAsyncException(Exception error)
        {
            if (_closed.Value || _closing.Value)
            {
                return;
            }
            if (ExceptionListener != null)
            {
                if (!(error is StompException))
                {
                    error = error.Create();
                }
                var e = (StompException)error;

                // Called in another thread so that processing can continue
                // here, ensures no lock contention.
                _executor.QueueUserWorkItem(AsyncCallExceptionListener, e);
            }
            else
            {
                Tracer.WarnFormat("Async exception with no exception listener: {0}", error.Message);
            }
        }
        public void TestTaskParamIsPropagated()
        {
            ThreadPoolExecutor executor = new ThreadPoolExecutor();

            Assert.IsNotNull(executor);
            Assert.IsFalse(executor.IsShutdown);

            executor.QueueUserWorkItem(TaskThatValidatesTheArg, new DummyClass(10));

            this.complete.WaitOne();
            Assert.IsTrue(this.waitingTaskCompleted);

            executor.Shutdown();
            Assert.IsTrue(executor.IsShutdown);
        }
        public void TestSingleTaskExecuted()
        {
            ThreadPoolExecutor executor = new ThreadPoolExecutor();

            Assert.IsNotNull(executor);
            Assert.IsFalse(executor.IsShutdown);

            executor.QueueUserWorkItem(TaskThatSignalsWhenItsComplete);

            this.complete.WaitOne();
            Assert.IsTrue(this.waitingTaskCompleted);

            executor.Shutdown();
            Assert.IsTrue(executor.IsShutdown);
        }
示例#9
0
        public void TestAwaitTermination()
        {
            ThreadPoolExecutor executor = new ThreadPoolExecutor();

            Assert.IsNotNull(executor);
            Assert.IsFalse(executor.IsShutdown);
            Assert.IsFalse(executor.IsTerminated);

            executor.QueueUserWorkItem(TaskThatSleeps);
            executor.Shutdown();

            Assert.IsFalse(executor.IsTerminated, "Terminated before await.");
            Assert.IsFalse(executor.AwaitTermination(TimeSpan.FromMilliseconds(500)), "Should be terminated yet.");
            Assert.IsFalse(executor.IsTerminated, "Terminated after await.");

            JoinPool(executor);
            Assert.IsTrue(executor.IsTerminated);
        }