aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zma...@apache.org
Subject aurora git commit: Replace BoundedQueue with Guava's EvictingQueue.
Date Wed, 09 Sep 2015 23:53:16 GMT
Repository: aurora
Updated Branches:
  refs/heads/master a5ac5b964 -> 98f692d16


Replace BoundedQueue with Guava's EvictingQueue.

Testing Done:
./gradlew build -Pq

Reviewed at https://reviews.apache.org/r/38202/


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

Branch: refs/heads/master
Commit: 98f692d168f24cbdfdfce952aad8c03770a6e741
Parents: a5ac5b9
Author: Zameer Manji <zmanji@apache.org>
Authored: Wed Sep 9 16:52:57 2015 -0700
Committer: Zameer Manji <zmanji@apache.org>
Committed: Wed Sep 9 16:52:57 2015 -0700

----------------------------------------------------------------------
 .../aurora/common/collections/BoundedQueue.java | 76 --------------------
 .../common/stats/TimeSeriesRepositoryImpl.java  | 10 +--
 .../common/collections/BoundedQueueTest.java    | 57 ---------------
 3 files changed, 5 insertions(+), 138 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/98f692d1/commons/src/main/java/org/apache/aurora/common/collections/BoundedQueue.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/collections/BoundedQueue.java
b/commons/src/main/java/org/apache/aurora/common/collections/BoundedQueue.java
deleted file mode 100644
index 3e2d5fa..0000000
--- a/commons/src/main/java/org/apache/aurora/common/collections/BoundedQueue.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.aurora.common.collections;
-
-import java.util.Iterator;
-import java.util.concurrent.LinkedBlockingDeque;
-
-/**
- * A limited implementation of a bounded queue.  Values can be added and iterated over, and
will
- * automatically expire when the queue exceeds capacity.
- *
- * @param <T> The type that this queue contains.
- *
- * @author William Farner
-*/
-public class BoundedQueue<T> implements Iterable<T> {
-  private final LinkedBlockingDeque<T> values;
-
-  /**
-   * Creates a new bounded queue.
-   *
-   * @param limit Maximum number of items that can be in the queue at any time.
-   */
-  public BoundedQueue(int limit) {
-    values = new LinkedBlockingDeque<T>(limit);
-  }
-
-  /**
-   * Adds a value to head of the queue, evicting the oldest item if the queue is at capacity.
-   *
-   * @param value Value to add.
-   */
-  public synchronized void add(T value) {
-    if (values.remainingCapacity() == 0) {
-      values.removeFirst();
-    }
-    values.addLast(value);
-  }
-
-  /**
-   * Removes all values from the queue.
-   */
-  public synchronized void clear() {
-    values.clear();
-  }
-
-  /**
-   * Returns the size of the queue.
-   *
-   * @return The current queue length.
-   */
-  public synchronized int size() {
-    return values.size();
-  }
-
-  @Override
-  public synchronized Iterator<T> iterator() {
-    return values.iterator();
-  }
-
-  @Override
-  public synchronized String toString() {
-    return values.toString();
-  }
-}

http://git-wip-us.apache.org/repos/asf/aurora/blob/98f692d1/commons/src/main/java/org/apache/aurora/common/stats/TimeSeriesRepositoryImpl.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/stats/TimeSeriesRepositoryImpl.java
b/commons/src/main/java/org/apache/aurora/common/stats/TimeSeriesRepositoryImpl.java
index 387e379..b0f2d06 100644
--- a/commons/src/main/java/org/apache/aurora/common/stats/TimeSeriesRepositoryImpl.java
+++ b/commons/src/main/java/org/apache/aurora/common/stats/TimeSeriesRepositoryImpl.java
@@ -25,6 +25,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
+import com.google.common.collect.EvictingQueue;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
@@ -33,7 +34,6 @@ import com.google.inject.name.Named;
 
 import org.apache.aurora.common.application.ShutdownRegistry;
 import org.apache.aurora.common.base.Command;
-import org.apache.aurora.common.collections.BoundedQueue;
 import org.apache.aurora.common.quantity.Amount;
 import org.apache.aurora.common.quantity.Time;
 import org.apache.aurora.common.util.Clock;
@@ -65,7 +65,7 @@ public class TimeSeriesRepositoryImpl implements TimeSeriesRepository {
 
   // We store TimeSeriesImpl, which allows us to add samples.
   private final LoadingCache<String, TimeSeriesImpl> timeSeries;
-  private final BoundedQueue<Number> timestamps;
+  private final EvictingQueue<Number> timestamps;
 
   private final StatRegistry statRegistry;
   private final Amount<Long, Time> samplePeriod;
@@ -104,7 +104,7 @@ public class TimeSeriesRepositoryImpl implements TimeSeriesRepository
{
           }
         });
 
-    timestamps = new BoundedQueue<Number>(retainedSampleLimit);
+    timestamps = EvictingQueue.create(retainedSampleLimit);
   }
 
   /**
@@ -175,11 +175,11 @@ public class TimeSeriesRepositoryImpl implements TimeSeriesRepository
{
 
   private class TimeSeriesImpl implements TimeSeries {
     private final String name;
-    private final BoundedQueue<Number> samples;
+    private final EvictingQueue<Number> samples;
 
     TimeSeriesImpl(String name) {
       this.name = name;
-      samples = new BoundedQueue<Number>(retainedSampleLimit);
+      samples = EvictingQueue.create(retainedSampleLimit);
     }
 
     @Override public String getName() {

http://git-wip-us.apache.org/repos/asf/aurora/blob/98f692d1/commons/src/test/java/org/apache/aurora/common/collections/BoundedQueueTest.java
----------------------------------------------------------------------
diff --git a/commons/src/test/java/org/apache/aurora/common/collections/BoundedQueueTest.java
b/commons/src/test/java/org/apache/aurora/common/collections/BoundedQueueTest.java
deleted file mode 100644
index d6e3c21..0000000
--- a/commons/src/test/java/org/apache/aurora/common/collections/BoundedQueueTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.aurora.common.collections;
-
-import java.util.Iterator;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-/**
- * @author William Farner
- */
-public class BoundedQueueTest {
-
-  private static final int SIZE = 4;
-
-  private BoundedQueue<Integer> queue;
-
-  @Before
-  public void setUp() {
-    queue = new BoundedQueue<Integer>(SIZE);
-  }
-
-  @Test
-  public void testEmpty() {
-    assertThat(queue.iterator().hasNext(), is(false));
-  }
-
-  @Test
-  public void testFIFO() {
-    queue.add(0);
-    queue.add(1);
-    queue.add(2);
-    queue.add(3);
-    queue.add(4);
-
-    Iterator<Integer> it = queue.iterator();
-    assertThat(it.next(), is(1));
-    assertThat(it.next(), is(2));
-    assertThat(it.next(), is(3));
-    assertThat(it.next(), is(4));
-  }
-}


Mime
View raw message