KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > corbaclient > workflowadmin > DeadlineChecker


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