Package org.jboss.fresh.shell

Examples of org.jboss.fresh.shell.Executable


                if (clazz == null) throw new ShellException("No Class attribute specified. (" + command + ")");
                command = clazz;
            }


            Executable exe = getInternal(command);
            if (exe != null) return exe;

        } catch (ShellException ex) {

            log.error(ex.getMessage(), ex);

            Executable exe = getInternal(command);
            if (exe != null) return exe;

            throw ex;

        } catch (VFSException ex) {
            log.error(ex.getMessage(), ex);
            throw new ShellException(ex.toString());
        }
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        Class execls = null;
        try {
            execls = cl.loadClass(command);
        } catch (ClassNotFoundException e) {
            throw new BadCommandException("Unknown command.", command);
        }

        Executable exe;
        try {
            exe = (Executable) execls.newInstance();
        } catch (InstantiationException e) {
            throw new ShellException("Could not instantiate class: " + execls);
        } catch (IllegalAccessException e) {
            throw new ShellException("Not allowed to instantiate class: " + execls);
        }

        exe.setFileInfo(inf);

        return exe;
    }
View Full Code Here


      if (ptimeout == 0 || ptimeout > PROC_TIMEOUT_MAX) {
        ptimeout = PROC_TIMEOUT_MAX;
      }
    }

    Executable exe = runtime.loadExe(command);



    // Exe is ok, we have created it.

//    System.out.println("Successfully loaded executable.");

    // Now we ask sysshell to create process.
//    System.out.println("Creating new process ...");
    Process p = sshell.createProcess(this);
    setupEnv(cmd, p);

    p.setIOTimeout(ptimeout);

//    System.out.println("Created process: " + p);

    // We only create in buffer if we are the first, otherwise we simply use
    // previous exe's output buffer. To know if we are first it would help to have
    // access to job list
    InBuffer in = null;
    if (joblist.size() == 0) {

      if (cmdl.getSLStdInRedir() != null) {
        try {
          InputStreamBuffer bin = new InputStreamBuffer(new FileInputStream(cmdl.getSLStdInRedir()), cmdl.isSLInObjMode());
          bin.setProperties(env);
          in = bin;
        } catch (IOException ex) {
          throw new ShellException("Exception occured while initializing input buffer: " + ex.toString());
        }

      } else if (cmdl.getStdInRedir() != null) {
        try {
          //in=new InputStreamBuffer(new VFSInputStream(new SecureVFS(vfs, uctx), cmdl.getStdInRedir()), cmdl.isInObjMode());
          if(cmdl.getStdInLines() != null) {
            String enc = env.getProperty("ENC");
            ByteArrayInputStream bain;
            if(enc != null) {
              bain = new ByteArrayInputStream(cmdl.getStdInLines().getBytes("ENC"));
            } else {
              bain = new ByteArrayInputStream(cmdl.getStdInLines().getBytes());
            }
            InputStreamBuffer bin = new InputStreamBuffer(bain, false);
            bin.setProperties(env);
            in = bin;
           
          } else {
            FileName fname = new FileName(cmdl.getStdInRedir());
            if (fname.isRelative()) {
              fname = new FileName(getEnvProperty("PWD")).absolutize(fname);
            }
            InputStreamBuffer bin = new InputStreamBuffer(new VFSInputStream(new SecureVFS(vfs, uctx), fname.toString()), cmdl.isInObjMode());
            bin.setProperties(env);
            in = bin;
          }

        } catch (IOException ex) {
          throw new ShellException("Exception occured while initializing input buffer: " + ex.toString());
        }

      }


      if (in == null) {
//log.debug("No output redirect setup...");
        if (hasin) {
          if (!"SINGLE".equals(getEnvProperty("TMODE"))) {
            in = new BufferImpl();
          } else {
            in = new MemFileBufferImpl();
          }
          // here we set whatever is maxsize for inputbuffer for this executable - we have this set
          // as attribute on the file or something ...
          // FIXME
          List input = cmdl.getStdInput();
          if(input != null) {
            in.setMaxSize(input.size());
            try {
              ((Buffer)in).putBuffer(new LinkedList(input), 1000);
              in.close();
            } catch (IOException ex) {
              throw new ShellException("Exception occured while initializing input buffer: " + ex.toString());
            }
          }
          in.setMaxSize(inbufmax); // should be a variable

        } else {
          in = new NullBuffer();
        }
      }

    } else {
//log.debug("Piping in previous out...");
      Object o_in = ((Process) joblist.getLast()).getOutputBuffer();
      if (!(o_in instanceof InBuffer)) {
        throw new ShellException("Invalid pipe chain. Trying to read from write-only buffer.");
      }
      in = (InBuffer) o_in;
    }

//log.debug("\n\nin = " + in);

    OutBuffer out = null;

    if (cmdl.size() == joblist.size() + 1) {

      if (cmdl.getSLStdOutRedir() != null) {
        try {
          OutputStreamBuffer bout = new OutputStreamBuffer(new FileOutputStream(cmdl.getSLStdOutRedir(), cmdl.getSLAppend()), cmdl.isSLOutObjMode());
          bout.setProperties(env);
          out = bout;
          p.setRedirected(true);
        } catch (IOException ex) {
          throw new ShellException("Exception occured while initializing output buffer: " + ex.toString());
        }

      } else if (cmdl.getStdOutRedir() != null) {
        try {
          ////out=new OutputStreamBuffer(new VFSOutputStream(new SecureVFS(vfs, uctx), cmdl.getStdOutRedir(), cmdl.getAppend()), cmdl.isOutObjMode());

          //if(TxSupport.isActive()) throw new ShellException("Illegal state - inside transaction.");
          //TxSupport.begin();
          try {
            FileName fname = new FileName(cmdl.getStdOutRedir());
            if (fname.isRelative()) {
              fname = new FileName(getEnvProperty("PWD")).absolutize(fname);
            }
            OutputStreamBuffer bout = new OutputStreamBuffer(new LazyVFSOutputStream(new SecureVFS(vfs, uctx), fname.toString(), cmdl.getAppend()), cmdl.isOutObjMode());
            bout.setProperties(env);
            out = bout;
            p.setRedirected(true);
            //TxSupport.commit();
          } catch (Exception ex) {
            //TxSupport.rollback();
            throw ex;
          }
        } catch (Exception ex) {
          log.error("Exception occured while initializing output buffer: ", ex);
          throw new ShellException("Exception occured while initializing output buffer: " + ex.toString());
        }
      }
    }
//log.debug("\n\nout = " + out);
    if (out == null) {
      if (hasout) {
        if (!"SINGLE".equals(getEnvProperty("TMODE"))) {
          out = new BufferImpl();
        } else {
          out = new MemFileBufferImpl();
        }
       
        // here we set whatever is maxsize for inputbuffer for this executable - we have this set
        // as attribute on the file or something ...
        // FIXME
        out.setMaxSize(outbufmax); //  should be a variable

      } else {
        out = new NullBuffer();
      }

      if ((cmdl.size() == joblist.size() + 1) && ui && interactive) {
        procmap.put(STDIN_ID, p);
        outreader.replacePrimaryBuffer((InBuffer) out);
      }
    }

//log.debug("\n\nfinal out = " + out);
    p.setInputBuffer(in);
    p.setOutputBuffer(out);

//    System.out.println("Set allocated resurces on executable ...");
//log.debug("exe stdin = " + in);
//log.debug("exe stdout = " + out);

    exe.setStdIn(in);
    exe.setStdOut(out);
    exe.setShell(this);

//    System.out.println("Setting executable on Process ...");
    p.setExecutable(exe);
    exe.setProcess(p);

    p.setCommandLine(command);
    p.setParams(params);
    p.setOriginalParams(cmd.getOriginalParams());
    p.setExePath(exepath);
View Full Code Here

        //log.debug("[ShellImpl] doGC : Process timed out : " + p.getID());
        log.info("Process timed out : " + p.getID());
        if (p.isFinished()) {
          sshell.endProcess(p.getID());
        } else {
          Executable e = p.getExecutable();
          if (e != null) {
            e.sendMessage("KILL");
          }
        }
        procmap.remove(p.getID());
        //log.debug("***\n***[doGC] Process timed out. (" + proc_tout + ")  Removed process " + p.getID() + "\n***");
        log.debug("Process timed out. (" + proc_tout + ")  Removed process " + p.getID());
View Full Code Here

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

   }

   @Override
   public Executable getExecutable(String command)
   {
      Executable executable = super.getExecutable(command);
      if (executable != null)
         return executable;

      if (factories == null)
         return null;
View Full Code Here

    }

    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;
        } else {
          break;
        }
View Full Code Here

TOP

Related Classes of org.jboss.fresh.shell.Executable

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.