[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-lib/master] Add an upper limit of 100 descriptors in the queue.
commit f154c86a316cff0180ed551041927273691e5bee
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Thu Apr 19 20:01:54 2012 +0200
Add an upper limit of 100 descriptors in the queue.
---
.../descriptor/impl/BlockingIteratorImpl.java | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/src/org/torproject/descriptor/impl/BlockingIteratorImpl.java b/src/org/torproject/descriptor/impl/BlockingIteratorImpl.java
index c023aec..e23034a 100644
--- a/src/org/torproject/descriptor/impl/BlockingIteratorImpl.java
+++ b/src/org/torproject/descriptor/impl/BlockingIteratorImpl.java
@@ -19,13 +19,20 @@ public class BlockingIteratorImpl<T> implements Iterator<T> {
protected BlockingIteratorImpl() {
}
- /* Add an object to the queue. */
+ /* Add an object to the queue if there's still room. */
+ final int MAX_DESCRIPTORS = 100;
protected synchronized void add(T object) {
if (this.outOfDescriptors) {
throw new IllegalStateException("Internal error: Adding results to "
+ "descriptor queue not allowed after sending end-of-stream "
+ "object.");
}
+ while (this.queue.size() >= this.MAX_DESCRIPTORS) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ }
+ }
this.queue.offer(object);
notifyAll();
}
@@ -68,6 +75,7 @@ public class BlockingIteratorImpl<T> implements Iterator<T> {
if (this.queue.peek() == null) {
throw new NoSuchElementException();
}
+ notifyAll();
return this.queue.remove();
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits