hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z..@apache.org
Subject hadoop git commit: HADOOP-13290. Appropriate use of generics in FairCallQueue. Contributed by Jonathan Hung.
Date Wed, 13 Jul 2016 23:57:54 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2.6 9684b659f -> fc335e529


HADOOP-13290. Appropriate use of generics in FairCallQueue. Contributed by Jonathan Hung.

(cherry picked from commit 728bf7f6988e13f17f03d2e3a4037b7238c4fd45)
(cherry picked from commit b95f1af8a9aafb3e482c7b8825f2097f2ceb0e8e)
(cherry picked from commit cbd885b6fa26b7a84a4a19d6084d95665f21378a)
(cherry picked from commit 45ed97e0d2a5a842842c3738f0413345aa633184)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/fc335e52
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/fc335e52
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/fc335e52

Branch: refs/heads/branch-2.6
Commit: fc335e52976d62f651d7b768a18bfb48d73aec61
Parents: 9684b65
Author: Zhe Zhang <zhz@apache.org>
Authored: Wed Jul 13 16:37:40 2016 -0700
Committer: Zhe Zhang <zhz@apache.org>
Committed: Wed Jul 13 16:52:38 2016 -0700

----------------------------------------------------------------------
 .../org/apache/hadoop/ipc/FairCallQueue.java    | 15 +++++++-------
 .../apache/hadoop/ipc/TestFairCallQueue.java    | 21 +++++++++++++++++++-
 2 files changed, 28 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/fc335e52/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/FairCallQueue.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/FairCallQueue.java
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/FairCallQueue.java
index 6a6701a..89f6799 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/FairCallQueue.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/FairCallQueue.java
@@ -313,7 +313,7 @@ public class FairCallQueue<E extends Schedulable> extends AbstractQueue<E>
   @Override
   public int size() {
     int size = 0;
-    for (BlockingQueue q : this.queues) {
+    for (BlockingQueue<E> q : this.queues) {
       size += q.size();
     }
     return size;
@@ -359,7 +359,7 @@ public class FairCallQueue<E extends Schedulable> extends AbstractQueue<E>
   @Override
   public int remainingCapacity() {
     int sum = 0;
-    for (BlockingQueue q : this.queues) {
+    for (BlockingQueue<E> q : this.queues) {
       sum += q.remainingCapacity();
     }
     return sum;
@@ -375,7 +375,7 @@ public class FairCallQueue<E extends Schedulable> extends AbstractQueue<E>
       new HashMap<String, MetricsProxy>();
 
     // Weakref for delegate, so we don't retain it forever if it can be GC'd
-    private WeakReference<FairCallQueue> delegate;
+    private WeakReference<FairCallQueue<? extends Schedulable>> delegate;
 
     // Keep track of how many objects we registered
     private int revisionNumber = 0;
@@ -394,14 +394,15 @@ public class FairCallQueue<E extends Schedulable> extends AbstractQueue<E>
       return mp;
     }
 
-    public void setDelegate(FairCallQueue obj) {
-      this.delegate = new WeakReference<FairCallQueue>(obj);
+    public void setDelegate(FairCallQueue<? extends Schedulable> obj) {
+      this.delegate
+          = new WeakReference<FairCallQueue<? extends Schedulable>>(obj);
       this.revisionNumber++;
     }
 
     @Override
     public int[] getQueueSizes() {
-      FairCallQueue obj = this.delegate.get();
+      FairCallQueue<? extends Schedulable> obj = this.delegate.get();
       if (obj == null) {
         return new int[]{};
       }
@@ -411,7 +412,7 @@ public class FairCallQueue<E extends Schedulable> extends AbstractQueue<E>
 
     @Override
     public long[] getOverflowedCalls() {
-      FairCallQueue obj = this.delegate.get();
+      FairCallQueue<? extends Schedulable> obj = this.delegate.get();
       if (obj == null) {
         return new long[]{};
       }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/fc335e52/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestFairCallQueue.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestFairCallQueue.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestFairCallQueue.java
index bc1b588..95b52a0 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestFairCallQueue.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestFairCallQueue.java
@@ -23,6 +23,9 @@ import static org.mockito.Mockito.when;
 
 import junit.framework.TestCase;
 
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import java.lang.management.ManagementFactory;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.BlockingQueue;
@@ -394,4 +397,20 @@ public class TestFairCallQueue extends TestCase {
     assertEquals(call, fcq.take());
     assertEquals(0, fcq.size());
   }
-}
\ No newline at end of file
+
+  public void testFairCallQueueMXBean() throws Exception {
+    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+    ObjectName mxbeanName = new ObjectName(
+        "Hadoop:service=ns,name=FairCallQueue");
+
+    Schedulable call = mockCall("c");
+    fcq.put(call);
+    int[] queueSizes = (int[]) mbs.getAttribute(mxbeanName, "QueueSizes");
+    assertEquals(1, queueSizes[0]);
+    assertEquals(0, queueSizes[1]);
+    fcq.take();
+    queueSizes = (int[]) mbs.getAttribute(mxbeanName, "QueueSizes");
+    assertEquals(0, queueSizes[0]);
+    assertEquals(0, queueSizes[1]);
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message