Java源码示例:com.netflix.hystrix.HystrixCommand.Setter

示例1
private HystrixCommand<Object> wrapHystrixCommand(final ProceedingJoinPoint point) {
	
	String className = point.getTarget().getClass().getSimpleName();
	String methodName = point.getSignature().getName();
	Setter setter = configHystrixCommand(className, methodName);
	
	return new HystrixCommand<Object>(setter) {
		
		@Override
		protected Object run() throws Exception {
			try {
				return point.proceed();
			} catch (Throwable throwable) {
				throw (Exception) throwable;
			}
		}
		
		@Override
		protected Object getFallback() {
			return null;
		}
	};
}
 
示例2
private HystrixCommand<Object> wrapHystrixCommand(final ProceedingJoinPoint point) {
	
	String className = point.getTarget().getClass().getSimpleName();
	String methodName = point.getSignature().getName();
	Setter setter = configHystrixCommand(className, methodName);
	
	return new HystrixCommand<Object>(setter) {
		
		@Override
		protected Object run() throws Exception {
			try {
				return point.proceed();
			} catch (Throwable throwable) {
				logger.error("micro service throw exception, {}", throwable.getMessage());
				throw (Exception) throwable;
			}
		}
		
		@Override
		protected Object getFallback() {
			logger.warn("micro service does not work normally...");
			return null;
		}
	};
}
 
示例3
/**
 * 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;
}
 
示例4
private HystrixCommand.Setter configHystrixCommand(String className, String methodName) {
	return HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(className + "Group"))
			.andCommandKey(HystrixCommandKey.Factory.asKey(className + "." + methodName))
			.andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(className + "ThreadPool"))
			.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
			.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD))
			.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(10));
}
 
示例5
private HystrixCommand.Setter configHystrixCommand(String className, String methodName) {
	return HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(className + "Group"))
			.andCommandKey(HystrixCommandKey.Factory.asKey(className + "." + methodName))
			.andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(className + "ThreadPool"))
			.andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD))
			.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(10));
}
 
示例6
/**
 * 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;
}
 
示例7
private HystrixCommandFacade(CheckedCommand<T> command, Setter hystrixConfiguration, ContextPropagation contextPropagation) {
	this.command = command;
	this.hystrixConfiguration = hystrixConfiguration;
	this.contextPropagation = Objects.requireNonNull(contextPropagation);
}
 
示例8
/**
 * @deprecated please use {@link #execute(CheckedCommand, Setter, ContextPropagation)}
 */
@Deprecated
public static <T> T execute(CheckedCommand<T> command, Setter settings) throws Throwable {
	return execute(command, settings, ContextPropagation.NONE);
}
 
示例9
public static <T> T execute(CheckedCommand<T> command, Setter settings, ContextPropagation contextPropagation) throws Throwable {
	return new HystrixCommandFacade<>(command, settings, contextPropagation).execute();
}