Java Code Examples for org.apache.commons.configuration.AbstractConfiguration#getInt()

The following examples show how to use org.apache.commons.configuration.AbstractConfiguration#getInt() . 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: RedisSyncSingleStorageImpl.java    From mithqtt with Apache License 2.0 6 votes vote down vote up
@Override
public void init(AbstractConfiguration config) {
    if (!config.getString("redis.type").equals("single")) {
        throw new IllegalStateException("RedisSyncSingleStorageImpl class can only be used with single redis setup, but redis.type value is " + config.getString("redis.type"));
    }

    List<String> address = parseRedisAddress(config.getString("redis.address"), 6379);
    int databaseNumber = config.getInt("redis.database", 0);
    String password = StringUtils.isNotEmpty(config.getString("redis.password")) ? config.getString("redis.password") + "@" : "";

    // lettuce
    RedisURI lettuceURI = RedisURI.create("redis://" + password + address.get(0) + "/" + databaseNumber);
    this.lettuce = RedisClient.create(lettuceURI);
    this.lettuceConn = this.lettuce.connect();

    // params
    initParams(config);
}
 
Example 2
Source File: RedisSyncSentinelStorageImpl.java    From mithqtt with Apache License 2.0 6 votes vote down vote up
@Override
public void init(AbstractConfiguration config) {
    if (!config.getString("redis.type").equals("sentinel")) {
        throw new IllegalStateException("RedisSyncSingleStorageImpl class can only be used with sentinel redis setup, but redis.type value is " + config.getString("redis.type"));
    }

    List<String> address = parseRedisAddress(config.getString("redis.address"), 26379);
    int databaseNumber = config.getInt("redis.database", 0);
    String password = StringUtils.isNotEmpty(config.getString("redis.password")) ? config.getString("redis.password") + "@" : "";
    String masterId = config.getString("redis.master");

    // lettuce
    RedisURI lettuceURI = RedisURI.create("redis-sentinel://" + password + String.join(",", address) + "/" + databaseNumber + "#" + masterId);
    this.lettuceSentinel = RedisClient.create(lettuceURI);
    this.lettuceSentinelConn = MasterSlave.connect(this.lettuceSentinel, new Utf8StringCodec(), lettuceURI);
    this.lettuceSentinelConn.setReadFrom(ReadFrom.valueOf(config.getString("redis.read")));

    // params
    initParams(config);
}
 
Example 3
Source File: RedisSyncMasterSlaveStorageImpl.java    From mithqtt with Apache License 2.0 6 votes vote down vote up
@Override
public void init(AbstractConfiguration config) {
    if (!config.getString("redis.type").equals("master_slave")) {
        throw new IllegalStateException("RedisSyncSingleStorageImpl class can only be used with master slave redis setup, but redis.type value is " + config.getString("redis.type"));
    }

    List<String> address = parseRedisAddress(config.getString("redis.address"), 6379);
    int databaseNumber = config.getInt("redis.database", 0);
    String password = StringUtils.isNotEmpty(config.getString("redis.password")) ? config.getString("redis.password") + "@" : "";

    // lettuce
    RedisURI lettuceURI = RedisURI.create("redis://" + password + address.get(0) + "/" + databaseNumber);
    this.lettuceMasterSlave = RedisClient.create(lettuceURI);
    this.lettuceMasterSlaveConn = MasterSlave.connect(this.lettuceMasterSlave, new Utf8StringCodec(), lettuceURI);
    this.lettuceMasterSlaveConn.setReadFrom(ReadFrom.valueOf(config.getString("redis.read")));

    // params
    initParams(config);
}
 
Example 4
Source File: LogConfigUtils.java    From singer with Apache License 2.0 5 votes vote down vote up
/**
 * Singer can restart itself if # of failures exceeds threshold, and in daily
 * cadence. The following is singer restart related configuration:
 *
 * singer.restart.onFailures=true singer.restart.numberOfFailuresAllowed=100
 * singer.restart.daily=true singer.restart.dailyRestartUtcTimeRangeBegin=02:30
 * singer.restart.dailyRestartUtcTimeRangeEnd=03:30
 */
private static SingerRestartConfig parseSingerRestartConfig(PropertiesConfiguration configHeader) throws ConfigurationException {
  SingerRestartConfig restartConfig = new SingerRestartConfig();
  AbstractConfiguration subsetConfig = new SubsetConfiguration(configHeader,
      SingerConfigDef.SINGER_RESTART_PREFIX);

  if (subsetConfig.containsKey(SingerConfigDef.ON_FAILURES)) {
    restartConfig.restartOnFailures = subsetConfig.getBoolean(SingerConfigDef.ON_FAILURES);
  }
  if (subsetConfig.containsKey(SingerConfigDef.NUMBER_OF_FAILURES_ALLOWED)) {
    restartConfig.numOfFailuesAllowed = subsetConfig
        .getInt(SingerConfigDef.NUMBER_OF_FAILURES_ALLOWED);
  }
  if (subsetConfig.containsKey(SingerConfigDef.DAILY_RESTART_FLAG)) {
    restartConfig.restartDaily = subsetConfig.getBoolean(SingerConfigDef.DAILY_RESTART_FLAG);
  }

  if (restartConfig.restartDaily) {
    if (!subsetConfig.containsKey(SingerConfigDef.DAILY_RESTART_TIME_BEGIN)
        || !subsetConfig.containsKey(SingerConfigDef.DAILY_RESTART_TIME_END)) {
      throw new ConfigurationException("Daily restart time range is not set correctly");
    }

    restartConfig.dailyRestartUtcTimeRangeBegin = subsetConfig
        .getString(SingerConfigDef.DAILY_RESTART_TIME_BEGIN);
    restartConfig.dailyRestartUtcTimeRangeEnd = subsetConfig
        .getString(SingerConfigDef.DAILY_RESTART_TIME_END);
    Date startTime = SingerUtils.convertToDate(restartConfig.dailyRestartUtcTimeRangeBegin);
    Date endTime = SingerUtils.convertToDate(restartConfig.dailyRestartUtcTimeRangeEnd);
    if (endTime.compareTo(startTime) <= 0) {
      throw new ConfigurationException("Daily restart end time is not later than start time");
    }
  }
  return restartConfig;
}
 
Example 5
Source File: RedisSyncClusterStorageImpl.java    From mithqtt with Apache License 2.0 5 votes vote down vote up
@Override
public void init(AbstractConfiguration config) {
    if (!config.getString("redis.type").equals("cluster")) {
        throw new IllegalStateException("RedisSyncSingleStorageImpl class can only be used with cluster redis setup, but redis.type value is " + config.getString("redis.type"));
    }

    List<String> address = parseRedisAddress(config.getString("redis.address"), 6379);
    int databaseNumber = config.getInt("redis.database", 0);
    String password = StringUtils.isNotEmpty(config.getString("redis.password")) ? config.getString("redis.password") + "@" : "";

    // lettuce
    RedisURI lettuceURI = RedisURI.create("redis://" + password + address.get(0) + "/" + databaseNumber);
    this.lettuceCluster = RedisClusterClient.create(lettuceURI);
    this.lettuceCluster.setOptions(ClusterClientOptions.builder()
            .topologyRefreshOptions(ClusterTopologyRefreshOptions.builder()
                    .enablePeriodicRefresh(config.getBoolean("redis.cluster.periodicRefreshEnabled", ClusterTopologyRefreshOptions.DEFAULT_PERIODIC_REFRESH_ENABLED))
                    .refreshPeriod(config.getLong("redis.cluster.refreshPeriod", ClusterTopologyRefreshOptions.DEFAULT_REFRESH_PERIOD), TimeUnit.SECONDS)
                    .closeStaleConnections(config.getBoolean("redis.cluster.closeStaleConnections", ClusterTopologyRefreshOptions.DEFAULT_CLOSE_STALE_CONNECTIONS))
                    .build())
            .validateClusterNodeMembership(config.getBoolean("redis.cluster.validateClusterNodeMembership", ClusterClientOptions.DEFAULT_VALIDATE_CLUSTER_MEMBERSHIP))
            .maxRedirects(config.getInt("redis.cluster.refreshPeriod", ClusterClientOptions.DEFAULT_MAX_REDIRECTS))
            .build());
    this.lettuceClusterConn = this.lettuceCluster.connect();
    this.lettuceClusterConn.setReadFrom(ReadFrom.valueOf(config.getString("redis.read")));

    // params
    initParams(config);
}
 
Example 6
Source File: LogConfigUtils.java    From singer with Apache License 2.0 4 votes vote down vote up
public static LogMonitorConfig parseLogMonitorConfig(AbstractConfiguration monitorConfiguration) {
  int monitorIntervalInSecs = monitorConfiguration.getInt("monitorIntervalInSecs");
  return new LogMonitorConfig(monitorIntervalInSecs);
}
 
Example 7
Source File: LogConfigUtils.java    From singer with Apache License 2.0 4 votes vote down vote up
private static KafkaWriterConfig parseKafkaWriterConfig(AbstractConfiguration kafkaWriterConfiguration) throws ConfigurationException {
  kafkaWriterConfiguration.setThrowExceptionOnMissing(true);
  String topic;
  try {
    topic = kafkaWriterConfiguration.getString(SingerConfigDef.TOPIC);
  } catch (Exception x) {
    throw new ConfigurationException("KafkaWriter topic is required for Singer Configuration");
  }
  KafkaProducerConfig producerConfig = parseProducerConfig(
      new SubsetConfiguration(kafkaWriterConfiguration, SingerConfigDef.PRODUCER_CONFIG_PREFIX));

  String auditTopic = null;

  boolean auditingEnabled = false;
  if (kafkaWriterConfiguration.containsKey(SingerConfigDef.AUDITING_ENABLED)) {
    auditingEnabled = kafkaWriterConfiguration.getBoolean(SingerConfigDef.AUDITING_ENABLED);

    if (auditingEnabled) {
      if (!kafkaWriterConfiguration.containsKey(SingerConfigDef.AUDIT_TOPIC)) {
        throw new ConfigurationException("Auditing enabled but missing audit topic");
      } else {
        auditTopic = kafkaWriterConfiguration.getString(SingerConfigDef.AUDIT_TOPIC);
      }
    }
  }

  boolean skipNoLeaderPartitions = false;
  if (kafkaWriterConfiguration.containsKey(SingerConfigDef.SKIP_NO_LEADER_PARTITIONS)) {
    skipNoLeaderPartitions = kafkaWriterConfiguration
        .getBoolean(SingerConfigDef.SKIP_NO_LEADER_PARTITIONS);
  }

  int writeTimeoutInSeconds = 60;
  if (kafkaWriterConfiguration.containsKey(SingerConfigDef.KAFKA_WRITE_TIMEOUT_IN_SECONDS)) {
    writeTimeoutInSeconds = kafkaWriterConfiguration
        .getInt(SingerConfigDef.KAFKA_WRITE_TIMEOUT_IN_SECONDS);
  }

  KafkaWriterConfig writerConfig = new KafkaWriterConfig(topic, producerConfig);
  writerConfig.setAuditTopic(auditTopic);
  writerConfig.setAuditingEnabled(auditingEnabled);
  writerConfig.setSkipNoLeaderPartitions(skipNoLeaderPartitions);
  writerConfig.setWriteTimeoutInSeconds(writeTimeoutInSeconds);
  return writerConfig;
}
 
Example 8
Source File: LogConfigUtils.java    From singer with Apache License 2.0 4 votes vote down vote up
private static ThriftReaderConfig parseThriftReaderConfig(AbstractConfiguration thriftReaderConfiguration) {
  thriftReaderConfiguration.setThrowExceptionOnMissing(true);
  int readerBufferSize = thriftReaderConfiguration.getInt("readerBufferSize");
  int maxMessageSize = thriftReaderConfiguration.getInt("maxMessageSize");
  return new ThriftReaderConfig(readerBufferSize, maxMessageSize);
}
 
Example 9
Source File: RedisSyncSingleStorageImpl.java    From mithqtt with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize MQTT parameters
 *
 * @param config Redis Configuration
 */
void initParams(AbstractConfiguration config) {
    this.inFlightQueueSize = config.getInt("mqtt.inflight.queue.size", 0);
    this.qos2QueueSize = config.getInt("mqtt.qos2.queue.size", 0);
    this.retainQueueSize = config.getInt("mqtt.retain.queue.size", 0);
}