blob: 9524f2fd314afa667e9c86f89d2daf0f626d9fa2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
package org.openslx.taskmanager.tasks;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.log4j.Logger;
import org.openslx.taskmanager.api.AbstractTask;
public class DummyTask extends AbstractTask
{
private static final Logger log = Logger.getLogger( DummyTask.class );
private DummyTaskStatus status = new DummyTaskStatus();
@Override
protected boolean initTask()
{
log.debug( "Initialized DummyTask with ID " + this.getId() );
return true;
}
@Override
protected boolean execute()
{
setStatusObject( status );
Process process = null;
try {
// Create process
process = Runtime.getRuntime().exec( "dummy", null, new File("/") );
// Read its output
BufferedReader reader = new BufferedReader( new InputStreamReader( process.getInputStream() ) );
String line;
while ( ( line = reader.readLine() ) != null ) {
line = reader.readLine();
if ( line.matches( "^\\d+%$" ) )
this.status.progress = Integer.parseInt( line.substring( 0, line.length() - 1 ) );
}
} catch ( IOException e ) {
log.warn( "Process of task " + this.getId() + " died." );
} finally {
if ( process != null )
process.destroy();
}
return this.status.progress == 100;
}
class DummyTaskStatus
{
protected int progress = 0;
}
}
|