meszibalu commented on a change in pull request #2685:
URL: https://github.com/apache/hbase/pull/2685#discussion_r527938826



##########
File path: hbase-client/src/main/java/org/apache/hadoop/hbase/util/PoolMap.java
##########
@@ -275,43 +272,70 @@ public static PoolType fuzzyMatch(String name) {
    *
    */
   @SuppressWarnings("serial")
-  static class RoundRobinPool<R> extends CopyOnWriteArrayList<R> implements 
Pool<R> {
-    private int maxSize;
-    private int nextResource = 0;
+  static class RoundRobinPool<R> implements Pool<R> {
+    private final List<R> resources;
+    private final int maxSize;
+
+    private int nextIndex;
 
     public RoundRobinPool(int maxSize) {
+      if (maxSize <= 0) {
+        throw new IllegalArgumentException("maxSize must be positive");
+      }
+
+      resources = new ArrayList<>(maxSize);
       this.maxSize = maxSize;
     }
 
     @Override
-    public R put(R resource) {
-      if (super.size() < maxSize) {
-        add(resource);
+    public R get() {
+      int size = resources.size();
+
+      /* letting pool to grow */
+      if (size < maxSize) {
+        return null;
       }
+
+      R resource = resources.get(nextIndex);
+
+      /* at this point size cannot be 0 */
+      nextIndex = (nextIndex + 1) % size;
+
+      return resource;
+    }
+
+    @Override
+    public R put(R resource) {
+      resources.add(resource);

Review comment:
       It was because of the `Map` conformity.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to