com.netflix.hystrix.HystrixEventType Java Examples

The following examples show how to use com.netflix.hystrix.HystrixEventType. 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: CircutBreakerEventNotifier.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Override
public void markEvent(HystrixEventType eventType, HystrixCommandKey key) {
  String keyName = key.name();
  AtomicBoolean flag = circuitFlag.computeIfAbsent(keyName, k -> new AtomicBoolean());
  switch (eventType) {
    case SHORT_CIRCUITED:
      if (flag.compareAndSet(false, true)) {
        eventBus.post(new CircutBreakerEvent(key, Type.OPEN));
      }
      break;

    case SUCCESS:
      if (flag.compareAndSet(true, false)) {
        eventBus.post(new CircutBreakerEvent(key, Type.CLOSE));
      }
      break;

    default:
      break;
  }
}
 
Example #2
Source File: SofaAsyncHystrixCommand.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
private String getExecutionEventsString() {
    List<HystrixEventType> executionEvents = getExecutionEvents();
    if (executionEvents == null) {
        executionEvents = Collections.emptyList();
    }
    StringBuilder message = new StringBuilder("[");
    for (HystrixEventType executionEvent : executionEvents) {
        message.append(HystrixEventType.class.getSimpleName()).append("#").append(executionEvent.name())
            .append(",");
    }
    for (SofaAsyncHystrixEvent event : events) {
        message.append(SofaAsyncHystrixEvent.class.getSimpleName()).append("#").append(event.name()).append(",");
    }
    if (message.length() > 1) {
        message.deleteCharAt(message.length() - 1);
    }
    return message.append("]").toString();
}
 
Example #3
Source File: CommandWithFallbackViaNetwork.java    From tools-journey with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
    HystrixRequestContext context = HystrixRequestContext.initializeContext();
    try {
        assertEquals(null, new CommandWithFallbackViaNetwork(1).execute());

        HystrixInvokableInfo<?> command1 = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().toArray(new HystrixInvokableInfo<?>[2])[0];
        assertEquals("GetValueCommand", command1.getCommandKey().name());
        assertTrue(command1.getExecutionEvents().contains(HystrixEventType.FAILURE));

        HystrixInvokableInfo<?> command2 = HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().toArray(new HystrixInvokableInfo<?>[2])[1];
        assertEquals("GetValueFallbackCommand", command2.getCommandKey().name());
        assertTrue(command2.getExecutionEvents().contains(HystrixEventType.FAILURE));
    } finally {
        context.shutdown();
    }
}
 
Example #4
Source File: QuickStart.java    From javabase with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #5
Source File: MultiEventNotifierDispatcher.java    From astrix with Apache License 2.0 6 votes vote down vote up
@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 {
        underlying()
                .map(notifier -> {
                    notifier.markCommandExecution(key, isolationStrategy, duration, eventsDuringExecution);
                    return null;
                })
                .orElseGet(() -> {
                    super.markCommandExecution(key, isolationStrategy, duration, eventsDuringExecution);
                    return null;
                });
    }
}
 
Example #6
Source File: MultiEventNotifierDispatcher.java    From astrix with Apache License 2.0 6 votes vote down vote up
@Override
public void markEvent(HystrixEventType eventType, HystrixCommandKey key) {
    if (MultiConfigId.hasMultiSourceId(key)) {
        strategies.get(MultiConfigId.readFrom(key))
                  .markEvent(eventType, MultiConfigId.decode(key));
    }
    else {
        underlying()
                .map(notifier -> {
                    notifier.markEvent(eventType, key);
                    return null;
                })
                .orElseGet(() -> {
                    super.markEvent(eventType, key);
                    return null;
                });
    }
}
 
Example #7
Source File: FailedServiceInvocationLogger.java    From astrix with Apache License 2.0 6 votes vote down vote up
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
	}
}
 
Example #8
Source File: HystrixFaulttoleranceIntegrationTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #9
Source File: FaultToleranceMetricsTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #10
Source File: HystrixObservableCommandFacadeTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #11
Source File: HystrixCommandFacadeTest.java    From astrix with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #12
Source File: FailedServiceInvocationLogger.java    From astrix with Apache License 2.0 5 votes vote down vote up
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
		}
	};
}
 
Example #13
Source File: EventNotifierDispatcher.java    From astrix with Apache License 2.0 5 votes vote down vote up
@Override
public void markCommandExecution(HystrixCommandKey key, 
								 ExecutionIsolationStrategy isolationStrategy, 
								 int duration,
								 List<HystrixEventType> eventsDuringExecution) {
	strategymapping.getHystrixStrategies(key)
				   .getHystrixEventNotifier()
				   .markCommandExecution(key, isolationStrategy, duration, eventsDuringExecution);
}
 
Example #14
Source File: TestCircutBreakerEventNotifier.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testMarkEvent() {
  Mockito.when(commandKey.name()).thenReturn("Consumer.springmvc.springmvcHello.sayHi");
  new Expectations(HystrixCommandMetrics.class) {
    {
      HystrixCommandMetrics.getInstance(commandKey);
      result = null;
    }
  };
  circutBreakerEventNotifier.markEvent(HystrixEventType.SHORT_CIRCUITED, commandKey);
  Assert.assertEquals(1, taskList.size());
  circutBreakerEventNotifier.markEvent(HystrixEventType.SUCCESS, commandKey);
  Assert.assertEquals(2, taskList.size());
}
 
Example #15
Source File: FailedServiceInvocationLogger.java    From astrix with Apache License 2.0 4 votes vote down vote up
private void logEvent(HystrixEventType eventType, HystrixCommandKey commandKey) {
	getBeanInvocationLogger(commandKey).orElse(createNonBeanInvocationCommandLogger(commandKey))
									   .accept(eventType);
}
 
Example #16
Source File: FailedServiceInvocationLogger.java    From astrix with Apache License 2.0 4 votes vote down vote up
@Override
public void markEvent(HystrixEventType eventType, HystrixCommandKey key) {
	logEvent(eventType, key);
}
 
Example #17
Source File: FailedServiceInvocationLogger.java    From astrix with Apache License 2.0 4 votes vote down vote up
private Optional<Consumer<HystrixEventType>> getBeanInvocationLogger(HystrixCommandKey commandKey) {
	return beanMapping.getBeanKey(commandKey)
					  .map(beanKey -> getOrCreateBeanInvocationLogger(commandKey, beanKey));
}
 
Example #18
Source File: FailedServiceInvocationLogger.java    From astrix with Apache License 2.0 4 votes vote down vote up
private Consumer<HystrixEventType> getOrCreateBeanInvocationLogger(HystrixCommandKey commandKey,
		AstrixBeanKey<?> beanKey) {
	return beanLoggerByBeanKey.computeIfAbsent(beanKey, k -> createLogger(commandKey, beanKey));
}
 
Example #19
Source File: FailedServiceInvocationLogger.java    From astrix with Apache License 2.0 4 votes vote down vote up
@Override
public void accept(HystrixEventType t) {
	logEvent(t);
}
 
Example #20
Source File: EventNotifierDispatcher.java    From astrix with Apache License 2.0 4 votes vote down vote up
@Override
public void markEvent(HystrixEventType eventType, HystrixCommandKey key) {
	strategymapping.getHystrixStrategies(key)
	   			   .getHystrixEventNotifier()
	   			   .markEvent(eventType, key);
}
 
Example #21
Source File: FailedServiceInvocationLogger.java    From astrix with Apache License 2.0 4 votes vote down vote up
private void logTimeoutRequest(HystrixEventType eventType) {
	log.info(String.format("Aborted command execution: cause=%s astrixBean=%s hystrixCommandKey=%s TIMEOUT=%s [ms]", 
			eventType, beanKey, hystrixCommandKey.name(), 
			beanConfiguration.get(AstrixBeanSettings.TIMEOUT).get()));
}
 
Example #22
Source File: FailedServiceInvocationLogger.java    From astrix with Apache License 2.0 4 votes vote down vote up
private void logThreadPoolRejectedRequest(HystrixEventType eventType) {
	log.info(String.format("Aborted command execution: cause=%s astrixBean=%s hystrixCommandKey=%s CORE_SIZE=%s QUEUE_SIZE_REJECTION_THRESHOLD=%s", 
			eventType, beanKey, hystrixCommandKey.name(), 
			beanConfiguration.get(AstrixBeanSettings.CORE_SIZE).get(), beanConfiguration.get(AstrixBeanSettings.QUEUE_SIZE_REJECTION_THRESHOLD).get()));
}
 
Example #23
Source File: FailedServiceInvocationLogger.java    From astrix with Apache License 2.0 4 votes vote down vote up
private void logSemaphoreRejectedRequest(HystrixEventType eventType) {
	log.info(String.format("Aborted command execution: cause=%s astrixBean=%s hystrixCommandKey=%s MAX_CONCURRENT_REQUESTS=%s", 
			eventType, beanKey, hystrixCommandKey.name(), 
			beanConfiguration.get(AstrixBeanSettings.MAX_CONCURRENT_REQUESTS).get()));
}
 
Example #24
Source File: HystrixKafkaCircuitBreaker.java    From nakadi with MIT License 4 votes vote down vote up
public void markFailure() {
    concurrentExecutionCount.decrementAndGet();
    HystrixThreadEventStream.getInstance()
            .executionDone(ExecutionResult.from(HystrixEventType.FAILURE), commandKey, threadPoolKey);
    circuitBreaker.markNonSuccess();
}
 
Example #25
Source File: HystrixKafkaCircuitBreaker.java    From nakadi with MIT License 4 votes vote down vote up
public void markSuccessfully() {
    concurrentExecutionCount.decrementAndGet();
    HystrixThreadEventStream.getInstance()
            .executionDone(ExecutionResult.from(HystrixEventType.SUCCESS), commandKey, threadPoolKey);
    circuitBreaker.markSuccess();
}