当前位置: 首页>>代码示例>>Java>>正文


Java HystrixRuntimeException.getCause方法代码示例

本文整理汇总了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;
        }
    }

}
 
开发者ID:Nike-Inc,项目名称:cerberus-management-service,代码行数:24,代码来源:HystrixVaultAdminClient.java

示例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;
    }
}
 
开发者ID:yammer,项目名称:tenacity,代码行数:18,代码来源:TenacityExceptionMapper.java

示例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;
}
 
开发者ID:xiaomin0322,项目名称:spring-integration-hystrix,代码行数:14,代码来源:HystrixCommandAspect.java

示例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);
}
 
开发者ID:xiaomin0322,项目名称:spring-integration-hystrix,代码行数:29,代码来源:HystrixCommandAspect.java

示例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());
	}
}
 
开发者ID:phoenixnap,项目名称:springmvc-raml-plugin-sample,代码行数:13,代码来源:TestDrinksClient.java

示例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());
}
 
开发者ID:Cantara,项目名称:Java-Auto-Update,代码行数:28,代码来源:RegisterClientExceptionHandler.java

示例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;
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:75,代码来源:HystrixCommandInterceptor.java


注:本文中的com.netflix.hystrix.exception.HystrixRuntimeException.getCause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。