org.redisson.config.Config.fromYAML()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(891)

本文整理了Java中org.redisson.config.Config.fromYAML()方法的一些代码示例,展示了Config.fromYAML()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Config.fromYAML()方法的具体详情如下:
包路径:org.redisson.config.Config
类名称:Config
方法名:fromYAML

Config.fromYAML介绍

[英]Read config object stored in YAML format from File
[中]从File读取以YAML格式存储的配置对象

代码示例

代码示例来源:origin: redisson/redisson

/**
 * Read config object stored in YAML format from <code>File</code>
 *
 * @param file object
 * @return config
 * @throws IOException error
 */
public static Config fromYAML(File file) throws IOException {
  return fromYAML(file, null);
}

代码示例来源:origin: redisson/redisson

/**
 * Read config object stored in YAML format from <code>File</code>
 *
 * @param file object
 * @return config
 * @throws IOException error
 */
public static Config fromYAML(File file) throws IOException {
  return fromYAML(file, null);
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(String configPath) {
  try {
    return Config.fromJSON(new File(configPath));
  } catch (IOException e) {
    // trying next format
    try {
      return Config.fromYAML(new File(configPath));
    } catch (IOException e1) {
      throw new CacheException("Can't parse default yaml config", e1);
    }
  }
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(String configPath) {
  try {
    return Config.fromJSON(new File(configPath));
  } catch (IOException e) {
    // trying next format
    try {
      return Config.fromYAML(new File(configPath));
    } catch (IOException e1) {
      throw new CacheException("Can't parse default yaml config", e1);
    }
  }
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(String configPath) {
  try {
    return Config.fromJSON(new File(configPath));
  } catch (IOException e) {
    // trying next format
    try {
      return Config.fromYAML(new File(configPath));
    } catch (IOException e1) {
      throw new CacheException("Can't parse default yaml config", e1);
    }
  }
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(String configPath) {
  try {
    return Config.fromJSON(new File(configPath));
  } catch (IOException e) {
    // trying next format
    try {
      return Config.fromYAML(new File(configPath));
    } catch (IOException e1) {
      throw new CacheException("Can't parse default yaml config", e1);
    }
  }
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(ClassLoader classLoader, String fileName) {
  InputStream is = classLoader.getResourceAsStream(fileName);
  if (is != null) {
    try {
      return Config.fromJSON(is);
    } catch (IOException e) {
      try {
        is = classLoader.getResourceAsStream(fileName);
        return Config.fromYAML(is);
      } catch (IOException e1) {
        throw new CacheException("Can't parse yaml config", e1);
      }
    }
  }
  return null;
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(URI uri) {
  Config config = null;
  try {
    URL jsonUrl = null;
    if (DEFAULT_URI_PATH.equals(uri.getPath())) {
      jsonUrl = JCachingProvider.class.getResource("/redisson-jcache.json");
    } else {
      jsonUrl = uri.toURL();
    }
    if (jsonUrl == null) {
      throw new IOException();
    }
    config = Config.fromJSON(jsonUrl);
  } catch (IOException e) {
    try {
      URL yamlUrl = null;
      if (DEFAULT_URI_PATH.equals(uri.getPath())) {
        yamlUrl = JCachingProvider.class.getResource("/redisson-jcache.yaml");
      } else {
        yamlUrl = uri.toURL();
      }
      if (yamlUrl != null) {
        config = Config.fromYAML(yamlUrl);
      }
    } catch (IOException e2) {
      // skip
    }
  }
  return config;
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(ClassLoader classLoader, String fileName) {
  InputStream is = classLoader.getResourceAsStream(fileName);
  if (is != null) {
    try {
      return Config.fromJSON(is);
    } catch (IOException e) {
      try {
        is = classLoader.getResourceAsStream(fileName);
        return Config.fromYAML(is);
      } catch (IOException e1) {
        throw new CacheException("Can't parse yaml config", e1);
      }
    }
  }
  return null;
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(ClassLoader classLoader, String fileName) {
  InputStream is = classLoader.getResourceAsStream(fileName);
  if (is != null) {
    try {
      return Config.fromJSON(is);
    } catch (IOException e) {
      try {
        is = classLoader.getResourceAsStream(fileName);
        return Config.fromYAML(is);
      } catch (IOException e1) {
        throw new CacheException("Can't parse yaml config", e1);
      }
    }
  }
  return null;
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(ClassLoader classLoader, String fileName) {
  InputStream is = classLoader.getResourceAsStream(fileName);
  if (is != null) {
    try {
      return Config.fromJSON(is);
    } catch (IOException e) {
      try {
        is = classLoader.getResourceAsStream(fileName);
        return Config.fromYAML(is);
      } catch (IOException e1) {
        throw new CacheException("Can't parse yaml config", e1);
      }
    }
  }
  return null;
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(URI uri) {
  Config config = null;
  try {
    URL jsonUrl = null;
    if (DEFAULT_URI_PATH.equals(uri.getPath())) {
      jsonUrl = JCachingProvider.class.getResource("/redisson-jcache.json");
    } else {
      jsonUrl = uri.toURL();
    }
    if (jsonUrl == null) {
      throw new IOException();
    }
    config = Config.fromJSON(jsonUrl);
  } catch (IOException e) {
    try {
      URL yamlUrl = null;
      if (DEFAULT_URI_PATH.equals(uri.getPath())) {
        yamlUrl = JCachingProvider.class.getResource("/redisson-jcache.yaml");
      } else {
        yamlUrl = uri.toURL();
      }
      if (yamlUrl != null) {
        config = Config.fromYAML(yamlUrl);
      }
    } catch (IOException e2) {
      // skip
    }
  }
  return config;
}

代码示例来源:origin: redisson/redisson

protected RedissonClient buildClient(String configPath) throws NamingException {
  Config config = null;
  try {
    config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
  } catch (IOException e) {
    // trying next format
    try {
      config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
    } catch (IOException e1) {
      NamingException ex = new NamingException("Can't parse yaml config " + configPath);
      ex.initCause(e1);
      throw ex;
    }
  }
  
  try {
    return Redisson.create(config);
  } catch (Exception e) {
    NamingException ex = new NamingException();
    ex.initCause(e);
    throw ex;
  }
}

代码示例来源:origin: redisson/redisson

protected RedissonClient buildClient(String configPath) throws NamingException {
  Config config = null;
  try {
    config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
  } catch (IOException e) {
    // trying next format
    try {
      config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
    } catch (IOException e1) {
      NamingException ex = new NamingException("Can't parse yaml config " + configPath);
      ex.initCause(e1);
      throw ex;
    }
  }
  
  try {
    return Redisson.create(config);
  } catch (Exception e) {
    NamingException ex = new NamingException();
    ex.initCause(e);
    throw ex;
  }
}

代码示例来源:origin: redisson/redisson

protected RedissonClient buildClient() throws LifecycleException {
  Config config = null;
  try {
    config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
  } catch (IOException e) {
    // trying next format
    try {
      config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
    } catch (IOException e1) {
      log.error("Can't parse json config " + configPath, e);
      throw new LifecycleException("Can't parse yaml config " + configPath, e1);
    }
  }
  
  try {
    return Redisson.create(config);
  } catch (Exception e) {
    throw new LifecycleException(e);
  }
}

代码示例来源:origin: redisson/redisson

protected RedissonClient buildClient() throws LifecycleException {
  Config config = null;
  try {
    config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
  } catch (IOException e) {
    // trying next format
    try {
      config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
    } catch (IOException e1) {
      log.error("Can't parse json config " + configPath, e);
      throw new LifecycleException("Can't parse yaml config " + configPath, e1);
    }
  }
  
  try {
    return Redisson.create(config);
  } catch (Exception e) {
    throw new LifecycleException(e);
  }
}

代码示例来源:origin: redisson/redisson

protected RedissonClient buildClient() throws LifecycleException {
  Config config = null;
  try {
    config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
  } catch (IOException e) {
    // trying next format
    try {
      config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
    } catch (IOException e1) {
      log.error("Can't parse json config " + configPath, e);
      throw new LifecycleException("Can't parse yaml config " + configPath, e1);
    }
  }
  
  try {
    return Redisson.create(config);
  } catch (Exception e) {
    throw new LifecycleException(e);
  }
}

代码示例来源:origin: redisson/redisson

protected RedissonClient buildClient() throws LifecycleException {
  Config config = null;
  try {
    config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
  } catch (IOException e) {
    // trying next format
    try {
      config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
    } catch (IOException e1) {
      log.error("Can't parse json config " + configPath, e);
      throw new LifecycleException("Can't parse yaml config " + configPath, e1);
    }
  }
  
  try {
    try {
    Config c = new Config(config);
    Codec codec = c.getCodec().getClass().getConstructor(ClassLoader.class)
            .newInstance(Thread.currentThread().getContextClassLoader());
    config.setCodec(codec);
    } catch (Exception e) {
      throw new IllegalStateException("Unable to initialize codec with ClassLoader parameter", e);
    }
    
    return Redisson.create(config);
  } catch (Exception e) {
    throw new LifecycleException(e);
  }
}

代码示例来源:origin: redisson/redisson

config = Config.fromYAML(is);
} catch (IOException e1) {
  throw new IllegalArgumentException("Can't parse config", e1);

代码示例来源:origin: dqeasycloud/easy-cloud

@Bean(destroyMethod = "shutdown")
RedissonClient redisson() throws IOException {
  Config config = Config.fromYAML(configFile.getInputStream());
  return Redisson.create(config);
}

相关文章