package simulator.workload.reader.archive.gwf; import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import simulator.workload.reader.archive.AbstractWAParser; /** * * @author Marcin Krystek * */ public class GWFParser extends AbstractWAParser { private Log log = LogFactory.getLog(GWFParser.class); public GWFParser(String fileName) throws IOException, NullPointerException { super(fileName); this.fieldsNo = 29; this.COMMENT = "#"; } public String[] readTask(String id) throws IOException { long filePointer = getFilePointer(); String fields[] = null; boolean found = false; // reads from current position to the end of file while(!found && (fields = readTask()) != null){ if(fields[GWFFields.DATA_JOB_ID].equals(id)) found = true; } if(!found){ // back to the beginning super.seek(0); // reads from the beginning of file to current position while(!found && filePointer != getFilePointer() && (fields = readTask()) != null){ if(fields[GWFFields.DATA_JOB_ID].equals(id)) found = true; } } if(found == false) return null; return fields; } protected void buildIdx(String line, long position){ if(line == null || line.length() == 0) return; String fields[] = line.split(FIELD_SEPARATOR+"+"); if(fields == null || fields.length != fieldsNo) { log.error("Can not build job index for line: " + line + "\nSome data fields are missing."); return; } String jobId = fields[GWFFields.DATA_JOB_ID]; this.jobIndex.put(jobId, position); } public int getType(){ return 1; } }