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 with
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() !
Note that as of Jan 2008, this class has not yet been used.
- Version:
- $Id: SizeBoundedQueue.java,v 1.4 2008/02/04 13:43:14 belaban Exp $
- Author:
- Bela Ban
Method Summary |
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 |
Methods inherited from interface java.util.Collection |
equals, hashCode |
SizeBoundedQueue
public SizeBoundedQueue()
add
public boolean add(java.lang.Object o)
- Specified by:
add
in interface java.util.Collection
- Specified by:
add
in interface java.util.concurrent.BlockingQueue
drainTo
public int drainTo(java.util.Collection c)
- Specified by:
drainTo
in interface java.util.concurrent.BlockingQueue
drainTo
public int drainTo(java.util.Collection c,
int maxElements)
- Specified by:
drainTo
in interface java.util.concurrent.BlockingQueue
offer
public boolean offer(java.lang.Object o)
- Specified by:
offer
in interface java.util.concurrent.BlockingQueue
- Specified by:
offer
in interface java.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 interface java.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 interface java.util.concurrent.BlockingQueue
- Throws:
java.lang.InterruptedException
put
public void put(java.lang.Object o)
throws java.lang.InterruptedException
- Specified by:
put
in interface java.util.concurrent.BlockingQueue
- Throws:
java.lang.InterruptedException
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacity
in interface java.util.concurrent.BlockingQueue
take
public java.lang.Object take()
throws java.lang.InterruptedException
- Specified by:
take
in interface java.util.concurrent.BlockingQueue
- Throws:
java.lang.InterruptedException
element
public java.lang.Object element()
- Specified by:
element
in interface java.util.Queue
peek
public java.lang.Object peek()
- Specified by:
peek
in interface java.util.Queue
poll
public java.lang.Object poll()
- Specified by:
poll
in interface java.util.Queue
remove
public java.lang.Object remove()
- Specified by:
remove
in interface java.util.Queue
addAll
public boolean addAll(java.util.Collection c)
- Specified by:
addAll
in interface java.util.Collection
clear
public void clear()
- Specified by:
clear
in interface java.util.Collection
contains
public boolean contains(java.lang.Object o)
- Specified by:
contains
in interface java.util.Collection
containsAll
public boolean containsAll(java.util.Collection c)
- Specified by:
containsAll
in interface java.util.Collection
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interface java.util.Collection
iterator
public java.util.Iterator iterator()
- Specified by:
iterator
in interface java.lang.Iterable
- Specified by:
iterator
in interface java.util.Collection
remove
public boolean remove(java.lang.Object o)
- Specified by:
remove
in interface java.util.Collection
removeAll
public boolean removeAll(java.util.Collection c)
- Specified by:
removeAll
in interface java.util.Collection
retainAll
public boolean retainAll(java.util.Collection c)
- Specified by:
retainAll
in interface java.util.Collection
size
public int size()
- Specified by:
size
in interface java.util.Collection
toArray
public java.lang.Object[] toArray()
- Specified by:
toArray
in interface java.util.Collection
toArray
public java.lang.Object[] toArray(java.lang.Object[] a)
- Specified by:
toArray
in interface java.util.Collection
Copyright © 1998-2009 Bela Ban / Red Hat. All Rights Reserved.