@Override public Object extractValue(Config config, String path) { return config.getLong(path); } },
@Override public long getLong(String path) { return c.getLong(path); }
/** * Constructor from a typesafe config object * @param serviceCfg the service configuration; must be local, i.e. any service namespace * prefix should be removed using {@link Config#getConfig(String)}. **/ public StandardServiceConfig(Config serviceCfg) { Config effectiveCfg = serviceCfg.withFallback(DEFAULT_CFG); this.startUpTimeoutMs = effectiveCfg.getLong(STARTUP_TIMEOUT_MS_PROP); this.shutDownTimeoutMs = effectiveCfg.getLong(SHUTDOWN_TIMEOUT_MS_PROP); } }
/** * Return {@link Long} value at <code>path</code> if <code>config</code> has path. If not return <code>def</code> * * @param config in which the path may be present * @param path key to look for in the config object * @return {@link Long} value at <code>path</code> if <code>config</code> has path. If not return <code>def</code> */ public static Long getLong(Config config, String path, Long def) { if (config.hasPath(path)) { return Long.valueOf(config.getLong(path)); } return def; }
public QPSPolicy(Config config) { Preconditions.checkArgument(config.hasPath(QPS), "QPS required."); this.qps = config.getLong(QPS); long fullRequestTimeoutMillis = config.hasPath(FULL_REQUEST_TIMEOUT_MILLIS) ? config.getLong(FULL_REQUEST_TIMEOUT_MILLIS) : DEFAULT_FULL_REQUEST_TIMEOUT; long maxBucketSizeMillis = config.hasPath(MAX_BUCKET_SIZE_MILLIS) ? config.getLong(MAX_BUCKET_SIZE_MILLIS) : DEFAULT_MAX_BUCKET_SIZE; this.tokenBucket = new DynamicTokenBucket(qps, fullRequestTimeoutMillis, maxBucketSizeMillis); }
/** Config accessor from a no namespaced typesafe config. */ public ConfigAccessor(Config cfg) { Config effectiveCfg = cfg.withFallback(getDefaultConfig().getConfig(CONFIG_PREFIX)); this.startTimeoutMs = effectiveCfg.getLong(START_TIMEOUT_MS); this.shutdownTimeoutMs = effectiveCfg.getLong(SHUTDOWN_TIMEOUT_MS); }
protected void slong(final String path, final Config config, final String name, final Consumer<Long> setter) { if (config.hasPath(name)) { long value = config.getLong(name); log.debug("setting {}.{} = {}", path, name, value); setter.accept(value); } }
@Override public ThrottlingPolicy createPolicy(SharedLimiterKey key, SharedResourcesBroker<ThrottlingServerScopes> broker, Config config) { Preconditions.checkArgument(config.hasPath(COUNT_KEY), "Missing key " + COUNT_KEY); return new CountBasedPolicy(config.getLong(COUNT_KEY)); } }
@Override public Limiter buildLimiter(Config config) { if (!config.hasPath(MAX_SECONDS_KEY)) { throw new RuntimeException("Missing key " + MAX_SECONDS_KEY); } return new TimeBasedLimiter(config.getLong(MAX_SECONDS_KEY)); } }
@Override public Limiter buildLimiter(Config config) { if (!config.hasPath(QPS_KEY)) { throw new RuntimeException("Missing key " + QPS_KEY); } return new RateBasedLimiter(config.getLong(QPS_KEY)); } }
@ValidateMe public long getMineMinBlockTimeoutMsec() { return config.getLong("mine.minBlockTimeoutMsec"); }
@Override public Limiter buildLimiter(Config config) { if (!config.hasPath(COUNT_KEY)) { throw new IllegalArgumentException("Missing key " + COUNT_KEY); } return new CountBasedLimiter(config.getLong(COUNT_KEY)); } }
@ValidateMe public long databaseResetBlock() { return config.getLong("database.resetBlock"); }
public YarnAppSecurityManager(Config config, HelixManager helixManager, FileSystem fs, Path tokenFilePath) throws IOException { this.config = config; this.helixManager = helixManager; this.fs = fs; this.tokenFilePath = tokenFilePath; this.fs.makeQualified(tokenFilePath); this.loginUser = UserGroupInformation.getLoginUser(); this.loginIntervalInMinutes = config.getLong(GobblinYarnConfigurationKeys.LOGIN_INTERVAL_IN_MINUTES); this.tokenRenewIntervalInMinutes = config.getLong(GobblinYarnConfigurationKeys.TOKEN_RENEW_INTERVAL_IN_MINUTES); this.loginExecutor = Executors.newSingleThreadScheduledExecutor( ExecutorsUtils.newThreadFactory(Optional.of(LOGGER), Optional.of("KeytabReLoginExecutor"))); this.tokenRenewExecutor = Executors.newSingleThreadScheduledExecutor( ExecutorsUtils.newThreadFactory(Optional.of(LOGGER), Optional.of("TokenRenewExecutor"))); }
/** Adds the maximum size and weight bounding settings. */ private void addMaximum() { if (isSet("policy.maximum.size")) { configuration.setMaximumSize(OptionalLong.of(merged.getLong("policy.maximum.size"))); } if (isSet("policy.maximum.weight")) { configuration.setMaximumWeight(OptionalLong.of(merged.getLong("policy.maximum.weight"))); } if (isSet("policy.maximum.weigher")) { configuration.setWeigherFactory(Optional.of( FactoryBuilder.factoryOf(merged.getString("policy.maximum.weigher")))); } }
/** * Generate a dagId from the given {@link Dag} instance. * @param dag instance of a {@link Dag}. * @return a String id associated corresponding to the {@link Dag} instance. */ static String generateDagId(Dag<JobExecutionPlan> dag) { Config jobConfig = dag.getStartNodes().get(0).getValue().getJobSpec().getConfig(); String flowGroup = jobConfig.getString(ConfigurationKeys.FLOW_GROUP_KEY); String flowName = jobConfig.getString(ConfigurationKeys.FLOW_NAME_KEY); Long flowExecutionId = jobConfig.getLong(ConfigurationKeys.FLOW_EXECUTION_ID_KEY); return Joiner.on("_").join(flowGroup, flowName, flowExecutionId); }
private static <T> Retryer<T> newExponentialRetryer(Config config) { return RetryerBuilder.<T> newBuilder() .retryIfException(RETRY_EXCEPTION_PREDICATE) .withWaitStrategy(WaitStrategies.exponentialWait(config.getLong(RETRY_MULTIPLIER), config.getLong(RETRY_INTERVAL_MS), TimeUnit.MILLISECONDS)) .withStopStrategy(StopStrategies.stopAfterDelay(config.getLong(RETRY_TIME_OUT_MS), TimeUnit.MILLISECONDS)) .build(); } }
public Ethash(SystemProperties config, long blockNumber) { this.config = config; this.blockNumber = blockNumber; this.epoch = blockNumber / ethashAlgo.getParams().getEPOCH_LENGTH(); if (config.getConfig().hasPath("mine.startNonce")) { startNonce = config.getConfig().getLong("mine.startNonce"); } }
private static <T> Retryer<T> newFixedRetryer(Config config) { return RetryerBuilder.<T> newBuilder() .retryIfException(RETRY_EXCEPTION_PREDICATE) .withWaitStrategy(WaitStrategies.fixedWait(config.getLong(RETRY_INTERVAL_MS), TimeUnit.MILLISECONDS)) .withStopStrategy(StopStrategies.stopAfterDelay(config.getLong(RETRY_TIME_OUT_MS), TimeUnit.MILLISECONDS)) .build(); }
@Test public void testFromProperties() { Properties props = new Properties(); props.put("a1", "a_value"); props.put("a2.b", "1"); props.put("a2.c.d", "12.34"); props.put("a2.c.d2", "true"); DefaultConfigurableImpl c = DefaultConfigurableImpl.createFromProperties(props); Assert.assertEquals(c.getConfig().getString("a1"), "a_value"); Assert.assertEquals(c.getConfig().getLong("a2.b"), 1L); Assert.assertEquals(c.getConfig().getDouble("a2.c.d"), 12.34); Assert.assertTrue(c.getConfig().getBoolean("a2.c.d2")); }