org.apache.qpid.client.util
Class FlowControllingBlockingQueue

java.lang.Object
  extended by org.apache.qpid.client.util.FlowControllingBlockingQueue

public class FlowControllingBlockingQueue
extends Object

A blocking queue that emits events above a user specified threshold allowing the caller to take action (e.g. flow control) to try to prevent the queue growing (much) further. The underlying queue itself is not bounded therefore the caller is not obliged to react to the events.

This implementation is only safe where we have a single thread adding items and a single (different) thread removing items.

Todo:
Make this implement java.util.Queue and hide the implementation. Then different queue types can be substituted.

Nested Class Summary
static interface FlowControllingBlockingQueue.ThresholdListener
           
 
Constructor Summary
FlowControllingBlockingQueue(int threshold, FlowControllingBlockingQueue.ThresholdListener listener)
           
FlowControllingBlockingQueue(int highThreshold, int lowThreshold, FlowControllingBlockingQueue.ThresholdListener listener)
           
 
Method Summary
 void add(Object o)
           
 boolean isEmpty()
           
 Iterator iterator()
           
 Object take()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FlowControllingBlockingQueue

public FlowControllingBlockingQueue(int threshold,
                                    FlowControllingBlockingQueue.ThresholdListener listener)

FlowControllingBlockingQueue

public FlowControllingBlockingQueue(int highThreshold,
                                    int lowThreshold,
                                    FlowControllingBlockingQueue.ThresholdListener listener)
Method Detail

isEmpty

public boolean isEmpty()

take

public Object take()
            throws InterruptedException
Throws:
InterruptedException

add

public void add(Object o)

iterator

public Iterator iterator()


Licensed to the Apache Software Foundation