source: DCWoRMS/trunk/src/simulator/workload/reader/archive/gwf/GWFParser.java @ 477

Revision 477, 1.6 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package simulator.workload.reader.archive.gwf;
2
3import java.io.IOException;
4
5import org.apache.commons.logging.Log;
6import org.apache.commons.logging.LogFactory;
7
8import simulator.workload.reader.archive.AbstractWAParser;
9
10/**
11 *
12 * @author Marcin Krystek
13 *
14 */
15
16public class GWFParser extends AbstractWAParser {
17
18        private Log log = LogFactory.getLog(GWFParser.class);
19       
20        public GWFParser(String fileName) throws IOException, NullPointerException {
21                super(fileName);
22                this.fieldsNo = 29;
23                this.COMMENT = "#";
24        }
25
26        public String[] readTask(String id) throws IOException {
27                long filePointer = getFilePointer();
28                String fields[] = null;
29                boolean found = false;
30               
31                // reads from current position to the end of file
32                while(!found && (fields = readTask()) != null){
33                        if(fields[GWFFields.DATA_JOB_ID].equals(id))
34                                found = true;
35                }
36               
37                if(!found){
38                        // back to the beginning
39                        super.seek(0);
40                        // reads from the beginning of file to current position
41                        while(!found && filePointer != getFilePointer() && (fields = readTask()) != null){
42                                if(fields[GWFFields.DATA_JOB_ID].equals(id))
43                                        found = true;
44                        }
45                }
46
47                if(found == false) return null;
48               
49                return fields;
50        }
51       
52        protected void buildIdx(String line, long position){
53                if(line == null || line.length() == 0)
54                        return;
55               
56                String fields[] = line.split(FIELD_SEPARATOR+"+");
57
58                if(fields == null || fields.length != fieldsNo) {
59                        log.error("Can not build job index for line: " + line +
60                                        "\nSome data fields are missing.");
61                        return;
62                }
63               
64                String jobId = fields[GWFFields.DATA_JOB_ID];
65                this.jobIndex.put(jobId, position);
66               
67        }
68       
69        public int getType(){
70                return 1;
71        }
72}
Note: See TracBrowser for help on using the repository browser.