Fix formatting issues from previous commit
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@171005 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
45f7b88bc6
commit
245554d888
|
@ -25,17 +25,17 @@ import org.apache.commons.collections.BufferUnderflowException;
|
||||||
/**
|
/**
|
||||||
* Decorates another <code>Buffer</code> to make {@link #get()} and
|
* Decorates another <code>Buffer</code> to make {@link #get()} and
|
||||||
* {@link #remove()} block when the <code>Buffer</code> is empty.
|
* {@link #remove()} block when the <code>Buffer</code> is empty.
|
||||||
* <p/>
|
* <p>
|
||||||
* If either <code>get</code> or <code>remove</code> is called on an empty
|
* If either <code>get</code> or <code>remove</code> is called on an empty
|
||||||
* <code>Buffer</code>, the calling thread waits for notification that
|
* <code>Buffer</code>, the calling thread waits for notification that
|
||||||
* an <code>add</code> or <code>addAll</code> operation has completed.
|
* an <code>add</code> or <code>addAll</code> operation has completed.
|
||||||
* <p/>
|
* <p>
|
||||||
* When one or more entries are added to an empty <code>Buffer</code>,
|
* When one or more entries are added to an empty <code>Buffer</code>,
|
||||||
* all threads blocked in <code>get</code> or <code>remove</code> are notified.
|
* all threads blocked in <code>get</code> or <code>remove</code> are notified.
|
||||||
* There is no guarantee that concurrent blocked <code>get</code> or
|
* There is no guarantee that concurrent blocked <code>get</code> or
|
||||||
* <code>remove</code> requests will be "unblocked" and receive data in the
|
* <code>remove</code> requests will be "unblocked" and receive data in the
|
||||||
* order that they arrive.
|
* order that they arrive.
|
||||||
* <p/>
|
* <p>
|
||||||
* This class is Serializable from Commons Collections 3.1.
|
* This class is Serializable from Commons Collections 3.1.
|
||||||
*
|
*
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
|
@ -74,7 +74,7 @@ public class BlockingBuffer extends SynchronizedBuffer {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public boolean add(Object o) {
|
public boolean add(Object o) {
|
||||||
synchronized(lock) {
|
synchronized (lock) {
|
||||||
boolean result = collection.add(o);
|
boolean result = collection.add(o);
|
||||||
notifyAll();
|
notifyAll();
|
||||||
return result;
|
return result;
|
||||||
|
@ -82,7 +82,7 @@ public class BlockingBuffer extends SynchronizedBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addAll(Collection c) {
|
public boolean addAll(Collection c) {
|
||||||
synchronized(lock) {
|
synchronized (lock) {
|
||||||
boolean result = collection.addAll(c);
|
boolean result = collection.addAll(c);
|
||||||
notifyAll();
|
notifyAll();
|
||||||
return result;
|
return result;
|
||||||
|
@ -90,12 +90,11 @@ public class BlockingBuffer extends SynchronizedBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object get() {
|
public Object get() {
|
||||||
synchronized(lock) {
|
synchronized (lock) {
|
||||||
while(collection.isEmpty()) {
|
while (collection.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
wait();
|
wait();
|
||||||
}
|
} catch (InterruptedException e) {
|
||||||
catch(InterruptedException e) {
|
|
||||||
PrintWriter out = new PrintWriter(new StringWriter());
|
PrintWriter out = new PrintWriter(new StringWriter());
|
||||||
e.printStackTrace(out);
|
e.printStackTrace(out);
|
||||||
throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString());
|
throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString());
|
||||||
|
@ -106,21 +105,20 @@ public class BlockingBuffer extends SynchronizedBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object get(final long timeout) {
|
public Object get(final long timeout) {
|
||||||
synchronized(lock) {
|
synchronized (lock) {
|
||||||
final long expiration = System.currentTimeMillis() + timeout;
|
final long expiration = System.currentTimeMillis() + timeout;
|
||||||
long timeLeft = expiration - System.currentTimeMillis();
|
long timeLeft = expiration - System.currentTimeMillis();
|
||||||
while(timeLeft > 0 && collection.isEmpty()) {
|
while (timeLeft > 0 && collection.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
wait(timeLeft);
|
wait(timeLeft);
|
||||||
timeLeft = expiration - System.currentTimeMillis();
|
timeLeft = expiration - System.currentTimeMillis();
|
||||||
}
|
} catch(InterruptedException e) {
|
||||||
catch(InterruptedException e) {
|
|
||||||
PrintWriter out = new PrintWriter(new StringWriter());
|
PrintWriter out = new PrintWriter(new StringWriter());
|
||||||
e.printStackTrace(out);
|
e.printStackTrace(out);
|
||||||
throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString());
|
throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(collection.isEmpty()) {
|
if (collection.isEmpty()) {
|
||||||
throw new BufferUnderflowException("Timeout expired.");
|
throw new BufferUnderflowException("Timeout expired.");
|
||||||
}
|
}
|
||||||
return getBuffer().get();
|
return getBuffer().get();
|
||||||
|
@ -128,12 +126,11 @@ public class BlockingBuffer extends SynchronizedBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object remove() {
|
public Object remove() {
|
||||||
synchronized(lock) {
|
synchronized (lock) {
|
||||||
while(collection.isEmpty()) {
|
while (collection.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
wait();
|
wait();
|
||||||
}
|
} catch (InterruptedException e) {
|
||||||
catch(InterruptedException e) {
|
|
||||||
PrintWriter out = new PrintWriter(new StringWriter());
|
PrintWriter out = new PrintWriter(new StringWriter());
|
||||||
e.printStackTrace(out);
|
e.printStackTrace(out);
|
||||||
throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString());
|
throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString());
|
||||||
|
@ -144,24 +141,24 @@ public class BlockingBuffer extends SynchronizedBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object remove(final long timeout) {
|
public Object remove(final long timeout) {
|
||||||
synchronized(lock) {
|
synchronized (lock) {
|
||||||
final long expiration = System.currentTimeMillis() + timeout;
|
final long expiration = System.currentTimeMillis() + timeout;
|
||||||
long timeLeft = expiration - System.currentTimeMillis();
|
long timeLeft = expiration - System.currentTimeMillis();
|
||||||
while(timeLeft > 0 && collection.isEmpty()) {
|
while (timeLeft > 0 && collection.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
wait(timeLeft);
|
wait(timeLeft);
|
||||||
timeLeft = expiration - System.currentTimeMillis();
|
timeLeft = expiration - System.currentTimeMillis();
|
||||||
}
|
} catch(InterruptedException e) {
|
||||||
catch(InterruptedException e) {
|
|
||||||
PrintWriter out = new PrintWriter(new StringWriter());
|
PrintWriter out = new PrintWriter(new StringWriter());
|
||||||
e.printStackTrace(out);
|
e.printStackTrace(out);
|
||||||
throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString());
|
throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(collection.isEmpty()) {
|
if (collection.isEmpty()) {
|
||||||
throw new BufferUnderflowException("Timeout expired.");
|
throw new BufferUnderflowException("Timeout expired.");
|
||||||
}
|
}
|
||||||
return getBuffer().remove();
|
return getBuffer().remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue