Package org.jboss.fresh.shell.impl

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


      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) {
            childls = new LinkedList();
            parentMap.put(shel.getSessionID(), childls);
          }

          childls.add(p);
        }
      }
    }



    it = singles.iterator();
    while (it.hasNext()) {
      ShellImpl shi = (ShellImpl) it.next();
      outputProcess(shi, null, 0, idleShells);
    }



View Full Code Here


      } 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);
View Full Code Here

            if (ln.length() != 0 && ln.charAt(0) != '#') {
                if (debug) {
                    log.debug(exePath + " - Executing " + line);
                }

                ShellImpl sh = (ShellImpl) getShell();
                try {
                    ProcessInfo pinfo = sh.execute(line);

                    InBuffer buf = null;
                    try {
                        buf = sh.getBuffer(pinfo.procid, 1);
                    } catch (org.jboss.fresh.shell.NoSuchProcessException ex) {
                        continue;
                    }

                    BufferObjectReader ein = new BufferObjectReader(buf); // get out buffer
View Full Code Here

TOP

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

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.