$darkmode
DENOPTIM
Task.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Vishwesh Venkatraman <vishwesh.venkatraman@ntnu.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.task;
20
21import java.io.File;
22import java.util.concurrent.Callable;
23
24
29public abstract class Task implements Callable<Object>
30{
35 protected boolean notifyGlobalTaskManager = false;
36
41 protected boolean completed = false;
42
46 protected boolean hasException = false;
47
51 public Object lock = new Object();
52
56 protected String errMsg = "";
57
61 protected Throwable thrownExc;
62
68 protected int id;
69
74
78 protected File workDir;
79
83 protected int verbosity = 0;
84
88 protected final String SEP = System.getProperty("file.separator");
89
93 protected final String NL = System.getProperty("line.separator");
94
95//------------------------------------------------------------------------------
96
97 public Task(final int id)
98 {
99 this.id = id;
100 }
101
102//------------------------------------------------------------------------------
103
104 public int getId()
105 {
106 return id;
107 }
108
109//------------------------------------------------------------------------------
110
114 public void setVerbosity(int verbosity)
115 {
116 this.verbosity = verbosity;
117 }
118//------------------------------------------------------------------------------
119
124 public void setWorkSpace(File workDir)
125 {
126 this.workDir = workDir;
127 }
128
129//------------------------------------------------------------------------------
130
134 public boolean isCompleted()
135 {
136 return completed;
137 }
138
139//------------------------------------------------------------------------------
140
146 public boolean foundException()
147 {
148 return hasException;
149 }
150
151//------------------------------------------------------------------------------
152
156 public Throwable getException()
157 {
158 return thrownExc;
159 }
160
161//------------------------------------------------------------------------------
162
166 public String getErrorMessage()
167 {
168 return errMsg;
169 }
170
171//------------------------------------------------------------------------------
172
177 public void stopTask()
178 {
179 if (completed)
180 {
181 return;
182 }
183 if (processHandler != null)
184 {
185 System.err.println("Calling stop on processes from "
186 + this.getClass().getName() + " " + id);
188 } else {
190 {
192 }
193 Thread.currentThread().interrupt();
194 }
195 }
196
197//------------------------------------------------------------------------------
198
204 @Override
205 public String toString()
206 {
207 StringBuilder sb = new StringBuilder();
208 sb.append(this.getClass().getName());
209 sb.append(" [id=").append(id);
210 sb.append(", hasException=").append(hasException);
211 sb.append(", completed=").append(completed).append("] ");
212 return sb.toString();
213 }
214
215//------------------------------------------------------------------------------
216
217 public void setNotify(boolean notify)
218 {
219 this.notifyGlobalTaskManager = notify;
220 }
221
222//------------------------------------------------------------------------------
223
224}
Manager for tasks submitted by the GUI.
A task that can throw exceptions.
Definition: Task.java:30
boolean notifyGlobalTaskManager
Flag controlling whether this task is expected to notify the static task manager.
Definition: Task.java:35
String toString()
Returns a string identifying this task by its ID and reporting whether an exception has been thrown a...
Definition: Task.java:205
void setNotify(boolean notify)
Definition: Task.java:217
File workDir
The file system location where we want to be placed when doing the work.
Definition: Task.java:78
boolean isCompleted()
Definition: Task.java:134
int id
A user-assigned id for this task.
Definition: Task.java:68
boolean completed
Flag about completion.
Definition: Task.java:41
Throwable getException()
Definition: Task.java:156
int verbosity
Verbosity level.
Definition: Task.java:83
Object lock
Lock for addressing synchronization issues.
Definition: Task.java:51
ProcessHandler processHandler
Executor for external bash script.
Definition: Task.java:73
String errMsg
Error message produced by any subtask.
Definition: Task.java:56
boolean foundException()
Definition: Task.java:146
boolean hasException
Flag about exception.
Definition: Task.java:46
void setVerbosity(int verbosity)
Set the verbosity: i.e., amount of log printed by this class.
Definition: Task.java:114
final String NL
System-dependent line separator (newline)
Definition: Task.java:93
void setWorkSpace(File workDir)
Sets the pathname of the work space, i.e., the location where the task is supposed to use move to or ...
Definition: Task.java:124
Task(final int id)
Definition: Task.java:97
void stopTask()
Stop the task if not already completed.
Definition: Task.java:177
String getErrorMessage()
Definition: Task.java:166
final String SEP
System-dependent file separator.
Definition: Task.java:88
Throwable thrownExc
Exception thrown.
Definition: Task.java:61