Search in sources :

Example 1 with Setter

use of com.netflix.hystrix.HystrixCommand.Setter in project feign by OpenFeign.

the class HystrixInvocationHandler method toSetters.

/**
   * Process all methods in the target so that appropriate setters are created.
   */
static Map<Method, Setter> toSetters(SetterFactory setterFactory, Target<?> target, Set<Method> methods) {
    Map<Method, Setter> result = new LinkedHashMap<Method, Setter>();
    for (Method method : methods) {
        method.setAccessible(true);
        result.put(method, setterFactory.create(target, method));
    }
    return result;
}
Also used : Setter(com.netflix.hystrix.HystrixCommand.Setter) Method(java.lang.reflect.Method) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with Setter

use of com.netflix.hystrix.HystrixCommand.Setter in project wildfly-swarm by wildfly-swarm.

the class HystrixCommandInterceptor method initSetter.

private Setter initSetter(HystrixCommandKey commandKey, Method method, FaultToleranceOperation operation) {
    HystrixCommandProperties.Setter propertiesSetter = HystrixCommandProperties.Setter();
    // Async and timeout operations use THREAD isolation strategy
    if (operation.isAsync() || operation.hasTimeout()) {
        propertiesSetter.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD);
    } else {
        propertiesSetter.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE);
    }
    if (nonFallBackEnable && operation.hasTimeout()) {
        Long value = Duration.of(operation.getTimeout().get(TimeoutConfig.VALUE), operation.getTimeout().get(TimeoutConfig.UNIT)).toMillis();
        if (value > Integer.MAX_VALUE) {
            LOGGER.warnf("Max supported value for @Timeout.value() is %s", Integer.MAX_VALUE);
            value = Long.valueOf(Integer.MAX_VALUE);
        }
        propertiesSetter.withExecutionTimeoutInMilliseconds(value.intValue());
        propertiesSetter.withExecutionIsolationThreadInterruptOnTimeout(true);
    } else {
        propertiesSetter.withExecutionTimeoutEnabled(false);
    }
    if (nonFallBackEnable && operation.hasCircuitBreaker()) {
        propertiesSetter.withCircuitBreakerEnabled(true).withCircuitBreakerRequestVolumeThreshold(operation.getCircuitBreaker().get(CircuitBreakerConfig.REQUEST_VOLUME_THRESHOLD)).withCircuitBreakerErrorThresholdPercentage(new Double((Double) operation.getCircuitBreaker().get(CircuitBreakerConfig.FAILURE_RATIO) * 100).intValue()).withCircuitBreakerSleepWindowInMilliseconds((int) Duration.of(operation.getCircuitBreaker().get(CircuitBreakerConfig.DELAY), operation.getCircuitBreaker().get(CircuitBreakerConfig.DELAY_UNIT)).toMillis());
    } else {
        propertiesSetter.withCircuitBreakerEnabled(false);
    }
    Setter setter = Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("DefaultCommandGroup")).andCommandKey(commandKey).andCommandPropertiesDefaults(propertiesSetter);
    if (nonFallBackEnable && operation.hasBulkhead()) {
        BulkheadConfig bulkhead = operation.getBulkhead();
        if (operation.isAsync()) {
            // Each bulkhead policy needs a dedicated thread pool
            setter.andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(commandKey.name()));
            HystrixThreadPoolProperties.Setter threadPoolSetter = HystrixThreadPoolProperties.Setter();
            threadPoolSetter.withAllowMaximumSizeToDivergeFromCoreSize(true);
            threadPoolSetter.withCoreSize(bulkhead.get(BulkheadConfig.VALUE));
            threadPoolSetter.withMaximumSize(bulkhead.get(BulkheadConfig.VALUE));
            threadPoolSetter.withMaxQueueSize(bulkhead.get(BulkheadConfig.WAITING_TASK_QUEUE));
            threadPoolSetter.withQueueSizeRejectionThreshold(bulkhead.get(BulkheadConfig.WAITING_TASK_QUEUE));
            setter.andThreadPoolPropertiesDefaults(threadPoolSetter);
        } else {
            // If used without @Asynchronous, the semaphore isolation approach must be used
            propertiesSetter.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE);
            propertiesSetter.withExecutionIsolationSemaphoreMaxConcurrentRequests(bulkhead.get(BulkheadConfig.VALUE));
            propertiesSetter.withExecutionIsolationThreadInterruptOnFutureCancel(true);
        }
    }
    return setter;
}
Also used : HystrixCommandProperties(com.netflix.hystrix.HystrixCommandProperties) BulkheadConfig(org.wildfly.swarm.microprofile.faulttolerance.deployment.config.BulkheadConfig) Setter(com.netflix.hystrix.HystrixCommand.Setter) HystrixThreadPoolProperties(com.netflix.hystrix.HystrixThreadPoolProperties)

Aggregations

Setter (com.netflix.hystrix.HystrixCommand.Setter)2 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)1 HystrixThreadPoolProperties (com.netflix.hystrix.HystrixThreadPoolProperties)1 Method (java.lang.reflect.Method)1 LinkedHashMap (java.util.LinkedHashMap)1 BulkheadConfig (org.wildfly.swarm.microprofile.faulttolerance.deployment.config.BulkheadConfig)1