Package org.jgroups.util
Class SizeBoundedQueue
- java.lang.Object
-
- org.jgroups.util.SizeBoundedQueue
-
- All Implemented Interfaces:
java.lang.Iterable,java.util.Collection,java.util.concurrent.BlockingQueue,java.util.Queue
public class SizeBoundedQueue extends java.lang.Object implements java.util.concurrent.BlockingQueueQueue as described in http://jira.jboss.com/jira/browse/JGRP-376. However, this queue only works withTP.IncomingPacketelements. The queue maintains a max number of bytes and a total of all of the messages in the internal queues. Whenever a message is added, we increment the total by the length of the message. When a message is removed, we decrement the total. Removal blocks until a message is available, addition blocks if the max size has been exceeded, until there is enough space to add another message. Note that the max size should always be greater than the size of the largest message to be received, otherwise an additon would always fail because msg.length > max size !
Access patterns: this instance is always accessed by the thread pool only ! Concurrent take() or poll() methods, but only a single thread at a time calls put() !- Version:
- $Id: SizeBoundedQueue.java,v 1.3 2006/12/31 14:29:52 belaban Exp $
- Author:
- Bela Ban
-
-
Constructor Summary
Constructors Constructor Description SizeBoundedQueue()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(java.lang.Object o)booleanaddAll(java.util.Collection c)voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection c)intdrainTo(java.util.Collection c)intdrainTo(java.util.Collection c, int maxElements)java.lang.Objectelement()booleanisEmpty()java.util.Iteratoriterator()booleanoffer(java.lang.Object o)booleanoffer(java.lang.Object o, long timeout, java.util.concurrent.TimeUnit unit)java.lang.Objectpeek()java.lang.Objectpoll()java.lang.Objectpoll(long timeout, java.util.concurrent.TimeUnit unit)voidput(java.lang.Object o)intremainingCapacity()java.lang.Objectremove()booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection c)booleanretainAll(java.util.Collection c)intsize()java.lang.Objecttake()java.lang.Object[]toArray()java.lang.Object[]toArray(java.lang.Object[] a)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Method Detail
-
add
public boolean add(java.lang.Object o)
- Specified by:
addin interfacejava.util.concurrent.BlockingQueue- Specified by:
addin interfacejava.util.Collection- Specified by:
addin interfacejava.util.Queue
-
drainTo
public int drainTo(java.util.Collection c)
- Specified by:
drainToin interfacejava.util.concurrent.BlockingQueue
-
drainTo
public int drainTo(java.util.Collection c, int maxElements)- Specified by:
drainToin interfacejava.util.concurrent.BlockingQueue
-
offer
public boolean offer(java.lang.Object o)
- Specified by:
offerin interfacejava.util.concurrent.BlockingQueue- Specified by:
offerin interfacejava.util.Queue
-
offer
public boolean offer(java.lang.Object o, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException- Specified by:
offerin interfacejava.util.concurrent.BlockingQueue- Throws:
java.lang.InterruptedException
-
poll
public java.lang.Object poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException- Specified by:
pollin interfacejava.util.concurrent.BlockingQueue- Throws:
java.lang.InterruptedException
-
put
public void put(java.lang.Object o) throws java.lang.InterruptedException- Specified by:
putin interfacejava.util.concurrent.BlockingQueue- Throws:
java.lang.InterruptedException
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacityin interfacejava.util.concurrent.BlockingQueue
-
take
public java.lang.Object take() throws java.lang.InterruptedException- Specified by:
takein interfacejava.util.concurrent.BlockingQueue- Throws:
java.lang.InterruptedException
-
element
public java.lang.Object element()
- Specified by:
elementin interfacejava.util.Queue
-
peek
public java.lang.Object peek()
- Specified by:
peekin interfacejava.util.Queue
-
poll
public java.lang.Object poll()
- Specified by:
pollin interfacejava.util.Queue
-
remove
public java.lang.Object remove()
- Specified by:
removein interfacejava.util.Queue
-
addAll
public boolean addAll(java.util.Collection c)
- Specified by:
addAllin interfacejava.util.Collection
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
containsin interfacejava.util.concurrent.BlockingQueue- Specified by:
containsin interfacejava.util.Collection
-
containsAll
public boolean containsAll(java.util.Collection c)
- Specified by:
containsAllin interfacejava.util.Collection
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection
-
iterator
public java.util.Iterator iterator()
- Specified by:
iteratorin interfacejava.util.Collection- Specified by:
iteratorin interfacejava.lang.Iterable
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
removein interfacejava.util.concurrent.BlockingQueue- Specified by:
removein interfacejava.util.Collection
-
removeAll
public boolean removeAll(java.util.Collection c)
- Specified by:
removeAllin interfacejava.util.Collection
-
retainAll
public boolean retainAll(java.util.Collection c)
- Specified by:
retainAllin interfacejava.util.Collection
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection
-
toArray
public java.lang.Object[] toArray(java.lang.Object[] a)
- Specified by:
toArrayin interfacejava.util.Collection
-
-