Package client

Source Code of client.Trace$CmpTime

package client;

import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;
import java.util.TreeMap;
import java.util.Vector;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import simulation.Simulation;
import events.NFSReadEvent;

public class Trace {
 
  class ReadRequest {
    public double time;
    public String fileHandle;
    public long offset;
    public long nbytes;
    ReadRequest(double time, String fileHandle, long offset, long nbytes) {
      this.time = time;
      this.fileHandle = fileHandle;
      this.offset = offset;
      this.nbytes = nbytes;
    }
  }
  class CmpTime implements Comparator<ReadRequest> {
    public int compare(ReadRequest r0, ReadRequest r1) {
      return Double.compare(r0.time, r1.time);
    }
  }
 
  Vector<ReadRequest> requests;
  TreeMap<String,TreeSet<ReadRequest>> requestsPerFile;
 
  public Trace(String csvTraceFile) throws IOException {
    Double time0 =  null;
    requests = new Vector<ReadRequest>();
    requestsPerFile = new TreeMap<String,TreeSet<ReadRequest>>();
    BufferedReader in = new BufferedReader(new FileReader(csvTraceFile));
    while (true) {
      String line = in.readLine();
      if (null == line)
        break;
      String fields[] = line.split(",");
      double time = Double.valueOf(fields[4]) * 1e3; // Convert to milliseconds.
      if (null == time0)
        time0 = new Double(time);
      time = time-time0;
      String fileHandle = fields[1];
      long offset = Long.valueOf(fields[2]);
      long nbytes = Long.valueOf(fields[3]);
      ReadRequest r = new ReadRequest(time, fileHandle, offset, nbytes);
      requests.add(r);
      if (!requestsPerFile.containsKey(fileHandle))
        requestsPerFile.put(fileHandle, new TreeSet<ReadRequest>(new CmpTime()));
      requestsPerFile.get(fileHandle).add(r);
    }
  }
 
  public void bulkImport(Simulation sim) {
    Iterator<ReadRequest> i = requests.iterator();
    while (i.hasNext()) {
      ReadRequest r = i.next();
      sim.simDriver.schedule(new NFSReadEvent(sim, r.time, "unknown_client", r.fileHandle, r.offset, r.nbytes));
    }
  }
 
}
TOP

Related Classes of client.Trace$CmpTime

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.
ew');