 1Content-type: application/x-Unknown; charset=UTF8package nmc.platform;

import java.util.Vector;

public class FifoQueue {
	
	private Vector v;
	
	public FifoQueue(int capacity) {
		v = new Vector(capacity);
	}
	

	public synchronized void enqueue(Object o) {
		v.addElement(o);
		notify();
	}
	
	public synchronized Object blockingDequeue() {
		if (v.isEmpty()) {
			try {
				wait();
			} catch (InterruptedException ie) {
				System.out.println("blockingDequeue() got exception: " + ie);
			}
		}
		
		Object retVal = null;
		if (! v.isEmpty()) {
			retVal = v.elementAt(0);
			v.removeElementAt(0);
		} else {
			// this should only happen if the wait
			// got an exception
		}
		return retVal;
	}
	
	public synchronized Object blockingDequeue(int timeout) {
		if  (v.isEmpty()) {
			try {
			wait(timeout);
			} catch (InterruptedException ie) {
			System.out.println("blockingDequeue(int timeout) got exception: " + ie);}
		}		
		Object retVal = null;
		if (! v.isEmpty()) {
			retVal = v.elementAt(0);
			v.removeElementAt(0);
		}
		return retVal;
	}

	
	public synchronized boolean isEmpty() {
		return v.isEmpty();
	}
	
}