org.archive.queue
Class DiskBackedQueue

java.lang.Object
  extended by org.archive.queue.DiskBackedQueue
All Implemented Interfaces:
java.io.Serializable, Queue
Direct Known Subclasses:
DiskBackedDeque

public class DiskBackedQueue
extends java.lang.Object
implements Queue, java.io.Serializable

Queue which uses a DiskQueue ('tailQ') for spillover entries once a in-memory LinkedList ('headQ') reaches a maximum size.

Author:
Gordon Mohr
See Also:
Serialized Form

Field Summary
protected static float DISCARD_BACKING_THRESHOLD
          if all contents would leave head less than this percent full, discard the backing file(s)
protected  int headMax
           
protected  java.util.LinkedList headQ
           
protected  java.lang.String name
           
protected  DiskQueue tailQ
           
 
Constructor Summary
DiskBackedQueue(java.io.File dir, java.lang.String name, boolean reuse, int headMax)
           
 
Method Summary
protected  java.lang.Object backingDequeue()
           
protected  void backingUpdate()
           
protected  boolean canDiscardBacking()
           
 long deleteMatchedItems(org.apache.commons.collections.Predicate matcher)
          All objects in the queue where matcher.match(object) returns true will be deleted from the queue.
 java.lang.Object dequeue()
          remove an entry from the start of the queue
protected  void discardBacking()
           
 void disconnect()
          Release any file-handles in arecoverable way.
 void enqueue(java.lang.Object o)
          Add an entry to the end of queue
protected  void fillHeadQ()
           
 java.util.Iterator getIterator(boolean inCacheOnly)
          Returns an iterator for the queue.
protected  int headTargetSize()
           
 boolean isEmpty()
          is the queue empty?
 long length()
          get the number of elements in the queue
 java.lang.Object peek()
          Give the top object in the queue, leaving it in place to be returned by future peek() or dequeue() invocations.
 void release()
          release any OS/IO resources associated with Queue
 void setHeadMax(int hm)
          Set the maximum number of items to keep in memory at the structure's top.
 void unpeek()
          Releases queue from the obligation to return in the next peek()/dequeue() the same object as returned by any previous peek().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DISCARD_BACKING_THRESHOLD

protected static final float DISCARD_BACKING_THRESHOLD
if all contents would leave head less than this percent full, discard the backing file(s)

See Also:
Constant Field Values

headMax

protected int headMax

headQ

protected java.util.LinkedList headQ

tailQ

protected DiskQueue tailQ

name

protected java.lang.String name
Constructor Detail

DiskBackedQueue

public DiskBackedQueue(java.io.File dir,
                       java.lang.String name,
                       boolean reuse,
                       int headMax)
                throws java.io.IOException
Parameters:
dir -
name -
reuse - whether to reuse any existing backing files
headMax -
Throws:
java.io.IOException
Method Detail

enqueue

public void enqueue(java.lang.Object o)
Description copied from interface: Queue
Add an entry to the end of queue

Specified by:
enqueue in interface Queue
Parameters:
o - the entry to queue
See Also:
Queue.enqueue(java.lang.Object)

isEmpty

public boolean isEmpty()
Description copied from interface: Queue
is the queue empty?

Specified by:
isEmpty in interface Queue
Returns:
true if the queue has no elements
See Also:
Queue.isEmpty()

dequeue

public java.lang.Object dequeue()
Description copied from interface: Queue
remove an entry from the start of the queue

Specified by:
dequeue in interface Queue
Returns:
the object
See Also:
Queue.dequeue()

backingUpdate

protected void backingUpdate()

discardBacking

protected void discardBacking()

disconnect

public void disconnect()
Release any file-handles in arecoverable way.


canDiscardBacking

protected boolean canDiscardBacking()
Returns:
True if can discard backing file.

fillHeadQ

protected void fillHeadQ()

backingDequeue

protected java.lang.Object backingDequeue()
Returns:
backing dequeue queue instance.

headTargetSize

protected int headTargetSize()
Returns:
Maximum size of head queue.

length

public long length()
Description copied from interface: Queue
get the number of elements in the queue

Specified by:
length in interface Queue
Returns:
the number of elements in the queue
See Also:
Queue.length()

release

public void release()
Description copied from interface: Queue
release any OS/IO resources associated with Queue

Specified by:
release in interface Queue
See Also:
Queue.release()

peek

public java.lang.Object peek()
Description copied from interface: Queue
Give the top object in the queue, leaving it in place to be returned by future peek() or dequeue() invocations.

Specified by:
peek in interface Queue
Returns:
top object, without removing it
See Also:
Queue.peek()

unpeek

public void unpeek()
Description copied from interface: Queue
Releases queue from the obligation to return in the next peek()/dequeue() the same object as returned by any previous peek().

Specified by:
unpeek in interface Queue

getIterator

public java.util.Iterator getIterator(boolean inCacheOnly)
Description copied from interface: Queue
Returns an iterator for the queue.

The returned iterator's remove method is considered unsafe.

Editing the queue while using the iterator is not safe.

Specified by:
getIterator in interface Queue
Returns:
an iterator for the queue
See Also:
Queue.getIterator(boolean)

deleteMatchedItems

public long deleteMatchedItems(org.apache.commons.collections.Predicate matcher)
Description copied from interface: Queue
All objects in the queue where matcher.match(object) returns true will be deleted from the queue.

Making other changes to the queue while this method is being processed is not safe.

Specified by:
deleteMatchedItems in interface Queue
Parameters:
matcher - a predicate
Returns:
the number of deleted items
See Also:
Queue.deleteMatchedItems(org.apache.commons.collections.Predicate)

setHeadMax

public void setHeadMax(int hm)
Set the maximum number of items to keep in memory at the structure's top. If more than that number are already in memory, they will remain in memory until dequeued, and thereafter the max will not be exceeded.

Parameters:
hm - Maximum number of items to keep in memory.


Copyright © 2003-2005 Internet Archive. All Rights Reserved.