Esempio n. 1
0
 public void cancel() {
   ShellProcess process = current.get();
   if (process != null) {
     process.cancel();
   } else {
     writer.println();
     writer.print(getPrompt());
     writer.flush();
   }
 }
Esempio n. 2
0
  public void run() {

    //
    String welcome = shell.getWelcome();
    writer.println(welcome);
    writer.flush();

    //
    while (true) {
      String prompt = getPrompt();
      String line;
      try {
        writer.println();
        writer.flush();
        if ((line = reader.readLine(prompt)) == null) {
          break;
        }
      } catch (IOException e) {
        // What should we do other than that ?
        break;
      }

      //
      ShellProcess process = shell.createProcess(line);
      JLineProcessContext context = new JLineProcessContext(this);
      current.set(process);
      try {
        process.execute(context);
        try {
          context.latch.await();
        } catch (InterruptedException ignore) {
          // At the moment
        }
      } finally {
        current.set(null);
      }
      ShellResponse response = context.resp.get();

      //
      if (response instanceof ShellResponse.Cancelled) {
        // Do nothing
      } else if (response instanceof ShellResponse.Close) {
        break;
      } else {
        response.getReader().writeAnsiTo(writer);
        writer.flush();
      }
    }
  }
Esempio n. 3
0
  public void cancel() {
    // Construcuted -> ISE
    // Evaluating -> Canceled
    // Queued -> Canceled
    // Cancelled -> Cancelled
    // Terminated -> Terminated
    boolean cancel;
    synchronized (lock) {
      switch (status) {
        case CONSTRUCTED:
          throw new IllegalStateException(
              "Cannot call cancel on process that was not scheduled for execution yet");
        case QUEUED:
          status = Status.CANCELED;
          cancel = false;
          break;
        case EVALUATING:
          status = Status.CANCELED;
          cancel = true;
          break;
        default:
          cancel = false;
          break;
      }
    }

    //
    if (cancel) {
      callee.cancel();
    }
  }