Package com.gargoylesoftware.base.trace
Class BlockingCircularQueue
- java.lang.Object
-
- com.gargoylesoftware.base.trace.BlockingCircularQueue
-
- All Implemented Interfaces:
java.io.Serializable
public class BlockingCircularQueue extends java.lang.Object implements java.io.Serializable
Internal use only.
.A circular queue with blocking semantics.
- Version:
- $Revision: 1.7 $
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BlockingCircularQueue()
Create the queue with a capacity of 20BlockingCircularQueue(int capacity)
Create the queue with the specified capacity
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(java.lang.Object object)
Add an object to the queue.protected void
assertNotNull(java.lang.String fieldName, java.lang.Object fieldValue)
Verify that the specified value is not null.void
clear()
Remove all items from the queueprivate int
incrementPosition(int position)
Utility method to increment the position and roll back to zero once we hit the end.boolean
isEmpty()
Return true if the collection is empty.java.lang.Object
next()
Return the next item in the queue.int
size()
Return the number of objects currently in the collection.java.lang.String
toString()
Return a string representation of this object.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
getLock_
private final java.lang.Object getLock_
-
addLock_
private final java.lang.Object addLock_
-
queue_
private final java.lang.Object[] queue_
-
capacity_
private final int capacity_
-
size_
private int size_
-
front_
private int front_
-
back_
private int back_
-
-
Method Detail
-
clear
public void clear()
Remove all items from the queue
-
add
public boolean add(java.lang.Object object)
Add an object to the queue. If the collection is currently full then block until an object is removed.- Parameters:
object
- The object to add.- Returns:
- true if the object was successfully added.
-
next
public java.lang.Object next()
Return the next item in the queue. The returned item is removed from the collection. If no objects are present then block until an object has been added.- Returns:
- The next item.
-
incrementPosition
private int incrementPosition(int position)
Utility method to increment the position and roll back to zero once we hit the end. Return the new position after the adjustment.- Parameters:
position
- The position to increment- Returns:
- the new position
-
size
public int size()
Return the number of objects currently in the collection.- Returns:
- The object count.
-
isEmpty
public boolean isEmpty()
Return true if the collection is empty.- Returns:
- true if the collection is empty.
-
toString
public java.lang.String toString()
Return a string representation of this object.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of this object.
-
assertNotNull
protected final void assertNotNull(java.lang.String fieldName, java.lang.Object fieldValue) throws DetailedNullPointerException
Verify that the specified value is not null. If it is then throw an exception- Parameters:
fieldName
- The name of the field to checkfieldValue
- The value of the field to check- Throws:
DetailedNullPointerException
- If fieldValue is null
-
-