Пример #1
1
  /** Fetch the classloader for the given ApplicationID. */
  static URLClassLoader getUrlClassLoader(ApplicationID appId, Map input) {
    NCube cpCube = getCube(appId, CLASSPATH_CUBE);
    if (cpCube
        == null) { // No sys.classpath cube exists, just create regular GroovyClassLoader with no
                   // URLs set into it.
      // Scope the GroovyClassLoader per ApplicationID
      return getLocalClassloader(appId);
    }

    final String envLevel = SystemUtilities.getExternalVariable("ENV_LEVEL");
    if (!input.containsKey("env")
        && StringUtilities.hasContent(
            envLevel)) { // Add in the 'ENV_LEVEL" environment variable when looking up sys.* cubes,
      // if there was not already an entry for it.
      input.put("env", envLevel);
    }
    if (!input.containsKey("username")) { // same as ENV_LEVEL, add it in if not already there.
      input.put("username", System.getProperty("user.name"));
    }
    Object urlCpLoader = cpCube.getCell(input);

    if (urlCpLoader instanceof URLClassLoader) {
      return (URLClassLoader) urlCpLoader;
    }

    throw new IllegalStateException(
        "If the sys.classpath cube exists it must return a URLClassLoader.");
  }
Пример #2
0
  public static Map<String, Object> getSystemParams() {
    final ConcurrentMap<String, Object> params = systemParams;

    if (params != null) {
      return params;
    }

    synchronized (NCubeManager.class) {
      if (systemParams == null) {
        String jsonParams = SystemUtilities.getExternalVariable(NCUBE_PARAMS);
        systemParams = new ConcurrentHashMap<>();

        if (StringUtilities.hasContent(jsonParams)) {
          try {
            systemParams = new ConcurrentHashMap<>(JsonReader.jsonToMaps(jsonParams));
          } catch (Exception e) {
            LOG.warn("Parsing of NCUBE_PARAMS failed.  " + jsonParams);
          }
        }
      }
    }
    return systemParams;
  }