net.sf.zig_project.gpl.common.queue
Class LinearDispatchQueue

java.lang.Object
  extended bynet.sf.zig_project.gpl.common.queue.LinearDispatchQueue
All Implemented Interfaces:
GenericBlockingQueue, OrderedBlockingQueue, Queue, SealableQueue

public class LinearDispatchQueue
extends Object
implements GenericBlockingQueue, SealableQueue

Thread-safe module for dispatching Objects.

Version:
January 20, 2005
Author:
Frank Ziglar

Constructor Summary
LinearDispatchQueue(LinearOrderedQueue q)
           
LinearDispatchQueue(LinearQueue q)
           
 
Method Summary
 void add(Object o)
          Adds a single Object to the Queue.
 void addSet(Enumeration e)
          Adds an entire Enumeration of elements to the Queue.
 void clear()
          Empties the Queue.
 boolean contains(Object o)
          Determines if the Queue contains a copy of the specified Object.
 Enumeration elements()
          Retrieves an enumerable form of the elements in the Queue.
 boolean isEmpty()
          Determines if the Queue is empty.
 boolean isSealed()
          Determines if the Queue is sealed.
 Object peekNext()
          Retrieves the next Object from the queue without removing it.
 Object remove(Object o)
          Removes the first found element that is equal to o from the queue.
 Object removeNext()
          Removes the next element from the Queue.
 void seal()
          Seals the Queue.
 boolean transferTo(Object o, GenericBlockingQueue q)
          Transfers an Object, if it exists, out of this Queue and into another.
 void unseal()
          Unseals the Queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinearDispatchQueue

public LinearDispatchQueue(LinearOrderedQueue q)

LinearDispatchQueue

public LinearDispatchQueue(LinearQueue q)
Method Detail

add

public void add(Object o)
Adds a single Object to the Queue.

Specified by:
add in interface GenericBlockingQueue
Parameters:
o - the Object to be added
Throws:
SealedQueueException - if the Queue is currently sealed

addSet

public void addSet(Enumeration e)
Adds an entire Enumeration of elements to the Queue.

Specified by:
addSet in interface GenericBlockingQueue
Parameters:
e - a enumerable set of elements
Throws:
SealedQueueException - if the Queue is currently sealed

isEmpty

public boolean isEmpty()
Description copied from interface: Queue
Determines if the Queue is empty. An empty queue contains no elements.

Specified by:
isEmpty in interface Queue
Returns:
true only if the Queue is empty

remove

public Object remove(Object o)
Description copied from interface: Queue
Removes the first found element that is equal to o from the queue.

Specified by:
remove in interface Queue
Parameters:
o - a copy of the Object to be removed
Returns:
the first copy of o found, or null if no copy was found.

peekNext

public Object peekNext()
Description copied from interface: OrderedBlockingQueue
Retrieves the next Object from the queue without removing it. This method will always return immediately.

Specified by:
peekNext in interface OrderedBlockingQueue
Returns:
the next Object in the queue, or null if the queue was empty

contains

public boolean contains(Object o)
Description copied from interface: Queue
Determines if the Queue contains a copy of the specified Object.

Specified by:
contains in interface Queue
Parameters:
o - an Object to look for copies of
Returns:
true if at least one copy of o was found in the queue

elements

public Enumeration elements()
Retrieves an enumerable form of the elements in the Queue. Warning! Since there is no way to ensure that the underlying queue is not modified after this method returns, it is not thread-safe.

Specified by:
elements in interface Queue
Returns:
an Enumeration of the elements in the queue

transferTo

public boolean transferTo(Object o,
                          GenericBlockingQueue q)
Description copied from interface: GenericBlockingQueue
Transfers an Object, if it exists, out of this Queue and into another. Generally, this method is designed for priority Queues, where the main queue must promote an Object from one Queue to another.

Specified by:
transferTo in interface GenericBlockingQueue
Parameters:
o - a copy of the Object to transfer
q - the Queue to transfer the copy to
Returns:
true only if a copy was found and transfered, otherwise false if no copy was found, and no element was added to the target Queue

removeNext

public Object removeNext()
                  throws InterruptedException
Removes the next element from the Queue. If the Queue is empty, this method will block until an element has been added to the Queue. Otherwise, this method will return immediately.

Specified by:
removeNext in interface OrderedBlockingQueue
Returns:
the next Object in the queue, or null if the queue was empty.
Throws:
InterruptedException - if the current thread is interrupted while waiting for an element to become available

isSealed

public boolean isSealed()
Description copied from interface: SealableQueue
Determines if the Queue is sealed.

Specified by:
isSealed in interface SealableQueue
Returns:
true if the Queue is currently Sealed, false otherwise

seal

public void seal()
Description copied from interface: SealableQueue
Seals the Queue. If this Queue is empty, and has threads currently waiting in removal operations, this method will wake them up, and they will normally return shortly after. If the Queue has already been sealed, this method does nothing.

Specified by:
seal in interface SealableQueue

unseal

public void unseal()
Description copied from interface: SealableQueue
Unseals the Queue. Subsequent add operations will be allowed to operate normally, and removal operations will revert to their default (potentially blocking) operation. If the Queue is not currently sealed, this call does nothing.

This method is provided as it improves flexibility with a minimum if additional difficulty. That is, reliance on this method may not be a good design. For example, if another thread is currently blocking in a remove operation, no guarantees are made that it will return immediately if the Queue is quickly sealed and then unsealed.

Specified by:
unseal in interface SealableQueue

clear

public void clear()
Description copied from interface: Queue
Empties the Queue. All elements are cleared out, and the Queue will be empty after this call.

Specified by:
clear in interface Queue