1 |
tdb |
1.1 |
class Consumer extends Thread { |
2 |
|
|
|
3 |
tdb |
1.3 |
public Consumer(Queue queue, long sleepTime, int repititions) { |
4 |
tdb |
1.1 |
_queue = queue; |
5 |
tdb |
1.2 |
_sleepTime = sleepTime; |
6 |
tdb |
1.3 |
_repititions = repititions; |
7 |
tdb |
1.1 |
} |
8 |
|
|
|
9 |
|
|
public void run() { |
10 |
tdb |
1.3 |
boolean run = true; |
11 |
|
|
_n = _queue.getQueue(); |
12 |
|
|
System.out.println("Got queue: "+_n); |
13 |
|
|
String s = null; |
14 |
|
|
int i = 0; |
15 |
tdb |
1.2 |
while(run) { |
16 |
|
|
try { Thread.sleep(_sleepTime); } catch(Exception e) {} |
17 |
tdb |
1.3 |
try { |
18 |
|
|
s = (String) _queue.get(_n); |
19 |
|
|
} |
20 |
|
|
catch(InvalidQueueException e) { |
21 |
|
|
System.out.println(e); |
22 |
|
|
run=false; |
23 |
|
|
} |
24 |
tdb |
1.2 |
System.out.println("["+_n+"] "+s); |
25 |
tdb |
1.3 |
i++; |
26 |
|
|
if(i==_repititions) { |
27 |
|
|
run = false; |
28 |
|
|
} |
29 |
tdb |
1.1 |
} |
30 |
tdb |
1.3 |
System.out.println("Closing down, and releasing queue "+_n); |
31 |
|
|
_queue.removeQueue(_n); |
32 |
tdb |
1.1 |
} |
33 |
|
|
|
34 |
|
|
private Queue _queue; |
35 |
tdb |
1.2 |
private int _n; |
36 |
|
|
private long _sleepTime; |
37 |
tdb |
1.3 |
private int _repititions; |
38 |
tdb |
1.1 |
|
39 |
|
|
} |