FileDocCategorySizeDatePackage
EventQueue.javaAPI DocJavaMail 1.4.34474Tue Nov 17 10:38:12 GMT 2009javax.mail

EventQueue

public class EventQueue extends Object implements Runnable
Package private class used by Store & Folder to dispatch events. This class implements an event queue, and a dispatcher thread that dequeues and dispatches events from the queue. Pieces stolen from sun.misc.Queue.
author
Bill Shannon

Fields Summary
private QueueElement
head
private QueueElement
tail
private Thread
qThread
Constructors Summary
public EventQueue()


      
	qThread = new Thread(this, "JavaMail-EventQueue");
	qThread.setDaemon(true);  // not a user thread
	qThread.start();
    
Methods Summary
private synchronized javax.mail.EventQueue$QueueElementdequeue()
Dequeue the oldest object on the queue. Used only by the run() method.

return
the oldest object on the queue.
exception
java.lang.InterruptedException if another thread has interrupted this thread.

	while (tail == null)
	    wait();
	QueueElement elt = tail;
	tail = elt.prev;
	if (tail == null) {
	    head = null;
	} else {
	    tail.next = null;
	}
	elt.prev = elt.next = null;
	return elt;
    
public synchronized voidenqueue(javax.mail.event.MailEvent event, java.util.Vector vector)
Enqueue an event.

	QueueElement newElt = new QueueElement(event, vector);

	if (head == null) {
	    head = newElt;
	    tail = newElt;
	} else {
	    newElt.next = head;
	    head.prev = newElt;
	    head = newElt;
	}
	notifyAll();
    
public voidrun()
Pull events off the queue and dispatch them.

	QueueElement qe;

	try {
	    loop:
	    while ((qe = dequeue()) != null) {
		MailEvent e = qe.event;
		Vector v = qe.vector;

		for (int i = 0; i < v.size(); i++)
		    try {
			e.dispatch(v.elementAt(i));
		    } catch (Throwable t) {
			if (t instanceof InterruptedException)
			    break loop;
			// ignore anything else thrown by the listener
		    }

		qe = null; e = null; v = null;
	    }
	} catch (InterruptedException e) {
	    // just die
	}
    
voidstop()
Stop the dispatcher so we can be destroyed.

	if (qThread != null) {
	    qThread.interrupt();	// kill our thread
	    qThread = null;
	}