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 TypeMethodDescriptionboolean
boolean
addAll
(Collection c) void
clear()
boolean
boolean
int
int
drainTo
(Collection c, int maxElements) element()
boolean
isEmpty()
iterator()
boolean
boolean
peek()
poll()
void
int
remove()
boolean
boolean
boolean
int
size()
take()
Object[]
toArray()
Object[]
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
SizeBoundedQueue
public SizeBoundedQueue()
-
-
Method Details
-
add
- Specified by:
add
in interfaceBlockingQueue
- Specified by:
add
in interfaceCollection
- Specified by:
add
in interfaceQueue
-
drainTo
- Specified by:
drainTo
in interfaceBlockingQueue
-
drainTo
- Specified by:
drainTo
in interfaceBlockingQueue
-
offer
- Specified by:
offer
in interfaceBlockingQueue
- Specified by:
offer
in interfaceQueue
-
offer
- Specified by:
offer
in interfaceBlockingQueue
- Throws:
InterruptedException
-
poll
- Specified by:
poll
in interfaceBlockingQueue
- Throws:
InterruptedException
-
put
- Specified by:
put
in interfaceBlockingQueue
- Throws:
InterruptedException
-
remainingCapacity
public int remainingCapacity()- Specified by:
remainingCapacity
in interfaceBlockingQueue
-
take
- Specified by:
take
in interfaceBlockingQueue
- Throws:
InterruptedException
-
element
-
peek
-
poll
-
remove
-
addAll
- Specified by:
addAll
in interfaceCollection
-
clear
public void clear()- Specified by:
clear
in interfaceCollection
-
contains
- Specified by:
contains
in interfaceBlockingQueue
- Specified by:
contains
in interfaceCollection
-
containsAll
- Specified by:
containsAll
in interfaceCollection
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection
-
iterator
- Specified by:
iterator
in interfaceCollection
- Specified by:
iterator
in interfaceIterable
-
remove
- Specified by:
remove
in interfaceBlockingQueue
- Specified by:
remove
in interfaceCollection
-
removeAll
- Specified by:
removeAll
in interfaceCollection
-
retainAll
- Specified by:
retainAll
in interfaceCollection
-
size
public int size()- Specified by:
size
in interfaceCollection
-
toArray
- Specified by:
toArray
in interfaceCollection
-
toArray
- Specified by:
toArray
in interfaceCollection
-