1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
22 |
|
|
23 |
package org.jsampler.task; |
package org.jsampler.task; |
24 |
|
|
25 |
|
import java.util.Date; |
26 |
import java.util.logging.Level; |
import java.util.logging.Level; |
27 |
|
|
28 |
import net.sf.juife.AbstractTask; |
import net.sf.juife.AbstractTask; |
44 |
private boolean stopped = false; |
private boolean stopped = false; |
45 |
private boolean silent = false; |
private boolean silent = false; |
46 |
private boolean showErrorDetails; |
private boolean showErrorDetails; |
47 |
|
private boolean calculateElapsedTime = false; |
48 |
|
private long elapsedTime = -1; |
49 |
|
|
50 |
public |
public |
51 |
EnhancedTask() { this(false); } |
EnhancedTask() { this(false); } |
57 |
|
|
58 |
public void |
public void |
59 |
run() { |
run() { |
60 |
try { exec(); } |
try { |
61 |
catch(java.net.SocketException x) { |
if(getCalculateElapsedTime()) { |
62 |
|
elapsedTime = new Date().getTime(); |
63 |
|
} |
64 |
|
|
65 |
|
exec(); |
66 |
|
|
67 |
|
if(getCalculateElapsedTime()) { |
68 |
|
elapsedTime = new Date().getTime() - elapsedTime; |
69 |
|
} |
70 |
|
if(getCalculateElapsedTime()) System.out.println("time: " + getElapsedTime()); |
71 |
|
} catch(java.net.SocketException x) { |
72 |
setErrorCode(SOCKET_ERROR); |
setErrorCode(SOCKET_ERROR); |
73 |
setErrorMessage(i18n.getError("SOCKET_ERROR")); |
setErrorMessage(i18n.getError("SOCKET_ERROR")); |
74 |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
CC.getLogger().log(Level.FINE, getErrorMessage(), x); |
84 |
exec() throws Exception { } |
exec() throws Exception { } |
85 |
|
|
86 |
public void |
public void |
87 |
onError(Exception e) { } |
onError(Exception e) { e.printStackTrace(); } |
88 |
|
|
89 |
/** |
/** |
90 |
* Marks that the execution of this task was interrupted. |
* Marks that the execution of this task was interrupted. |
108 |
isSilent() { return silent; } |
isSilent() { return silent; } |
109 |
|
|
110 |
/** |
/** |
111 |
* DSets whether an error message should be shown |
* Sets whether an error message should be shown |
112 |
* if the execution of the task fail. |
* if the execution of the task fail. |
113 |
*/ |
*/ |
114 |
public void |
public void |
129 |
} |
} |
130 |
} |
} |
131 |
} |
} |
132 |
|
|
133 |
|
/** Determines whether to calculate the elapsed time for this task. */ |
134 |
|
public boolean |
135 |
|
getCalculateElapsedTime() { return calculateElapsedTime; } |
136 |
|
|
137 |
|
/** Sets whether to calculate the elapsed time for this task. */ |
138 |
|
public void |
139 |
|
setCalculateElapsedTime(boolean b) { calculateElapsedTime = b; } |
140 |
|
|
141 |
|
/** Gets the elapsed time for this task. */ |
142 |
|
public long |
143 |
|
getElapsedTime() { return elapsedTime; } |
144 |
} |
} |