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.BlockingQueue
Queue as described in http://jira.jboss.com/jira/browse/JGRP-376. However, this queue only works withTP.IncomingPacket
elements. 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 boolean
add(java.lang.Object o)
boolean
addAll(java.util.Collection c)
void
clear()
boolean
contains(java.lang.Object o)
boolean
containsAll(java.util.Collection c)
int
drainTo(java.util.Collection c)
int
drainTo(java.util.Collection c, int maxElements)
java.lang.Object
element()
boolean
isEmpty()
java.util.Iterator
iterator()
boolean
offer(java.lang.Object o)
boolean
offer(java.lang.Object o, long timeout, java.util.concurrent.TimeUnit unit)
java.lang.Object
peek()
java.lang.Object
poll()
java.lang.Object
poll(long timeout, java.util.concurrent.TimeUnit unit)
void
put(java.lang.Object o)
int
remainingCapacity()
java.lang.Object
remove()
boolean
remove(java.lang.Object o)
boolean
removeAll(java.util.Collection c)
boolean
retainAll(java.util.Collection c)
int
size()
java.lang.Object
take()
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:
add
in interfacejava.util.concurrent.BlockingQueue
- Specified by:
add
in interfacejava.util.Collection
- Specified by:
add
in interfacejava.util.Queue
-
drainTo
public int drainTo(java.util.Collection c)
- Specified by:
drainTo
in interfacejava.util.concurrent.BlockingQueue
-
drainTo
public int drainTo(java.util.Collection c, int maxElements)
- Specified by:
drainTo
in interfacejava.util.concurrent.BlockingQueue
-
offer
public boolean offer(java.lang.Object o)
- Specified by:
offer
in interfacejava.util.concurrent.BlockingQueue
- Specified by:
offer
in interfacejava.util.Queue
-
offer
public boolean offer(java.lang.Object o, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
offer
in 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:
poll
in interfacejava.util.concurrent.BlockingQueue
- Throws:
java.lang.InterruptedException
-
put
public void put(java.lang.Object o) throws java.lang.InterruptedException
- Specified by:
put
in interfacejava.util.concurrent.BlockingQueue
- Throws:
java.lang.InterruptedException
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacity
in interfacejava.util.concurrent.BlockingQueue
-
take
public java.lang.Object take() throws java.lang.InterruptedException
- Specified by:
take
in interfacejava.util.concurrent.BlockingQueue
- Throws:
java.lang.InterruptedException
-
element
public java.lang.Object element()
- Specified by:
element
in interfacejava.util.Queue
-
peek
public java.lang.Object peek()
- Specified by:
peek
in interfacejava.util.Queue
-
poll
public java.lang.Object poll()
- Specified by:
poll
in interfacejava.util.Queue
-
remove
public java.lang.Object remove()
- Specified by:
remove
in interfacejava.util.Queue
-
addAll
public boolean addAll(java.util.Collection c)
- Specified by:
addAll
in interfacejava.util.Collection
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Collection
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
contains
in interfacejava.util.concurrent.BlockingQueue
- Specified by:
contains
in interfacejava.util.Collection
-
containsAll
public boolean containsAll(java.util.Collection c)
- Specified by:
containsAll
in interfacejava.util.Collection
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfacejava.util.Collection
-
iterator
public java.util.Iterator iterator()
- Specified by:
iterator
in interfacejava.util.Collection
- Specified by:
iterator
in interfacejava.lang.Iterable
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
remove
in interfacejava.util.concurrent.BlockingQueue
- Specified by:
remove
in interfacejava.util.Collection
-
removeAll
public boolean removeAll(java.util.Collection c)
- Specified by:
removeAll
in interfacejava.util.Collection
-
retainAll
public boolean retainAll(java.util.Collection c)
- Specified by:
retainAll
in interfacejava.util.Collection
-
size
public int size()
- Specified by:
size
in interfacejava.util.Collection
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArray
in interfacejava.util.Collection
-
toArray
public java.lang.Object[] toArray(java.lang.Object[] a)
- Specified by:
toArray
in interfacejava.util.Collection
-
-