Examples of InBuffer


Examples of org.jboss.fresh.io.InBuffer

      if (job.size() > 1) {
        ProcessGroup p = sshell.createProcessGroup(job);
        if (p == null) {
          throw new ShellException("[ShellImpl][execute] Failed to create ProcessGroup.");
        }
        InBuffer ib = ((Process) job.getFirst()).getInputBuffer();
        OutBuffer ob = ((Process) job.getLast()).getOutputBuffer();
        p.setRedirected(((Process) job.getLast()).isRedirected());

//log.debug("PRocessGroup ib: " + ib);
//log.debug("PRocessGroup ob: " + ob);
        p.setInputBuffer(ib);
        p.setOutputBuffer(ob);
        p.setCommandLine(cmdline);


        if (active == null) {
          active = p;
        }

//      if(interactive) {
//        outreader.replacePrimaryBuffer(ob);
//      }

        procmap.put(p.getID(), p);
        p.setUserInitiated(ui);

        hi.setProcessID(p.getID());

                // We don't use it anywhere - WRONG - we use it when NoProcessForID Exceptions occur
                LinkedList chs = hi.getChildren();
        LinkedList ls = p.getProcessList();
        it = ls.iterator();
        while(it.hasNext()) {
          Process cp = (Process) it.next();
          chs.add(cp);
        }

        if (!prepareOnly) {
          p.start(); // We have a problem with concurrent modification on job
        } else {
          preparedProcess.set(p);
        }
       
        ProcessInfo pinfo = new ProcessInfo();
        pinfo.procid = p.getID();
        pinfo.inbuf_maxsize = ib.getMaxSize();
        pinfo.outbuf_maxsize = ob.getMaxSize();
        return pinfo;
      } else {
        Process p = (Process) job.getFirst();
//    System.out.println("Putting the process in the procmap: " + p.getID() + " : " + p);

        InBuffer ib = p.getInputBuffer();
        OutBuffer ob = p.getOutputBuffer();

//log.debug("PRocess ib: " + ib);
//log.debug("PRocess ob: " + ob);

        if (active == null) {
          active = p;
        }
//      if(interactive) {
//        outreader.replacePrimaryBuffer(ob);
//      }

//      System.out.println("ACTIVE SET: " + active);

        procmap.put(p.getID(), p);
//log.debug("***\n***[execute] Created process " + p.getID() + "\n***");
        log.debug("Created process " + p.getID());

        p.setUserInitiated(ui);

        hi.setProcessID(p.getID());
        hi.getChildren().add(p);

        if (!prepareOnly) {
          p.start();
        } else {
          preparedProcess.set(p);
        }
       
//    System.out.println("Started the process.");

        ProcessInfo pinfo = new ProcessInfo();
        pinfo.procid = p.getID();
        pinfo.inbuf_maxsize = ib.getMaxSize();
        pinfo.outbuf_maxsize = ob.getMaxSize();
        return pinfo;
      }
    } catch (SessionTimeoutException ex) {
            throw new SessionTimeoutException("Exception executing: " + cmdline + " - " + ex.getMessage());
View Full Code Here

Examples of org.jboss.fresh.io.InBuffer

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

Examples of org.jboss.fresh.io.InBuffer

    try {
      ProcessInfo pinfo = _execute(cmdline, input, false, true, ui, false); // NullInput In case no redirects specified of course

      // read one object from its std out
//      System.out.println(">>>BUFFER : " + getBuffer(pinfo.procid, 1));
      InBuffer buf = null;
      try {
        buf = getBuffer(pinfo.procid, 1);
      } catch(org.jboss.fresh.shell.NoSuchProcessException ex) {
        return null;
      }
View Full Code Here

Examples of org.jboss.fresh.io.InBuffer

      }

      p.using();
      // we need an input stream around outputbuffer
      // we need to save it like together with the Process
      InBuffer b = (InBuffer) p.getOutputBuffer();
//      System.out.println("ShellImpl: read() : getting from buffer: " + b);

      // if(list.size()>b.getMaxSize()) throw new ShellIOException("Buffer sent by client exeeds the communicated maximum size.");

      LinkedList list = b.getBuffer(p.getIOTimeout(), maxsize);
      if (p.isRedirected() && b.isClosed()) {
        p.markCompleted();
      }

      if (log.isDebugEnabled()) {
        log.debug(" --- Shell Impl --- readBuffer() " + list);
View Full Code Here

Examples of org.jboss.fresh.io.InBuffer

      }

      p.using();
      // we need an input stream around outputbuffer
      // we need to save it like together with the Process
      InBuffer b = (InBuffer) p.getOutputBuffer();
//      System.out.println("ShellImpl: read() : getting from buffer: " + b);

      Object obj = b.get(p.getIOTimeout());

      if (log.isDebugEnabled()) {
        log.debug(" --- Shell Impl --- read() " + obj);
      }
View Full Code Here

Examples of org.jboss.fresh.io.InBuffer

      //throw new ShellIOException(ex);
    }

    if (streamid == 0) {
      // close stdin
      InBuffer b = p.getInputBuffer();
//log.debug("[shell-impl] ********* closing " + b);
      log.debug("closing input " + b);
      if (b != null) {
        b.close();
      }
    } else if (streamid == 1) {
      OutBuffer b = p.getOutputBuffer();
//log.debug("[shell-impl] ********* closing " + b);
      log.debug("closing output " + b);
      // closeAndDiscard explicitly tells OutBuffer that nothing will
      // be read from it any more. Not even what it may still have inside.
      b.closeAndDiscard();
    } else {
      throw new ShellIOException(new ShellException("Wrong stream id: " + streamid));
    }
  }
View Full Code Here

Examples of org.jboss.fresh.io.InBuffer

         procs = new HashMap(procmap);
      }
      Iterator it = procs.values().iterator();
      while (it.hasNext()) {
        Process p = (Process) it.next();
        InBuffer b = p.getInputBuffer();
//log.debug("[shell impl] dispose: closing in " + b);
        log.debug("dispose: closing in " + b);
        if (b != null) {
          b.close();
        }
        OutBuffer b2 = p.getOutputBuffer();
//log.debug("[shell impl] dispose: closing out " + b);
        log.debug("dispose: closing out " + b2);
        if (b2 != null) {
View Full Code Here

Examples of org.jboss.fresh.io.InBuffer

    outStream = getStdOutStream();
    context = shell.getContext();
    props = shell.getEnvProperties();
    out = new PrintWriter(new BufferedWriter(new BufferWriter(getStdOut())), true);
    in = new BufferedReader(new BufferReader(getStdIn()));
    InBuffer stdin = getStdIn();
    OutBuffer stdout = getStdOut();

    manager.declareBean("args", args, args.getClass());
    manager.declareBean("shell", shell, shell.getClass());
    manager.declareBean("instream", inStream, inStream.getClass());
    manager.declareBean("outstream", outStream, outStream.getClass());
    manager.declareBean("context", context, context.getClass());
    manager.declareBean("props", props, props.getClass());
    manager.declareBean("out", out, out.getClass());
    manager.declareBean("cin", in, in.getClass());
    manager.declareBean("stdin", stdin, stdin.getClass());
    manager.declareBean("stdout", stdout, stdout.getClass());
    manager.declareBean("console", System.out, System.out.getClass());

    log.debug("Info: Scripting language: " + langName);
    try {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.