本文整理汇总了Java中com.netflix.hystrix.exception.HystrixRuntimeException.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java HystrixRuntimeException.getCause方法的具体用法?Java HystrixRuntimeException.getCause怎么用?Java HystrixRuntimeException.getCause使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.netflix.hystrix.exception.HystrixRuntimeException
的用法示例。
在下文中一共展示了HystrixRuntimeException.getCause方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入方法依赖的package包/类
/**
* Execute a function that returns a value
*/
private static <T> T execute(String commandKey, Supplier<T> function) {
try {
return new HystrixCommand<T>(buildSetter(commandKey)) {
@Override
protected T run() {
return function.get();
}
}.execute();
} catch (HystrixRuntimeException e) {
LOGGER.error("commandKey:" + commandKey);
if (e.getCause() instanceof RuntimeException) {
// Convert back to the underlying exception type
throw (RuntimeException) e.getCause();
} else {
throw e;
}
}
}
示例2: isTenacityException
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入方法依赖的package包/类
public static boolean isTenacityException(HystrixRuntimeException exception) {
switch (exception.getFailureType()) {
case TIMEOUT:
case SHORTCIRCUIT:
case REJECTED_THREAD_EXECUTION:
case REJECTED_SEMAPHORE_EXECUTION:
case REJECTED_SEMAPHORE_FALLBACK:
return true;
case COMMAND_EXCEPTION:
//TODO: Remove this and set to false by default
//SocketTimeoutExceptions should be fixed by the application if they are being thrown within the context
//of a TenacityCommand
return exception.getCause() instanceof SocketTimeoutException;
default:
return false;
}
}
示例3: handleException
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入方法依赖的package包/类
private Object handleException(HystrixRuntimeException e, ProceedingJoinPoint joinPoint,
com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand cb) throws Throwable {
if (cb.fallbackMethod().length() > 0) {
return executeFallback(e, joinPoint, cb);
}
if (e.getCause() instanceof TimeoutException) {
throw new CircuitBreakerTimeoutException();
}
if (e.getCause() != null) {
throw e.getCause();
}
throw e;
}
示例4: executeFallback
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入方法依赖的package包/类
private Object executeFallback(HystrixRuntimeException e, ProceedingJoinPoint joinPoint,
com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand cb)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Method method = getMethod(joinPoint);
Class<?> clazz = method.getDeclaringClass();
String name = cb.fallbackMethod();
Class<?> params[] = method.getParameterTypes();
Object[] args = joinPoint.getArgs();
Method m = ReflectionUtils.findMethod(clazz, name, params);
if (m == null) {
Class<?>[] temp = params;
params = new Class<?>[params.length + 1];
System.arraycopy(temp, 0, params, 0, temp.length);
params[params.length - 1] = Throwable.class;
Object[] tempArgs = args;
args = new Object[tempArgs.length + 1];
System.arraycopy(tempArgs, 0, args, 0, tempArgs.length);
args[args.length - 1] = e.getCause() == null ? e : e.getCause();
m = ReflectionUtils.findMethod(clazz, name, params);
}
if (m == null) {
throw new CircuitBreakerFallbackMethodMissing(clazz, name, params);
}
return m.invoke(joinPoint.getTarget(), args);
}
示例5: getDrinkByIdIntegrationTest_Fail_NotFound
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入方法依赖的package包/类
@Test
public void getDrinkByIdIntegrationTest_Fail_NotFound() throws Exception {
try {
drinkClient.getDrinkById("sprite");
Assert.fail("The item should not be available! Are the server and client working properly?!");
} catch (HttpClientErrorException hce) {
Assert.assertEquals(HttpStatus.NOT_FOUND, hce.getStatusCode());
} catch (HystrixRuntimeException hre) {
FeignException cause = (FeignException) hre.getCause();
Assert.assertEquals(HttpStatus.NOT_FOUND.value(), cause.status());
}
}
示例6: handleRegisterClientException
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入方法依赖的package包/类
public static void handleRegisterClientException(HystrixRuntimeException e, BackOff exponentialBackOff,
BackOffExecution backOffExecution, String configServiceUrl) {
Throwable cause = e.getCause();
log.debug("Exception registering client, exception getMessage={}", e.getMessage());
log.debug("Exception registering client, cause getMessage={}", cause.getMessage());
if (cause instanceof ConnectException) {
log.debug("Connection refused to ConfigService url={}", configServiceUrl);
} else if (cause instanceof InternalServerErrorException) {
log.debug("Internal server error in ConfigService url={}", configServiceUrl);
} else if(cause instanceof NotFoundException) {
log.debug("404 not found to ConfigService url={}", configServiceUrl);
} else if (cause instanceof BadRequestException) {
log.error("400 Bad Request. Probably need to fix something on the client. Exiting after a" +
" wait, so as to not DDoS the server.");
// TODO Do a sensible BackOff implementation class comparissmnet before this!!!
SleepUtil.sleepWithLogging(((ExponentialBackOff)exponentialBackOff).getMaxInterval() * 2);
System.exit(1);
} else if (cause instanceof TimeoutException) {
log.debug("CommandRegisterClient timed out.");
} else {
log.error("Couldn't handle exception: {}", e);
}
SleepUtil.sleepWithLogging(backOffExecution.nextBackOff());
}
示例7: interceptCommand
import com.netflix.hystrix.exception.HystrixRuntimeException; //导入方法依赖的package包/类
@AroundInvoke
public Object interceptCommand(InvocationContext ic) throws Exception {
Method method = ic.getMethod();
ExecutionContextWithInvocationContext ctx = new ExecutionContextWithInvocationContext(ic);
boolean shouldRunCommand = true;
Object res = null;
LOGGER.tracef("FT operation intercepted: %s", method);
CommandMetadata metadata = commandMetadataMap.computeIfAbsent(method, CommandMetadata::new);
RetryContext retryContext = nonFallBackEnable && metadata.operation.hasRetry() ? new RetryContext(metadata.operation.getRetry()) : null;
SynchronousCircuitBreaker syncCircuitBreaker = null;
while (shouldRunCommand) {
shouldRunCommand = false;
if (nonFallBackEnable && syncCircuitBreakerEnabled && metadata.hasCircuitBreaker()) {
syncCircuitBreaker = getSynchronousCircuitBreaker(metadata.commandKey, metadata.operation.getCircuitBreaker());
}
DefaultCommand command = new DefaultCommand(metadata.setter, ctx, metadata.getFallback(ctx), retryContext, metadata.hasCircuitBreaker());
try {
if (metadata.operation.isAsync()) {
LOGGER.debugf("Queue up command for async execution: %s", metadata.operation);
res = new AsyncFuture(command.queue());
} else {
LOGGER.debugf("Sync execution: %s]", metadata.operation);
res = command.execute();
}
if (syncCircuitBreaker != null) {
syncCircuitBreaker.executionSucceeded();
}
} catch (HystrixRuntimeException e) {
if (syncCircuitBreaker != null) {
syncCircuitBreaker.executionFailed();
}
HystrixRuntimeException.FailureType failureType = e.getFailureType();
LOGGER.tracef("Hystrix runtime failure [%s] when invoking %s", failureType, method);
switch (failureType) {
case TIMEOUT:
TimeoutException timeoutException = new TimeoutException(e);
if (retryContext != null && retryContext.shouldRetry()) {
shouldRunCommand = shouldRetry(retryContext, timeoutException);
if (shouldRunCommand) {
continue;
}
}
throw timeoutException;
case SHORTCIRCUIT:
throw new CircuitBreakerOpenException(method.getName());
case REJECTED_THREAD_EXECUTION:
case REJECTED_SEMAPHORE_EXECUTION:
case REJECTED_SEMAPHORE_FALLBACK:
BulkheadException bulkheadException = new BulkheadException(e);
if (retryContext != null && retryContext.shouldRetry()) {
shouldRunCommand = shouldRetry(retryContext, bulkheadException);
if (shouldRunCommand) {
continue;
}
}
throw bulkheadException;
case COMMAND_EXCEPTION:
if (retryContext != null && retryContext.shouldRetry()) {
shouldRunCommand = shouldRetry(retryContext, e);
continue;
}
default:
throw (e.getCause() instanceof Exception) ? (Exception) e.getCause() : e;
}
}
}
return res;
}