1 | package simulator.workload.reader.archive.gwf; |
---|
2 | |
---|
3 | import java.io.IOException; |
---|
4 | |
---|
5 | import org.apache.commons.logging.Log; |
---|
6 | import org.apache.commons.logging.LogFactory; |
---|
7 | |
---|
8 | import simulator.workload.reader.archive.AbstractWAParser; |
---|
9 | |
---|
10 | /** |
---|
11 | * |
---|
12 | * @author Marcin Krystek |
---|
13 | * |
---|
14 | */ |
---|
15 | |
---|
16 | public 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 | } |
---|