Ejemplo n.º 1
0
 public GCloudLicense getLicense() {
   if (license == null) {
     license = new GCloudLicense();
     license.initLicense(ConfigContext.getInstance().getString("license.path"));
   }
   return license;
 }
Ejemplo n.º 2
0
  public void loadLicence(String licencePath, Boolean override) throws GeneralException {
    try {
      File file = new File(licencePath);
      if (!file.exists()) {
        reason = "许可文件不存在";
        isAuthorized = false;
        return;
      }
      license.initLicense(licencePath);

      // validate static information.
      staticInfoValidate();

      // validate dynamic information
      if (!getLicense().isUnlimited() && isAuthorized) {
        Runnable r =
            new Runnable() {
              public void run() {
                while (true) {
                  if (!isAuthorized) break;
                  try {
                    // validate once every twenty-four hours.
                    Thread.sleep(24 * 60 * 60 * 1000L);
                    // for test
                    // Thread.sleep(60 * 1000L);
                    dynamicInfoValidate();
                  } catch (InterruptedException e) {
                    e.printStackTrace();
                  }
                }
              }
            };
        Thread t = new Thread(r, "license-validate");
        t.start();
      }

      if (override) {
        FileUtils.copyFile(file, new File(ConfigContext.getInstance().getString("license.path")));
      }

    } catch (Exception e) {
      logger.error("加载许可失败", e);
      throw new GeneralException(Messages.getMessage("license_load_error", e.getMessage()), e);
    }
  }