Package org.jboss.fresh.io

Examples of org.jboss.fresh.io.OutBuffer


      return;
    }

    Shell sh = getShell();
    VFS vfs = sh.getVFS();
    OutBuffer out = getStdOut();
    FileName fname;
    if (params == null || params.length == 0) {
      fname = new FileName(sh.getEnvProperty("PWD"));
    } else {
      fname = new FileName(sh.getEnvProperty("PWD")).absolutize(params[0]);
    }

    if (vfs.exists(null, fname, false)) {
      out.put("\n Directory of " + fname + "\n\n", 10000L);
      Collection col = vfs.list(null, fname, false);
      Iterator it = col.iterator();

      out.put("                            " + "\t<DIR>" + "\t..\n", 10000L);
      while (it.hasNext()) {
        FileInfo fd = (FileInfo) it.next();
        String ftyp = "";
        if (fd.isLink()) {
          // dobi extra
          FileInfo extra = fd.getExtra();
          if (extra == null) {
            ftyp = "-dead L";
          } else {
            if (extra.isDirectory())
              ftyp = "<DIR> L";
            else
              ftyp = "file  L";
          }
        } else {
          if (fd.isDirectory())
            ftyp = "<DIR>  ";
          else
            ftyp = "file   ";
        }

        out.put(fd.getLastModified() + "\t" + ftyp + "\t" + fd.getFileName().getName() + "\n", 10000L);
      }

    } else {
      out.put("Path does not exist!", 10000L);
    }

    log.debug("done");
  }
View Full Code Here


        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());
        } catch (ParseException ex) {
View Full Code Here

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

      }

      p.using();
      // we need an input stream around outputbuffer
      // we need to save it like together with the Process
      OutBuffer b = (OutBuffer) p.getInputBuffer();
//      System.out.println("ShellImpl: read() : getting from buffer: " + b);
            if(b == null) {
          if (!p.isDone()) {
            throw new EOFException("StdIn not available any more (funny: process not done yet)");
          } else {
            throw new EOFException("StdIn not available any more (process done executing)");
          }
            }
      if (list.size() > b.getMaxSize()) {
        throw new ShellException("Buffer sent by client exeeds the communicated maximum size.");
      }

      b.putBuffer(list, p.getIOTimeout());
    } catch (EOFException ex) {
      if (p.getThrowable() != null) {
        throw new ShellIOException(p.getThrowable());
      } else {
        throw ex;
View Full Code Here

      }

      p.using();
      // we need an input stream around outputbuffer
      // we need to save it like together with the Process
      OutBuffer b = (OutBuffer) p.getInputBuffer();
//      System.out.println("ShellImpl: read() : getting from buffer: " + b);
            if(b == null) {
          if (!p.isDone()) {
            throw new EOFException("StdIn not available any more (funny: process not done yet)");
          } else {
            throw new EOFException("StdIn not available any more (process done executing)");
          }
            }


      boolean res = b.put(obj, 0);
      if (!res) {
        throw new IOException("Timeout while trying to write in the buffer: " + b);
      }
    } catch (EOFException ex) {
      if (p.getThrowable() != null) {
View Full Code Here

      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

//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) {
          b2.close();
        }
      }
    } catch (IOException ex) {
      log.error(ex.getMessage(), ex);
    }
View Full Code Here

    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 {
      manager.exec(langName, fname, (isFile ? 1 : 2), 0,
View Full Code Here

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

    OutBuffer out = getStdOut();
    if (params == null || params.length == 0) {
      out.put(" cp: No directory specified.\n", 10000L);
      log.debug("done");
      return;
    }

    Shell sh = getShell();
    VFS vfs = sh.getVFS();
    String to = params[0];
    FileName fname = new FileName(to);
    if (fname.isRelative())
      fname = new FileName(sh.getEnvProperty("PWD")).absolutize(fname);

//    System.out.println("****");
//    System.out.println("****  fname: " + fname);
//    System.out.println("****");
//    if(vfs.exists(null, fname, false)) {
//      sh._setPWD(fname.toString());
//    }


    FileInfo info = vfs.getFileInfo(null, fname, false);
    if (info == null || !info.isDirectory()) {
      if (canThrowEx()) {
        throw new RuntimeException("Can't find the path specified: " + fname + "\n\n");
      } else {
        out.put("Can't find the path specified: " + fname + "\n\n", 10000L);
      }
    } else {
      sh._setPWD(fname.toString());
    }

View Full Code Here

                //    trap_on = true;
                //    trap_flag.set("1");
                //}
                prepareLineage().add(this);
//System.out.println("          Execute   START : " + executable);
                OutBuffer bufOut = executable.getStdOut();
                executable.setStdOut(new CloseProtectedOutBufferImpl(bufOut));
                executable.execute(exepath, params);

                /*if(!"1".equals(shell.getEnvProperty("TX_ACTIVE")) && TxSupport.isActive())
                        TxSupport.commit();*/
 
View Full Code Here

TOP

Related Classes of org.jboss.fresh.io.OutBuffer

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.