static ExceptionClassifier mergeExceptionClassifiers(Iterable<? extends ExceptionClassifier> classifiers) { List<ExceptionClassifier> exceptionClassifiers = ImmutableList.copyOf(requireNonNull(classifiers, "classifiers is null")); return throwable -> exceptionClassifiers.stream() .map(classifier -> classifier.classifyException(throwable)) .collect(mergeExceptionClassifications()); }
static ExceptionClassifier mergeExceptionClassifiers(Iterable<? extends ExceptionClassifier> classifiers) { List<ExceptionClassifier> exceptionClassifiers = ImmutableList.copyOf(requireNonNull(classifiers, "classifiers is null")); return throwable -> exceptionClassifiers.stream() .map(classifier -> classifier.classifyException(throwable)) .collect(mergeExceptionClassifications()); }
public ExceptionClassification classifyException(Throwable throwable, boolean idempotent) { if (throwable instanceof ConnectionFailedException) { return new ExceptionClassification(Optional.of(TRUE), DOWN); } if (idempotent && throwable instanceof RequestTimeoutException) { // We don't know if the server is overloaded, or if this specific // request just takes to long, so just mark the server as normal. return new ExceptionClassification(Optional.of(TRUE), NORMAL); } if (throwable instanceof MessageTooLargeException) { return new ExceptionClassification(Optional.of(FALSE), NORMAL); } // interrupted exceptions are always an immediate failure if (throwable instanceof InterruptedException || throwable instanceof InterruptedIOException) { return new ExceptionClassification(Optional.of(FALSE), NORMAL); } // allow classifier to return a hard result ExceptionClassification result = exceptionClassifier.classifyException(unwrapUserException(throwable)); if (result.isRetry().isPresent()) { return result; } if (idempotent && throwable instanceof TTransportException) { // We don't know if there is a problem with this server or if this // is a general network error, so just mark the server as normal. return new ExceptionClassification(Optional.of(TRUE), NORMAL); } return result; }
public ExceptionClassification classifyException(Throwable throwable, boolean idempotent) { if (throwable instanceof ConnectionFailedException) { return new ExceptionClassification(Optional.of(TRUE), DOWN); } if (idempotent && throwable instanceof RequestTimeoutException) { // We don't know if the server is overloaded, or if this specific // request just takes to long, so just mark the server as normal. return new ExceptionClassification(Optional.of(TRUE), NORMAL); } if (throwable instanceof MessageTooLargeException) { return new ExceptionClassification(Optional.of(FALSE), NORMAL); } // interrupted exceptions are always an immediate failure if (throwable instanceof InterruptedException || throwable instanceof InterruptedIOException) { return new ExceptionClassification(Optional.of(FALSE), NORMAL); } // allow classifier to return a hard result ExceptionClassification result = exceptionClassifier.classifyException(unwrapUserException(throwable)); if (result.isRetry().isPresent()) { return result; } if (idempotent && throwable instanceof TTransportException) { // We don't know if there is a problem with this server or if this // is a general network error, so just mark the server as normal. return new ExceptionClassification(Optional.of(TRUE), NORMAL); } return result; }