com.typesafe.config.Config.getDuration()方法的使用及代码示例

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

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

Config.getDuration介绍

[英]Gets a value as a duration in a specified java.util.concurrent.TimeUnit. If the value is already a number, then it's taken as milliseconds and then converted to the requested TimeUnit; if it's a string, it's parsed understanding units suffixes like "10m" or "5ns" as documented in the the spec.
[中]获取一个值作为指定java中的持续时间。util。同时发生的时间单位。如果该值已经是一个数字,那么它将以毫秒为单位,然后转换为请求的时间单位;如果它是一个字符串,则解析时需要理解the spec中记录的“10m”或“5ns”等单位后缀。

代码示例

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

@Override
  public Object extractValue(Config config, String path)
  {
    return config.getDuration(path);
  }
},

代码示例来源:origin: jooby-project/jooby

protected void sms(final String path, final Config config, final String name,
  final Consumer<Long> setter) {
 if (config.hasPath(name)) {
  long value = config.getDuration(name, TimeUnit.MILLISECONDS);
  log.debug("setting {}.{} = {}", path, name, value);
  setter.accept(value);
 }
}

代码示例来源:origin: jooby-project/jooby

protected void sseconds(final String path, final Config config, final String name,
  final Consumer<Long> setter) {
 if (config.hasPath(name)) {
  long value = config.getDuration(name, TimeUnit.SECONDS);
  log.debug("setting {}.{} = {}", path, name, value);
  setter.accept(value);
 }
}

代码示例来源:origin: jooby-project/jooby

protected void siseconds(final String path, final Config config, final String name,
  final Consumer<Integer> setter) {
 if (config.hasPath(name)) {
  int value = (int) config.getDuration(name, TimeUnit.SECONDS);
  log.debug("setting {}.{} = {}", path, name, value);
  setter.accept(value);
 }
}

代码示例来源:origin: apache/incubator-gobblin

public AWSJobConfigurationManager(EventBus eventBus, Config config) {
 super(eventBus, config);
 this.jobConfFiles = Maps.newHashMap();
 if (config.hasPath(GobblinAWSConfigurationKeys.JOB_CONF_REFRESH_INTERVAL)) {
  this.refreshIntervalInSeconds = config.getDuration(GobblinAWSConfigurationKeys.JOB_CONF_REFRESH_INTERVAL,
    TimeUnit.SECONDS);
 } else {
  this.refreshIntervalInSeconds = DEFAULT_JOB_CONF_REFRESH_INTERVAL;
 }
 this.fetchJobConfExecutor = Executors.newSingleThreadScheduledExecutor(
   ExecutorsUtils.newThreadFactory(Optional.of(LOGGER), Optional.of("FetchJobConfExecutor")));
}

代码示例来源:origin: ben-manes/caffeine

/** Adds the Caffeine refresh settings. */
public void addRefresh() {
 if (isSet("policy.refresh.after-write")) {
  long nanos = merged.getDuration("policy.refresh.after-write", NANOSECONDS);
  configuration.setRefreshAfterWrite(OptionalLong.of(nanos));
 }
}

代码示例来源:origin: jooby-project/jooby

static <T> void withMs(final String path, final Config conf,
  final Consumer<Long> callback) {
 withPath(path, conf, callback, () -> conf.getDuration(path, TimeUnit.MILLISECONDS));
}

代码示例来源:origin: ben-manes/caffeine

/** Returns the duration for the expiration time. */
private @Nullable Duration getDurationFor(String path) {
 if (!isSet(path)) {
  return null;
 }
 if (merged.getString(path).equalsIgnoreCase("eternal")) {
  return Duration.ETERNAL;
 }
 long millis = merged.getDuration(path, MILLISECONDS);
 return new Duration(MILLISECONDS, millis);
}

代码示例来源:origin: ben-manes/caffeine

/** Adds the Caffeine eager expiration settings. */
public void addEagerExpiration() {
 if (isSet("policy.eager-expiration.after-write")) {
  long nanos = merged.getDuration("policy.eager-expiration.after-write", NANOSECONDS);
  configuration.setExpireAfterWrite(OptionalLong.of(nanos));
 }
 if (isSet("policy.eager-expiration.after-access")) {
  long nanos = merged.getDuration("policy.eager-expiration.after-access", NANOSECONDS);
  configuration.setExpireAfterAccess(OptionalLong.of(nanos));
 }
 if (isSet("policy.eager-expiration.variable")) {
  configuration.setExpiryFactory(Optional.of(FactoryBuilder.factoryOf(
    merged.getString("policy.eager-expiration.variable"))));
 }
}

代码示例来源:origin: jooby-project/jooby

public UndertowWebSocket(final Config config) {
 idleTimeout = config.getDuration("undertow.ws.IdleTimeout", TimeUnit.MILLISECONDS);
 maxBinaryBufferSize = config.getBytes("undertow.ws.MaxBinaryBufferSize");
 maxTextBufferSize = config.getBytes("undertow.ws.MaxTextBufferSize");
}

代码示例来源:origin: jooby-project/jooby

private static Object eval(final Config config, final String expr,
   final BiFunction<String[], Object, Object> mapper) {
  String value = expr.trim();
  try {
   value = config.getString(value);
  } catch (ConfigException.BadPath | ConfigException.Missing ex) {
   // shh
  }
  String[] values = value.split(";");
  Config eval = ConfigFactory.empty()
    .withValue("expr", ConfigValueFactory.fromAnyRef(values[0]));
  try {
   return mapper.apply(values, eval.getDuration("expr", TimeUnit.MILLISECONDS));
  } catch (ConfigException.WrongType | ConfigException.BadValue ex) {
   return mapper.apply(values, value);
  }
 }
}

代码示例来源:origin: jooby-project/jooby

private static int seconds(final String value) {
 try {
  return Integer.parseInt(value);
 } catch (NumberFormatException ex) {
  Config config = ConfigFactory.empty()
    .withValue("timeout", ConfigValueFactory.fromAnyRef(value));
  return (int) config.getDuration("timeout", TimeUnit.SECONDS);
 }
}

代码示例来源:origin: jooby-project/jooby

private static int seconds(final String value) {
 try {
  return Integer.parseInt(value);
 } catch (NumberFormatException ex) {
  Config config = ConfigFactory.empty()
    .withValue("timeout", ConfigValueFactory.fromAnyRef(value));
  return (int) config.getDuration("timeout", TimeUnit.SECONDS);
 }
}

代码示例来源:origin: jooby-project/jooby

private static int seconds(final String value) {
 try {
  return Integer.parseInt(value);
 } catch (NumberFormatException ex) {
  Config config = ConfigFactory.empty()
    .withValue("timeout", ConfigValueFactory.fromAnyRef(value));
  return (int) config.getDuration("timeout", TimeUnit.SECONDS);
 }
}

代码示例来源:origin: jooby-project/jooby

private static long seconds(final String value) {
 try {
  return Long.parseLong(value);
 } catch (NumberFormatException ex) {
  Config config = ConfigFactory.empty()
    .withValue("timeout", ConfigValueFactory.fromAnyRef(value));
  return config.getDuration("timeout", TimeUnit.SECONDS);
 }
}

代码示例来源:origin: jooby-project/jooby

private static long seconds(final String value) {
  try {
   return Long.parseLong(value);
  } catch (NumberFormatException ex) {
   Config config = ConfigFactory.empty()
     .withValue("timeout", ConfigValueFactory.fromAnyRef(value));
   return config.getDuration("timeout", TimeUnit.SECONDS);
  }
 }
}

代码示例来源:origin: jooby-project/jooby

private static int seconds(final String value) {
 try {
  return Integer.parseInt(value);
 } catch (NumberFormatException ex) {
  Config config = ConfigFactory.empty()
    .withValue(TIMEOUT, ConfigValueFactory.fromAnyRef(value));
  return (int) config.getDuration(TIMEOUT, TimeUnit.SECONDS);
 }
}

代码示例来源:origin: jooby-project/jooby

private static int seconds(final String value) {
  try {
   return Integer.parseInt(value);
  } catch (NumberFormatException ex) {
   Config config = ConfigFactory.empty()
     .withValue("timeout", ConfigValueFactory.fromAnyRef(value));
   return (int) config.getDuration("timeout", TimeUnit.SECONDS);
  }
 }
}

代码示例来源:origin: jooby-project/jooby

@Override
public void configure(final Env env, final Config config, final Binder binder) {
 /**
  * Pool
  */
 GenericObjectPoolConfig poolConfig = poolConfig(config, name);
 int timeout = (int) config.getDuration("jedis.timeout", TimeUnit.MILLISECONDS);
 URI uri = URI.create(config.getString(name));
 JedisPool pool = new JedisPool(poolConfig, uri, timeout);
 RedisProvider provider = new RedisProvider(pool, uri, poolConfig);
 env.onStart(provider::start);
 env.onStop(provider::stop);
 Provider<Jedis> jedis = (Provider<Jedis>) () -> pool.getResource();
 ServiceKey serviceKey = env.serviceKey();
 serviceKey.generate(JedisPool.class, name, k -> binder.bind(k).toInstance(pool));
 serviceKey.generate(Jedis.class, name,
   k -> binder.bind(k).toProvider(jedis));
}

代码示例来源:origin: jooby-project/jooby

/**
 * Parse value as {@link Duration}. If the value is already a number then it uses as seconds.
 * Otherwise, it parse expressions like: 8m, 1h, 365d, etc...
 *
 * @param maxAge Set the cache header max-age value in seconds.
 * @return This handler.
 */
public AssetHandler maxAge(final String maxAge) {
 Try.apply(() -> Long.parseLong(maxAge))
   .recover(x -> ConfigFactory.empty()
     .withValue("v", ConfigValueFactory.fromAnyRef(maxAge))
     .getDuration("v")
     .getSeconds())
   .onSuccess(this::maxAge);
 return this;
}

相关文章