01: package com.sun.portal.subscriptions.profiler;
02:
03: import java.util.*;
04:
05: public class NotificationQueue {
06:
07: private Vector data = null;
08: private boolean status = false;
09:
10: public NotificationQueue() {
11: this .data = new Vector();
12: this .status = true;
13: }
14:
15: public NotificationQueue(Collection c) {
16: try {
17: this .data = new Vector(c);
18: } catch (Exception e) {
19: System.out.println("UserQueue.constructor exception");
20: e.printStackTrace(System.err);
21: }
22: }
23:
24: synchronized public void setStatus(boolean status) {
25: this .status = status;
26: notifyAll();
27: }
28:
29: synchronized public boolean getStatus() {
30: return status;
31: }
32:
33: synchronized public void put(Object obj) throws NotifierException {
34: if (!status) {
35: throw new NotifierException(
36: "Can't put Notifications from unused NotificationQueue");
37: }
38: data.addElement(obj);
39: notify();
40: }
41:
42: synchronized public Object get() {
43: Object obj = null;
44: while (data.size() == 0 && status) {
45: try {
46: wait();
47: } catch (InterruptedException e) {
48: // TODO: handle exception
49: }
50: }
51: if (!status) {
52: if (data.size() == 0) {
53: return null;
54: } // otherwise empty the queue
55: }
56: obj = data.elementAt(0);
57: data.removeElementAt(0);
58: return obj;
59: }
60: }
|