KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > tasks > AbstractTask


1 package com.sslexplorer.tasks;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collection JavaDoc;
5
6 import com.sslexplorer.boot.Util;
7 import com.sslexplorer.security.SessionInfo;
8
9 public abstract class AbstractTask implements Task {
10     
11     private String JavaDoc bundle;
12     private String JavaDoc name;
13     private String JavaDoc note;
14     private Collection JavaDoc<TaskProgressBar> progressBars;
15     private SessionInfo session;
16     private boolean completed;
17     private int id;
18     private boolean configured;
19     private Object JavaDoc configLock = new Object JavaDoc();
20     
21     public AbstractTask(String JavaDoc bundle, String JavaDoc name) {
22         this.bundle = bundle;
23         this.name = name;
24         progressBars = new ArrayList JavaDoc<TaskProgressBar>();
25     }
26     
27     public void configured() {
28         if(configured) {
29             throw new IllegalStateException JavaDoc("Already configured.");
30         }
31         notifyConfigLock();
32     }
33     
34     void notifyConfigLock() {
35         synchronized(configLock) {
36             configured = true;
37             configLock.notifyAll();
38         }
39     }
40
41     public void waitForConfiguration() {
42         synchronized(configLock) {
43             while(!completed && !configured) {
44                 try {
45                     configLock.wait(1000);
46                 } catch (InterruptedException JavaDoc e) {
47                 }
48             }
49         }
50         
51     }
52
53     public SessionInfo getSession() {
54         return session;
55     }
56     
57     public void init(SessionInfo session, int id) {
58         if(this.session != null) {
59             throw new IllegalStateException JavaDoc("Task already attached to session.");
60         }
61         this.id = id;
62         this.session = session;
63     }
64     
65     public void addProgressBar(TaskProgressBar progressBar) {
66         progressBars.add(progressBar);
67     }
68     
69     public void clearProgressBars() {
70         progressBars.clear();
71     }
72
73     public String JavaDoc getBundle() {
74         return bundle;
75     }
76
77     public String JavaDoc getName() {
78         return name;
79     }
80     
81     public void setNote(String JavaDoc note) {
82         this.note = note;
83     }
84
85     public String JavaDoc getNote() {
86         return note;
87     }
88
89     public Collection JavaDoc<TaskProgressBar> getProgressBars() {
90         return progressBars;
91     }
92     
93     public boolean isComplete() {
94         return completed;
95     }
96     
97     public boolean isConfigured() {
98         return configured;
99     }
100     
101     public int getId() {
102         return id;
103     }
104     
105     public void complete() {
106         if(completed) {
107             throw new IllegalStateException JavaDoc("Already completed.");
108         }
109         completed = true;
110         notifyConfigLock();
111     }
112
113 }
114
Popular Tags