Java Code Examples for org.springframework.retry.RetryContext#getLastThrowable()
The following examples show how to use
org.springframework.retry.RetryContext#getLastThrowable() .
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: LoadBalancedRecoveryCallback.java From spring-cloud-commons with Apache License 2.0 | 6 votes |
@Override public T recover(RetryContext context) throws Exception { Throwable lastThrowable = context.getLastThrowable(); if (lastThrowable != null) { if (lastThrowable instanceof RetryableStatusCodeException) { RetryableStatusCodeException ex = (RetryableStatusCodeException) lastThrowable; return createResponse((R) ex.getResponse(), ex.getUri()); } else if (lastThrowable instanceof Exception) { throw (Exception) lastThrowable; } } throw new RetryException("Could not recover", lastThrowable); }
Example 2
Source File: ApiExceptionRetryPolicy.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public boolean canRetry(RetryContext context) { Throwable lastThrowable = context.getLastThrowable(); if (lastThrowable == null) { return true; } if (lastThrowable instanceof ApiException) { if (context.getRetryCount() <= maxAttempts) { int code = ((ApiException) lastThrowable).getCode(); if (code != 0) { HttpStatus httpStatus = HttpStatus.valueOf(code); boolean httpStatus5xxServerError = httpStatus.is5xxServerError(); LOGGER.warn("{} Exception occurred during CM API call, retryable: {} ({}/{})", code, httpStatus5xxServerError, context.getRetryCount(), maxAttempts); return httpStatus5xxServerError; } } else { return false; } } return false; }
Example 3
Source File: JerseyClientRetryPolicy.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public boolean canRetry(RetryContext context) { Throwable lastThrowable = context.getLastThrowable(); if (lastThrowable == null) { return true; } else { LOGGER.debug(String.format("Retry attempt %s. %s", context.getRetryCount(), context.getLastThrowable())); if (lastThrowable instanceof WebApplicationException) { WebApplicationException wae = (WebApplicationException) lastThrowable; Response.StatusType statusInfo = wae.getResponse().getStatusInfo(); if (statusInfo.getFamily() == Response.Status.Family.CLIENT_ERROR) { return false; } else if (statusInfo.getStatusCode() == Response.Status.BAD_REQUEST.getStatusCode()) { return false; } } } return context.getRetryCount() <= RETRY_LIMIT; }
Example 4
Source File: SqlRetryPolicy.java From spring-cloud-aws with Apache License 2.0 | 3 votes |
/** * Returns if this method is retryable based on the {@link RetryContext}. If there is * no Throwable registered, then this method returns <code>true</code> without * checking any further conditions. If there is a Throwable registered, this class * checks if the registered Throwable is a retryable Exception in the context of SQL * exception. If not successful, this class also checks the cause if there is a nested * retryable exception available. * <p> * Before checking exception this class checks that the current retry count (fetched * through {@link org.springframework.retry.RetryContext#getRetryCount()} is smaller * or equals to the {@link #maxNumberOfRetries} * </p> * @param context - the retry context holding information about the retryable * operation (number of retries, throwable if any) * @return <code>true</code> if there is no throwable registered, if there is a * retryable exception and the number of maximum numbers of retries have not been * reached. */ @Override public boolean canRetry(RetryContext context) { Throwable candidate = context.getLastThrowable(); if (candidate == null) { return true; } return context.getRetryCount() <= this.maxNumberOfRetries && isRetryAbleException(candidate); }
Example 5
Source File: DatabaseInstanceStatusRetryPolicy.java From spring-cloud-aws with Apache License 2.0 | 2 votes |
/** * Implementation that checks if there is an exception registered through * {@link #registerThrowable(org.springframework.retry.RetryContext, Throwable)}. * Returns <code>true</code> if there is no exception registered at all and verifies * the database instance status if there is one registered. * @param context - the retry context which may contain a registered exception * @return <code>true</code> if there is no exception registered or if there is a * retry useful which is verified by the {@link InstanceStatus} enum. */ @Override public boolean canRetry(RetryContext context) { // noinspection ThrowableResultOfMethodCallIgnored return (context.getLastThrowable() == null || isDatabaseAvailable(context)); }