public void TestConstructor()
        {
            ThreadPoolExecutor executor = new ThreadPoolExecutor();

            Assert.IsNotNull(executor);
            Assert.IsFalse(executor.IsShutdown);
            executor.Shutdown();
            Assert.IsTrue(executor.IsShutdown);
        }
Пример #2
0
 /// <summary>
 /// Wait out termination of a thread pool or fail doing so
 /// </summary>
 public void JoinPool(ThreadPoolExecutor exec)
 {
     try
     {
         exec.Shutdown();
         Assert.IsTrue(exec.AwaitTermination(TimeSpan.FromSeconds(20)));
     }
     catch (Exception)
     {
         Assert.Fail("Unexpected exception");
     }
 }
Пример #3
0
        internal virtual void Shutdown()
        {
            if (cacheExecutor != null)
            {
                cacheExecutor.Shutdown();
            }
            ICollection <KeyValuePair <string, BlockPoolSlice> > set = bpSlices;

            foreach (KeyValuePair <string, BlockPoolSlice> entry in set)
            {
                entry.Value.Shutdown();
            }
        }
Пример #4
0
 /// <exception cref="System.Exception"/>
 protected override void ServiceStop()
 {
     launcherHandlingThread.Interrupt();
     try
     {
         launcherHandlingThread.Join();
     }
     catch (Exception ie)
     {
         Log.Info(launcherHandlingThread.GetName() + " interrupted during join ", ie);
     }
     launcherPool.Shutdown();
 }
Пример #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);
        }
        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);
        }
        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);
        }
 /// <summary>
 /// Perform a shutdown on the ThreadPoolExecutor.
 /// </summary>
 public void Shutdown()
 {
     if (logger.IsInfoEnabled)
     {
         logger.Info("Shutting down ThreadPoolExecutor" + (_objectName != null ? " '" + _objectName + "'" : ""));
     }
     if (_waitForTasksToCompleteOnShutdown)
     {
         _threadPoolExecutor.Shutdown();
     }
     else
     {
         _threadPoolExecutor.ShutdownNow();
     }
 }
        public void TestAllTasksComplete()
        {
            ThreadPoolExecutor executor = new ThreadPoolExecutor();

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

            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);
        }
Пример #10
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);
        }
 /// <summary>Stops AsyncLazyPersistService for a volume.</summary>
 /// <param name="volume">the root of the volume.</param>
 internal virtual void RemoveVolume(FilePath volume)
 {
     lock (this)
     {
         if (executors == null)
         {
             throw new RuntimeException("AsyncDiskService is already shutdown");
         }
         ThreadPoolExecutor executor = executors[volume];
         if (executor == null)
         {
             throw new RuntimeException("Can not find volume " + volume + " to remove.");
         }
         else
         {
             executor.Shutdown();
             Sharpen.Collections.Remove(executors, volume);
         }
     }
 }
        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);
        }
 public void Stop()
 {
     // Changing the isStarted flag will signal the thread that it needs to shut down.
     if (started.CompareAndSet(true, false))
     {
         DoStopAgent();
         if (worker != null)
         {
             // wait for the worker to stop.
             if (!worker.Join(WORKER_KILL_TIME_SECONDS))
             {
                 Tracer.Info("!! Timeout waiting for discovery agent localThread to stop");
                 worker.Abort();
             }
             worker = null;
             Tracer.Debug("Multicast discovery agent worker thread stopped");
         }
         executor.Shutdown();
         if (!executor.AwaitTermination(TimeSpan.FromMinutes(1)))
         {
             Tracer.DebugFormat("Failed to properly shutdown agent executor {0}", this);
         }
     }
 }
Пример #14
0
 public void Close()
 {
     _closed.Set(true);
     _executor.Shutdown();
 }
Пример #15
0
        public void Close()
        {
            if (!this.closed.Value && !transportFailed.Value)
            {
                this.Stop();
            }

            lock (connectedLock)
            {
                if (this.closed.Value)
                {
                    return;
                }

                try
                {
                    Tracer.InfoFormat("Connection[{0}]: Closing Connection Now.", this.ClientId);
                    this.closing.Value = true;

                    Scheduler scheduler = this.scheduler;
                    if (scheduler != null)
                    {
                        try
                        {
                            scheduler.Stop();
                        }
                        catch (Exception e)
                        {
                            throw NMSExceptionSupport.Create(e);
                        }
                    }

                    lock (sessions.SyncRoot)
                    {
                        foreach (Session session in sessions)
                        {
                            session.Shutdown();
                        }
                    }
                    sessions.Clear();

                    // Connected is true only when we've successfully sent our CONNECT
                    // to the broker, so if we haven't announced ourselves there's no need to
                    // inform the broker of a remove, and if the transport is failed, why bother.
                    if (connected.Value && !transportFailed.Value)
                    {
                        DISCONNECT disconnect = new DISCONNECT();
                        transport.Oneway(disconnect);
                    }

                    executor.Shutdown();
                    if (!executor.AwaitTermination(TimeSpan.FromMinutes(1)))
                    {
                        Tracer.DebugFormat("Connection[{0}]: Failed to properly shutdown its executor", this.ClientId);
                    }

                    Tracer.DebugFormat("Connection[{0}]: Disposing of the Transport.", this.ClientId);
                    transport.Stop();
                    transport.Dispose();
                }
                catch (Exception ex)
                {
                    Tracer.ErrorFormat("Connection[{0}]: Error during connection close: {1}", ClientId, ex);
                }
                finally
                {
                    if (executor != null)
                    {
                        executor.Shutdown();
                    }

                    this.transport       = null;
                    this.closed.Value    = true;
                    this.connected.Value = false;
                    this.closing.Value   = false;
                }
            }
        }
Пример #16
0
        public void Close()
        {
            if (!this.closed.Value && !transportFailed.Value)
            {
                this.Stop();
            }

            lock (myLock)
            {
                if (this.closed.Value)
                {
                    return;
                }

                try
                {
                    Tracer.InfoFormat("Connection[{0}]: Closing Connection Now.", this.ConnectionId);
                    this.closing.Value = true;

                    if (this.advisoryConsumer != null)
                    {
                        this.advisoryConsumer.Dispose();
                        this.advisoryConsumer = null;
                    }

                    lock (sessions.SyncRoot)
                    {
                        foreach (Session session in sessions)
                        {
                            session.Shutdown();
                        }
                    }
                    sessions.Clear();

                    if (this.tempDests.Count > 0)
                    {
                        // Make a copy of the destinations to delete, because the act of deleting
                        // them will modify the collection.
                        ActiveMQTempDestination[] tempDestsToDelete = new ActiveMQTempDestination[this.tempDests.Count];

                        this.tempDests.Values.CopyTo(tempDestsToDelete, 0);
                        foreach (ActiveMQTempDestination dest in tempDestsToDelete)
                        {
                            dest.Delete();
                        }
                    }

                    // Connected is true only when we've successfully sent our ConnectionInfo
                    // to the broker, so if we haven't announced ourselves there's no need to
                    // inform the broker of a remove, and if the transport is failed, why bother.
                    if (connected.Value && !transportFailed.Value)
                    {
                        DisposeOf(ConnectionId);
                        ShutdownInfo shutdowninfo = new ShutdownInfo();
                        transport.Oneway(shutdowninfo);
                    }

                    executor.Shutdown();

                    Tracer.DebugFormat("Connection[{0}]: Disposing of the Transport.", this.ConnectionId);
                    transport.Stop();
                    transport.Dispose();
                }
                catch (Exception ex)
                {
                    Tracer.ErrorFormat("Connection[{0}]: Error during connection close: {1}", ConnectionId, ex);
                }
                finally
                {
                    if (executor != null)
                    {
                        executor.Shutdown();
                    }

                    this.transport       = null;
                    this.closed.Value    = true;
                    this.connected.Value = false;
                    this.closing.Value   = false;
                }
            }
        }
Пример #17
0
        public void Close()
        {
            if (!this.closed.Value && !transportFailed.Value)
            {
                this.Stop();
            }

            lock (myLock)
            {
                if (this.closed.Value)
                {
                    return;
                }

                try
                {
                    Tracer.Info("Connection.Close(): Closing Connection Now.");
                    this.closing.Value = true;

                    if (this.advisoryConsumer != null)
                    {
                        this.advisoryConsumer.Dispose();
                        this.advisoryConsumer = null;
                    }

                    lock (sessions.SyncRoot)
                    {
                        foreach (Session session in sessions)
                        {
                            session.Shutdown();
                        }
                    }
                    sessions.Clear();

                    foreach (ActiveMQTempDestination dest in this.tempDests.Values)
                    {
                        dest.Delete();
                    }

                    // Connected is true only when we've successfully sent our ConnectionInfo
                    // to the broker, so if we haven't announced ourselves there's no need to
                    // inform the broker of a remove, and if the transport is failed, why bother.
                    if (connected.Value && !transportFailed.Value)
                    {
                        DisposeOf(ConnectionId);
                        ShutdownInfo shutdowninfo = new ShutdownInfo();
                        transport.Oneway(shutdowninfo);
                    }

                    executor.Shutdown();

                    Tracer.Info("Connection: Disposing of the Transport.");
                    transport.Dispose();
                }
                catch (Exception ex)
                {
                    Tracer.ErrorFormat("Error during connection close: {0}", ex);
                }
                finally
                {
                    if (executor != null)
                    {
                        executor.Shutdown();
                    }

                    this.transport       = null;
                    this.closed.Value    = true;
                    this.connected.Value = false;
                    this.closing.Value   = false;
                }
            }
        }