本文整理汇总了Java中com.netflix.hystrix.HystrixCommand.Setter类的典型用法代码示例。如果您正苦于以下问题:Java Setter类的具体用法?Java Setter怎么用?Java Setter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Setter类属于com.netflix.hystrix.HystrixCommand包,在下文中一共展示了Setter类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ManagedHystrixCommandFactory
import com.netflix.hystrix.HystrixCommand.Setter; //导入依赖的package包/类
/**
* Creates a new ManagedHystrixCommandFactory
* @param setter the command setter
* @param key The command key
* @param commandPropertySetter the command property setter
* @param threadPoolPropertySetter the thread pool property setter
*/
public ManagedHystrixCommandFactory(final Setter setter, final String key, final HystrixCommandProperties.Setter commandPropertySetter, final HystrixThreadPoolProperties.Setter threadPoolPropertySetter) {
this.setter = setter;
this.key = key;
this.commandPropertySetter = commandPropertySetter;
this.threadPoolPropertySetter = threadPoolPropertySetter;
final HystrixCommand<Object> sampleCommand = new HystrixCommand<Object>(setter) {
@Override
protected Object run() throws Exception {
return null;
}
};
ObjectName tmp = null;
try {
tmp = JMXHelper.objectName(String.format(OBJECT_NAME_TEMPLATE, sampleCommand.getCommandGroup().name(), sampleCommand.getCommandKey().name(), sampleCommand.getThreadPoolKey().name()));
} catch (Exception ex) {
tmp = JMXHelper.objectName(String.format(OBJECT_NAME_TEMPLATE,
ObjectName.quote(sampleCommand.getCommandGroup().name()),
ObjectName.quote(sampleCommand.getCommandKey().name()),
ObjectName.quote(sampleCommand.getThreadPoolKey().name())
));
}
objectName = tmp;
}
示例2: toSetters
import com.netflix.hystrix.HystrixCommand.Setter; //导入依赖的package包/类
/**
* 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;
}
示例3: defaultSetter
import com.netflix.hystrix.HystrixCommand.Setter; //导入依赖的package包/类
private static Setter defaultSetter(AmazonS3 s3) {
return Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("s3"))
.andCommandKey(HystrixCommandKey.Factory.asKey(s3.getRegionName()))
.andCommandPropertiesDefaults(
HystrixCommandProperties.defaultSetter()
.withCircuitBreakerRequestVolumeThreshold(5)
.withExecutionTimeoutEnabled(false))
.andThreadPoolPropertiesDefaults(
HystrixThreadPoolProperties.defaultSetter()
.withMaxQueueSize(5)
.withQueueSizeRejectionThreshold(5));
}
示例4: getAsHystrixCommand
import com.netflix.hystrix.HystrixCommand.Setter; //导入依赖的package包/类
@Override
public HystrixCommand<String> getAsHystrixCommand() {
Setter hystrixMetadata = HystrixCommand.Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey("FallbackUnknownApi"));
return new HystrixCommand<String>(hystrixMetadata) {
@Override
protected String run() throws Exception {
return "this is BadApi (command) fallback!";
}
};
}
示例5: create
import com.netflix.hystrix.HystrixCommand.Setter; //导入依赖的package包/类
public Setter create(String groupName, String commandName) {
HystrixCommandProperties.Setter properties =
HystrixCommandProperties.Setter().withExecutionTimeoutEnabled(false);
return Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupName))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandName))
.andCommandPropertiesDefaults(properties);
}
示例6: HystrixS3Decorator
import com.netflix.hystrix.HystrixCommand.Setter; //导入依赖的package包/类
private HystrixS3Decorator(AmazonS3 delegate, Setter setter) {
this.delegate = checkNotNull(delegate, "delegate");
this.setter = checkNotNull(setter, "setter");
}
示例7: decorate
import com.netflix.hystrix.HystrixCommand.Setter; //导入依赖的package包/类
public static HystrixS3Decorator decorate(AmazonS3 s3, Setter setter) {
return new HystrixS3Decorator(s3, setter);
}
示例8: S3Command
import com.netflix.hystrix.HystrixCommand.Setter; //导入依赖的package包/类
private S3Command(Setter setter, Supplier<T> callable) {
super(setter);
this.callable = callable;
}
示例9: HystrixCommandEndpointCallExecutableFactory
import com.netflix.hystrix.HystrixCommand.Setter; //导入依赖的package包/类
public HystrixCommandEndpointCallExecutableFactory(Setter hystrixMetadata) {
super(hystrixMetadata);
}
示例10: initSetter
import com.netflix.hystrix.HystrixCommand.Setter; //导入依赖的package包/类
private Setter initSetter(HystrixCommandKey commandKey, Method method, FaultToleranceOperation operation) {
HystrixCommandProperties.Setter propertiesSetter = HystrixCommandProperties.Setter();
if (operation.isAsync()) {
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());
} 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"))
// Each method must have a unique command key
.andCommandKey(commandKey).andCommandPropertiesDefaults(propertiesSetter);
if (nonFallBackEnable && operation.hasBulkhead()) {
// TODO: these options need further review
BulkheadConfig bulkhead = operation.getBulkhead();
propertiesSetter.withExecutionIsolationSemaphoreMaxConcurrentRequests(bulkhead.get(BulkheadConfig.VALUE));
propertiesSetter.withExecutionIsolationThreadInterruptOnFutureCancel(true);
// 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);
}
return setter;
}
示例11: MethodInfo
import com.netflix.hystrix.HystrixCommand.Setter; //导入依赖的package包/类
public MethodInfo(final Method method,
final RestAdapterConfig restAdapterConfig) {
// GET HTTP ANNOTATION
http = Arrays
.stream(method.getAnnotations())
.filter(a -> Http.class.equals(a.annotationType()))
.map(a -> (Http) a)
.findFirst()
.orElseThrow(
() -> new IllegalStateException(
"No Http annotation present."));
cookiesAnnotation = Arrays.stream(method.getAnnotations())
.filter(a -> Cookies.class.equals(a.annotationType()))
.map(a -> (Cookies) a).findFirst();
responseType = Arrays.stream(method.getAnnotations())
.filter(a -> ResponseType.class.equals(a.annotationType()))
.map(a -> (ResponseType) a).findFirst();
// GET HYSTRIX ANNOTATION
hystrix = Arrays
.stream(method.getAnnotations())
.filter(a -> HystrixGroup.class.equals(a.annotationType()))
.map(a -> (HystrixGroup) a)
.findFirst()
.orElseThrow(
() -> new IllegalStateException(
"No Hystrix annotation present."));
cacheKeyGroup = Arrays.stream(method.getAnnotations())
.filter(a -> CacheKeyGroup.class.equals(a.annotationType()))
.map(a -> a == null ? null : ((CacheKeyGroup) a).value())
.findFirst().orElse(null);
this.setter = Setter.withGroupKey(
HystrixCommandGroupKey.Factory.asKey(hystrix.groupKey()))
.andCommandKey(
HystrixCommandKey.Factory.asKey(hystrix.commandKey()));
this.parameters = method.getParameters();
this.headers = Arrays.stream(http.headers()).collect(
Collectors.toMap(t -> t.name(), t -> t.value()));
if (headers.containsKey("Cookie")) {
cookies.add(this.headers.remove("Cookie"));
}
if (cookiesAnnotation.isPresent()) {
cookies.addAll(Arrays.stream(cookiesAnnotation.get().cookies())
.map(cookie -> cookie.name() + "=" + cookie.value())
.collect(Collectors.toList()));
}
@SuppressWarnings("rawtypes")
final Class returnType = method.getReturnType();
@SuppressWarnings("rawtypes")
final Class httpClass;
if (responseType.isPresent()) {
httpClass = responseType.get().responseClass();
} else {
httpClass = null;
}
this.isObservable = Observable.class.equals(returnType);
if (this.isObservable) {
this.responseClass = Optional.ofNullable(httpClass).orElseThrow(
() -> new IllegalStateException(
"Http responseClass is required for observables"));
} else {
this.responseClass = Optional.ofNullable(httpClass).orElse(
returnType);
}
this.restAdapterConfig = restAdapterConfig;
}
示例12: HystrixCommandFacade
import com.netflix.hystrix.HystrixCommand.Setter; //导入依赖的package包/类
private HystrixCommandFacade(CheckedCommand<T> command, Setter hystrixConfiguration) {
this.command = command;
this.hystrixConfiguration = hystrixConfiguration;
}
示例13: execute
import com.netflix.hystrix.HystrixCommand.Setter; //导入依赖的package包/类
public static <T> T execute(CheckedCommand<T> command, Setter settings) throws Throwable {
return new HystrixCommandFacade<>(command, settings).execute();
}
示例14: getSetter
import com.netflix.hystrix.HystrixCommand.Setter; //导入依赖的package包/类
public Setter getSetter() {
return setter;
}