本文整理汇总了Java中com.netflix.hystrix.HystrixEventType类的典型用法代码示例。如果您正苦于以下问题:Java HystrixEventType类的具体用法?Java HystrixEventType怎么用?Java HystrixEventType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HystrixEventType类属于com.netflix.hystrix包,在下文中一共展示了HystrixEventType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: commandWithFallbackViaNetworkTest
import com.netflix.hystrix.HystrixEventType; //导入依赖的package包/类
private static void commandWithFallbackViaNetworkTest() {
HystrixRequestContext context = HystrixRequestContext.initializeContext();
try {
log.info(new CommandWithFallbackViaNetwork(1).execute());
HystrixInvokableInfo<?> command1 = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().toArray(new HystrixInvokableInfo<?>[2])[0];
log.info(command1.getCommandKey().name());
log.info(""+command1.getExecutionEvents().contains(HystrixEventType.FAILURE));
HystrixInvokableInfo<?> command2 = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().toArray(new HystrixInvokableInfo<?>[2])[1];
log.info(command2.getCommandKey().name());
log.info(""+command2.getExecutionEvents().contains(HystrixEventType.FAILURE));
} finally {
context.shutdown();
}
}
示例2: BEC
import com.netflix.hystrix.HystrixEventType; //导入依赖的package包/类
@Ignore("This test interferes with other tests using the BEC (they probably use the same HystrixRequestLog)")
@Test
public void whenSending100Queries_TheyAreSentInBatch() {
List<Observable<QueryResponse>> all = new ArrayList<>();
// Increasing the max delay so eveyrthing goes in a single batch
try (BatchExecutorClient loader = loader(MAX_DELAY * 100)) {
int n = 100;
generate(this::query).limit(n).forEach(q ->
all.add(loader.add(q, keyspace, true))
);
int completed = allObservable(all).toBlocking().first().size();
assertEquals(n, completed);
assertEquals(1, HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().size());
HystrixCommand<?> command = HystrixRequestLog.getCurrentRequest()
.getAllExecutedCommands()
.toArray(new HystrixCommand<?>[1])[0];
// assert the command is the one we're expecting
assertEquals("CommandQueries", command.getCommandKey().name());
// confirm that it was a COLLAPSED command execution
assertTrue(command.getExecutionEvents().contains(HystrixEventType.COLLAPSED));
// and that it was successful
assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS));
}
}
示例3: logEvent
import com.netflix.hystrix.HystrixEventType; //导入依赖的package包/类
private void logEvent(HystrixEventType eventType) {
switch (eventType) {
case FAILURE:
log.info(String.format("Aborted command execution: cause=%s astrixBean=%s hystrixCommandKey=%s", eventType, beanKey, hystrixCommandKey.name()));
break;
case SEMAPHORE_REJECTED:
logSemaphoreRejectedRequest(eventType);
break;
case THREAD_POOL_REJECTED:
logThreadPoolRejectedRequest(eventType);
break;
case TIMEOUT:
logTimeoutRequest(eventType);
break;
case SHORT_CIRCUITED:
log.info(String.format("Aborted command execution: cause=%s astrixBean=%s hystrixCommandKey=%s", eventType, beanKey, hystrixCommandKey.name()));
break;
default:
// Do nothing
}
}
示例4: call
import com.netflix.hystrix.HystrixEventType; //导入依赖的package包/类
@Override
public String call() {
List<TpsAndLatencyData> tpsAndLatencyData = HystrixCommandMetrics.getInstances()
.stream()
.map(instance -> new TpsAndLatencyData(instance.getRollingCount(HystrixEventType.SUCCESS),
instance.getRollingCount(HystrixEventType.FAILURE), instance.getExecutionTimeMean(),
instance.getProperties().metricsRollingStatisticalWindowInMilliseconds().get()))
.collect(Collectors.toList());
return calculateTpsAndLatency(tpsAndLatencyData);
}
示例5: getFallback
import com.netflix.hystrix.HystrixEventType; //导入依赖的package包/类
@Override
protected T getFallback() {
failMeter.mark();
final List<HystrixEventType> events = getExecutionEvents();
if (isFailure(events)) {
final Throwable throwable = getFailedExecutionException();
logger.warn("{}", kvp("command_name", commandName,
"fallback_event", "error",
"time_millis", this.getExecutionTimeInMilliseconds(),
"err", "[" + throwable.getMessage() + "]"
), throwable);
}
if (events.contains(HystrixEventType.TIMEOUT)) {
warn(commandName, HystrixEventType.TIMEOUT.name());
}
if (events.contains(HystrixEventType.SHORT_CIRCUITED)) {
warn(commandName, HystrixEventType.SHORT_CIRCUITED.name());
}
if (events.contains(HystrixEventType.BAD_REQUEST)) {
warn(commandName, HystrixEventType.BAD_REQUEST.name());
}
return fallbackAction.get();
}
示例6: testCollapser
import com.netflix.hystrix.HystrixEventType; //导入依赖的package包/类
/**
* 测试合并请求
* @throws Exception
*/
@Test
public void testCollapser() throws Exception {
HystrixRequestContext context = HystrixRequestContext.initializeContext();
try {
Future<String> f1 = new CommandCollapserGetValueForKey(1).queue();
Future<String> f2 = new CommandCollapserGetValueForKey(2).queue();
Future<String> f3 = new CommandCollapserGetValueForKey(3).queue();
Future<String> f4 = new CommandCollapserGetValueForKey(4).queue();
assertEquals("ValueForKey: 1", f1.get());
assertEquals("ValueForKey: 2", f2.get());
assertEquals("ValueForKey: 3", f3.get());
assertEquals("ValueForKey: 4", f4.get());
// assert that the batch command 'GetValueForKey' was in fact
// executed and that it executed only once
assertEquals(1, HystrixRequestLog.getCurrentRequest().getExecutedCommands().size());
HystrixCommand<?> command = HystrixRequestLog.getCurrentRequest().getExecutedCommands().toArray(new HystrixCommand<?>[1])[0];
// assert the command is the one we're expecting
assertEquals("GetValueForKey", command.getCommandKey().name());
// confirm that it was a COLLAPSED command execution
assertTrue(command.getExecutionEvents().contains(HystrixEventType.COLLAPSED));
// and that it was successful
assertTrue(command.getExecutionEvents().contains(HystrixEventType.SUCCESS));
} finally {
context.shutdown();
}
}
示例7: markCommandExecution
import com.netflix.hystrix.HystrixEventType; //导入依赖的package包/类
@Override
public void markCommandExecution(HystrixCommandKey key, ExecutionIsolationStrategy isolationStrategy, int duration,
List<HystrixEventType> eventsDuringExecution) {
if (MultiConfigId.hasMultiSourceId(key)) {
strategies.get(MultiConfigId.readFrom(key))
.markCommandExecution(MultiConfigId.decode(key), isolationStrategy, duration, eventsDuringExecution);
} else {
defaultStrategy.markCommandExecution(key, isolationStrategy, duration, eventsDuringExecution);
}
}
示例8: markEvent
import com.netflix.hystrix.HystrixEventType; //导入依赖的package包/类
@Override
public void markEvent(HystrixEventType eventType, HystrixCommandKey key) {
if (MultiConfigId.hasMultiSourceId(key)) {
strategies.get(MultiConfigId.readFrom(key))
.markEvent(eventType, MultiConfigId.decode(key));
} else {
defaultStrategy.markEvent(eventType, key);
}
}
示例9: markCommandExecution
import com.netflix.hystrix.HystrixEventType; //导入依赖的package包/类
@Override
public void markCommandExecution(HystrixCommandKey key,
ExecutionIsolationStrategy isolationStrategy,
int duration,
List<HystrixEventType> eventsDuringExecution) {
strategymapping.getHystrixStrategies(key)
.getHystrixEventNotifier()
.markCommandExecution(key, isolationStrategy, duration, eventsDuringExecution);
}
示例10: createNonBeanInvocationCommandLogger
import com.netflix.hystrix.HystrixEventType; //导入依赖的package包/类
private Consumer<HystrixEventType> createNonBeanInvocationCommandLogger(HystrixCommandKey key) {
return eventType -> {
switch (eventType) {
case FAILURE:
case SEMAPHORE_REJECTED:
case THREAD_POOL_REJECTED:
case TIMEOUT:
case SHORT_CIRCUITED:
log.info(String.format("Aborted command execution: cause=%s astrixBean=null hystrixCommandKey=%s", eventType, key.name()));
break;
default:
// Do nothing
}
};
}
示例11: initMetrics
import com.netflix.hystrix.HystrixEventType; //导入依赖的package包/类
private void initMetrics(Ping ping) throws InterruptedException {
// Black hystrix magic here :(
try {
ping.ping("foo");
} catch (Exception e) {
}
HystrixFaultToleranceFactory faultTolerance = (HystrixFaultToleranceFactory) AstrixApplicationContext.class.cast(this.context).getInstance(BeanFaultToleranceFactorySpi.class);
HystrixCommandKey key = faultTolerance.getCommandKey(AstrixBeanKey.create(Ping.class));
HystrixCommandMetrics.getInstance(key).getCumulativeCount(HystrixEventType.SUCCESS);
}
示例12: initMetrics
import com.netflix.hystrix.HystrixEventType; //导入依赖的package包/类
private void initMetrics(Ping ping) throws InterruptedException {
// Black hystrix magic here :(
try {
ping.ping();
} catch (Exception e) {
}
HystrixFaultToleranceFactory faultTolerance = (HystrixFaultToleranceFactory) AstrixApplicationContext.class.cast(this.context).getInstance(BeanFaultToleranceFactorySpi.class);
HystrixCommandKey key = faultTolerance.getCommandKey(AstrixBeanKey.create(Ping.class));
HystrixCommandMetrics.getInstance(key).getCumulativeCount(HystrixEventType.SUCCESS);
}
示例13: initMetrics
import com.netflix.hystrix.HystrixEventType; //导入依赖的package包/类
private void initMetrics(Ping ping, AstrixContext context) {
try {
ping.ping("foo");
} catch (Exception e) {
}
HystrixFaultToleranceFactory faultTolerance = (HystrixFaultToleranceFactory) AstrixApplicationContext.class.cast(context).getInstance(BeanFaultToleranceFactorySpi.class);
HystrixCommandKey key = faultTolerance.getCommandKey(AstrixBeanKey.create(Ping.class));
HystrixCommandMetrics.getInstance(key).getCumulativeCount(HystrixEventType.SUCCESS);
}
示例14: getFallback
import com.netflix.hystrix.HystrixEventType; //导入依赖的package包/类
@Override protected R getFallback() {
failMeter.mark();
final List<HystrixEventType> events = getExecutionEvents();
if (isFailure(events)) {
final Throwable throwable = getFailedExecutionException();
if (throwable instanceof ProvisionedThroughputExceededException) {
// todo: figure out how to handle this via fallbackAction and retries
throughputFailMeter.mark();
logger.error("{}",
kvp("command_name", commandName,
"fallback_event", "ProvisionedThroughputExceededException",
"time_millis", this.getExecutionTimeInMilliseconds(),
"err", "[" + throwable.getMessage() + "]"
),
throwable);
} else {
logger.warn("{}",
kvp("command_name", commandName,
"fallback_event", "error",
"time_millis", this.getExecutionTimeInMilliseconds(),
"err", "[" + throwable.getMessage() + "]"
),
throwable);
}
}
if (events.contains(HystrixEventType.TIMEOUT)) {
warn(commandName, HystrixEventType.TIMEOUT.name());
}
if (events.contains(HystrixEventType.SHORT_CIRCUITED)) {
warn(commandName, HystrixEventType.SHORT_CIRCUITED.name());
}
if (events.contains(HystrixEventType.BAD_REQUEST)) {
warn(commandName, HystrixEventType.BAD_REQUEST.name());
}
return fallbackAction.get();
}
示例15: isFailure
import com.netflix.hystrix.HystrixEventType; //导入依赖的package包/类
private boolean isFailure(List<HystrixEventType> eventTypes) {
return eventTypes.contains(HystrixEventType.EXCEPTION_THROWN)
|| eventTypes.contains(HystrixEventType.FAILURE);
}