@Override public Object extractValue(Config config, String path) { return config.getDuration(path); } },
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); } }
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); } }
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); } }
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"))); }
/** 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)); } }
static <T> void withMs(final String path, final Config conf, final Consumer<Long> callback) { withPath(path, conf, callback, () -> conf.getDuration(path, TimeUnit.MILLISECONDS)); }
/** 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); }
/** 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")))); } }
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"); }
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); } } }
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); } }
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); } }
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); } }
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); } }
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); } } }
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); } }
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); } } }
@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)); }
/** * 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; }