Java Code Examples for com.netflix.hystrix.HystrixObservableCommand#Setter

The following examples show how to use com.netflix.hystrix.HystrixObservableCommand#Setter . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReactiveHystrixCircuitBreaker.java    From spring-cloud-circuitbreaker-demo with Apache License 2.0 6 votes vote down vote up
private <T> HystrixObservableCommand<T> createCommand(Publisher<T> toRun, Function fallback) {
	HystrixObservableCommand.Setter setter = HystrixObservableCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(id))
			.andCommandPropertiesDefaults(commandPropertiesSetter);
	HystrixObservableCommand<T> command = new HystrixObservableCommand<T>(setter) {
		@Override
		protected Observable<T> construct() {
			return RxReactiveStreams.toObservable(toRun);
		}

		@Override
		protected Observable<T> resumeWithFallback() {
			if(fallback == null) {
				super.resumeWithFallback();
			}
			return RxReactiveStreams.toObservable((Publisher)fallback.apply(this.getExecutionException()));
		}
	};
	return command;
}
 
Example 2
Source File: HttpResourceObservableCommand.java    From ribbon with Apache License 2.0 6 votes vote down vote up
public HttpResourceObservableCommand(HttpClient<ByteBuf, ByteBuf> httpClient,
                                     HttpClientRequest<ByteBuf> httpRequest, String hystrixCacheKey,
                                     Map<String, Object> requestProperties,
                                     FallbackHandler<T> fallbackHandler,
                                     ResponseValidator<HttpClientResponse<ByteBuf>> validator,
                                     Class<? extends T> classType,
                                     HystrixObservableCommand.Setter setter) {
    super(setter);
    this.httpClient = httpClient;
    this.fallbackHandler = fallbackHandler;
    this.validator = validator;
    this.httpRequest = httpRequest;
    this.hystrixCacheKey = hystrixCacheKey;
    this.classType = classType;
    this.requestProperties = requestProperties;
}
 
Example 3
Source File: HystrixBuilder.java    From soul with Apache License 2.0 5 votes vote down vote up
/**
 * this is build HystrixObservableCommand.Setter.
 *
 * @param hystrixHandle {@linkplain HystrixHandle}
 * @return {@linkplain HystrixObservableCommand.Setter}
 */
public static HystrixObservableCommand.Setter build(final HystrixHandle hystrixHandle) {
    if (hystrixHandle.getMaxConcurrentRequests() == 0) {
        hystrixHandle.setMaxConcurrentRequests(Constants.MAX_CONCURRENT_REQUESTS);
    }
    if (hystrixHandle.getErrorThresholdPercentage() == 0) {
        hystrixHandle.setErrorThresholdPercentage(Constants.ERROR_THRESHOLD_PERCENTAGE);
    }
    if (hystrixHandle.getRequestVolumeThreshold() == 0) {
        hystrixHandle.setRequestVolumeThreshold(Constants.REQUEST_VOLUME_THRESHOLD);
    }
    if (hystrixHandle.getSleepWindowInMilliseconds() == 0) {
        hystrixHandle.setSleepWindowInMilliseconds(Constants.SLEEP_WINDOW_INMILLISECONDS);
    }
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey(hystrixHandle.getGroupKey());
    HystrixCommandKey commandKey = HystrixCommandKey.Factory.asKey(hystrixHandle.getCommandKey());
    final HystrixCommandProperties.Setter propertiesSetter =
            HystrixCommandProperties.Setter()
                    .withExecutionTimeoutInMilliseconds((int) hystrixHandle.getTimeout())
                    .withCircuitBreakerEnabled(true)
                    .withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE)
                    .withExecutionIsolationSemaphoreMaxConcurrentRequests(hystrixHandle.getMaxConcurrentRequests())
                    .withCircuitBreakerErrorThresholdPercentage(hystrixHandle.getErrorThresholdPercentage())
                    .withCircuitBreakerRequestVolumeThreshold(hystrixHandle.getRequestVolumeThreshold())
                    .withCircuitBreakerSleepWindowInMilliseconds(hystrixHandle.getSleepWindowInMilliseconds());
    return HystrixObservableCommand.Setter
            .withGroupKey(groupKey)
            .andCommandKey(commandKey)
            .andCommandPropertiesDefaults(propertiesSetter);
}
 
Example 4
Source File: CloudReactiveFeign.java    From feign-reactive with Apache License 2.0 5 votes vote down vote up
@Override
public HystrixObservableCommand.Setter create(Target<?> target, MethodMetadata methodMetadata) {
    String groupKey = target.name();
    String commandKey = methodMetadata.configKey();
    return HystrixObservableCommand.Setter
            .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
            .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
}
 
Example 5
Source File: HystrixBuilder.java    From bird-java with MIT License 5 votes vote down vote up
/**
 * this is build HystrixObservableCommand.Setter.
 *
 * @param hystrixHandle {@linkplain HystrixHandle}
 * @return {@linkplain HystrixObservableCommand.Setter}
 */
public static HystrixObservableCommand.Setter build(final HystrixHandle hystrixHandle) {

    if (hystrixHandle.getMaxConcurrentRequests() == 0) {
        hystrixHandle.setMaxConcurrentRequests(GatewayConstant.MAX_CONCURRENT_REQUESTS);
    }
    if (hystrixHandle.getErrorThresholdPercentage() == 0) {
        hystrixHandle.setErrorThresholdPercentage(GatewayConstant.ERROR_THRESHOLD_PERCENTAGE);
    }
    if (hystrixHandle.getRequestVolumeThreshold() == 0) {
        hystrixHandle.setRequestVolumeThreshold(GatewayConstant.REQUEST_VOLUME_THRESHOLD);
    }
    if (hystrixHandle.getSleepWindowInMilliseconds() == 0) {
        hystrixHandle.setSleepWindowInMilliseconds(GatewayConstant.SLEEP_WINDOW_INMILLISECONDS);
    }

    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey(hystrixHandle.getGroupKey());

    HystrixCommandKey commandKey = HystrixCommandKey.Factory.asKey(hystrixHandle.getCommandKey());

    final HystrixCommandProperties.Setter propertiesSetter =
            HystrixCommandProperties.Setter()
                    .withExecutionTimeoutInMilliseconds(hystrixHandle.getTimeout())
                    .withCircuitBreakerEnabled(true)
                    .withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE)
                    .withExecutionIsolationSemaphoreMaxConcurrentRequests(hystrixHandle.getMaxConcurrentRequests())
                    .withCircuitBreakerErrorThresholdPercentage(hystrixHandle.getErrorThresholdPercentage())
                    .withCircuitBreakerRequestVolumeThreshold(hystrixHandle.getRequestVolumeThreshold())
                    .withCircuitBreakerSleepWindowInMilliseconds(hystrixHandle.getSleepWindowInMilliseconds());

    return HystrixObservableCommand.Setter
            .withGroupKey(groupKey)
            .andCommandKey(commandKey)
            .andCommandPropertiesDefaults(propertiesSetter);
}
 
Example 6
Source File: BizkeeperCommand.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
protected BizkeeperCommand(String type, Invocation invocation, HystrixObservableCommand.Setter setter) {
  super(setter);
  this.type = type;
  this.invocation = invocation;
}
 
Example 7
Source File: HttpRequestTemplate.java    From ribbon with Apache License 2.0 4 votes vote down vote up
protected HttpRequestTemplate(String name, HttpResourceGroup group, Class<? extends T> classType, HystrixObservableCommand.Setter setter,
                    HttpMethod method, HttpHeaders headers, ParsedTemplate uriTemplate,
                    FallbackHandler<T> fallbackHandler, ResponseValidator<HttpClientResponse<ByteBuf>> validator, CacheProviderWithKeyTemplate<T> cacheProvider,
                    ParsedTemplate hystrixCacheKeyTemplate) {
    this.group = group;
    this.name = name;
    this.classType = classType;
    this.method = method;
    this.parsedUriTemplate = uriTemplate;
    this.fallbackHandler = fallbackHandler;
    this.validator = validator;
    this.cacheProvider = cacheProvider;
    this.hystrixCacheKeyTemplate = hystrixCacheKeyTemplate;
    this.client = group.getClient();
    this.headers = headers;
    if (client instanceof LoadBalancingRxClient) {
        LoadBalancingRxClient ribbonClient = (LoadBalancingRxClient) client;
        maxResponseTime = ribbonClient.getResponseTimeOut();
        concurrentRequestLimit = ribbonClient.getMaxConcurrentRequests();
    } else {
        maxResponseTime = -1;
        concurrentRequestLimit = -1;
    }
    String cacheName = name + CACHE_HYSTRIX_COMMAND_SUFFIX;
    cacheSetter = HystrixObservableCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(cacheName))
            .andCommandKey(HystrixCommandKey.Factory.asKey(cacheName));
    HystrixCommandProperties.Setter cacheCommandProps = HystrixCommandProperties.Setter();
    cacheCommandProps.withExecutionIsolationThreadTimeoutInMilliseconds(DEFAULT_CACHE_TIMEOUT);
    cacheSetter.andCommandPropertiesDefaults(cacheCommandProps);
    if (setter != null) {
        this.setter = setter;
    } else {
        this.setter = HystrixObservableCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(client.name()))
                .andCommandKey(HystrixCommandKey.Factory.asKey(name()));
        HystrixCommandProperties.Setter commandProps = HystrixCommandProperties.Setter();
        if (maxResponseTime > 0) {
            commandProps.withExecutionIsolationThreadTimeoutInMilliseconds(maxResponseTime);
        }
        if (concurrentRequestLimit > 0) {
            commandProps.withExecutionIsolationSemaphoreMaxConcurrentRequests(concurrentRequestLimit);
        }
        this.setter.andCommandPropertiesDefaults(commandProps);
    }
}
 
Example 8
Source File: CloudReactiveFeign.java    From feign-reactive with Apache License 2.0 votes vote down vote up
HystrixObservableCommand.Setter create(Target<?> target, MethodMetadata methodMetadata); 
Example 9
Source File: ResourceGroup.java    From ribbon with Apache License 2.0 votes vote down vote up
public abstract TemplateBuilder withHystrixProperties(HystrixObservableCommand.Setter setter);