comparison src/org/dancres/blitz/notify/BlockingDispatchImpl.java @ 0:3dc0c5604566

Initial checkin of blitz 2.0 fcs - no installer yet.
author Dan Creswell <dan.creswell@gmail.com>
date Sat, 21 Mar 2009 11:00:06 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3dc0c5604566
1 package org.dancres.blitz.notify;
2
3 class BlockingDispatchImpl implements DispatchTask {
4 private EventQueue theQueue;
5 private QueueEvent theEvent;
6
7 private boolean isDone = false;
8 private boolean isResolvable = false;
9 private int myTotalDispatches = 0;
10 private int myCompletedDispatches = 0;
11
12 BlockingDispatchImpl(EventQueue aQueue, QueueEvent anEvent) {
13 theQueue = aQueue;
14 theEvent = anEvent;
15 }
16
17 public void run() {
18 theQueue.dispatchImpl(this);
19 }
20
21 public QueueEvent getEvent() {
22 return theEvent;
23 }
24
25 public void block() throws InterruptedException {
26 synchronized(this) {
27 while (! isDone) {
28 try {
29 wait();
30 } catch (InterruptedException anIE) {
31 }
32 }
33 }
34 }
35
36 public void newDispatch() {
37 synchronized(this) {
38 ++myTotalDispatches;
39 }
40 }
41
42 public void dispatched() {
43 synchronized(this) {
44 ++myCompletedDispatches;
45 }
46
47 checkAndFire();
48 }
49
50 public void enableResolve() {
51 synchronized(this) {
52 isResolvable = true;
53 }
54
55 checkAndFire();
56 }
57
58 private void checkAndFire() {
59 synchronized(this) {
60 if (!isResolvable)
61 return;
62
63 if (myTotalDispatches == myCompletedDispatches) {
64 isDone = true;
65 notify();
66 }
67 }
68 }
69 }