Exemplo n.º 1
0
 // 代表启动计算机
 public void start() {
   memory.read();
   memory.write();
   cpu.read();
   cpu.write();
   disk.read();
   disk.write();
 }
Exemplo n.º 2
0
  public void turnOff() {
    System.out.println("System is shutting down");

    powerOn = false;
    cdrom.turnOff();
    hdd.turnOff();
    ram.turnOff();
    cpu.turnOff();
  }
Exemplo n.º 3
0
  public void turnOn() {
    powerOn = true;
    cpu.turnOn();
    ram.turnOn();
    hdd.turnOn();
    cdrom.turnOn();

    System.out.println("System is ready");
  }
Exemplo n.º 4
0
  public void scanViruses() {
    if (this.powerOn != false) {
      String dataForScan = ram.read();
      cpu.scanForVirus(ram, dataForScan);

      dataForScan = hdd.read();
      cpu.scanForVirus(hdd, dataForScan);

      if (cdrom.isDiskInserted() == true) {
        dataForScan = cdrom.read();
        cpu.scanForVirus(cdrom, dataForScan);
      } else {
        System.out.println("No disk in CDROM");
      }

    } else {
      System.out.println("Before scan, turn on your PC");
    }
  }
Exemplo n.º 5
0
 @Override
 public void writeTo(StreamOutput out) throws IOException {
   out.writeVLong(timestamp);
   cpu.writeTo(out);
   mem.writeTo(out);
   swap.writeTo(out);
   if (out.getVersion().onOrAfter(Version.V_5_1_1_UNRELEASED)) {
     out.writeOptionalWriteable(cgroup);
   }
 }
Exemplo n.º 6
0
 @Override
 public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
   builder.startObject(Fields.OS);
   builder.field(Fields.TIMESTAMP, getTimestamp());
   cpu.toXContent(builder, params);
   mem.toXContent(builder, params);
   swap.toXContent(builder, params);
   if (cgroup != null) {
     cgroup.toXContent(builder, params);
   }
   builder.endObject();
   return builder;
 }
Exemplo n.º 7
0
  public void startTime() throws FileNotFoundException {

    PrintWriter outFile = new PrintWriter("output.data");

    Pcb cpuProc;

    while (!arrivalQueue.isEmpty() || !readyQueue.isEmpty()) {

      if (!arrivalQueue.isEmpty()) // makes pointer to head object of arrival queue
      test = arrivalQueue.peek();

      if (test.getArrivalTime() == sysTime
          && !arrivalQueue.isEmpty()) // adds to ready queue from arrival queue
      {
        readyQueue.add(arrivalQueue.remove());
        //				System.out.println("Job " + test.getId() + " entered the Ready Queue.");
      }

      if (cpu.currentProc == null && !readyQueue.isEmpty()) // puts the first job in cpu
      {
        cpu.currentProc = readyQueue.remove();
        //				System.out.println("This job is in the cpu and has an id of: " +
        // cpu.currentProc.getId());
        outFile.print(sysTime + " "); // entered cpu
      }

      if (!readyQueue.isEmpty()) test = readyQueue.peek();

      if (cpu.currentProc != null
          && !readyQueue.isEmpty()
          && cpu.currentProc.getPriority() < test.getPriority()) {
        Pcb cpuTemp = cpu.currentProc;

        outFile.println(sysTime + " " + cpu.currentProc.getId());

        cpu.currentProc = readyQueue.remove();
        readyQueue.add(cpuTemp);
        outFile.print(sysTime + " "); // entered cpu

        //				System.out.println("Job " + cpu.currentProc.getId() + " entered the CPU. With priority
        // " + cpu.currentProc.getPriority());

      }

      if (cpu.currentProc != null && cpu.currentProc.getCpuBurstTime() == 0) {
        outFile.println(sysTime + " " + cpu.currentProc.getId()); // lefted cpu

        cpu.currentProc = readyQueue.remove();

        outFile.print(sysTime + " "); // entered cpu

        //				System.out.println("the process in the cpu got it's burst time to zero.");
        //			 System.out.println("Job " + cpu.currentProc.getId() + " entered the CPU. With priority
        // " + cpu.currentProc.getPriority());
      }

      if (cpu.currentProc != null) {
        cpu.currentProc.setCpuBurstTime(cpu.currentProc.getCpuBurstTime() - 1);
        //		System.out.println("Tried to subtact one from cpu burst time");
      }

      sysTime++;
    }

    while (cpu.currentProc.getCpuBurstTime() != 0) {
      cpu.currentProc.setCpuBurstTime(cpu.currentProc.getCpuBurstTime() - 1);
      sysTime++;
    }

    System.out.println("Jobs are finished");

    outFile.println(sysTime + " " + cpu.currentProc.getId()); // lefted cpu	

    outFile.close();
    // after both Queues are empty finish the process in the cpu
  }
Exemplo n.º 8
0
  private void generateReport(String reportName, long time) {
    FileWriter outFile = null;
    try {
      outFile = new FileWriter(reportName);
    } catch (Exception e) {
      e.printStackTrace();
    }
    PrintWriter out = new PrintWriter(outFile);
    String bigline =
        "*************************************************************************************************\n";
    String shortLine = "*******************************************\n";
    out.write(bigline);
    out.write(" GLOBAL REPORT OF THE SCHEDULE OPTIMIZATION\n");
    out.write(bigline);
    out.write("\n");
    out.write("\n");

    out.write(shortLine);
    out.write("Time of the optimization:\n");
    out.write(Float.valueOf(time / 1000) + " sec\n");
    out.write(shortLine);
    out.write("\n");
    out.write("\n");

    out.write(shortLine);
    out.write("Number of generated and analysed schedules:\n");
    out.write(String.valueOf(this.nbSchedulesAnalysed) + "\n");
    out.write(shortLine);
    out.write("\n");
    out.write("\n");

    out.write(shortLine);
    out.write("Description of the schedules:\n");
    for (List<Pschedule> s : this.schedules_analysed) {
      out.write("**\n");
      out.write("Schedule number: " + String.valueOf(this.schedules_analysed.indexOf(s)) + "\n");
      out.write("TimeStamp: " + String.valueOf(s.get(0).getTime()) + "\n");
      out.write("Revenue: " + String.valueOf(s.get(0).getTotalRevenue()) + "\n");

      out.write("CPUs: \n");
      for (Pschedule row : s) {
        Cpu cpu = row.getCpu();
        List<Job> jobs = Integration.getJobRows(cpu.getCpuid());
        if (jobs.size() > 0) {
          out.write("     id: " + String.valueOf(cpu.getCpuid()) + "\n");
          out.write("     Jobs: \n");

          for (Job job : jobs) {
            out.write("        **\n");
            out.write("		id: " + String.valueOf(job.getJid()) + "\n");
            out.write("		duration: " + String.valueOf(job.getDuration()) + "\n");
            out.write("		priority: " + String.valueOf(job.getPriority()) + "\n");
            out.write("		revenue: " + String.valueOf(job.getRevenue()) + "\n");
            out.write("        **\n");
          }
        }
      }
      out.write("**\n");
    }
    out.write(shortLine);
    out.write("\n");
    out.write("\n");

    out.write(shortLine);
    out.write("Result of the optimization:\n");
    out.write("Optimized schedule found ? (YES/NO): ");
    if (this.profit_optimized) {
      out.write("YES\n");
    } else {
      out.write("NO\n");
      out.write("\n");
      out.write("Schedule with profit found ? (YES/NO): ");
      if (this.profit_found) {
        out.write("YES\n");
      } else {
        out.write("NO\n");
      }
    }
    out.write(shortLine);
    out.write("\n");
    out.write("\n");

    if ((this.opti_schedule != null)) {
      out.write(shortLine);
      if (this.profit_optimized) {
        out.write("Optimized schedule:\n");
      } else {
        out.write("Best schedule:\n");
      }
      List<Schedule> schedule = Integration.getScheduleRows();
      out.write(
          "Schedule number: "
              + String.valueOf(this.schedules_analysed.indexOf(this.opti_schedule))
              + "\n");
      out.write("TimeStamp: " + String.valueOf(schedule.get(0).getTime()) + "\n");
      out.write("Revenue: " + String.valueOf(schedule.get(0).getTotalRevenue()) + "\n");
      out.write("CPUs: \n");
      for (Schedule row : schedule) {
        Cpu cpu = row.getCpu();
        List<Job> jobs = Integration.getJobRows(cpu.getCpuid());
        if (jobs.size() > 0) {
          out.write("     id: " + String.valueOf(cpu.getCpuid()) + "\n");
          out.write("     Jobs: \n");

          for (Job job : jobs) {
            out.write("        **\n");
            out.write("		id: " + String.valueOf(job.getJid()) + "\n");
            out.write("		duration: " + String.valueOf(job.getDuration()) + "\n");
            out.write("		priority: " + String.valueOf(job.getPriority()) + "\n");
            out.write("		revenue: " + String.valueOf(job.getRevenue()) + "\n");
            out.write("        **\n");
          }
        }
      }
      out.write("**\n");
      out.write("Profit: " + String.valueOf(this.opti_profit) + "\n");
      out.write(shortLine);
      out.write("\n");
      out.write("\n");

      out.write(shortLine);
      out.write("Cpu Health Model:\n");
      out.write("\n");
      boolean noDead = true;
      for (Schedule row : schedule) {
        Cpu cpu = row.getCpu();
        if (cpu.getHealth().getStatus() == 1) {
          if (noDead) {
            out.write("CPUs that will need to be replaced: \n");
          }
          noDead = false;
          out.write("id: " + String.valueOf(cpu.getCpuid()) + "\n");
          out.write("Pmap1s: " + String.valueOf(cpu.getPmap1s()) + "\n");
          out.write("Pmap2s: " + String.valueOf(cpu.getPmap2s()) + "\n");
        }
      }
      if (noDead) {
        out.write("No CPUs will need to be replaced: \n");
      }
      out.write("\n");
      out.write("\n");
    }
    out.close();
  }
Exemplo n.º 9
0
 public void startComputer() {
   cpu.freeze();
   memory.load(BOOT_ADDRESS, harDrive.read(BOOT_SECTOR, SECTOR_SIZE));
   cpu.execute();
 }