KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > utilities > DeadlineChecker


1 package org.enhydra.shark.utilities;
2
3 import org.enhydra.shark.api.client.wfservice.DeadlineAdministration;
4
5 /**
6  * Checks deadlines.
7  *
8  * @author Sasa Bojanic
9  */

10 public class DeadlineChecker extends Thread JavaDoc {
11
12    private DeadlineAdministration deadlineAdmin;
13    private long delay;
14
15    boolean stopped=false;
16
17    public DeadlineChecker(DeadlineAdministration da,long delay) {
18       this.deadlineAdmin=da;
19       this.delay=delay;
20       System.out.println("Deadline checking time initialized to "+delay+" ms");
21       start();
22    }
23
24    public void setDelay (long delay) {
25       this.delay=delay;
26    }
27
28    public void stopChecker () {
29       stopped=true;
30    }
31
32    public void startChecker () {
33       stopped=false;
34    }
35
36    public void run() {
37       while (true) {
38          try {
39             sleep(delay);
40             if (!stopped) {
41                System.out.println("Checking deadlines ...");
42                long start=System.currentTimeMillis();
43                String JavaDoc[] failed = deadlineAdmin.checkDeadlines(5, 12);
44                for (int i = 0; i < failed.length; i++) {
45                   deadlineAdmin.checkDeadlines(failed[i]);
46                }
47                long end=System.currentTimeMillis();
48                System.out.println("Deadline check finished - it lasted "+(end-start)+" ms");
49             }
50          } catch (Exception JavaDoc e) {
51             e.printStackTrace();
52          }
53       }
54    }
55
56 }
57
58
Popular Tags