00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 package fr.dyade.aaa.util;
00022
00023 import java.util.Vector;
00024
00037 public class Queue extends Vector {
00039 private static final long serialVersionUID = 1L;
00040
00045 private boolean stopping;
00046
00050 public Queue() {
00051 super();
00052 start();
00053 }
00054
00061 public synchronized void push(Object item) {
00062 if (stopping)
00063 throw new StoppedQueueException();
00064
00065 addElement(item);
00066 notify();
00067 }
00068
00075 public synchronized Object get() throws InterruptedException {
00076 while (size() == 0)
00077 wait();
00078
00079 return elementAt(0);
00080 }
00081
00088 public synchronized Object pop() {
00089 if (size() == 0)
00090 throw new EmptyQueueException();
00091
00092 Object obj = elementAt(0);
00093 removeElementAt(0);
00094
00095 if (stopping && size() == 0)
00096 notify();
00097
00098 return obj;
00099 }
00100
00107 public synchronized Object getAndPop() throws InterruptedException {
00108 while (size() == 0)
00109 wait();
00110
00111 Object obj = elementAt(0);
00112 removeElementAt(0);
00113
00114 if (stopping && size() == 0)
00115 notify();
00116
00117 return obj;
00118 }
00119
00121 public void start() {
00122 stopping = false;
00123 }
00124
00129 public synchronized void stop() throws InterruptedException {
00130 stopping = true;
00131 if (size() != 0) wait();
00132 }
00133 }