Пример #1
0
 private void checkSize(ConfigWeb config, Resource dir, long maxSize, ResourceFilter filter) {
   if (!dir.exists()) return;
   Resource res = null;
   int count = ArrayUtil.size(filter == null ? dir.list() : dir.list(filter));
   long size = ResourceUtil.getRealSize(dir, filter);
   PrintWriter out = config.getOutWriter();
   SystemOut.printDate(out, "check size of directory [" + dir + "]");
   SystemOut.printDate(out, "- current size	[" + size + "]");
   SystemOut.printDate(out, "- max size 	[" + maxSize + "]");
   int len = -1;
   while (count > 100000 || size > maxSize) {
     Resource[] files = filter == null ? dir.listResources() : dir.listResources(filter);
     if (len == files.length) break; // protect from inifinti loop
     len = files.length;
     for (int i = 0; i < files.length; i++) {
       if (res == null || res.lastModified() > files[i].lastModified()) {
         res = files[i];
       }
     }
     if (res != null) {
       size -= res.length();
       try {
         res.remove(true);
         count--;
       } catch (IOException e) {
         SystemOut.printDate(out, "cannot remove resource " + res.getAbsolutePath());
         break;
       }
     }
     res = null;
   }
 }
Пример #2
0
  public static Coder getInstance() {

    if (instance == null) {
      instance = new JRECoder();

      // try to load Sanselan, does not load when lib not exists
      try {
        SanselanCoder sanselan = new SanselanCoder();
        instance = new DoubleCoder(sanselan, instance);
        SystemOut.printDate("use Sanselan and JRE Image Coder ");
      } catch (Throwable t) {
        SystemOut.printDate("use JRE Image Coder ");
      }
    }
    return instance;
  }
Пример #3
0
  @Override
  public void checkPermGenSpace(boolean check) {
    // print.e(Runtime.getRuntime().freeMemory());
    // Runtime.getRuntime().freeMemory()<200000 ||
    // long pgs=SystemUtil.getFreePermGenSpaceSize();
    int promille = SystemUtil.getFreePermGenSpacePromille();

    // Pen Gen Space info not available
    if (promille == -1) { // if(pgs==-1) {
      if (countLoadedPages() > 500) shrink();
    } else if (!check || promille < 50) { // else if(!check || pgs<1024*1024){
      SystemOut.printDate(
          getErrWriter(),
          "+Free Perm Gen Space is less than 1mb (free:"
              + ((SystemUtil.getFreePermGenSpaceSize()) / 1024)
              + "kb), shrink all template classloaders");
      // first just call GC and check if it help
      System.gc();
      // if(SystemUtil.getFreePermGenSpaceSize()>1024*1024)
      if (SystemUtil.getFreePermGenSpacePromille() > 50) return;

      shrink();
    }
  }
Пример #4
0
 private void err(PageContext pc, Throwable t) {
   String msg = ExceptionUtil.getStacktrace(t, true);
   SystemOut.print(pc.getConfig().getErrWriter(), msg);
 }
Пример #5
0
 private void err(PageContext pc, String msg) {
   SystemOut.print(pc.getConfig().getErrWriter(), msg);
 }
Пример #6
0
  protected static void _parseChildren(
      Log log,
      StringBuffer content,
      IndexWriter writer,
      String root,
      URL base,
      List urlsDone,
      String[] extensions,
      boolean recurse,
      int deep,
      long timeout)
      throws IOException {

    if (recurse) {
      List urls = htmlUtil.getURLS(content.toString(), base);

      // loop through all children
      int len = urls.size();
      List childIndexer = len > 1 ? new ArrayList() : null;
      ChildrenIndexer ci;
      // print.out("getting content");

      for (int i = 0; i < len; i++) {
        URL url = (URL) urls.get(i);
        /*if(url.toExternalForm().indexOf("80")!=-1){
        	SystemOut.printDate("base:"+base);
        	SystemOut.printDate("url:"+url);
        }*/

        url = translateURL(url);

        if (urlsDone.contains(url.toExternalForm())) continue;
        // urlsDone.add(url.toExternalForm());

        String protocol = url.getProtocol().toLowerCase();
        String file = url.getPath();
        if ((protocol.equals("http") || protocol.equals("https"))
            && validExtension(extensions, file)
            && base.getHost().equalsIgnoreCase(url.getHost())) {
          try {
            ci =
                new ChildrenIndexer(
                    log, writer, root, url, urlsDone, extensions, recurse, deep + 1, timeout);

            childIndexer.add(ci);
            ci.start();
          } catch (Throwable t) {
            // print.printST(t);
          }
        }
      }

      if (childIndexer != null && !childIndexer.isEmpty()) {
        Iterator it = childIndexer.iterator();
        while (it.hasNext()) {
          ci = (ChildrenIndexer) it.next();
          if (ci.isAlive()) {
            try {
              ci.join(timeout);

            } catch (InterruptedException e) {
              // print.printST(e);
            }
          }
          // timeout exceptionif(ci.isAlive()) throw new IOException("timeout occur while invoking
          // page ["+ci.url+"]");

          if (ci.isAlive()) {
            ci.interrupt();
            Config config = ThreadLocalPageContext.getConfig();
            SystemOut.printDate(
                config != null ? config.getErrWriter() : new PrintWriter(System.err),
                "timeout [" + timeout + " ms] occur while invoking page [" + ci.url + "]");
          }
        }

        // print.out("exe child");
        it = childIndexer.iterator();
        while (it.hasNext()) {
          ci = (ChildrenIndexer) it.next();
          // print.out("exec-child:"+ci.url);
          // print.out(content);
          if (ci.content != null)
            _parseChildren(
                log,
                ci.content,
                writer,
                root,
                ci.url,
                urlsDone,
                extensions,
                recurse,
                deep,
                timeout);
        }
      }

      urls.clear();
    }
    // print.out("end:"+base);
  }