package com.eactive.eai.common.worker;

public class Slot {
	private Object slotVal;

	public synchronized void put(Object val) {
		while (slotVal != null) {
			try {
				wait();
			} catch (InterruptedException e) {
				;
			}
		}
		slotVal = val;
		notifyAll();
	}

	public synchronized Object get() {
		Object rval;
		while (slotVal == null) {
			try {
				if (slotVal == null)
					wait();
			} catch (InterruptedException e) {
				break;
			}
		}

		rval = slotVal;
		slotVal = null;
		notifyAll();
		return rval;
	}

	public synchronized Object get(long timeout) {
		Object rval;
		try {
			if (slotVal == null)
				wait(timeout);
		} catch (InterruptedException e) {
			rval = slotVal;
		}

		rval = slotVal;
		slotVal = null;
		notifyAll();
		return rval;
	}
}
