nl.justobjects.pushlet.core
Class EventQueue

java.lang.Object
  extended by nl.justobjects.pushlet.core.EventQueue

public class EventQueue
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: EventQueue.java,v 1.3 2007/11/23 14:33:07 justb Exp $
Author:
Just van den Broecke - Just Objects ©

Field Summary
private  int capacity
          Defines maximum queue size
private  int front
           
private  Event[] queue
           
private  int rear
           
 
Constructor Summary
EventQueue()
          Construct queue with default (8) capacity.
EventQueue(int capacity)
          Construct queue with specified capacity.
 
Method Summary
 Event deQueue()
          Get head; if empty wait until something in queue.
 Event deQueue(long maxWaitTime)
          Get head; if empty wait for specified time at max.
 Event[] deQueueAll(long maxWaitTime)
          Get all queued Events.
 boolean enQueue(Event item)
          Put item in queue; waits() indefinitely if queue is full.
 boolean enQueue(Event item, long maxWaitTime)
          Put item in queue; if full wait maxtime.
private  Event fetchNext()
          Circular counter.
 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, toString, wait, wait, wait
 

Field Detail

capacity

private int capacity
Defines maximum queue size


queue

private Event[] queue

front

private int front

rear

private int rear
Constructor Detail

EventQueue

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


EventQueue

public EventQueue(int capacity)
Construct queue with specified capacity.

Method Detail

enQueue

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

Throws:
java.lang.InterruptedException

enQueue

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

Throws:
java.lang.InterruptedException

deQueue

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

Throws:
java.lang.InterruptedException

deQueue

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

Throws:
java.lang.InterruptedException

deQueueAll

public Event[] deQueueAll(long maxWaitTime)
                   throws java.lang.InterruptedException
Get all queued Events.

Throws:
java.lang.InterruptedException

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.


fetchNext

private Event fetchNext()
Circular counter.


p

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

main

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


Copyright 2000-2003 - Just Objects B.V.