@Override protected void configure() { if (LOG.isInfoEnabled() && hasEnabled(config, LOG_CONFIG_ON_START, OLD_LOG_CONFIG_ON_START)) { LOG.info(config.root().render()); } bind(Config.class).toInstance(config); bindConfig(); }
private void bindPrimitive(final Named key, final long value) { bindConstant().annotatedWith(key).to(value); LOG.trace("bound {} to {}", key.value(), value); }
private void bindList(final Named key, final List<Object> values, final ConfigValue configValue) { if (values.isEmpty()) { bindList(key, INT_LIST, Collections.<Integer>emptyList()); bindList(key, DOUBLE_LIST, Collections.<Double>emptyList()); bindList(key, BOOL_LIST, Collections.<Boolean>emptyList()); bindList(key, STRING_LIST, Collections.<String>emptyList()); } else { final Object head = values.get(0); if (head instanceof Integer) { bindList(key, INT_LIST, collectFrom(values, Integer.class)); } else if (head instanceof Long) { bindList(key, LONG_LIST, collectFrom(values, Long.class)); } else if (head instanceof Double) { bindList(key, DOUBLE_LIST, collectFrom(values, Double.class)); } else if (head instanceof Boolean) { bindList(key, BOOL_LIST, collectFrom(values, Boolean.class)); } else if (head instanceof String) { bindList(key, STRING_LIST, collectFrom(values, String.class)); } else { throw unexpectedListType(head, configValue); } } }
private static Injector getInjector() { final ConfigModule configModule = new ConfigModule(); final Config config = configModule.getConfig(); LoggingConfigurator.configureFrom(config); return Guice.createInjector( configModule, new PersistenceModule(), new JacksonObjectMapperModule(), new JpaHibernateModule(config) ); } }
switch (configValue.valueType()) { case BOOLEAN: bindPrimitive(key, (Boolean) configValue.unwrapped()); break; bindPrimitive(key, ((Number) configValue.unwrapped()).longValue()); break; final String configKey = entry.getKey(); final boolean specialValue = tryParseDuration(configKey, key) || tryParseBoolean(configKey, key); if (!specialValue) { bindPrimitive(key, configValue.unwrapped().toString()); bindList(key, (List<Object>) configValue.unwrapped(), configValue); break; throw unexpectedConfigType(configValue);
private boolean tryParseBoolean(final String configKey, final Named bindKey) { try { final boolean duration = config.getBoolean(configKey); bindPrimitive(bindKey, duration); return true; } catch (final ConfigException.BadValue | ConfigException.WrongType ignore) { return false; } }
private <T> void bindList(final Named key, final TypeLiteral<List<T>> typeLiteral, final List<T> values) { bind(typeLiteral).annotatedWith(key).toInstance(values); LOG.trace("bound {} to {}", key.value(), values); }
public static void configureFrom(final Config config) { Preconditions.checkNotNull(config); final String loggingPath = config.getString(LOGGING_PATH_CONFIG); final Optional<String> logLevel = ConfigModule.firstString(config, LOGGING_CONFIG_ROOT + LOGLEVEL_CONFIG, DEPRECATED_CONFIG_ROOT + LOGLEVEL_CONFIG); final Optional<String> rootLogLevel = ConfigModule.firstString(config, LOGGING_CONFIG_ROOT + ROOT_LOGLEVEL_CONFIG, DEPRECATED_CONFIG_ROOT + ROOT_LOGLEVEL_CONFIG); final boolean resetLoggingContext = !config.getBoolean(TO_CONSOLE_CONFIG); configure( loggingPath, logLevel.orElse("default"), rootLogLevel.orElse("default"), resetLoggingContext); }
public static Injector getInjector() { final ConfigModule configModule = new ConfigModule(); final Config config = configModule.getConfig(); LoggingConfigurator.configureFrom(config); return Guice.createInjector( configModule, new PersistenceModule(), new JacksonObjectMapperModule(), new JpaHibernateModule(config) ); }
private boolean tryParseDuration(final String configKey, final Named bindKey) { try { final long duration = config.getDuration(configKey, TimeUnit.MILLISECONDS); bindPrimitive(bindKey, duration); return true; } catch (final ConfigException.BadValue | ConfigException.WrongType ignore) { return false; } }
public static Injector getInjector() { final ConfigModule configModule = new ConfigModule(); final Config config = configModule.getConfig(); LoggingConfigurator.configureFrom(config); final JacksonObjectMapperModule objectMapperModule = new JacksonObjectMapperModule() .include(JsonInclude.Include.NON_NULL, JsonInclude.Include.NON_EMPTY) .withoutTransformation(); return Guice.createInjector( configModule, objectMapperModule, new PersistenceModule(), new ConverterModule(), new JpaHibernateModule(config) ); }
private void bindPrimitive(final Named key, final Boolean value) { bindConstant().annotatedWith(key).to(value); LOG.trace("bound {} to {}", key.value(), value); }
private void bindPrimitive(final Named key, final String value) { bindConstant().annotatedWith(key).to(value); LOG.trace("bound {} to {}", key.value(), value); }