[XXX]: Probably this method should be used to a test utility * class ?!
@@ -102,7 +102,7 @@ if ( buf.length() > 0 ) buf.deleteCharAt(buf.length()-1); return buf.toString(); } - + /* -------------------------------------------------------------------- */ /* -- Public attributes ----------------------------------------------- */ /* -------------------------------------------------------------------- */ @@ -116,11 +116,11 @@ /* -------------------------------------------------------------------- */ /* -- Private attributes ---------------------------------------------- */ /* -------------------------------------------------------------------- */ - + /** * Thread for the dispatching of events after transaction success. */ - private final Thread dispatcher = new Thread(new EventsDelivery()); + private final Thread dispatcher = new Thread(new EventsDelivery(), "MDR event dispatcher"); /** * Maps: event => set of pre-change listeners. @@ -131,14 +131,14 @@ * Maps: event => set of change listeners. */ private final Hashtable changeListeners = new Hashtable(); - + /** * Queue for the events of the currently running write transaction. * The events are stored to inform their listeners either about * rollback or success. */ private final LinkedList localQueue = new LinkedList(); - + /** * Queue for the events of successfully finished transactions, the * listeners of which still have to be informed. @@ -148,7 +148,7 @@ /* -------------------------------------------------------------------- */ /* -- Constructor (public) -------------------------------------------- */ /* -------------------------------------------------------------------- */ - + /** * Starts the dispatcher thread as daemon. */ @@ -183,8 +183,8 @@ Logger.getDefault().notify(Logger.INFORMATIONAL, e); } } - } - + } + /** * Calls {@link MDRPreChangeListener.changeCancelled(MDRChangeEvent)} * on all pre-change listeners of all events of the transaction to be @@ -210,6 +210,14 @@ localQueue.clear(); } + private boolean shuttingDown = false; + public void shutdown() { + synchronized (globalQueue) { + shuttingDown = true; + globalQueue.notify(); + } + } + /* -------------------------------------------------------------------- */ /* -- EventNotifier.EventDelivery (inner class, private) -------------- */ /* -------------------------------------------------------------------- */ @@ -229,10 +237,15 @@ public void run() { Collection collected; MDRChangeEvent event; - + while (true) { synchronized (globalQueue) { - while (globalQueue.isEmpty()) { + for (;;) { + if (!globalQueue.isEmpty()) + break; + else if (shuttingDown) + return; + try { globalQueue.wait(); } catch (InterruptedException e) {