Skip navigation links

Oracle Internet Directory API Reference
11g Release 1 (11.1.1)

E10664-01


oracle.ldap.util
Class WorkQueue

java.lang.Object
  extended by oracle.ldap.util.WorkQueue


public class WorkQueue
extends java.lang.Object

This class implements a queue whose elements are added based on a priority. The minimum priority is 1 and the maximum priority by default is 1. Elements are added to this Q based on the specified priority.

 For e.x
       ....
       WorkQueue m_jobQ = new WorkQueue(5);
       ...
 Will create a Queue object which can hold elements of 5 different priorities.

                |- - - - |  - Priority 5 elements will be added here
                |- - - - |  - Priority 4            ..
                |- - - - |  - Priority 3            .. 
                |- - - - |  - Priority 2            .. 
                |- - - - |  - Priority 1            ..
 

When the queue is closed, new elements could not be added to it. However DeQueue should be possible if there are any elements left in it. When there are no elements in the Queue and it is closed and if dequeueing operation is performed then it will throw a QClosedException

When a thread tries to dequeue an element and if there are no elements in the queue it will wait until an element is added to the queue. However if the queue is closed, it will return QClosedException

The highest priority element and the one that was added first will be dequeued. If there are no elements in that priority list then next lower priority list will be considered for dequeuing

See Also:
QClosedException

Constructor Summary
WorkQueue()
          Default Constructor.
WorkQueue(int nMaxPriority)
          Constructor to create a queue, whose elements are classified into a given number of priority types.
WorkQueue(int nMaxElements, int nMaxPriority)
          Constructor to create a queue which has a limit on upper bound and also the maximum number of priority types it can hold.

 

Method Summary
 void close()
          Use this method to close the queue.
 java.lang.Object dequeue()
           
 java.lang.Object dequeue(java.util.logging.Logger lgr)
          Dequeues an object.
 java.lang.Object dequeueNoWait()
          Dequeues an object from the queue but does not wait if the Q is empty.
 void enqueue(java.lang.Object obj)
           
 void enqueue(java.lang.Object obj, int priority)
           
 void enqueue(java.lang.Object obj, int priority, java.util.logging.Logger lgr)
          This method adds an object to the queue based on specified priority.
 void enqueueNoWait(java.lang.Object obj)
           
 boolean enqueueNoWait(java.lang.Object obj, int priority)
          This method adds an object to the queue but does not wait if the Q is full.
 int getSize()
          Returns the number of objects in the Q.
 boolean isEmpty()
          This method returns true if the priority Q is empty
 boolean isFull()
          This method returns true if the priority Q has an upper limit set and it is full.
static void main(java.lang.String[] args)
          A Test Driver
 java.lang.String toString()
          Returns information about the queue in string form

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

 

Constructor Detail

WorkQueue

public WorkQueue()
Default Constructor. Creates a priority Q with a default of only one priority type and no limit on number of elements that could be added to the queue.

WorkQueue

public WorkQueue(int nMaxPriority)
Constructor to create a queue, whose elements are classified into a given number of priority types. This queue object will not have a limit on number of elements stored in it.
Parameters:
nMaxPriority - maximum number of priority types the Q can hold

WorkQueue

public WorkQueue(int nMaxElements,
                 int nMaxPriority)
Constructor to create a queue which has a limit on upper bound and also the maximum number of priority types it can hold. If a thread tries to add an element when the queue is full it will be put to wait until there is a room for the new element.
Parameters:
nMaxElements - maximum number of elements the queue can contain
nMaxPriority - maximum number of priority types the Q can hold

Method Detail

enqueue

public void enqueue(java.lang.Object obj,
                    int priority,
                    java.util.logging.Logger lgr)
             throws QClosedException
This method adds an object to the queue based on specified priority. If the queue has a size restriction and it is full then the calling thread will be put to wait until there is a space to add the new element to the queue
Parameters:
obj - The object to be put in the Q
priority - the priority category to which the object needs to be added
Throws:
QClosedException - if the queue is closed.
java.lang.IllegalArgumentException - if obj is null or the priority is invalid

enqueue

public void enqueue(java.lang.Object obj,
                    int priority)
             throws QClosedException
Throws:
QClosedException

enqueue

public void enqueue(java.lang.Object obj)
             throws QClosedException
Throws:
QClosedException

enqueueNoWait

public boolean enqueueNoWait(java.lang.Object obj,
                             int priority)
                      throws QClosedException
This method adds an object to the queue but does not wait if the Q is full.
Parameters:
obj - The object to be put in the Q
priority - the priority category to which the object needs to be added
Returns:
ture if enqueuing is successful, false if the Q is full.
Throws:
QClosedException - if the queue is closed.
java.lang.IllegalArgumentException - if obj is null or the priority is invalid

enqueueNoWait

public void enqueueNoWait(java.lang.Object obj)
                   throws QClosedException
Throws:
QClosedException

dequeue

public java.lang.Object dequeue(java.util.logging.Logger lgr)
                         throws QClosedException
Dequeues an object. Dequeuing returns the element that was first added to the highest priroity category. If there are no elements in that category then next highest priority category is tried. If the Q is empty then the calling thread is made to wait until some other thread adds an element to the queue.
Returns:
the object that was added first.
Throws:
QClosedException - if the queue is empty and closed.

dequeue

public java.lang.Object dequeue()
                         throws QClosedException
Throws:
QClosedException

dequeueNoWait

public java.lang.Object dequeueNoWait()
                               throws QClosedException
Dequeues an object from the queue but does not wait if the Q is empty. Dequeuing returns the element that was first added to the highest priroity category. If there are no elements in that category then next highest priority category is tried. If the Q is empty then null is returned.
Returns:
the object that was added first. If the Queue is empty but not not closed then null is returned
Throws:
QClosedException - if the queue is empty and closed.

close

public void close()
Use this method to close the queue. When the queue is closed no more elements will be allowed to be added and dequeuing will not possible when there are no elements i.e. the calling thread will not be put to wait when the queue is empty and closed

isEmpty

public boolean isEmpty()
This method returns true if the priority Q is empty
Returns:
true if Q is empty

isFull

public boolean isFull()
This method returns true if the priority Q has an upper limit set and it is full.
Returns:
true if Q is full

getSize

public int getSize()
Returns the number of objects in the Q.
Returns:
the number objects in the Q

toString

public java.lang.String toString()
Returns information about the queue in string form
Overrides:
toString in class java.lang.Object
Returns:
queue information as string

main

public static void main(java.lang.String[] args)
A Test Driver

Skip navigation links

Oracle Internet Directory API Reference
11g Release 1 (11.1.1)

E10664-01


Copyright © 1999, 2009 Oracle. All Rights Reserved.