Package org.jgroups.util
Class SizeBoundedQueue
java.lang.Object
org.jgroups.util.SizeBoundedQueue
- All Implemented Interfaces:
Iterable,Collection,BlockingQueue,Queue
Queue as described in http://jira.jboss.com/jira/browse/JGRP-376. However, this queue only works with
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() !
TP.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 -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection c) voidclear()booleanbooleanintintdrainTo(Collection c, int maxElements) element()booleanisEmpty()iterator()booleanbooleanpeek()poll()voidintremove()booleanbooleanbooleanintsize()take()Object[]toArray()Object[]Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
SizeBoundedQueue
public SizeBoundedQueue()
-
-
Method Details
-
add
- Specified by:
addin interfaceBlockingQueue- Specified by:
addin interfaceCollection- Specified by:
addin interfaceQueue
-
drainTo
- Specified by:
drainToin interfaceBlockingQueue
-
drainTo
- Specified by:
drainToin interfaceBlockingQueue
-
offer
- Specified by:
offerin interfaceBlockingQueue- Specified by:
offerin interfaceQueue
-
offer
- Specified by:
offerin interfaceBlockingQueue- Throws:
InterruptedException
-
poll
- Specified by:
pollin interfaceBlockingQueue- Throws:
InterruptedException
-
put
- Specified by:
putin interfaceBlockingQueue- Throws:
InterruptedException
-
remainingCapacity
public int remainingCapacity()- Specified by:
remainingCapacityin interfaceBlockingQueue
-
take
- Specified by:
takein interfaceBlockingQueue- Throws:
InterruptedException
-
element
-
peek
-
poll
-
remove
-
addAll
- Specified by:
addAllin interfaceCollection
-
clear
public void clear()- Specified by:
clearin interfaceCollection
-
contains
- Specified by:
containsin interfaceBlockingQueue- Specified by:
containsin interfaceCollection
-
containsAll
- Specified by:
containsAllin interfaceCollection
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection
-
iterator
- Specified by:
iteratorin interfaceCollection- Specified by:
iteratorin interfaceIterable
-
remove
- Specified by:
removein interfaceBlockingQueue- Specified by:
removein interfaceCollection
-
removeAll
- Specified by:
removeAllin interfaceCollection
-
retainAll
- Specified by:
retainAllin interfaceCollection
-
size
public int size()- Specified by:
sizein interfaceCollection
-
toArray
- Specified by:
toArrayin interfaceCollection
-
toArray
- Specified by:
toArrayin interfaceCollection
-