Example #1
0
 private void checkCacheFileSize(ConfigWeb config) {
   checkSize(
       config,
       config.getCacheDir(),
       config.getCacheDirSize(),
       new ExtensionResourceFilter(".cache"));
 }
Example #2
0
  public Object call(
      String cfcPath,
      String id,
      String functionName,
      Struct arguments,
      boolean cfcPeristent,
      Object defaultValue)
      throws PageException {
    DevNullOutputStream os = DevNullOutputStream.DEV_NULL_OUTPUT_STREAM;
    String requestURI = toRequestURI(cfcPath);

    PageContext oldPC = ThreadLocalPageContext.get();
    PageContextImpl pc =
        ThreadUtil.createPageContext(
            config, os, "localhost", requestURI, "", null, null, null, null);
    pc.setRequestTimeout(999999999999999999L);
    try {
      ThreadLocalPageContext.register(pc);
      Component cfc = getCFC(pc, requestURI, cfcPath, id, cfcPeristent);
      if (cfc.containsKey(functionName)) {
        return cfc.callWithNamedValues(pc, functionName, arguments);
      }
    } finally {
      CFMLFactory factory = config.getFactory();
      factory.releasePageContext(pc);
      ThreadLocalPageContext.register(oldPC);
    }
    return defaultValue;
  }
Example #3
0
 private void doCheckMappings(ConfigWeb config) {
   Mapping[] mappings = config.getMappings();
   for (int i = 0; i < mappings.length; i++) {
     Mapping mapping = mappings[i];
     mapping.check();
   }
 }
Example #4
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;
   }
 }
Example #5
0
  private void checkOldClientFile(ConfigWeb config) {
    ExtensionResourceFilter filter = new ExtensionResourceFilter(".script", false);

    // move old structured file in new structure
    try {
      Resource dir = config.getClientScopeDir(), trgres;
      Resource[] children = dir.listResources(filter);
      String src, trg;
      int index;
      for (int i = 0; i < children.length; i++) {
        src = children[i].getName();
        index = src.indexOf('-');

        trg = ClientFile.getFolderName(src.substring(0, index), src.substring(index + 1), false);
        trgres = dir.getRealResource(trg);
        if (!trgres.exists()) {
          trgres.createFile(true);
          ResourceUtil.copy(children[i], trgres);
        }
        // children[i].moveTo(trgres);
        children[i].delete();
      }
    } catch (Throwable t) {
    }
  }
Example #6
0
 private PageSourcePool[] getPageSourcePools(ConfigWeb config) {
   return getPageSourcePools(config.getMappings());
 }
Example #7
0
 private void checkTempDirectorySize(ConfigWeb config) {
   checkSize(config, config.getTempDirectory(), 1024 * 1024 * 1024, null);
 }
Example #8
0
  private void run(
      CFMLFactoryImpl cfmlFactory, boolean doMinute, boolean doHour, boolean firstRun) {

    try {
      boolean isRunning = cfmlFactory.getUsedPageContextLength() > 0;
      if (isRunning) {
        cfmlFactory.checkTimeout();
      }
      ConfigWeb config = null;

      if (firstRun) {
        config = cfmlFactory.getConfig();
        ThreadLocalConfig.register(config);

        config.reloadTimeServerOffset();
        checkOldClientFile(config);

        // try{checkStorageScopeFile(config,Session.SCOPE_CLIENT);}catch(Throwable t){}
        // try{checkStorageScopeFile(config,Session.SCOPE_SESSION);}catch(Throwable t){}
        try {
          config.reloadTimeServerOffset();
        } catch (Throwable t) {
        }
        try {
          checkTempDirectorySize(config);
        } catch (Throwable t) {
        }
        try {
          checkCacheFileSize(config);
        } catch (Throwable t) {
        }
        try {
          cfmlFactory.getScopeContext().clearUnused();
        } catch (Throwable t) {
        }
      }

      if (config == null) {
        config = cfmlFactory.getConfig();
        ThreadLocalConfig.register(config);
      }

      // every Minute
      if (doMinute) {
        if (config == null) {
          config = cfmlFactory.getConfig();
          ThreadLocalConfig.register(config);
        }
        // clear unused DB Connections
        try {
          ((ConfigImpl) config).getDatasourceConnectionPool().clear();
        } catch (Throwable t) {
        }
        // clear all unused scopes
        try {
          cfmlFactory.getScopeContext().clearUnused();
        } catch (Throwable t) {
        }
        // Memory usage
        // clear Query Cache
        try {
          cfmlFactory.getDefaultQueryCache().clearUnused(null);
        } catch (Throwable t) {
        }
        // contract Page Pool
        // try{doClearPagePools((ConfigWebImpl) config);}catch(Throwable t){}
        // try{checkPermGenSpace((ConfigWebImpl) config);}catch(Throwable t){}
        try {
          doCheckMappings(config);
        } catch (Throwable t) {
        }
        try {
          doClearMailConnections();
        } catch (Throwable t) {
        }
        // clean LockManager
        if (cfmlFactory.getUsedPageContextLength() == 0)
          try {
            ((LockManagerImpl) config.getLockManager()).clean();
          } catch (Throwable t) {
          }
      }
      // every hour
      if (doHour) {
        if (config == null) {
          config = cfmlFactory.getConfig();
          ThreadLocalConfig.register(config);
        }
        // time server offset
        try {
          config.reloadTimeServerOffset();
        } catch (Throwable t) {
        }
        // check file based client/session scope
        // try{checkStorageScopeFile(config,Session.SCOPE_CLIENT);}catch(Throwable t){}
        // try{checkStorageScopeFile(config,Session.SCOPE_SESSION);}catch(Throwable t){}
        // check temp directory
        try {
          checkTempDirectorySize(config);
        } catch (Throwable t) {
        }
        // check cache directory
        try {
          checkCacheFileSize(config);
        } catch (Throwable t) {
        }
      }
    } catch (Throwable t) {

    } finally {
      ThreadLocalConfig.release();
    }
  }