Esempio n. 1
0
 /// <exception cref="System.IO.IOException"/>
 internal Emptier(TrashPolicyDefault _enclosing, Configuration conf, long emptierInterval
                  )
 {
     this._enclosing      = _enclosing;
     this.conf            = conf;
     this.emptierInterval = emptierInterval;
     if (emptierInterval > this._enclosing.deletionInterval || emptierInterval == 0)
     {
         TrashPolicyDefault.Log.Info("The configured checkpoint interval is " + (emptierInterval
                                                                                 / TrashPolicyDefault.MsecsPerMinute) + " minutes." + " Using an interval of " +
                                     (this._enclosing.deletionInterval / TrashPolicyDefault.MsecsPerMinute) + " minutes that is used for deletion instead"
                                     );
         this.emptierInterval = this._enclosing.deletionInterval;
     }
 }
Esempio n. 2
0
            public virtual void Run()
            {
                if (this.emptierInterval == 0)
                {
                    return;
                }
                // trash disabled
                long now = Time.Now();
                long end;

                while (true)
                {
                    end = this.Ceiling(now, this.emptierInterval);
                    try
                    {
                        // sleep for interval
                        Thread.Sleep(end - now);
                    }
                    catch (Exception)
                    {
                        break;
                    }
                    // exit on interrupt
                    try
                    {
                        now = Time.Now();
                        if (now >= end)
                        {
                            FileStatus[] homes = null;
                            try
                            {
                                homes = this._enclosing.fs.ListStatus(this._enclosing.homesParent);
                            }
                            catch (IOException e)
                            {
                                // list all home dirs
                                TrashPolicyDefault.Log.Warn("Trash can't list homes: " + e + " Sleeping.");
                                continue;
                            }
                            foreach (FileStatus home in homes)
                            {
                                // dump each trash
                                if (!home.IsDirectory())
                                {
                                    continue;
                                }
                                try
                                {
                                    TrashPolicyDefault trash = new TrashPolicyDefault(this._enclosing.fs, home.GetPath
                                                                                          (), this.conf);
                                    trash.DeleteCheckpoint();
                                    trash.CreateCheckpoint();
                                }
                                catch (IOException e)
                                {
                                    TrashPolicyDefault.Log.Warn("Trash caught: " + e + ". Skipping " + home.GetPath()
                                                                + ".");
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        TrashPolicyDefault.Log.Warn("RuntimeException during Trash.Emptier.run(): ", e);
                    }
                }
                try
                {
                    this._enclosing.fs.Close();
                }
                catch (IOException e)
                {
                    TrashPolicyDefault.Log.Warn("Trash cannot close FileSystem: ", e);
                }
            }