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/04/16 03:50:29 UTC

svn commit: r529114 - /mina/trunk/core/src/main/java/org/apache/mina/filter/reqres/Request.java

Author: trustin
Date: Sun Apr 15 18:50:28 2007
New Revision: 529114

URL: http://svn.apache.org/viewvc?view=rev&rev=529114
Log:
* Added 'useResponseQueue' property to Request to avoid OutOfMemoryError when there are too many partial responses

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=529114&r1=529113&r2=529114
==============================================================================
--- 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 Sun Apr 15 18:50:28 2007
@@ -35,16 +35,17 @@
 
     private final Object id;
     private final Object message;
+    private final boolean useResponseQueue;
     private final long timeoutMillis;
     private volatile TimerTask timerTask;
 
     private final BlockingQueue<Object> responses = new LinkedBlockingQueue<Object>();
     
-    public Request(Object id, Object message, long timeoutMillis) {
-        this(id, message, timeoutMillis, TimeUnit.MILLISECONDS);
+    public Request(Object id, Object message, boolean useResponseQueue, long timeoutMillis) {
+        this(id, message, useResponseQueue, timeoutMillis, TimeUnit.MILLISECONDS);
     }
     
-    public Request(Object id, Object message, long timeout, TimeUnit unit) {
+    public Request(Object id, Object message, boolean useResponseQueue, long timeout, TimeUnit unit) {
         if (id == null) {
             throw new NullPointerException("id");
         }
@@ -64,6 +65,7 @@
         
         this.id = id;
         this.message = message;
+        this.useResponseQueue = useResponseQueue;
         this.timeoutMillis = unit.toMillis(timeout);
     }
     
@@ -79,11 +81,17 @@
         return timeoutMillis;
     }
     
+    public boolean isUseResponseQueue() {
+        return useResponseQueue;
+    }
+    
     public Response awaitResponse() throws RequestTimeoutException, InterruptedException {
+        checkUseResponseQueue();
         return convertToResponse(responses.take());
     }
     
     public Response awaitResponse(long timeout, TimeUnit unit) throws RequestTimeoutException, InterruptedException {
+        checkUseResponseQueue();
         return convertToResponse(responses.poll(timeout, unit));
     }
 
@@ -105,6 +113,7 @@
     }
 
     public Response awaitResponseUninterruptibly() throws RequestTimeoutException {
+        checkUseResponseQueue();
         for (;;) {
             try {
                 return awaitResponse();
@@ -113,6 +122,13 @@
         }
     }
     
+    private void checkUseResponseQueue() {
+        if (!useResponseQueue) {
+            throw new IllegalStateException(
+                    "Response queue is not available; useResponseQueue is false.");
+        }
+    }
+    
     void signal(Response response) {
         signal0(response);
         if (response.getType() != ResponseType.PARTIAL) {
@@ -126,7 +142,9 @@
     }
     
     private void signal0(Object answer) {
-        responses.offer(answer);
+        if (useResponseQueue) {
+            responses.offer(answer);
+        }
     }
     
     @Override