blob: 84df9b3a3aed4811c79b9433bff7b47720235f0b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// This class encapsulates a Consumer. The consumer dq's from the queue
// Supports both a timed and blocking consumer.
// Each instance of this class creates a different thread of control.
// On timeout, the producer returns.
// The producer tries to dq "iteration" number of times, unless it times out
//package NexusII.util ;
public class Consumer extends Thread
{
public static final int DEFAULT_ITERATIONS = 1 ;
public Consumer(MT_Bounded_Queue queue)
{
this.queue_ = queue ;
this.iterations_ = new Integer(DEFAULT_ITERATIONS);
this.time_out_ = -1 ;
}
public Consumer(MT_Bounded_Queue queue, String name)
{
super(name);
this.queue_ = queue ;
this.iterations_ = new Integer(DEFAULT_ITERATIONS);
this.time_out_ = -1 ;
}
public Consumer(MT_Bounded_Queue queue, String name, Integer iterations)
{
super(name);
this.queue_ = queue ;
this.iterations_ = iterations ;
this.time_out_ = -1 ;
}
public Consumer(MT_Bounded_Queue queue, String name, Integer iterations, long msec_timeout)
{
super(name);
this.queue_ = queue ;
this.iterations_ = iterations ;
this.time_out_ = msec_timeout ;
}
public void run()
{
for(int i=0;i<iterations_.intValue();i++)
{
if(time_out_ < 0)
System.out.println(getName() + ": dequeued " + queue_.dq());
else
{
Object err = queue_.dq(time_out_);
if(err == null)
{
System.out.println(getName() + ": Timedout\n");
return ;
}
else
System.out.println(getName() + ": dequeued " + err);
}
}
}
protected MT_Bounded_Queue queue_ ;
private Integer iterations_ ;
private long time_out_ ;
}
|