View Javadoc

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.JobStatusNotifier;
5   import org.apache.log4j.Logger;
6   import org.globus.io.gass.server.JobOutputListener;
7   
8   import java.io.*;
9   
10  /* ***************************************************
11   * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
12   * ***             http://cc.in2p3.fr/             ***
13   * ***************************************************
14   * File:   LCGCEJobMonitorListener
15   * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
16   * Date:   23 juin 2010
17   * ***************************************************
18   * Description:                                      */
19  /**
20   *
21   */
22  public class LCGCEJobMonitorListener implements JobOutputListener {
23      private static Logger s_logger = Logger.getLogger(LCGCEJobMonitorListener.class);
24  
25      private JobStatusNotifier m_notifier;
26  
27      public LCGCEJobMonitorListener(JobStatusNotifier notifier) {
28          m_notifier = notifier;
29      }
30  
31      public void outputChanged(String s) {
32          BufferedReader reader = new BufferedReader(new StringReader(s));
33          try {
34              String timestamps = reader.readLine();
35              String line;
36              while ( !"GRIDMONEOF".equals(line=reader.readLine()) ) {
37                  String array[] = line.split(" +");
38                  if (array.length == 2) {
39                      String nativeJobId = array[0];
40                      Integer stateCode = new Integer(array[1]);
41                      String stateString = array[1];
42                      JobStatus status = new GatekeeperJobStatus(nativeJobId, stateCode, stateString);
43                      m_notifier.notifyChange(status);
44                  } else {
45                      s_logger.warn("Syntax error in grid-monitor output: "+line);
46                  }
47              }
48              reader.close();
49          } catch (IOException e) {
50              s_logger.warn("Failed to read grid-monitor output");
51          }
52      }
53  
54      public void outputClosed() {
55          // do nothing
56      }
57  }