blob: d34439dcf9b9afd7c9a99fb3dac18b3470a22517 (
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
75
76
77
78
79
80
|
// ============================================================================
//
// = PACKAGE
// tests.Reactor
//
// = FILENAME
// TimerQueueTest.java
//
// = AUTHOR
// Prashant Jain
//
// ============================================================================
package tests.Reactor;
import JACE.OS.*;
import JACE.ASX.*;
import JACE.Reactor.*;
public class TimerQueueTest implements EventHandler
{
public int handleTimeout (TimeValue tv, Object obj)
{
ACE.DEBUG ("handleTimeout: " + tv.toString () + " " + (String) obj);
return 0;
}
public static void main (String args [])
{
TimerQueue tq = new TimerQueue (true);
TimerQueueTest th1 = new TimerQueueTest ();
int n = 5;
try
{
if (args.length == 1)
{
n = Integer.parseInt (args[0]);
}
}
catch (NumberFormatException e)
{
ACE.ERROR ("Illegal argument.");
}
// Set a periodic timer
int id= tq.scheduleTimer (th1,
"periodic",
new TimeValue (2),
new TimeValue (3));
int i;
// Set a bunch of single timers
for (i=1; i <= n; i++)
{
tq.scheduleTimer (th1,
"A-timer-" + new Integer (i),
new TimeValue (i*2));
}
TimerQueueTest th2 = new TimerQueueTest ();
for (i=1; i <= n; i++)
{
tq.scheduleTimer (th2,
"B-timer-" + new Integer (i),
new TimeValue (i*3));
}
// Cancel all timers associated with this handler
tq.cancelTimer (th2);
try
{
Thread.sleep (30000);
}
catch (InterruptedException e)
{
}
tq.cancelTimer (id);
System.exit (0);
}
}
|