org.activemq.io.util
Class MemoryBoundedQueue

java.lang.Object
  extended byorg.activemq.io.util.MemoryBoundedQueue
All Implemented Interfaces:
MemoryBoundedObject
Direct Known Subclasses:
MemoryBoundedPrioritizedQueue

public class MemoryBoundedQueue
extends Object
implements MemoryBoundedObject

MemoryBoundedQueue is a queue bounded by memory usage for MemoryManageables

Version:
$Revision: 1.1.1.1 $

Field Summary
protected  boolean closed
           
protected  Object inLock
           
protected  Object outLock
           
protected  boolean stopped
           
protected static int WAIT_TIMEOUT
           
 
Constructor Summary
MemoryBoundedQueue(MemoryBoundedQueueManager manager, String name)
          Constructor
 
Method Summary
 void clear()
          remove any MemoryManageables in the queue
 void close()
          close and remove this queue from the MemoryBoundedQueueManager
protected  void decrementMemoryUsed(MemoryManageable packet)
           
 MemoryManageable dequeue()
           
 MemoryManageable dequeue(long timeInMillis)
          Dequeues a MemoryManageable from the head of the queue
 MemoryManageable dequeueNoWait()
          dequeues a MemoryManageable from the head of the queue
 void enqueue(MemoryManageable packet)
          Enqueue a MemoryManageable to this queue
 void enqueueAllFirstNoBlock(List packets)
          Enqueue an array of packets to the head of the queue with total disregard for memory constraints
 void enqueueFirst(MemoryManageable packet)
          Enqueue a MemoryManageable to the head of the queue
 void enqueueFirstNoBlock(MemoryManageable packet)
          Enqueue a packet to the head of the queue with total disregard for memory constraints
 void enqueueNoBlock(MemoryManageable packet)
          Enqueue a MemoryManageable without checking memory usage limits
 MemoryManageable get(int index)
          retrieve a MemoryManageable at an indexed position in the queue
 List getContents()
          Retrieve a shallow copy of the contents as a list
 long getLocalMemoryUsedByThisQueue()
           
 String getName()
           
protected  void incrementMemoryUsed(MemoryManageable packet)
           
 boolean isEmpty()
           
 boolean isStarted()
           
 boolean remove(MemoryManageable packet)
          Remove a packet from the queue
 MemoryManageable remove(Object id)
          Remove a MemoryManageable by it's id
 int size()
           
 void start()
          enable dequeueing
 void stop()
          disable dequeueing
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

WAIT_TIMEOUT

protected static final int WAIT_TIMEOUT
See Also:
Constant Field Values

outLock

protected final Object outLock

inLock

protected final Object inLock

stopped

protected boolean stopped

closed

protected boolean closed
Constructor Detail

MemoryBoundedQueue

public MemoryBoundedQueue(MemoryBoundedQueueManager manager,
                          String name)
Constructor

Parameters:
name -
manager -
Method Detail

toString

public String toString()
Returns:
a pretty print of this queue

size

public int size()
Returns:
the number of items held by this queue

getLocalMemoryUsedByThisQueue

public long getLocalMemoryUsedByThisQueue()
Returns:
an aproximation the memory used by this queue

close

public void close()
close and remove this queue from the MemoryBoundedQueueManager

Specified by:
close in interface MemoryBoundedObject

enqueueNoBlock

public void enqueueNoBlock(MemoryManageable packet)
Enqueue a MemoryManageable without checking memory usage limits

Parameters:
packet -

enqueue

public void enqueue(MemoryManageable packet)
Enqueue a MemoryManageable to this queue

Parameters:
packet -

enqueueFirstNoBlock

public void enqueueFirstNoBlock(MemoryManageable packet)
Enqueue a packet to the head of the queue with total disregard for memory constraints

Parameters:
packet -

enqueueAllFirstNoBlock

public void enqueueAllFirstNoBlock(List packets)
Enqueue an array of packets to the head of the queue with total disregard for memory constraints

Parameters:
packets -

enqueueFirst

public void enqueueFirst(MemoryManageable packet)
                  throws InterruptedException
Enqueue a MemoryManageable to the head of the queue

Parameters:
packet -
Throws:
InterruptedException

dequeue

public MemoryManageable dequeue()
                         throws InterruptedException
Returns:
the first dequeued MemoryManageable or blocks until one is available
Throws:
InterruptedException

dequeue

public MemoryManageable dequeue(long timeInMillis)
                         throws InterruptedException
Dequeues a MemoryManageable from the head of the queue

Parameters:
timeInMillis - time to wait for a MemoryManageable to be available
Returns:
the first MemoryManageable or null if none available within timeInMillis
Throws:
InterruptedException

dequeueNoWait

public MemoryManageable dequeueNoWait()
                               throws InterruptedException
dequeues a MemoryManageable from the head of the queue

Returns:
the MemoryManageable at the head of the queue or null, if none is available
Throws:
InterruptedException

isStarted

public boolean isStarted()
Returns:
true if the queue is enabled for dequeing (default = true)

stop

public void stop()
disable dequeueing


start

public void start()
enable dequeueing


remove

public boolean remove(MemoryManageable packet)
Remove a packet from the queue

Parameters:
packet -
Returns:
true if the packet was found

remove

public MemoryManageable remove(Object id)
Remove a MemoryManageable by it's id

Parameters:
id -
Returns:

clear

public void clear()
remove any MemoryManageables in the queue


isEmpty

public boolean isEmpty()
Returns:
true if the queue is empty

get

public MemoryManageable get(int index)
retrieve a MemoryManageable at an indexed position in the queue

Parameters:
index -
Returns:

getContents

public List getContents()
Retrieve a shallow copy of the contents as a list

Returns:
a list containing the bounded queue contents

incrementMemoryUsed

protected void incrementMemoryUsed(MemoryManageable packet)

decrementMemoryUsed

protected void decrementMemoryUsed(MemoryManageable packet)

getName

public String getName()
Returns:
Returns the name.


Copyright © 2004-2007 Protique, Ltd.. All Rights Reserved.