You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by tr...@apache.org on 2007/05/02 07:54:42 UTC
svn commit: r534322 -
/mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/Request.java
Author: trustin
Date: Tue May 1 22:54:41 2007
New Revision: 534322
URL: http://svn.apache.org/viewvc?view=rev&rev=534322
Log:
Fixed a bug that Request.awaitResponse() doesn't throw NoSuchElementException more than once
Modified:
mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/Request.java
Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/Request.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/Request.java?view=diff&rev=534322&r1=534321&r2=534322
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/Request.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/Request.java Tue May 1 22:54:41 2007
@@ -31,8 +31,6 @@
* @version $Rev$, $Date$
*/
public class Request {
- private static final Object END = new Object();
-
private final Object id;
private final Object message;
private final boolean useResponseQueue;
@@ -40,6 +38,7 @@
private volatile TimerTask timerTask;
private final BlockingQueue<Object> responses = new LinkedBlockingQueue<Object>();
+ private volatile boolean endOfResponses;
public Request(Object id, Object message, long timeoutMillis) {
this(id, message, true, timeoutMillis);
@@ -95,11 +94,13 @@
public Response awaitResponse() throws RequestTimeoutException, InterruptedException {
checkUseResponseQueue();
+ chechEndOfResponses();
return convertToResponse(responses.take());
}
public Response awaitResponse(long timeout, TimeUnit unit) throws RequestTimeoutException, InterruptedException {
checkUseResponseQueue();
+ chechEndOfResponses();
return convertToResponse(responses.poll(timeout, unit));
}
@@ -112,16 +113,10 @@
return null;
}
- if (o == END) {
- throw new NoSuchElementException(
- "All responses has been retrieved already.");
- }
-
throw (RequestTimeoutException) o;
}
public Response awaitResponseUninterruptibly() throws RequestTimeoutException {
- checkUseResponseQueue();
for (;;) {
try {
return awaitResponse();
@@ -130,6 +125,13 @@
}
}
+ private void chechEndOfResponses() {
+ if (endOfResponses && responses.isEmpty() && useResponseQueue) {
+ throw new NoSuchElementException(
+ "All responses has been retrieved already.");
+ }
+ }
+
private void checkUseResponseQueue() {
if (!useResponseQueue) {
throw new IllegalStateException(
@@ -140,13 +142,13 @@
void signal(Response response) {
signal0(response);
if (response.getType() != ResponseType.PARTIAL) {
- signal0(END);
+ endOfResponses = true;
}
}
void signal(RequestTimeoutException e) {
signal0(e);
- signal0(END);
+ endOfResponses = true;
}
private void signal0(Object answer) {