hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r630389 - in /hadoop/hbase/trunk: CHANGES.txt src/java/org/apache/hadoop/hbase/Leases.java
Date Sat, 23 Feb 2008 04:44:12 GMT
Author: jimk
Date: Fri Feb 22 20:44:11 2008
New Revision: 630389

URL: http://svn.apache.org/viewvc?rev=630389&view=rev
Log:
HBASE-461   Simplify leases.

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/Leases.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=630389&r1=630388&r2=630389&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Fri Feb 22 20:44:11 2008
@@ -59,7 +59,8 @@
    HBASE-414   Move client classes into client package
    HBASE-79    When HBase needs to be migrated, it should display a message on
                stdout, not just in the logs
-   
+   HBASE-461   Simplify leases.
+
 Branch 0.1
 
   INCOMPATIBLE CHANGES

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/Leases.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/Leases.java?rev=630389&r1=630388&r2=630389&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/Leases.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/Leases.java Fri Feb 22 20:44:11 2008
@@ -50,8 +50,6 @@
   private volatile DelayQueue<Lease> leaseQueue = new DelayQueue<Lease>();
 
   protected final Map<String, Lease> leases = new HashMap<String, Lease>();
-  protected final Map<String, LeaseListener> listeners =
-    new HashMap<String, LeaseListener>();
   private volatile boolean stopRequested = false;
 
   /**
@@ -84,17 +82,14 @@
         continue;
       }
       // A lease expired
-      LeaseListener listener = null;
       synchronized (leaseQueue) {
-        String leaseName = lease.getLeaseName();
-        leases.remove(leaseName);
-        listener = listeners.remove(leaseName);
-        if (listener == null) {
-          LOG.error("lease listener is null for lease " + leaseName);
+        leases.remove(lease.getLeaseName());
+        if (lease.getListener() == null) {
+          LOG.error("lease listener is null for lease " + lease.getLeaseName());
           continue;
         }
       }
-      listener.leaseExpired();
+      lease.getListener().leaseExpired();
     }
     close();
   }
@@ -120,7 +115,6 @@
     synchronized (leaseQueue) {
       leaseQueue.clear();
       leases.clear();
-      listeners.clear();
       leaseQueue.notifyAll();
     }
     LOG.info(Thread.currentThread().getName() + " closed leases");
@@ -136,14 +130,14 @@
     if (stopRequested) {
       return;
     }
-    Lease lease = new Lease(leaseName, System.currentTimeMillis() + leasePeriod);
+    Lease lease = new Lease(leaseName, listener,
+        System.currentTimeMillis() + leasePeriod);
     synchronized (leaseQueue) {
       if (leases.containsKey(leaseName)) {
         throw new IllegalStateException("lease '" + leaseName +
             "' already exists");
       }
       leases.put(leaseName, lease);
-      listeners.put(leaseName, listener);
       leaseQueue.add(lease);
     }
   }
@@ -179,17 +173,18 @@
             "' does not exist");
       }
       leaseQueue.remove(lease);
-      listeners.remove(leaseName);
     }
   }
 
   /** This class tracks a single Lease. */
   private static class Lease implements Delayed {
     private final String leaseName;
+    private final LeaseListener listener;
     private long expirationTime;
 
-    Lease(final String leaseName, long expirationTime) {
+    Lease(final String leaseName, LeaseListener listener, long expirationTime) {
       this.leaseName = leaseName;
+      this.listener = listener;
       this.expirationTime = expirationTime;
     }
 
@@ -197,6 +192,11 @@
     public String getLeaseName() {
       return leaseName;
     }
+    
+    /** @return listener */
+    public LeaseListener getListener() {
+      return this.listener;
+    }
 
     /** {@inheritDoc} */
     @Override
@@ -219,16 +219,9 @@
     /** {@inheritDoc} */
     public int compareTo(Delayed o) {
       long delta = this.getDelay(TimeUnit.MILLISECONDS) -
-      o.getDelay(TimeUnit.MILLISECONDS);
+        o.getDelay(TimeUnit.MILLISECONDS);
 
-      int value = 0;
-      if (delta > 0) {
-        value = 1;
-
-      } else if (delta < 0) {
-        value = -1;
-      }
-      return value;
+      return this.equals(o) ? 0 : (delta > 0 ? 1 : -1);
     }
 
     /** @param expirationTime the expirationTime to set */



Mime
View raw message