Java Code Examples for com.typesafe.config.Config#getBoolean()

The following examples show how to use com.typesafe.config.Config#getBoolean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypesafeConfigurator.java    From caffeine with Apache License 2.0 6 votes vote down vote up
/** Adds the entry listeners settings. */
private void addListeners() {
  for (String path : merged.getStringList("listeners")) {
    Config listener = root.getConfig(path);

    Factory<? extends CacheEntryListener<? super K, ? super V>> listenerFactory =
        factoryCreator.factoryOf(listener.getString("class"));
    Factory<? extends CacheEntryEventFilter<? super K, ? super V>> filterFactory = null;
    if (listener.hasPath("filter")) {
      filterFactory = factoryCreator.factoryOf(listener.getString("filter"));
    }
    boolean oldValueRequired = listener.getBoolean("old-value-required");
    boolean synchronous = listener.getBoolean("synchronous");
    configuration.addCacheEntryListenerConfiguration(
        new MutableCacheEntryListenerConfiguration<>(
            listenerFactory, filterFactory, oldValueRequired, synchronous));
  }
}
 
Example 2
Source File: AuthenticationServlet.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
@Inject
public AuthenticationServlet(AccountStore accountStore,
                             Configuration configuration,
                             SessionManager sessionManager,
                             @Named(CoreSettingsNames.WAVE_SERVER_DOMAIN) String domain,
                             Config config,
                             WelcomeRobot welcomeBot) {
  Preconditions.checkNotNull(accountStore, "AccountStore is null");
  Preconditions.checkNotNull(configuration, "Configuration is null");
  Preconditions.checkNotNull(sessionManager, "Session manager is null");

  this.accountStore = accountStore;
  this.configuration = configuration;
  this.sessionManager = sessionManager;
  this.domain = domain.toLowerCase();
  this.isClientAuthEnabled = config.getBoolean("security.enable_clientauth");
  this.clientAuthCertDomain = config.getString("security.clientauth_cert_domain").toLowerCase();
  this.isRegistrationDisabled = config.getBoolean("administration.disable_registration");
  this.isLoginPageDisabled = config.getBoolean("administration.disable_loginpage");
  this.welcomeBot = welcomeBot;
  this.analyticsAccount = config.getString("administration.analytics_account");
}
 
Example 3
Source File: Init.java    From andesite-node with MIT License 6 votes vote down vote up
public static void preInit(Config config) {
    ((Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)).setLevel(
            Level.valueOf(config.getString("log-level").toUpperCase())
    );
    if(config.getBoolean("prometheus.enabled")) {
        PrometheusUtils.setup();
        var listener = new GCListener();
        for(var gcBean : ManagementFactory.getGarbageCollectorMXBeans()) {
            if(gcBean instanceof NotificationEmitter) {
                ((NotificationEmitter) gcBean)
                        .addNotificationListener(listener, null, gcBean);
            }
        }
    }
    if(config.getBoolean("sentry.enabled")) {
        SentryUtils.setup(config);
    }
}
 
Example 4
Source File: R2ClientFactory.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
private Client createHttpClient(Config config) {
  boolean isSSLEnabled = config.getBoolean(SSL_ENABLED);
  SSLContext sslContext = null;
  SSLParameters sslParameters = null;

  if (isSSLEnabled) {
    sslContext = SSLContextFactory.createInstance(config);
    sslParameters = sslContext.getDefaultSSLParameters();
  }
  Map<String, Object> properties = new HashMap<>();
  properties.put(HttpClientFactory.HTTP_SSL_CONTEXT, sslContext);
  properties.put(HttpClientFactory.HTTP_SSL_PARAMS, sslParameters);

  if (config.hasPath(PROPERTIES)) {
    properties.putAll(toMap(config.getConfig(PROPERTIES)));
  }

  return new R2HttpClientProxy(new HttpClientFactory(), properties);
}
 
Example 5
Source File: AgentClient.java    From amcgala with Educational Community License v2.0 6 votes vote down vote up
public AgentClient(String agentConfiguration) {
    Config config =  ConfigFactory.load().getConfig("client").withFallback(ConfigFactory.load(agentConfiguration).withFallback(ConfigFactory.load("amcgala")));
    boolean localMode = config.getBoolean("org.amcgala.agent.simulation.local-mode");
    if (localMode) {
        system = ActorSystem.create("Client", config);
        ActorRef simulationManager = system.actorOf(Props.create(SimulationManager.class), "simulation-manager");
        simulationManager.tell(new SimulationManager.SimulationCreation(config), ActorRef.noSender());
    }else{
        system = ActorSystem.create("Client", config);
    }

    List<List<String>> lists = (List<List<String>>) config.getAnyRefList("org.amcgala.agent.client.agents");
    for (List<String> l : lists) {
        try {
            int numberOfAgents = Integer.parseInt(l.get(0));
            Class agentClass = ClassLoader.getSystemClassLoader().loadClass(l.get(1));
            createAgents(numberOfAgents, agentClass);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

}
 
Example 6
Source File: Configurator.java    From xio with Apache License 2.0 6 votes vote down vote up
public static Configurator build(Config config) {
  Config configurationUpdateServer = config.getConfig("configurationUpdateServer");
  if (configurationUpdateServer.getBoolean("enabled") == false) {
    return new NullConfigurator();
  }
  CuratorFramework client = new ZooKeeperClientFactory(config.getConfig("zookeeper")).newClient();
  client.start();
  ZooKeeperWriteProvider zkWriter = new ZooKeeperWriteProvider(new ThriftMarshaller(), client);
  ZooKeeperReadProvider zkReader = new ZooKeeperReadProvider(new ThriftUnmarshaller(), client);

  Config configurationManager = config.getConfig("configurationManager");
  Ruleset rules = new Ruleset(configurationManager);
  rules.read(zkReader);
  ZooKeeperUpdateHandler zkUpdater = new ZooKeeperUpdateHandler(zkWriter, rules);
  ZooKeeperValidator zkValidator = new ZooKeeperValidator(zkReader, rules, configurationManager);

  Duration writeInterval = configurationUpdateServer.getDuration("writeInterval");
  InetSocketAddress serverAddress =
      new InetSocketAddress(
          configurationUpdateServer.getString("bindIp"),
          configurationUpdateServer.getInt("bindPort"));
  Configurator server =
      new Configurator(zkUpdater, writeInterval, serverAddress, rules, zkValidator);
  return server;
}
 
Example 7
Source File: XConfig.java    From xrpc with Apache License 2.0 6 votes vote down vote up
private CorsConfig buildCorsConfig(Config config) {
  if (!config.getBoolean("enable")) {
    return CorsConfigBuilder.forAnyOrigin().disable().build();
  }

  CorsConfigBuilder builder =
      CorsConfigBuilder.forOrigins(getStrings(config, "allowed_origins"))
          .allowedRequestHeaders(getStrings(config, "allowed_headers"))
          .allowedRequestMethods(getHttpMethods(config, "allowed_methods"));
  if (config.getBoolean("allow_credentials")) {
    builder.allowCredentials();
  }
  if (config.getBoolean("short_circuit")) {
    builder.shortCircuit();
  }
  return builder.build();
}
 
Example 8
Source File: StageableTableMetadata.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
public StageableTableMetadata(Config config, @Nullable Table referenceTable) {
  Preconditions.checkArgument(config.hasPath(DESTINATION_TABLE_KEY), String.format("Key %s is not specified", DESTINATION_TABLE_KEY));
  Preconditions.checkArgument(config.hasPath(DESTINATION_DB_KEY), String.format("Key %s is not specified", DESTINATION_DB_KEY));
  Preconditions.checkArgument(config.hasPath(DESTINATION_DATA_PATH_KEY),
      String.format("Key %s is not specified", DESTINATION_DATA_PATH_KEY));

  // Required
  this.destinationTableName = referenceTable == null ? config.getString(DESTINATION_TABLE_KEY)
      : HiveDataset.resolveTemplate(config.getString(DESTINATION_TABLE_KEY), referenceTable);
  this.destinationStagingTableName = String.format("%s_%s", this.destinationTableName, "staging"); // Fixed and non-configurable
  this.destinationDbName = referenceTable == null ? config.getString(DESTINATION_DB_KEY)
      : HiveDataset.resolveTemplate(config.getString(DESTINATION_DB_KEY), referenceTable);
  this.destinationDataPath = referenceTable == null ? config.getString(DESTINATION_DATA_PATH_KEY)
      : HiveDataset.resolveTemplate(config.getString(DESTINATION_DATA_PATH_KEY), referenceTable);

  // By default, this value is true and subDir "/final" is being added into orc output location.
  this.dataDstPathUseSubdir = !config.hasPath(DESTINATION_DATA_PATH_ADD_SUBDIR) || config.getBoolean(DESTINATION_DATA_PATH_ADD_SUBDIR);

  // Optional
  this.destinationTableProperties =
      convertKeyValueListToProperties(ConfigUtils.getStringList(config, DESTINATION_TABLE_PROPERTIES_LIST_KEY));
  this.clusterBy = ConfigUtils.getStringList(config, CLUSTER_BY_KEY);
  this.numBuckets = Optional.fromNullable(ConfigUtils.getInt(config, NUM_BUCKETS_KEY, null));

  this.hiveRuntimeProperties =
      convertKeyValueListToProperties(ConfigUtils.getStringList(config, HIVE_RUNTIME_PROPERTIES_LIST_KEY));
  this.evolutionEnabled = ConfigUtils.getBoolean(config, EVOLUTION_ENABLED, false);
  this.casePreserved = ConfigUtils.getBoolean(config, OUTPUT_FILE_CASE_PRESERVED, false);
  this.rowLimit = Optional.fromNullable(ConfigUtils.getInt(config, ROW_LIMIT_KEY, null));
  this.sourceDataPathIdentifier = ConfigUtils.getStringList(config, SOURCE_DATA_PATH_IDENTIFIER_KEY);
}
 
Example 9
Source File: HttpConfig.java    From haystack-agent with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("PMD.NPathComplexity")
public static HttpConfig from(Config config) {
    final int port = config.hasPath(PORT_CONFIG_KEY) ? config.getInt(PORT_CONFIG_KEY) : 9411;
    final int maxThreads = config.hasPath(MAX_THREADS_CONFIG_KEY) ? config.getInt(MAX_THREADS_CONFIG_KEY) : 16;
    final int minThreads = config.hasPath(MIN_THREADS_CONFIG_KEY) ? config.getInt(MIN_THREADS_CONFIG_KEY) : 2;
    final int idleTimeout = config.hasPath(IDLE_TIMEOUT_MILLIS_CONFIG_KEY) ? config.getInt(IDLE_TIMEOUT_MILLIS_CONFIG_KEY) : 60000;
    final int stopTimeout = config.hasPath(STOP_TIMEOUT_MILLIS_CONFIG_KEY) ? config.getInt(STOP_TIMEOUT_MILLIS_CONFIG_KEY) : 30000;
    final int gzipBufferSize = config.hasPath(GZIP_BUFFER_SIZE) ? config.getInt(GZIP_BUFFER_SIZE) : 16384;
    final boolean gzipEnabled = !config.hasPath(GZIP_ENABLED_KEY) || config.getBoolean(GZIP_ENABLED_KEY); // default is true
    return new HttpConfig(port, minThreads, maxThreads, idleTimeout, stopTimeout, gzipEnabled, gzipBufferSize);
}
 
Example 10
Source File: UserRegistrationServlet.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Inject
public UserRegistrationServlet(
  AccountStore accountStore,
  @Named(CoreSettingsNames.WAVE_SERVER_DOMAIN) String domain,
  Config config,
  WelcomeRobot welcomeBot) {

  this.accountStore = accountStore;
  this.domain = domain;
  this.welcomeBot = welcomeBot;
  this.registrationDisabled = config.getBoolean("administration.disable_registration");
  this.analyticsAccount = config.getString("administration.analytics_account");
}
 
Example 11
Source File: MessagesService.java    From BungeeChat2 with GNU General Public License v3.0 5 votes vote down vote up
private static Stream<Predicate<BungeeChatAccount>> serverListToPredicate(Config section) {
  if (section.getBoolean("enabled")) {
    // TODO: Use wildcard string
    List<String> allowedServers = section.getStringList("list");

    return Stream.of(account -> allowedServers.contains(account.getServerName()));
  } else {
    return Stream.empty();
  }
}
 
Example 12
Source File: HyperParams.java    From ytk-learn with MIT License 5 votes vote down vote up
public HyperParams(Config config, String prefix) {
    switch_on = config.getBoolean(prefix + KEY + "switch_on");
    restart = config.getBoolean(prefix + KEY + "restart");
    mode = Mode.getMode(config.getString(prefix + KEY + "mode"));
    hoag = new Hoag(config, prefix + KEY);
    grid = new Grid(config, prefix + KEY);

    CheckUtils.check(mode != Mode.UNKNOWN, "unknown %smode:%s, only support:%s",
            prefix + KEY, mode, Mode.allToString());
}
 
Example 13
Source File: QueryQueueConfigImpl.java    From Bats with Apache License 2.0 5 votes vote down vote up
/**
 * Assigns either supplied or default values for the optional queue configuration. For required configuration uses
 * the supplied value in queueConfig object or throws proper exception if not present
 * @param queueConfig Config object for ResourcePool queue
 * @throws RMConfigException in case of error while parsing config
 */
private void parseQueueConfig(Config queueConfig) throws RMConfigException {
  this.maxAdmissibleQuery = queueConfig.hasPath(MAX_ADMISSIBLE_KEY) ?
    queueConfig.getInt(MAX_ADMISSIBLE_KEY) : MAX_ADMISSIBLE_QUERY_COUNT;
  this.maxWaitingQuery = queueConfig.hasPath(MAX_WAITING_KEY) ?
    queueConfig.getInt(MAX_WAITING_KEY) : MAX_WAITING_QUERY_COUNT;
  this.maxWaitingTimeout = queueConfig.hasPath(MAX_WAIT_TIMEOUT_KEY) ?
    queueConfig.getInt(MAX_WAIT_TIMEOUT_KEY) : RMCommonDefaults.MAX_WAIT_TIMEOUT_IN_MS;
  this.waitForPreferredNodes = queueConfig.hasPath(WAIT_FOR_PREFERRED_NODES_KEY) ?
    queueConfig.getBoolean(WAIT_FOR_PREFERRED_NODES_KEY) : RMCommonDefaults.WAIT_FOR_PREFERRED_NODES;
  this.queryPerNodeResourceShare = parseAndGetNodeShare(queueConfig);
}
 
Example 14
Source File: KerberosUtils.java    From envelope with Apache License 2.0 5 votes vote down vote up
private static boolean isKerberosDebug(Config config) {
  if (config.hasPath(DEBUG)) {
    return config.getBoolean(DEBUG);
  } else {
    return DEFAULT_DEBUG;
  }
}
 
Example 15
Source File: AuthenticationService.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Inject
public AuthenticationService(AccountStore accountStore, Configuration configuration,
    SessionManager sessionManager, Config config) {

  super(sessionManager);
  this.accountStore = accountStore;
  this.configuration = configuration;
  this.domain = config.getString("core.wave_server_domain");
  this.isClientAuthEnabled = config.getBoolean("security.enable_clientauth");
  this.clientAuthCertDomain = config.getString("security.clientauth_cert_domain").toLowerCase();

}
 
Example 16
Source File: XConfig.java    From xrpc with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a config object using the provided configuration, falling back on the default
 * configuration values <a
 * href="https://github.com/Nordstrom/xrpc/blob/master/src/main/resources/com/nordstrom/xrpc/xrpc.conf">here</a>.
 *
 * @throws RuntimeException if there is an error reading one of path_to_cert or path_to_key
 */
public XConfig(Config configOverrides) {
  Config defaultConfig = ConfigFactory.parseResources(this.getClass(), "xrpc.conf");
  Config config = configOverrides.withFallback(defaultConfig);

  readerIdleTimeout = config.getInt("reader_idle_timeout_seconds");
  writerIdleTimeout = config.getInt("writer_idle_timeout_seconds");
  allIdleTimeout = config.getInt("all_idle_timeout_seconds");
  workerNameFormat = config.getString("worker_name_format");
  bossThreadCount = config.getInt("boss_thread_count");
  workerThreadCount = config.getInt("worker_thread_count");
  asyncHealthCheckThreadCount = config.getInt("async_health_check_thread_count");
  long maxPayloadBytesLong = config.getBytes("max_payload_bytes");
  Preconditions.checkArgument(
      maxPayloadBytesLong <= Integer.MAX_VALUE,
      String.format(
          "value %d for max_payload_bytes must be less than or equal to %d",
          maxPayloadBytesLong, Integer.MAX_VALUE));
  maxPayloadBytes = (int) maxPayloadBytesLong;
  maxConnections = config.getInt("max_connections");
  rateLimiterPoolSize = config.getInt("rate_limiter_pool_size");
  softReqPerSec = config.getDouble("soft_req_per_sec");
  hardReqPerSec = config.getDouble("hard_req_per_sec");
  adminRoutesEnableInfo = config.getBoolean("admin_routes.enable_info");
  adminRoutesEnableUnsafe = config.getBoolean("admin_routes.enable_unsafe");
  defaultContentType = config.getString("default_content_type");
  globalSoftReqPerSec = config.getDouble("global_soft_req_per_sec");
  globalHardReqPerSec = config.getDouble("global_hard_req_per_sec");
  port = config.getInt("server.port");
  slf4jReporter = config.getBoolean("slf4j_reporter");
  jmxReporter = config.getBoolean("jmx_reporter");
  consoleReporter = config.getBoolean("console_reporter");
  slf4jReporterPollingRate = config.getInt("slf4j_reporter_polling_rate");
  consoleReporterPollingRate = config.getInt("console_reporter_polling_rate");
  enableWhiteList = config.getBoolean("enable_white_list");
  enableBlackList = config.getBoolean("enable_black_list");

  ipBlackList =
      ImmutableSet.<String>builder().addAll(config.getStringList("ip_black_list")).build();
  ipWhiteList =
      ImmutableSet.<String>builder().addAll(config.getStringList("ip_white_list")).build();

  corsConfig = buildCorsConfig(config.getConfig("cors"));

  sslContext = SslContextFactory.buildServerContext(buildTlsConfig(config.getConfig("tls")));

  populateClientOverrideList(config.getObjectList("req_per_second_override"));
}
 
Example 17
Source File: ServerMain.java    From swellrt with Apache License 2.0 4 votes vote down vote up
public static void run(Module coreSettings) throws PersistenceException,
    ConfigurationException, WaveServerException {
  Injector injector = Guice.createInjector(coreSettings);
  Module profilingModule = injector.getInstance(StatModule.class);
  ExecutorsModule executorsModule = injector.getInstance(ExecutorsModule.class);
  injector = injector.createChildInjector(profilingModule, executorsModule);

  Config config = injector.getInstance(Config.class);
  boolean enableFederation = config.getBoolean("federation.enable_federation");

  Module serverModule = injector.getInstance(ServerModule.class);
  Module federationModule = buildFederationModule(injector, enableFederation);
  PersistenceModule persistenceModule = injector.getInstance(PersistenceModule.class);
  // Module searchModule = injector.getInstance(SearchModule.class);
  // Module profileFetcherModule = injector.getInstance(ProfileFetcherModule.class);
  Module emailModule = injector.getInstance(EmailModule.class); // SwellRT
  // injector = injector.createChildInjector(serverModule, persistenceModule, robotApiModule,
  //    federationModule, searchModule, profileFetcherModule);
  injector = injector.createChildInjector(serverModule, persistenceModule, federationModule, emailModule);

  ServerRpcProvider server = injector.getInstance(ServerRpcProvider.class);
  WaveBus waveBus = injector.getInstance(WaveBus.class);

  String domain = config.getString("core.wave_server_domain");
  if (!ParticipantIdUtil.isDomainAddress(ParticipantIdUtil.makeDomainAddress(domain))) {
    throw new WaveServerException("Invalid wave domain: " + domain);
  }

  initializeServer(injector, domain);
  initializeServlets(server, config);
  // initializeRobotAgents(server);
  // initializeRobots(injector, waveBus);
  initializeFrontend(injector, server);
  initializeFederation(injector);
  // initializeSearch(injector, waveBus);
  initializeShutdownHandler(server);
  initializeSwellRt(injector, waveBus);

  LOG.info("Starting server");
  server.startWebSocketServer(injector);
}
 
Example 18
Source File: ConfigBeanImpl.java    From mpush with Apache License 2.0 4 votes vote down vote up
private static Object getValue(Class<?> beanClass, Type parameterType, Class<?> parameterClass, Config config,
                               String configPropName) {
    if (parameterClass == Boolean.class || parameterClass == boolean.class) {
        return config.getBoolean(configPropName);
    } else if (parameterClass == Integer.class || parameterClass == int.class) {
        return config.getInt(configPropName);
    } else if (parameterClass == Double.class || parameterClass == double.class) {
        return config.getDouble(configPropName);
    } else if (parameterClass == Long.class || parameterClass == long.class) {
        return config.getLong(configPropName);
    } else if (parameterClass == String.class) {
        return config.getString(configPropName);
    } else if (parameterClass == Duration.class) {
        return config.getDuration(configPropName);
    } else if (parameterClass == ConfigMemorySize.class) {
        return config.getMemorySize(configPropName);
    } else if (parameterClass == Object.class) {
        return config.getAnyRef(configPropName);
    } else if (parameterClass == List.class) {
        return getListValue(beanClass, parameterType, parameterClass, config, configPropName);
    } else if (parameterClass == Map.class) {
        // we could do better here, but right now we don't.
        Type[] typeArgs = ((ParameterizedType) parameterType).getActualTypeArguments();
        if (typeArgs[0] != String.class || typeArgs[1] != Object.class) {
            throw new ConfigException.BadBean("Bean property '" + configPropName + "' of class " + beanClass.getName() + " has unsupported Map<" + typeArgs[0] + "," + typeArgs[1] + ">, only Map<String,Object> is supported right now");
        }
        return config.getObject(configPropName).unwrapped();
    } else if (parameterClass == Config.class) {
        return config.getConfig(configPropName);
    } else if (parameterClass == ConfigObject.class) {
        return config.getObject(configPropName);
    } else if (parameterClass == ConfigValue.class) {
        return config.getValue(configPropName);
    } else if (parameterClass == ConfigList.class) {
        return config.getList(configPropName);
    } else if (hasAtLeastOneBeanProperty(parameterClass)) {
        return createInternal(config.getConfig(configPropName), parameterClass);
    } else {
        throw new ConfigException.BadBean("Bean property " + configPropName + " of class " + beanClass.getName() + " has unsupported type " + parameterType);
    }
}
 
Example 19
Source File: AbstractServingModelManager.java    From oryx with Apache License 2.0 4 votes vote down vote up
/**
 * @param config Oryx {@link Config} object
 * @since 2.0.0
 */
protected AbstractServingModelManager(Config config) {
  this.config = config;
  this.readOnly = config.getBoolean("oryx.serving.api.read-only");
}
 
Example 20
Source File: FeatureHashParams.java    From ytk-learn with MIT License 4 votes vote down vote up
public FeatureHashParams(Config config, String prefix) {
    need_feature_hash = config.getBoolean(prefix + KEY + "need_feature_hash");
    bucket_size = config.getInt(prefix + KEY + "bucket_size");
    seed = config.getInt(prefix + KEY + "seed");
    feature_prefix = config.getString(prefix + KEY + "feature_prefix");
}