Ejemplo n.º 1
0
  @Override
  public Boolean execute() throws JobException {

    String basdir = Silica.getResourceDirectory();
    File root = new File(basdir).getParentFile();
    LOG.info("cleaning old modules in {}", basdir);

    if (!root.isDirectory()) {
      throw new JobException(MessageFormat.format("Could not found base directory {0}", basdir));
    }

    String[] sortedFileNames = root.list();
    Arrays.sort(sortedFileNames);
    boolean cleaned = true;
    for (int i = sortedFileNames.length - 1 - Silica.getNumOfKeepDeployed(); i >= 0; i--) {
      File f = new File(root, sortedFileNames[i]);
      if (!f.getAbsolutePath().contains("silica")) { // Just in case.
        throw new JobException(
            "Do not remove the folder "
                + f.getAbsolutePath()
                + ". File path must contains 'silica'.");
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug(MessageFormat.format("Cleaning file: {0}", f.getAbsolutePath()));
      }
      if (!deleteChildren(f)) {
        LOG.error(MessageFormat.format("Could not clean file: {0}", f.getAbsolutePath()));
        cleaned = false;
      }
    }
    return Boolean.valueOf(cleaned);
  }
Ejemplo n.º 2
0
  private ServerSelector() {

    try {
      {
        String classname = Silica.getGlobalConfig("server.select.logic");

        Class<?> s = ServerSelector.class.getClassLoader().loadClass(classname);

        selectLogic = (SelectLogic) s.newInstance();
      }
      {
        String classname = Silica.getGlobalConfig("server.class");
        Class<?> s = ServerSelector.class.getClassLoader().loadClass(classname);

        String[] addresses = Silica.getGlobalConfig("server.addresses").split(",");

        for (String address : addresses) {
          if (address == null) {
            continue;
          }
          address = address.trim();
          if (address.length() == 0) {
            continue;
          }
          if (serverMap.get(address) == null) {
            createServer(address, s);
          } else {
            LOG.warn("server [{}] is already in silica config file.", address);
          }
        }
      }
    } catch (Exception e) {

      LOG.error("Could not initialize ServerSelector.", e);
    }
  }
Ejemplo n.º 3
0
  /**
   * ローカルサーバを返す
   *
   * @return ローカルサーバ
   */
  public Server getLocalServer() {

    return serverMap.get(Silica.getGlobalConfig(Config.KEY_HOST_ADDRESS));
  }