1 package fr.in2p3.jsaga.adaptor.job;
2
3 import fr.in2p3.jsaga.adaptor.job.monitor.JobStatus;
4 import fr.in2p3.jsaga.adaptor.job.monitor.QueryIndividualJob;
5 import org.ogf.saga.error.NoSuccessException;
6 import org.ogf.saga.error.TimeoutException;
7
8 import java.io.*;
9
10
11
12
13
14
15
16
17
18
19
20
21
22 public class EmulatorJobMonitorAdaptor extends EmulatorJobAdaptorAbstract implements QueryIndividualJob {
23 public int getDefaultPort() {return 5678;}
24
25 public JobStatus getStatus(String nativeJobId) throws TimeoutException, NoSuccessException {
26 File job = super.getJob(nativeJobId);
27 if (job.exists()) {
28 long endTime;
29 try {
30
31 BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(job)));
32 String line = in.readLine();
33 in.close();
34
35
36 endTime = Long.parseLong(line);
37 } catch (Exception e) {
38 SubState status = SubState.FAILED_ERROR;
39 return new EmulatorJobStatus(nativeJobId, status, e);
40 }
41 SubState status;
42 if (endTime == 0L) {
43 status = SubState.CANCELED;
44 } else if (System.currentTimeMillis() > endTime) {
45 status = SubState.DONE;
46 } else {
47 status = SubState.RUNNING_ACTIVE;
48 }
49 return new EmulatorJobStatus(nativeJobId, status);
50 } else {
51 throw new NoSuccessException("Job does not exist: "+nativeJobId);
52 }
53 }
54 }