org.archive.queue
Class DiskQueue

java.lang.Object
  extended by org.archive.queue.DiskQueue
All Implemented Interfaces:
java.io.Serializable, Queue

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

Queue which stores all its objects to disk using object serialization, on top of a DiskBackedByteQueue. The serialization state is reset after each enqueue(). Care should be taken not to enqueue() items which will pull out excessive referenced objects, or objects which will be redundantly reinstantiated upon dequeue() from disk. This class is not synchronized internally.

Author:
Gordon Mohr
See Also:
Serialized Form

Field Summary
(package private)  DiskByteQueue bytes
          The object which shuffles raw bytes to/from disk.
(package private)  java.lang.Object headObject
          top item in queue, pulled into memory for peek()
(package private)  java.io.ObjectInputStream headStream
           
(package private)  long length
          the number of elements currently in the queue
(package private)  java.lang.String prefix
          the prefix for the files created in the scratchDir
(package private)  java.io.ObjectOutputStream tailStream
           
 
Constructor Summary
DiskQueue(java.io.File file, java.lang.String file_prefix)
          Create a new DiskQueue which creates its temporary files in a given directory, with a given prefix.
DiskQueue(java.io.File dir, java.lang.String prefix, boolean reuse)
          Create a new DiskQueue which creates its temporary files in a given directory, with a given prefix, and reuse any prexisting backing files as directed.
 
Method Summary
 void connect()
          Reconnect to disk-based backing
 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
 void disconnect()
          Disconnect from any backing files, without deleting those files, allowing reattachment later.
 void enqueue(java.lang.Object o)
          Add an entry to the end of queue
 java.util.Iterator getIterator(boolean inCacheOnly)
          Returns an iterator for the queue.
 boolean isEmpty()
          is the queue empty?
protected  boolean isInitialized()
           
 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 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

length

long length
the number of elements currently in the queue


headObject

java.lang.Object headObject
top item in queue, pulled into memory for peek()


prefix

java.lang.String prefix
the prefix for the files created in the scratchDir


bytes

DiskByteQueue bytes
The object which shuffles raw bytes to/from disk.


tailStream

transient java.io.ObjectOutputStream tailStream

headStream

transient java.io.ObjectInputStream headStream
Constructor Detail

DiskQueue

public DiskQueue(java.io.File dir,
                 java.lang.String prefix,
                 boolean reuse)
          throws java.io.IOException
Create a new DiskQueue which creates its temporary files in a given directory, with a given prefix, and reuse any prexisting backing files as directed.

Parameters:
dir - the directory in which to create the data files
prefix -
reuse - whether to reuse any existing backing files
Throws:
java.io.IOException - if we cannot create an appropriate file

DiskQueue

public DiskQueue(java.io.File file,
                 java.lang.String file_prefix)
          throws java.io.IOException
Create a new DiskQueue which creates its temporary files in a given directory, with a given prefix.

Parameters:
file -
file_prefix -
Throws:
java.io.IOException
Method Detail

isInitialized

protected boolean isInitialized()

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()

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

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()

disconnect

public void disconnect()
Disconnect from any backing files, without deleting those files, allowing reattachment later.


connect

public void connect()
Reconnect to disk-based backing


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:
iterator
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)


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