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));
});
}
Aggregations