コード例 #1
0
 /// <summary>
 /// Periodically check in with the namenode and renew all the leases
 /// when the lease period is half over.
 /// </summary>
 /// <exception cref="System.Exception"/>
 private void Run(int id)
 {
     for (long lastRenewed = Time.MonotonicNow(); !Sharpen.Thread.Interrupted(); Sharpen.Thread
          .Sleep(GetSleepPeriod()))
     {
         long elapsed = Time.MonotonicNow() - lastRenewed;
         if (elapsed >= GetRenewalTime())
         {
             try
             {
                 Renew();
                 if (Log.IsDebugEnabled())
                 {
                     Log.Debug("Lease renewer daemon for " + ClientsString() + " with renew id " + id
                               + " executed");
                 }
                 lastRenewed = Time.MonotonicNow();
             }
             catch (SocketTimeoutException ie)
             {
                 Log.Warn("Failed to renew lease for " + ClientsString() + " for " + (elapsed / 1000
                                                                                      ) + " seconds.  Aborting ...", ie);
                 lock (this)
                 {
                     while (!dfsclients.IsEmpty())
                     {
                         DFSClient dfsClient = dfsclients[0];
                         dfsClient.CloseAllFilesBeingWritten(true);
                         CloseClient(dfsClient);
                     }
                     //Expire the current LeaseRenewer thread.
                     emptyTime = 0;
                 }
                 break;
             }
             catch (IOException ie)
             {
                 Log.Warn("Failed to renew lease for " + ClientsString() + " for " + (elapsed / 1000
                                                                                      ) + " seconds.  Will retry shortly ...", ie);
             }
         }
         lock (this)
         {
             if (id != currentId || IsRenewerExpired())
             {
                 if (Log.IsDebugEnabled())
                 {
                     if (id != currentId)
                     {
                         Log.Debug("Lease renewer daemon for " + ClientsString() + " with renew id " + id
                                   + " is not current");
                     }
                     else
                     {
                         Log.Debug("Lease renewer daemon for " + ClientsString() + " with renew id " + id
                                   + " expired");
                     }
                 }
                 //no longer the current daemon or expired
                 return;
             }
             // if no clients are in running state or there is no more clients
             // registered with this renewer, stop the daemon after the grace
             // period.
             if (!ClientsRunning() && emptyTime == long.MaxValue)
             {
                 emptyTime = Time.MonotonicNow();
             }
         }
     }
 }