Пример #1
0
  private void control(CFMLFactoryImpl[] factories, boolean firstRun) {
    long now = System.currentTimeMillis();
    boolean doMinute = lastMinuteInterval + 60000 < now;
    if (doMinute) lastMinuteInterval = now;
    boolean doHour = (lastHourInterval + (1000 * 60 * 60)) < now;
    if (doHour) lastHourInterval = now;

    // broadcast cluster scope
    try {
      ScopeContext.getClusterScope(configServer, true).broadcast();
    } catch (Throwable t) {
      t.printStackTrace();
    }

    // every minute
    if (doMinute) {
      // deploy extensions, archives ...
      try {
        DeployHandler.deploy(configServer);
      } catch (Throwable t) {
        t.printStackTrace();
      }
      try {
        XMLConfigAdmin.checkForChangesInConfigFile(configServer);
      } catch (Throwable t) {
      }
    }
    // every hour
    if (doHour) {
      try {
        configServer.checkPermGenSpace(true);
      } catch (Throwable t) {
      }
    }

    for (int i = 0; i < factories.length; i++) {
      control(factories[i], doMinute, doHour, firstRun);
    }
  }
Пример #2
0
  private void control(
      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);

        // double check templates
        try {
          ((ConfigWebImpl) config).getCompiler().checkWatched();
        } catch (Throwable t) {
          t.printStackTrace();
        }

        // deploy extensions, archives ...
        try {
          DeployHandler.deploy(config);
        } catch (Throwable t) {
          t.printStackTrace();
        }

        // clear unused DB Connections
        try {
          ((ConfigImpl) config).getDatasourceConnectionPool().clear(false);
        } catch (Throwable t) {
        }
        // clear all unused scopes
        try {
          cfmlFactory.getScopeContext().clearUnused();
        } catch (Throwable t) {
        }
        // Memory usage
        // clear Query Cache
        /*try{
        	ConfigWebUtil.getCacheHandlerFactories(config).query.clean(null);
        	ConfigWebUtil.getCacheHandlerFactories(config).include.clean(null);
        	ConfigWebUtil.getCacheHandlerFactories(config).function.clean(null);
        	//cfmlFactory.getDefaultQueryCache().clearUnused(null);
        }catch(Throwable t){t.printStackTrace();}*/
        // 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) {
          }

        try {
          XMLConfigAdmin.checkForChangesInConfigFile(config);
        } 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) {
        }
      }

      try {
        configServer.checkPermGenSpace(true);
      } catch (Throwable t) {
      }
    } catch (Throwable t) {

    } finally {
      ThreadLocalConfig.release();
    }
  }
Пример #3
0
  @Override
  public void run() {
    // scheduleThread.start();
    boolean firstRun = true;
    List<ControlerThread> threads = new ArrayList<ControlerThread>();
    CFMLFactoryImpl factories[] = null;
    while (state.active()) {
      // sleep
      SystemUtil.sleep(interval);

      factories = toFactories(factories, contextes);
      // start the thread that calls control
      ControlerThread ct =
          new ControlerThread(this, factories, firstRun, configServer.getLog("application"));
      ct.start();
      threads.add(ct);

      if (threads.size() > 10 && lastMinuteInterval + 60000 < System.currentTimeMillis())
        configServer
            .getLog("application")
            .info("controller", threads.size() + " active controller threads");

      // now we check all threads we have
      Iterator<ControlerThread> it = threads.iterator();
      long time;
      while (it.hasNext()) {
        ct = it.next();
        // print.e(ct.hashCode());
        time = System.currentTimeMillis() - ct.start;
        // done
        if (ct.done >= 0) {
          if (time > 10000)
            configServer
                .getLog("application")
                .info("controller", "controler took " + ct.done + "ms to execute sucessfully.");
          it.remove();
        }
        // failed
        else if (ct.t != null) {
          LogUtil.log(configServer.getLog("application"), Log.LEVEL_ERROR, "controler", ct.t);
          it.remove();
        }
        // stop it!
        else if (time > TIMEOUT) {
          SystemUtil.stop(ct);
          // print.e(ct.getStackTrace());
          if (!ct.isAlive()) {
            configServer
                .getLog("application")
                .error(
                    "controller",
                    "controler thread [" + ct.hashCode() + "] forced to stop after " + time + "ms");
            it.remove();
          } else {
            LogUtil.log(
                configServer.getLog("application"),
                Log.LEVEL_ERROR,
                "controler",
                "was not able to stop controller thread running for " + time + "ms",
                ct.getStackTrace());
          }
        }
      }

      if (factories.length > 0) firstRun = false;
    }
  }