mirror of https://github.com/apache/cassandra
make TSD threadsafe; note that BSD is not (since FailureDetector does its own locking). patch by jbellis
git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@772765 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c129b6d5d7
commit
ccfe2d7c9e
|
|
@ -3,6 +3,9 @@ package org.apache.cassandra.utils;
|
|||
import java.util.ArrayDeque;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* not threadsafe. caller is responsible for any locking necessary.
|
||||
*/
|
||||
public class BoundedStatsDeque extends AbstractStatsDeque
|
||||
{
|
||||
private final int size;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import java.util.ArrayDeque;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** threadsafe. */
|
||||
public class TimedStatsDeque extends AbstractStatsDeque
|
||||
{
|
||||
private final ArrayDeque<Tuple> deque;
|
||||
|
|
@ -25,10 +26,11 @@ public class TimedStatsDeque extends AbstractStatsDeque
|
|||
}
|
||||
}
|
||||
|
||||
public Iterator<Double> iterator()
|
||||
public synchronized Iterator<Double> iterator()
|
||||
{
|
||||
purge();
|
||||
// I expect this method to be called relatively infrequently so inefficiency is ok.
|
||||
// (this has the side benefit of making iteration threadsafe w/o having to use LinkedBlockingDeque.)
|
||||
List<Double> L = new ArrayList<Double>(deque.size());
|
||||
for (Tuple t : deque)
|
||||
{
|
||||
|
|
@ -37,19 +39,19 @@ public class TimedStatsDeque extends AbstractStatsDeque
|
|||
return L.iterator();
|
||||
}
|
||||
|
||||
public int size()
|
||||
public synchronized int size()
|
||||
{
|
||||
purge();
|
||||
return deque.size();
|
||||
}
|
||||
|
||||
public void add(double o)
|
||||
public synchronized void add(double o)
|
||||
{
|
||||
purge();
|
||||
deque.add(new Tuple(o, System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
public void clear()
|
||||
public synchronized void clear()
|
||||
{
|
||||
deque.clear();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue