Package org.jboss.fresh.shell.impl

Examples of org.jboss.fresh.shell.impl.Process


      return;
    }

    if (outproc != null) {
      SystemShellImpl ss = (SystemShellImpl) ((ShellImpl) getShell()).getSystemShell();
      Process proc = ss.findProcess(outproc);
      if (proc == null) {
        Map m = ss.getShellMap();
        Iterator it = m.entrySet().iterator();
        while (it.hasNext()) {
          Map.Entry ent = (Map.Entry) it.next();
          ShellImpl shel = (ShellImpl) ent.getValue();
          Map procs = shel.getProcesses();
          proc = (Process) procs.get(outproc);
          if (proc != null) break;
        }

        if (proc == null) {
          error("No process for id: " + outproc);
          return;
        }
      }

      Object outb = proc.getOutputBuffer();
      pout.println("Out buffer: " + outb + " [" + (outb == null ? "" : outb.getClass().getName()) + "]");

      if (outb instanceof BufferImpl) {
        List ls = ((BufferImpl) outb).getBufferCopy();
        pout.println("\nContent: ");
        pout.println(ls);
      }

      pout.flush();
      return;
    }

    if(fullThreadDump) {
      Set allTraces = Thread.getAllStackTraces().entrySet();
      Iterator it = allTraces.iterator();
      while(it.hasNext()) {
        Map.Entry ent = (Map.Entry) it.next();

        Thread key = (Thread) ent.getKey();
        StackTraceElement [] traces = (StackTraceElement []) ent.getValue();

        boolean netlight = false;
        boolean plain = false;
        boolean highlight = key.getState() != Thread.State.BLOCKED && key.getState() != Thread.State.TIMED_WAITING && key.getState() != Thread.State.WAITING;
        if(highlight && traces.length > 0 &&
          (("java.net.PlainSocketImpl".equals(traces[0].getClassName())
            && "socketAccept".equals(traces[0].getMethodName()))
          || ("java.net.SocketInputStream".equals(traces[0].getClassName())
            && "socketRead0".equals(traces[0].getMethodName())))
              ) {
          netlight = true;
        }

        if(netlight) {
          pout.print("\u001B[0;36m");
        } else if(traces.length == 0) {
          highlight = true;
          pout.print("\u001B[0;31m");
        } else if(highlight) {
          plain = true;
          pout.print("\u001B[1;33m");
        }

        pout.println(ent.getKey());

        if(plain) {
          pout.print("\u001B[0m\u001B[0;33m");
        }

        for(int i=0; i<traces.length; i++) {
          pout.println("    " + traces[i]);
        }

        if(highlight)
          pout.print("\u001B[0m");

      }
      pout.flush();
      return;
    }

    if (order != null) {
      try {
        comptor = new TableComparator(order, (alles ? COLS_LONG : COLS_SHORT));
        rows = new TreeSet(comptor);
      } catch (Exception ex) {
        error(ex.getMessage());
        return;
      }
    }

    //print("Processes: ");
    // Let's list all info for all processes first

/*
    Map m = ((ShellImpl) getShell()).getProcesses();
    Iterator it = m.entrySet().iterator();
    print("pID\tTime\tActive\tDone\tsessID\tType\tCmd\tErr");
    while (it.hasNext()) {
      Map.Entry me = (Map.Entry) it.next();
      //log.debug("Key: " + me.getKey());
      Process p = (Process) me.getValue();
      print(p.getID() + "\t" +
          elapsedTime(p.getStartTime()) + "\t" +
          !p.isFinished() + "\t" +
          p.canDispose() + "\t" +
          getShell().getSessionID() + "\t" +
          p.getClass().getName() + "\t" +
          p.getCommandLine() + "\t" +
          p.getThrowable());
    }
*/
    //print("Sessions:");
    int idlen = longForm ? 40 : 10;


    if (alles) {
      fmt = new LineFormat(new int[]{idlen, idlen, 8, 8, 8, 5, 8, 7, 15, 3}, new String[]{"l", "l", "l", "l", "l", "l", "l", "l", "l"}, new int[]{0, 2, 2, 2, 2, 2, 2, 2, 2, 2});
      print(fmt.print(COLS_LONG), 0);
    } else {
      fmt = new LineFormat(new int[]{idlen, idlen, 8, 8, 8, 3}, new String[]{"l", "l", "l", "l", "l", "l"}, new int[]{0, 2, 2, 2, 2, 2});
      print(fmt.print(COLS_SHORT), 0);
    }

    //print("\n");

    Iterator it = null;
    Map procMap = null;
    if (xall) {
      procMap = ((SystemShellImpl) ((ShellImpl) getShell()).getSystemShell()).getShellMap();
      //it = m.entrySet().iterator();
    } else {
      procMap = new HashMap();
      procMap.put("0", getShell());
      //it = m.entrySet().iterator();
    }

    HashSet singles = new HashSet();

    // prepare hierarchies
    it = procMap.entrySet().iterator();
    while(it.hasNext()) {
      Map.Entry ent = (Map.Entry)it.next();
      ShellImpl shel = (ShellImpl) ent.getValue();
      singles.add(shel);

      Map pcs = shel.getProcesses();
      Iterator it2 = pcs.entrySet().iterator();
      while (it2.hasNext()) {
        Map.Entry me2 = (Map.Entry) it2.next();
        //log.debug("Key: " + me.getKey());
        if ("0".equals(me2.getKey())) continue;

        Process p = (Process) me2.getValue();
        if(p.getParent() != null) {
          List childls = (List) parentMap.get(p.getParent().getID());
          if(childls == null) {
            childls = new LinkedList();
            parentMap.put(p.getParent().getID(), childls);
          }
          childls.add(p);
        } else {
          List childls = (List) parentMap.get(shel.getSessionID());
          if(childls == null) {
View Full Code Here


    Thread t = p != null ? p.getThread() : null;
      int activeChildren = 0;
      if(children != null) {
        Iterator it = children.iterator();
        while(it.hasNext()) {
           Process pcs = (Process) it.next();
           if(!pcs.isFinished()) {
              activeChildren++;
              break;
           }
        }
      }
      if(((tracesOn && activeChildren == 0) ||
           (parentTracesOn && p != null && p.getParent() == null))
         && p != null && t != null) {
      StackTraceElement [] traces = t.getStackTrace();
      StringBuffer sb = new StringBuffer("\r\n");
      boolean found = false;
      for(int i=0; i<traces.length; i++) {
        Executable exu = p.getExecutable();
        String exc = exu != null ? exu.getClass().getName() : null;
        if(traces[i].getClassName().equals(exc)) {
          found = true;
        } else if(found) {
          break;
        }
           sb.append("\r\n\t").append(String.valueOf(traces[i]));
        }

      if (order != null) {
        row[row.length-1] = row[row.length-1] + sb;
        rows.add(row);
      } else {
        print(fmt.print(row) + sb, depth);
      }
    } else {
      if (order != null)
        rows.add(row);
      else
        print(fmt.print(row), depth);
    }

    // if process has children
    if(children != null) {
      Iterator it = children.iterator();
      while(it.hasNext()) {
        Process pcs = (Process) it.next();
        outputProcess(shel, pcs, depth+1, idleShells);
      }
    }
  }
View Full Code Here

      Properties p = null;
      if(procid == null) {
        p = getProcess().getEnv().getEnvProperties();
      } else {
        SystemShellImpl ss = (SystemShellImpl) ((ShellImpl) getShell()).getSystemShell();
        Process proc = ss.findProcess(procid);
        if (proc == null) {
          Map m = ss.getShellMap();
          ShellImpl shel = (ShellImpl) m.get(procid);
          if(shel == null) {
            error("No process / shell found for id: " + procid);
            return;
          }
          p = shell.getEnv().getEnvProperties();
        } else {
          if(proc.getEnv() != null) {
            error("Process has no environment - it means it exited but wasn't yet evicted");
            return;
          }
          p = proc.getEnv().getEnvProperties();
        }
       
      }
      HashMap map = new HashMap();
      Enumeration enu = p.propertyNames();
      while (enu.hasMoreElements()) {
        String nm = (String) enu.nextElement();
        map.put(nm, p.getProperty(nm));
      }

      TreeMap sm = new TreeMap(map);
      Iterator it = sm.entrySet().iterator();
      while (it.hasNext()) {
        Map.Entry ent = (Map.Entry) it.next();
        pout.println(ent.getKey() + "=" + ent.getValue());
      }

      pout.close();
      log.debug("done");
      return;
    }

        if(procid == null) {
          if(key == null) {
              error("Nothing to do");
              return;
          }
 
          if(key.length() == 0) {
              error("ENV variable name not specified");
              return;
          }
        }

    if(!eq) {
            // just display the value
      if(procid == null) {
        val = getProcess().getEnv().getEnvProperty(key);
      } else {
        SystemShellImpl ss = (SystemShellImpl) ((ShellImpl) getShell()).getSystemShell();
        Process proc = ss.findProcess(procid);
        if (proc == null) {
          Map m = ss.getShellMap();
          ShellImpl shel = (ShellImpl) m.get(procid);
          if(shel == null) {
            error("No process / shell found for id: " + procid);
            return;
          }
          val = shell.getEnv().getEnvProperty(key);
        } else {
          val = proc.getEnv().getEnvProperty(key);
        }
      }

      getStdOut().put(key + "=" + (val == null ? "" : val), 10000L);
            return;
View Full Code Here

      error("Process id not specified");
      return;
    }

    Map m = ((ShellImpl) getShell()).getProcesses();
    Process p = (Process) m.get(pid);
   
    Executable ex = null;
    if(p != null)
      ex = p.getExecutable();

    if (ex != null) {
      ex.sendMessage(sig);
      log.debug("done");
      return;
    }

    m = ((SystemShellImpl) ((ShellImpl) getShell()).getSystemShell()).getProcMap();
    p = (Process) m.get(pid);
    if(p != null)
      ex = p.getExecutable();

    if (ex != null) {
      ex.sendMessage(sig);
      log.debug("done");
      return;
    }
   
   
    Iterator it = m.entrySet().iterator();
    while(it.hasNext()) {
      Map.Entry ent = (Map.Entry) it.next();
      String id = (String) ent.getKey();
      if(match(id, pid)) {
        p = (Process) ent.getValue();

        if(p != null)
          ex = p.getExecutable();

        if (ex != null) {
          ex.sendMessage(sig);
          log.debug("done");
          return;
View Full Code Here

TOP

Related Classes of org.jboss.fresh.shell.impl.Process

Copyright © 2018 www.massapicom. 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.