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

The following examples show how to use com.typesafe.config.Config#getObject() . 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: DispatcherActor.java    From Nickle-Scheduler with Apache License 2.0 6 votes vote down vote up
/**
 * 执行注册
 *
 * @param clientRegisterEvent
 */
private void execRegister(ClientRegisterEvent clientRegisterEvent) throws InterruptedException {
    Config config = getContext().getSystem().settings().config();
    //一直注册直到服务器返回数据
    if (!ObjectUtils.isEmpty(masterList)) {
        if (registerSuccess) {
            log.info("已注册成功");
            return;
        }
        ConfigObject configObject = config.getObject("akka.remote.netty.tcp");
        String hostname = configObject.get("hostname").unwrapped().toString();
        String portStr = configObject.get("port").unwrapped().toString();
        Integer port = Integer.valueOf(portStr);
        registerEvent = new RegisterEvent(hostname, port, clientRegisterEvent.getJobDataList(), clientRegisterEvent.getTriggerDataList());
        masterRouter.route(registerEvent, getSelf());
        //睡眠1s后注册,避免频繁注册
        Thread.sleep(1000);
        this.getSelf().tell(clientRegisterEvent, getSelf());
    } else {
        log.error("master地址为空,将不继续注册");
        ClientUtils.exit(getContext());
    }
}
 
Example 2
Source File: Rules.java    From Stargraph with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<Language, List<QueryPlanPatterns>> loadQueryPlanPatterns(Config config) {
    Map<Language, List<QueryPlanPatterns>> rulesByLang = new LinkedHashMap<>();
    ConfigObject configObject = config.getObject("rules.planner-pattern");

    configObject.keySet().forEach(strLang -> {
        Language language = Language.valueOf(strLang.toUpperCase());
        List<QueryPlanPatterns> plans = new ArrayList<>();

        List<? extends ConfigObject> innerCfg = configObject.toConfig().getObjectList(strLang);
        innerCfg.forEach(e -> {
            Map<String, Object> plan = e.unwrapped();
            String planId = plan.keySet().toArray(new String[1])[0];
            List<String> triplePatterns = (List<String>)plan.values().toArray()[0];
            plans.add(new QueryPlanPatterns(planId,
                    triplePatterns.stream().map(TriplePattern::new).collect(Collectors.toList())));
        });

        rulesByLang.put(language, plans);
    });

    return rulesByLang;
}
 
Example 3
Source File: Rules.java    From Stargraph with MIT License 6 votes vote down vote up
private Map<Language, List<Pattern>> loadStopPatterns(Config config) {
    Map<Language, List<Pattern>> rulesByLang = new LinkedHashMap<>();
    ConfigObject configObject = config.getObject("rules.stop-pattern");

    configObject.keySet().forEach(strLang -> {
        Language language = Language.valueOf(strLang.toUpperCase());
        List<String> patternStr = configObject.toConfig().getStringList(strLang);

        rulesByLang.compute(language,
                (lang, pattern) -> patternStr.stream().map(Pattern::compile).collect(Collectors.toList()));

        logger.info(marker, "Loaded {} Stop patterns for '{}'", rulesByLang.get(language).size(), language);

    });

    return rulesByLang;
}
 
Example 4
Source File: TestRangeRowRule.java    From envelope with Apache License 2.0 6 votes vote down vote up
@Test
public void testRangeDataTypes() throws Exception {
  Config config = ConfigUtils.configFromResource("/dq/dq-range-rules.conf").getConfig("steps");
  StructType schema = new StructType(new StructField[] {
    new StructField("fa", DataTypes.LongType, false, Metadata.empty()),
    new StructField("fi", DataTypes.IntegerType, false, Metadata.empty()),
    new StructField("fl", DataTypes.LongType, false, Metadata.empty()),
    new StructField("ff", DataTypes.FloatType, false, Metadata.empty()),
    new StructField("fe", DataTypes.DoubleType, false, Metadata.empty()),
    new StructField("fd", DataTypes.createDecimalType(), false, Metadata.empty())
  });
  Row row = new RowWithSchema(schema, new Long(2), 2, new Long(2), new Float(2.0), 2.0, new BigDecimal("2.0"));
    
  ConfigObject rro =  config.getObject("dq1.deriver.rules") ;
  for ( String rulename : rro.keySet() ) {
    Config rrc = rro.toConfig().getConfig(rulename);
    RangeRowRule rrr = new RangeRowRule() ;
    rrr.configure(rrc);
    rrr.configureName(rulename);
    assertTrue("Row should pass rule " + rulename, rrr.check(row));
  }
}
 
Example 5
Source File: HeartBeatActor.java    From Nickle-Scheduler with Apache License 2.0 5 votes vote down vote up
public HeartBeatActor(Router masterRouter, ActorRef dispatcherActor) {
    Config config = getContext().getSystem().settings().config();
    ConfigObject configObject = config.getObject("akka.remote.netty.tcp");
    localHostName = configObject.get("hostname").unwrapped().toString();
    localPort = Integer.valueOf(configObject.get("port").unwrapped().toString());
    this.masterRouter = masterRouter;
    this.dispatcherActor = dispatcherActor;
}
 
Example 6
Source File: Rules.java    From Stargraph with MIT License 5 votes vote down vote up
private Map<Language, List<DataModelTypePattern>> loadDataModelTypePatterns(Config config) {
    Map<Language, List<DataModelTypePattern>> rulesByLang = new HashMap<>();
    ConfigObject configObject = config.getObject("rules.syntatic-pattern");

    configObject.keySet().forEach(strLang -> {
        Language language = Language.valueOf(strLang.toUpperCase());

        rulesByLang.compute(language, (l, r) -> {

            List<DataModelTypePattern> rules = new ArrayList<>();
            List<? extends Config> patternCfg = configObject.toConfig().getConfigList(strLang);

            for (Config cfg : patternCfg) {
                Map.Entry<String, ConfigValue> entry = cfg.entrySet().stream().findFirst().orElse(null);
                String modelStr = entry.getKey();
                @SuppressWarnings("unchecked")
                List<String> patternList = (List<String>) entry.getValue().unwrapped();
                rules.addAll(patternList.stream()
                        .map(p -> new DataModelTypePattern(p, DataModelType.valueOf(modelStr)))
                        .collect(Collectors.toList()));
            }

            logger.info(marker, "Loaded {} Data Model Type patterns for '{}'", rules.size(), l);

            return rules;
        });
    });


    return rulesByLang;
}
 
Example 7
Source File: Rules.java    From Stargraph with MIT License 5 votes vote down vote up
private Map<Language, List<QueryTypePatterns>> loadQueryTypePatterns(Config config) {
    Map<Language, List<QueryTypePatterns>> rulesByLang = new HashMap<>();
    ConfigObject configObject = config.getObject("rules.query-pattern");

    configObject.keySet().forEach(strLang -> {
        Language language = Language.valueOf(strLang.toUpperCase());

        ConfigObject innerCfg = configObject.toConfig().getObject(strLang);

        List<QueryTypePatterns> patterns = new ArrayList<>();

        rulesByLang.compute(language, (l, q) -> {
            innerCfg.keySet().forEach(key -> {
                QueryType queryType = QueryType.valueOf(key);
                List<String> patternStr = innerCfg.toConfig().getStringList(key);
                patterns.add(new QueryTypePatterns(queryType,
                        patternStr.stream().map(Pattern::compile).collect(Collectors.toList())));
            });

            logger.info(marker, "Loaded {} Query Type patterns for '{}'", patterns.size(), language);
            return patterns;
        });

    });

    return rulesByLang;
}
 
Example 8
Source File: ConfigValidator.java    From J-Kinopoisk2IMDB with Apache License 2.0 5 votes vote down vote up
/**
 * Checks the db and db.additional settings
 *
 * @throws ConfigException
 */
private void checkDataBase() {
    final Config dbConfig = config.getConfig("db");

    checkArgument(!isNullOrEmpty(dbConfig.getString("driver")), "db.driver is not set!");
    checkArgument(!isNullOrEmpty(dbConfig.getString("url")), "db.url is not set!");

    dbConfig.getString("user");
    dbConfig.getString("password");
    dbConfig.getObject("additional");
}
 
Example 9
Source File: KafkaSourcedSpoutScheme.java    From Eagle with Apache License 2.0 5 votes vote down vote up
public KafkaSourcedSpoutScheme(String deserClsName, Config context){
	try{
		Properties prop = new Properties();
           if(context.getObject("eagleProps") != null) {
               prop.putAll(context.getObject("eagleProps"));
           }
		Constructor<?> constructor =  Class.forName(deserClsName).getConstructor(Properties.class);
		deserializer = (SpoutKafkaMessageDeserializer) constructor.newInstance(prop);
	}catch(Exception ex){
		throw new RuntimeException("Failed to create new instance for decoder class " + deserClsName, ex);
	}
}
 
Example 10
Source File: Instruments.java    From parity with Apache License 2.0 5 votes vote down vote up
/**
 * Get the instruments from a configuration object.
 *
 * @param config a configuration object
 * @param path the path expression
 * @return the instruments
 * @throws ConfigException if a configuration error occurs
 */
public static Instruments fromConfig(Config config, String path) {
    ConfigObject root = config.getObject(path);

    Config rootConfig = root.toConfig();

    int priceIntegerDigits = getInt(rootConfig, "price-integer-digits", 1);
    int sizeIntegerDigits  = getInt(rootConfig, "size-integer-digits",  1);

    Set<String> instruments = root.keySet();

    instruments.remove("price-integer-digits");
    instruments.remove("size-integer-digits");

    Instrument[] values = instruments.stream()
            .map(instrument -> Instrument.fromConfig(rootConfig, instrument))
            .toArray(Instrument[]::new);

    int maxPriceFractionDigits = max(values, Instrument::getPriceFractionDigits);
    int maxSizeFractionDigits  = max(values, Instrument::getSizeFractionDigits);

    for (Instrument value : values) {
        value.setPriceFormat(priceIntegerDigits, maxPriceFractionDigits);
        value.setSizeFormat(sizeIntegerDigits, maxSizeFractionDigits);
    }

    return new Instruments(values, priceIntegerDigits, maxPriceFractionDigits,
            sizeIntegerDigits, maxSizeFractionDigits);
}
 
Example 11
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 12
Source File: AlertExecutorCreationUtils.java    From Eagle with Apache License 2.0 4 votes vote down vote up
/**
    * Build DAG Tasks based on persisted alert definition and schemas from eagle store.
    *
    * <h3>Require configuration:</h3>
    *
    * <ul>
    * <li>eagleProps.site: program site id.</li>
    * <li>eagleProps.dataSource: program data source.</li>
    * <li>alertExecutorConfigs: only configured executor will be built into execution tasks.</li>
    * </ul>
    *
    * <h3>Steps:</h3>
    *
    * <ol>
    * <li>(upstreamTasks) => Map[streamName:String,upstreamTask:Task]</li>
    * <li>(dataSource) => Map[alertExecutorId:String,streamName:List[String]]</li>
    * <li>(site,dataSource) => Map[alertExecutorId,Map[policyId,alertDefinition]]</li>
    * <li>(config["alertExecutorConfigs"]) => AlertExecutor(alertExecutorID, partitioner, numPartitions, partitionSeq, alertDefs, alertDefDAO, sourceStreams)[]</li>
    * </ol>
    */
public static AlertExecutor[] createAlertExecutors(Config config, AlertDefinitionDAO alertDefDAO,
		List<String> streamNames, String alertExecutorId) throws Exception{
	// Read `alertExecutorConfigs` from configuration and get config for this alertExecutorId
       int numPartitions =1;
       String partitionerCls = DefaultPolicyPartitioner.class.getCanonicalName();
       String alertExecutorConfigsKey = "alertExecutorConfigs";
       if(config.hasPath(alertExecutorConfigsKey)) {
           Map<String, ConfigValue> alertExecutorConfigs = config.getObject(alertExecutorConfigsKey);
           if(alertExecutorConfigs !=null && alertExecutorConfigs.containsKey(alertExecutorConfigs)) {
               Map<String, Object> alertExecutorConfig = (Map<String, Object>) alertExecutorConfigs.get(alertExecutorId).unwrapped();
               int parts = 0;
               if(alertExecutorConfig.containsKey("parallelism")) parts = (int) (alertExecutorConfig.get("parallelism"));
               numPartitions = parts == 0 ? 1 : parts;
               if(alertExecutorConfig.containsKey("partitioner")) partitionerCls = (String) alertExecutorConfig.get("partitioner");
           }
       }

       return createAlertExecutors(alertDefDAO, streamNames, alertExecutorId, numPartitions, partitionerCls);
}