58 this.vector = vector;
59 }
60 }
61
62 private QueueElement head = null;
63 private QueueElement tail = null;
64 private Thread qThread;
65
66 // package private
67 EventQueue() {
68 qThread = Obj.helper.createThread(this);
69 qThread.setDaemon(true); // not a user thread
70 qThread.start();
71 }
72
73 // package private;
74 /**
75 * Enqueue an event.
76 * @param event Either a <tt>NamingExceptionEvent</tt> or a subclass
77 * of <tt>NamingEvent</tt> or
78 * <tt>UnsolicitedNotificatoniEvent</tt>.
79 * If it is a subclass of <tt>NamingEvent</tt>, all listeners must implement
80 * the corresponding subinterface of <tt>NamingListener</tt>.
81 * For example, for a <tt>ObjectAddedEvent</tt>, all listeners <em>must</em>
82 * implement the <tt>ObjectAddedListener</tt> interface.
83 * <em>The current implementation does not check this before dispatching
84 * the event.</em>
85 * If the event is a <tt>NamingExceptionEvent</tt>, then all listeners
86 * are notified.
87 * @param vector List of NamingListeners that will be notified of event.
88 */
89 synchronized void enqueue(EventObject event, Vector<NamingListener> vector) {
90 QueueElement newElt = new QueueElement(event, vector);
91
92 if (head == null) {
93 head = newElt;
94 tail = newElt;
95 } else {
96 newElt.next = head;
97 head.prev = newElt;
98 head = newElt;
124 }
125
126 /**
127 * Pull events off the queue and dispatch them.
128 */
129 public void run() {
130 QueueElement qe;
131
132 try {
133 while ((qe = dequeue()) != null) {
134 EventObject e = qe.event;
135 Vector<NamingListener> v = qe.vector;
136
137 for (int i = 0; i < v.size(); i++) {
138
139 // Dispatch to corresponding NamingListener
140 // The listener should only be getting the event that
141 // it is interested in. (No need to check mask or
142 // instanceof subinterfaces.)
143 // It is the responsibility of the enqueuer to
144 // only enqueue events with listseners of the correct type.
145
146 if (e instanceof NamingEvent) {
147 ((NamingEvent)e).dispatch(v.elementAt(i));
148
149 // An exception occurred: if notify all naming listeners
150 } else if (e instanceof NamingExceptionEvent) {
151 ((NamingExceptionEvent)e).dispatch(v.elementAt(i));
152 } else if (e instanceof UnsolicitedNotificationEvent) {
153 ((UnsolicitedNotificationEvent)e).dispatch(
154 (UnsolicitedNotificationListener)v.elementAt(i));
155 }
156 }
157
158 qe = null; e = null; v = null;
159 }
160 } catch (InterruptedException e) {
161 // just die
162 }
163 }
164
|
58 this.vector = vector;
59 }
60 }
61
62 private QueueElement head = null;
63 private QueueElement tail = null;
64 private Thread qThread;
65
66 // package private
67 EventQueue() {
68 qThread = Obj.helper.createThread(this);
69 qThread.setDaemon(true); // not a user thread
70 qThread.start();
71 }
72
73 // package private;
74 /**
75 * Enqueue an event.
76 * @param event Either a <tt>NamingExceptionEvent</tt> or a subclass
77 * of <tt>NamingEvent</tt> or
78 * <tt>UnsolicitedNotificationEvent</tt>.
79 * If it is a subclass of <tt>NamingEvent</tt>, all listeners must implement
80 * the corresponding subinterface of <tt>NamingListener</tt>.
81 * For example, for a <tt>ObjectAddedEvent</tt>, all listeners <em>must</em>
82 * implement the <tt>ObjectAddedListener</tt> interface.
83 * <em>The current implementation does not check this before dispatching
84 * the event.</em>
85 * If the event is a <tt>NamingExceptionEvent</tt>, then all listeners
86 * are notified.
87 * @param vector List of NamingListeners that will be notified of event.
88 */
89 synchronized void enqueue(EventObject event, Vector<NamingListener> vector) {
90 QueueElement newElt = new QueueElement(event, vector);
91
92 if (head == null) {
93 head = newElt;
94 tail = newElt;
95 } else {
96 newElt.next = head;
97 head.prev = newElt;
98 head = newElt;
124 }
125
126 /**
127 * Pull events off the queue and dispatch them.
128 */
129 public void run() {
130 QueueElement qe;
131
132 try {
133 while ((qe = dequeue()) != null) {
134 EventObject e = qe.event;
135 Vector<NamingListener> v = qe.vector;
136
137 for (int i = 0; i < v.size(); i++) {
138
139 // Dispatch to corresponding NamingListener
140 // The listener should only be getting the event that
141 // it is interested in. (No need to check mask or
142 // instanceof subinterfaces.)
143 // It is the responsibility of the enqueuer to
144 // only enqueue events with listeners of the correct type.
145
146 if (e instanceof NamingEvent) {
147 ((NamingEvent)e).dispatch(v.elementAt(i));
148
149 // An exception occurred: if notify all naming listeners
150 } else if (e instanceof NamingExceptionEvent) {
151 ((NamingExceptionEvent)e).dispatch(v.elementAt(i));
152 } else if (e instanceof UnsolicitedNotificationEvent) {
153 ((UnsolicitedNotificationEvent)e).dispatch(
154 (UnsolicitedNotificationListener)v.elementAt(i));
155 }
156 }
157
158 qe = null; e = null; v = null;
159 }
160 } catch (InterruptedException e) {
161 // just die
162 }
163 }
164
|