Search in sources :

Example 1 with RetryPolicyFactory

use of com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicyFactory in project styx by ExpediaGroup.

the class ServiceProvision method loadRetryPolicy.

/**
 * Create factory configured with a particular key, then uses the factory's create method
 * to create its product.
 *
 * @param <E>           service type
 * @param configuration Styx configuration
 * @param key           Factory configuration attribute
 * @param serviceClass  Service class
 * @return service, if such a configuration key exists
 */
public static <E extends RetryPolicy> Optional<E> loadRetryPolicy(Configuration configuration, Environment environment, String key, Class<? extends E> serviceClass) {
    return configuration.get(key, ServiceFactoryConfig.class).map(factoryConfig -> {
        RetryPolicyFactory factory = newInstance(factoryConfig.factory(), RetryPolicyFactory.class);
        JsonNodeConfig config = factoryConfig.config();
        return serviceClass.cast(factory.create(environment, config));
    });
}
Also used : ServiceFactoryConfig(com.hotels.styx.spi.config.ServiceFactoryConfig) JsonNodeConfig(com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig) RetryPolicyFactory(com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicyFactory)

Aggregations

RetryPolicyFactory (com.hotels.styx.api.extension.retrypolicy.spi.RetryPolicyFactory)1 JsonNodeConfig (com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig)1 ServiceFactoryConfig (com.hotels.styx.spi.config.ServiceFactoryConfig)1