Use offer to wait (with timeout of 30secs) for space in case the queue is full.

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@384419 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adrian T. Co 2006-03-09 03:59:03 +00:00
parent 0c21d86151
commit d34b2fe072
1 changed files with 10 additions and 1 deletions

View File

@ -18,6 +18,7 @@ package org.apache.activemq.transport.http;
import edu.emory.mathcs.backport.java.util.Queue;
import edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue;
import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
import org.apache.activemq.command.Command;
import org.apache.activemq.transport.TransportSupport;
@ -35,6 +36,8 @@ import java.io.IOException;
* @version $Revision$
*/
public class BlockingQueueTransport extends TransportSupport {
public static final long MAX_TIMEOUT = 30000L;
private BlockingQueue queue;
public BlockingQueueTransport(BlockingQueue channel) {
@ -46,7 +49,13 @@ public class BlockingQueueTransport extends TransportSupport {
}
public void oneway(Command command) throws IOException {
queue.add(command);
try {
boolean success = queue.offer(command, MAX_TIMEOUT, TimeUnit.MILLISECONDS);
if (!success)
throw new IOException("Fail to add to BlockingQueue. Add timed out after " + MAX_TIMEOUT + "ms: size=" + queue.size());
} catch (InterruptedException e) {
throw new IOException("Fail to add to BlockingQueue. Interrupted while waiting for space: size=" + queue.size());
}
}
protected void doStart() throws Exception {