예제 #1
0
  /**
   * Returns the process which is bound to the given address. This returns null if there isn't any
   * process with the given binding.
   *
   * @param binding The address to inspect.
   * @return The process which binds itself to the given address.
   */
  public Process getProcess(Address binding) {

    for (Process process : getAllProcesses()) {
      if (process.getExecutor().getPacketListener(binding) != null) {
        return process;
      }
    }

    return null;
  }
예제 #2
0
  /**
   * Calculates and returns a new pid for a new process.
   *
   * @return The calculated pid.
   */
  public synchronized int requestPid() {

    List<Integer> pids = new ArrayList<Integer>();
    for (Process process : getAllProcesses()) {
      pids.add(process.getPid());
    }
    int pid = 0;
    while (pids.contains(pid)) {
      pid++;
    }
    return pid;
  }
예제 #3
0
  /**
   * Returns a list of all current running processes.
   *
   * @return A list of all current running processes.
   */
  public List<Process> getAllProcesses() {

    List<Process> processes = new ArrayList<Process>();
    processes.add(rootProcess);
    processes.addAll(rootProcess.getAllChildren());
    return processes;
  }
예제 #4
0
  @Override
  public int hashCode() {

    final int prime = 31;
    int result = 1;
    result = prime * result + (rootProcess == null ? 0 : rootProcess.hashCode());
    return result;
  }
예제 #5
0
  /**
   * Changes the running state of the process manager.
   *
   * @param running True if the process manager is running, false if not.
   */
  public void setRunning(boolean running) {

    if (running) {
      rootProcess =
          new Process(
              host, null, 0, host.getFileSystemManager().getFile("C:/system/boot/kernel"), null);
    } else {
      rootProcess.interrupt(true);
    }
  }
예제 #6
0
  @Override
  public boolean equals(Object obj) {

    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    ProcessManager other = (ProcessManager) obj;
    if (rootProcess == null) {
      if (other.rootProcess != null) {
        return false;
      }
    } else if (!rootProcess.equals(other.rootProcess)) {
      return false;
    }
    return true;
  }