de.javakaffee.simplequeue
Class BDBQueue

java.lang.Object
  extended by de.javakaffee.simplequeue.BDBQueue

public class BDBQueue
extends Object

Fast queue implementation on top of Berkley DB Java Edition. This class is thread-safe.

This is based on .

Created on Jun 27, 2011

Author:
Martin Grotzke (initial creation)

Constructor Summary
BDBQueue(String queueEnvPath, String queueName, int cacheSize)
          Creates instance of persistent queue.
 
Method Summary
 int clear()
           
 void close()
          Closes this queue and frees up all resources associated to it.
 String getQueueName()
          Returns this queue name.
 boolean isEmpty()
          Determines if this queue is empty (equivalent to size() == 0).
static void mkdir(File dir)
          Asserts that the given directory exists and creates it if necessary.
 byte[] peek()
          Retrieves element from the head of this queue.
 byte[] poll()
          Retrieves and and removes element from the head of this queue.
 void push(byte[] element)
          Pushes element to the tail of this queue.
 void remove()
          Removes the eldest element.
 long size()
          Returns the size of this queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BDBQueue

public BDBQueue(String queueEnvPath,
                String queueName,
                int cacheSize)
         throws IOException
Creates instance of persistent queue.

Parameters:
queueEnvPath - queue database environment directory path
queueName - descriptive queue name
cacheSize - how often to sync the queue to disk
Throws:
IOException - thrown when the given queueEnvPath does not exist and cannot be created.
Method Detail

mkdir

public static void mkdir(@Nonnull
                         File dir)
                  throws IOException
Asserts that the given directory exists and creates it if necessary.

Parameters:
dir - the directory that shall exist
Throws:
IOException - thrown if the directory could not be created.

poll

public byte[] poll()
            throws IOException
Retrieves and and removes element from the head of this queue.

Returns:
element from the head of the queue or null if queue is empty
Throws:
IOException - in case of disk IO failure

peek

public byte[] peek()
            throws IOException
Retrieves element from the head of this queue.

Returns:
element from the head of the queue or null if queue is empty
Throws:
IOException - in case of disk IO failure

remove

public void remove()
            throws NoSuchElementException
Removes the eldest element.

Throws:
NoSuchElementException

push

public void push(byte[] element)
          throws IOException
Pushes element to the tail of this queue.

Parameters:
element - element
Throws:
IOException - in case of disk IO failure

clear

public int clear()

size

public long size()
Returns the size of this queue.

Returns:
the size of the queue

isEmpty

public boolean isEmpty()
Determines if this queue is empty (equivalent to size() == 0).

Returns:
true if this queue is empty, otherwise false.

getQueueName

public String getQueueName()
Returns this queue name.

Returns:
this queue name

close

public void close()
Closes this queue and frees up all resources associated to it.



Copyright © 2010-2011. All Rights Reserved.