nl.justobjects.toolkit.collection
Class GuardedQueue

java.lang.Object
  |
  +--nl.justobjects.toolkit.collection.GuardedQueue

public class GuardedQueue
extends java.lang.Object

FIFO queue with guarded suspension. Purpose

Implementation
FIFO queue class implemented with circular array. The enQueue() and deQueue() methods use guarded suspension according to a readers/writers pattern, implemented with java.lang.Object.wait()/notify(). Examples


Version:
$Id: GuardedQueue.java,v 1.5 2003/01/06 00:23:48 just Exp $
Author:
Just van den Broecke - Just Objects ©

Field Summary
private  int capacity
          Defines maximum queue size
private  int front
           
private  java.lang.Object[] queue
           
private  int rear
           
 
Constructor Summary
GuardedQueue()
          Construct queue with default (8) capacity.
GuardedQueue(int capacity)
          Construct queue with specified capacity.
 
Method Summary
 java.lang.Object deQueue()
          Get head; if empty wait until something in queue.
 java.lang.Object deQueue(long maxWaitTime)
          Get head; if empty wait for specified time at max.
 boolean enQueue(java.lang.Object item)
          Put item in queue; waits() indefinitely if queue is full.
 boolean enQueue(java.lang.Object item, long maxWaitTime)
          Put item in queue; if full wait maxtime.
 int getSize()
           
 boolean isEmpty()
          Is the queue empty ?
 boolean isFull()
          Is the queue full ?
static void main(java.lang.String[] args)
           
private  int next(int index)
          Circular counter.
static void p(java.lang.String s)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

capacity

private int capacity
Defines maximum queue size

queue

private java.lang.Object[] queue

front

private int front

rear

private int rear
Constructor Detail

GuardedQueue

public GuardedQueue()
Construct queue with default (8) capacity.

GuardedQueue

public GuardedQueue(int capacity)
Construct queue with specified capacity.
Method Detail

enQueue

public boolean enQueue(java.lang.Object item)
                throws java.lang.InterruptedException
Put item in queue; waits() indefinitely if queue is full.

enQueue

public boolean enQueue(java.lang.Object item,
                       long maxWaitTime)
                throws java.lang.InterruptedException
Put item in queue; if full wait maxtime.

deQueue

public java.lang.Object deQueue()
                         throws java.lang.InterruptedException
Get head; if empty wait until something in queue.

deQueue

public java.lang.Object deQueue(long maxWaitTime)
                         throws java.lang.InterruptedException
Get head; if empty wait for specified time at max.

getSize

public int getSize()

isEmpty

public boolean isEmpty()
Is the queue empty ?

isFull

public boolean isFull()
Is the queue full ?

next

private int next(int index)
Circular counter.

p

public static void p(java.lang.String s)

main

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


Copyright © 2000-2001 - Just Objects B.V.