public class WorkQueue
extends java.lang.Object
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
QClosedException
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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
|
public WorkQueue()
public WorkQueue(int nMaxPriority)
nMaxPriority
- maximum number of priority types the Q can holdpublic WorkQueue(int nMaxElements, int nMaxPriority)
nMaxElements
- maximum number of elements the queue can containnMaxPriority
- maximum number of priority types the Q can holdpublic void enqueue(java.lang.Object obj, int priority, java.util.logging.Logger lgr) throws QClosedException
obj
- The object to be put in the Qpriority
- the priority category to which the object needs to be addedQClosedException
- if the queue is closed.java.lang.IllegalArgumentException
- if obj is null or the priority is invalidpublic void enqueue(java.lang.Object obj, int priority) throws QClosedException
QClosedException
public void enqueue(java.lang.Object obj) throws QClosedException
QClosedException
public boolean enqueueNoWait(java.lang.Object obj, int priority) throws QClosedException
obj
- The object to be put in the Qpriority
- the priority category to which the object needs to be addedQClosedException
- if the queue is closed.java.lang.IllegalArgumentException
- if obj is null or the priority is invalidpublic void enqueueNoWait(java.lang.Object obj) throws QClosedException
QClosedException
public java.lang.Object dequeue(java.util.logging.Logger lgr) throws QClosedException
QClosedException
- if the queue is empty and closed.public java.lang.Object dequeue() throws QClosedException
QClosedException
public java.lang.Object dequeueNoWait() throws QClosedException
QClosedException
- if the queue is empty and closed.public void close()
public boolean isEmpty()
public boolean isFull()
public int getSize()
public java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] args)