/** * Returns the value to which the specified key is mapped, converted to String * or {@code Optional.absent} if this configuration source contains no mapping for the key. * * @param key the key whose associated value is to be returned * @return the value to which the specified key is mapped, or * {@code Optional.absent} if this map contains no mapping for the key */ default Optional<String> get(String key) { return get(key, String.class); }
/** * Create an instance of the product. * * @param environment environment * @param serviceConfiguration configuration specific to the factory product * @param objects objects that service might depend on * @return product instance */ default E create(Environment environment, Configuration serviceConfiguration, ActiveOrigins objects) { return create(environment, serviceConfiguration); } }
@Override public <X> X as(Class<X> type) { return configuration.as(type); }
@Override public Registry<BackendService> create(Environment environment, Configuration registryConfiguration) { String originsFile = registryConfiguration.get("originsFile", String.class) .map(Factory::requireNonEmpty) .orElseThrow(() -> new ConfigurationException( "missing [services.registry.factory.config.originsFile] config value for factory class FileBackedBackendServicesRegistry.Factory")); FileMonitorSettings monitorSettings = registryConfiguration.get("monitor", FileMonitorSettings.class) .orElseGet(FileMonitorSettings::new); return registry(originsFile, monitorSettings); }
private String factoryClassName(String strategyName) { String key = format("loadBalancing.strategies.%s.factory.class", strategyName); return configurations.get(key).orElseThrow(() -> new MissingConfigurationException(key)); } }
@Override protected Path convert(java.lang.String value) { Path location = Paths.get(removeFilePrefix(value)); if (!isReadable(location)) { throw new ConfigurationException(format("%s=%s is not a readable configuration path.", name(), location)); } return location; }
/** * Return the value associated with the setting. * * @param setting a setting * @param <T> setting value type * @return the value associated with the setting * @throws com.hotels.styx.api.configuration.NoSystemPropertyDefined if there is no associated value */ public static <T> T valueOf(Setting<T> setting) { return setting.value().orElseThrow(() -> new NoSystemPropertyDefined(setting.name())); }
private static String requireNonEmpty(String originsFile) { if (originsFile.isEmpty()) { throw new ConfigurationException("empty [services.registry.factory.config.originsFile] config value for factory class FileBackedBackendServicesRegistry.Factory"); } else { return originsFile; } } }
private static StyxConfig styxConfig(Builder builder) { return new StyxConfig(new MapBackedConfiguration() .set("proxy", proxyServerConfig(builder)) .set("admin", adminServerConfig(builder))); }
default <X> X as(Class<X> type) throws ConversionException { throw new ConversionException("Cannot convert self to " + type); }
/** * Return the value associated with the setting, or default value if no value is associated. * * @param setting a setting * @param defaultValue default value * @param <T> setting value type * @return the value associated with the setting */ public static <T> T valueOf(Setting<T> setting, T defaultValue) { return setting.value().orElse(defaultValue); }
@Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) { Configuration.Context context = configurationContextResolver.resolve(request); chain.context().add("config.context", context); return chain.proceed(request); } }
/** * Returns the value to which the specified key is mapped, converted to String * or {@code Optional.absent} if this configuration source contains no mapping for the key. * * @param key the key whose associated value is to be returned * @return the value to which the specified key is mapped, or * {@code Optional.absent} if this map contains no mapping for the key */ default Optional<String> get(String key) { return get(key, String.class); }
@Override public Registry<BackendService> create(Environment environment, Configuration registryConfiguration) { BackendService service = registryConfiguration.get("backendService", BackendService.class) .orElseThrow(() -> new ConfigurationException( "missing [services.registry.factory.config.backendService] config value for factory class TestBackendProvider.Factory")); return new TestBackendProvider(service); } }
/** * Create an instance of the product. * * @param environment environment * @param serviceConfiguration configuration specific to the factory product * @param objects objects that service might depend on * @return product instance */ default E create(Environment environment, Configuration serviceConfiguration, ActiveOrigins objects) { return create(environment, serviceConfiguration); } }
default <X> X as(Class<X> type) throws ConversionException { throw new ConversionException("Cannot convert self to " + type); }
@Override public <T> Optional<T> get(String key, Class<T> tClass) { return configuration.get(key, tClass); }
private Optional<PluginsMetadata> readPluginsConfig() { return configuration.get("plugins", PluginsMetadata.class); }
@Override public LoadBalancerFactory get() { return configurations.get(LOAD_BALANCING_STRATEGY_KEY) .map(this::newFactoryInstance) .orElseGet(this::busyConnectionBalancer); }
@Override public RetryPolicy create(Environment environment, Configuration retryPolicyConfiguration) { int retriesCount = retryPolicyConfiguration.get("count", Integer.class) .orElse(1); return new RetryNTimes(retriesCount); } }