public void ShutdownNoContinueExisting()
        {
            ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor(5, Executors.DefaultThreadFactory());

            e.SetExecuteExistingDelayedTasksAfterShutdownPolicy(false);

            bool run = false;

            e.Schedule(new RunnableAction(delegate {
                run = true;
            }), 100, TimeUnit.MILLISECONDS);

            Thread.Sleep(50);

            e.Shutdown();
            Assert.IsTrue(e.IsShutdown());
            Assert.IsTrue(e.IsTerminated(), "Terminated");
            Assert.IsFalse(e.IsTerminating(), "Terminating");

            Thread.Sleep(100);

            Assert.IsFalse(run);
            Assert.IsTrue(e.IsTerminated(), "Terminated");
            Assert.IsFalse(e.IsTerminating(), "Terminating");
        }
        public void Shutdown()
        {
            ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor (5, Executors.DefaultThreadFactory ());
            bool run = false;
            e.Schedule (new RunnableAction (delegate {
                run = true;
            }),100, TimeUnit.MILLISECONDS);

            Thread.Sleep (50);

            e.Shutdown ();
            Assert.IsTrue (e.IsShutdown ());
            Assert.IsFalse (e.IsTerminated (), "Terminated");
            Assert.IsTrue (e.IsTerminating (), "Terminating");

            Thread.Sleep (100);

            Assert.IsTrue (run, "Not run");
            Assert.IsTrue (e.IsTerminated (), "Terminated");
            Assert.IsFalse (e.IsTerminating (), "Terminating");
        }
        public void Shutdown()
        {
            ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor(5, Executors.DefaultThreadFactory());
            bool run = false;

            e.Schedule(new RunnableAction(delegate {
                run = true;
            }), 100, TimeUnit.MILLISECONDS);

            Thread.Sleep(50);

            e.Shutdown();
            Assert.IsTrue(e.IsShutdown());
            Assert.IsFalse(e.IsTerminated(), "Terminated");
            Assert.IsTrue(e.IsTerminating(), "Terminating");

            Thread.Sleep(100);

            Assert.IsTrue(run, "Not run");
            Assert.IsTrue(e.IsTerminated(), "Terminated");
            Assert.IsFalse(e.IsTerminating(), "Terminating");
        }
Exemplo n.º 4
0
 /// <exception cref="System.Exception"/>
 protected override void ServiceStop()
 {
     Log.Info("Stopping JobHistory");
     if (scheduledExecutor != null)
     {
         Log.Info("Stopping History Cleaner/Move To Done");
         scheduledExecutor.Shutdown();
         bool interrupted = false;
         long currentTime = Runtime.CurrentTimeMillis();
         while (!scheduledExecutor.IsShutdown() && Runtime.CurrentTimeMillis() > currentTime
                + 1000l && !interrupted)
         {
             try
             {
                 Sharpen.Thread.Sleep(20);
             }
             catch (Exception)
             {
                 interrupted = true;
             }
         }
         if (!scheduledExecutor.IsShutdown())
         {
             Log.Warn("HistoryCleanerService/move to done shutdown may not have " + "succeeded, Forcing a shutdown"
                      );
             scheduledExecutor.ShutdownNow();
         }
     }
     if (storage != null && storage is Org.Apache.Hadoop.Service.Service)
     {
         ((Org.Apache.Hadoop.Service.Service)storage).Stop();
     }
     if (hsManager != null)
     {
         hsManager.Stop();
     }
     base.ServiceStop();
 }
Exemplo n.º 5
0
        /// <summary>
        /// Queries datanodes for the blocks specified in <code>datanodeBlocks</code>,
        /// making one RPC to each datanode.
        /// </summary>
        /// <remarks>
        /// Queries datanodes for the blocks specified in <code>datanodeBlocks</code>,
        /// making one RPC to each datanode. These RPCs are made in parallel using a
        /// threadpool.
        /// </remarks>
        /// <param name="datanodeBlocks">Map of datanodes to the blocks present on the DN</param>
        /// <returns>metadatas Map of datanodes to block metadata of the DN</returns>
        /// <exception cref="Org.Apache.Hadoop.Hdfs.Security.Token.Block.InvalidBlockTokenException
        ///     ">if client does not have read access on a requested block</exception>
        internal static IDictionary <DatanodeInfo, HdfsBlocksMetadata> QueryDatanodesForHdfsBlocksMetadata
            (Configuration conf, IDictionary <DatanodeInfo, IList <LocatedBlock> > datanodeBlocks
            , int poolsize, int timeoutMs, bool connectToDnViaHostname)
        {
            IList <BlockStorageLocationUtil.VolumeBlockLocationCallable> callables = CreateVolumeBlockLocationCallables
                                                                                         (conf, datanodeBlocks, timeoutMs, connectToDnViaHostname, Trace.CurrentSpan());
            // Use a thread pool to execute the Callables in parallel
            IList <Future <HdfsBlocksMetadata> > futures = new AList <Future <HdfsBlocksMetadata> >
                                                               ();
            ExecutorService executor = new ScheduledThreadPoolExecutor(poolsize);

            try
            {
                futures = executor.InvokeAll(callables, timeoutMs, TimeUnit.Milliseconds);
            }
            catch (Exception)
            {
            }
            // Swallow the exception here, because we can return partial results
            executor.Shutdown();
            IDictionary <DatanodeInfo, HdfsBlocksMetadata> metadatas = Maps.NewHashMapWithExpectedSize
                                                                           (datanodeBlocks.Count);

            // Fill in metadatas with results from DN RPCs, where possible
            for (int i = 0; i < futures.Count; i++)
            {
                BlockStorageLocationUtil.VolumeBlockLocationCallable callable = callables[i];
                DatanodeInfo datanode = callable.GetDatanodeInfo();
                Future <HdfsBlocksMetadata> future = futures[i];
                try
                {
                    HdfsBlocksMetadata metadata = future.Get();
                    metadatas[callable.GetDatanodeInfo()] = metadata;
                }
                catch (CancellationException e)
                {
                    Log.Info("Cancelled while waiting for datanode " + datanode.GetIpcAddr(false) + ": "
                             + e.ToString());
                }
                catch (ExecutionException e)
                {
                    Exception t = e.InnerException;
                    if (t is InvalidBlockTokenException)
                    {
                        Log.Warn("Invalid access token when trying to retrieve " + "information from datanode "
                                 + datanode.GetIpcAddr(false));
                        throw (InvalidBlockTokenException)t;
                    }
                    else
                    {
                        if (t is NotSupportedException)
                        {
                            Log.Info("Datanode " + datanode.GetIpcAddr(false) + " does not support" + " required #getHdfsBlocksMetadata() API"
                                     );
                            throw (NotSupportedException)t;
                        }
                        else
                        {
                            Log.Info("Failed to query block locations on datanode " + datanode.GetIpcAddr(false
                                                                                                          ) + ": " + t);
                        }
                    }
                    if (Log.IsDebugEnabled())
                    {
                        Log.Debug("Could not fetch information from datanode", t);
                    }
                }
                catch (Exception)
                {
                    // Shouldn't happen, because invokeAll waits for all Futures to be ready
                    Log.Info("Interrupted while fetching HdfsBlocksMetadata");
                }
            }
            return(metadatas);
        }
		public void ShutdownNoContinueExisting ()
		{
			ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor (5, Executors.DefaultThreadFactory ());
			e.SetExecuteExistingDelayedTasksAfterShutdownPolicy (false);
			
			bool run = false;
			e.Schedule (new RunnableAction (delegate {
				run = true;
			}),100, TimeUnit.MILLISECONDS);
			
			Thread.Sleep (50);
			
			e.Shutdown ();
			Assert.IsTrue (e.IsShutdown ());
			Assert.IsTrue (e.IsTerminated (), "Terminated");
			Assert.IsFalse (e.IsTerminating (), "Terminating");
			
			Thread.Sleep (100);
			
			Assert.IsFalse (run);
			Assert.IsTrue (e.IsTerminated (), "Terminated");
			Assert.IsFalse (e.IsTerminating (), "Terminating");
		}
Exemplo n.º 7
0
        protected override void OnPause()
        {
            updater.Shutdown();

            base.OnPause();
        }