Search in sources :

Example 1 with HystrixCollapserProperties

use of com.netflix.hystrix.HystrixCollapserProperties in project Hystrix by Netflix.

the class HystrixPropertiesFactory method getCollapserProperties.

/**
 * Get an instance of {@link HystrixCollapserProperties} with the given factory {@link HystrixPropertiesStrategy} implementation for each {@link HystrixCollapserKey} instance.
 *
 * @param key
 *            Pass-thru to {@link HystrixPropertiesStrategy#getCollapserProperties} implementation.
 * @param builder
 *            Pass-thru to {@link HystrixPropertiesStrategy#getCollapserProperties} implementation.
 * @return {@link HystrixCollapserProperties} instance
 */
public static HystrixCollapserProperties getCollapserProperties(HystrixCollapserKey key, HystrixCollapserProperties.Setter builder) {
    HystrixPropertiesStrategy hystrixPropertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
    String cacheKey = hystrixPropertiesStrategy.getCollapserPropertiesCacheKey(key, builder);
    if (cacheKey != null) {
        HystrixCollapserProperties properties = collapserProperties.get(cacheKey);
        if (properties != null) {
            return properties;
        } else {
            if (builder == null) {
                builder = HystrixCollapserProperties.Setter();
            }
            // create new instance
            properties = hystrixPropertiesStrategy.getCollapserProperties(key, builder);
            // cache and return
            HystrixCollapserProperties existing = collapserProperties.putIfAbsent(cacheKey, properties);
            if (existing == null) {
                return properties;
            } else {
                return existing;
            }
        }
    } else {
        // no cacheKey so we generate it with caching
        return hystrixPropertiesStrategy.getCollapserProperties(key, builder);
    }
}
Also used : HystrixCollapserProperties(com.netflix.hystrix.HystrixCollapserProperties)

Aggregations

HystrixCollapserProperties (com.netflix.hystrix.HystrixCollapserProperties)1