software.amazon.awssdk.core.exception.AbortedException Java Examples
The following examples show how to use
software.amazon.awssdk.core.exception.AbortedException.
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: TimeoutExceptionHandlingStage.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
private Exception handleTimeoutCausedException(RequestExecutionContext context, Exception e) { if (e instanceof SdkInterruptedException) { ((SdkInterruptedException) e).getResponseStream().ifPresent(r -> invokeSafely(r::close)); } if (isCausedByApiCallTimeout(context)) { return new InterruptedException(); } if (isCausedByApiCallAttemptTimeout(context)) { // Clear the interrupt status Thread.interrupted(); return generateApiCallAttemptTimeoutException(context); } if (e instanceof InterruptedException) { Thread.currentThread().interrupt(); return AbortedException.create("Thread was interrupted", e); } return e; }
Example #2
Source File: ApiCallAttemptTimeoutTrackingStage.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * Determine if an interrupted exception is caused by the api call timeout task * interrupting the current thread or some other task interrupting the thread for another * purpose. * * @return {@link ApiCallTimeoutException} if the {@link InterruptedException} was * caused by the {@link SyncTimeoutTask}. Otherwise re-interrupts the current thread * and returns a {@link AbortedException} wrapping an {@link InterruptedException} */ private RuntimeException handleInterruptedException(RequestExecutionContext context, InterruptedException e) { if (e instanceof SdkInterruptedException) { ((SdkInterruptedException) e).getResponseStream().ifPresent(r -> invokeSafely(r::close)); } if (context.apiCallAttemptTimeoutTracker().hasExecuted()) { // Clear the interrupt status Thread.interrupted(); return generateApiCallAttemptTimeoutException(context); } Thread.currentThread().interrupt(); return AbortedException.create("Thread was interrupted", e); }
Example #3
Source File: CloudWatchMetricsFactory.java From amazon-kinesis-client with Apache License 2.0 | 5 votes |
public void shutdown() { runnable.shutdown(); try { publicationThread.join(); } catch (InterruptedException e) { throw AbortedException.builder().message(e.getMessage()).cause(e).build(); } }
Example #4
Source File: InterruptFlagAlwaysClearsTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private void executeRequestIgnoreErrors(SdkSyncClientHandler syncHttpClient) { try { syncHttpClient.execute(new ClientExecutionParams<SdkRequest, SdkResponse>() .withOperationName("SomeOperation") .withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler) .withInput(NoopTestRequest.builder().build()) .withMarshaller(marshaller)); Assert.fail(); } catch (AbortedException | ApiCallAttemptTimeoutException | SdkServiceException e) { // Ignored } }
Example #5
Source File: SdkInputStream.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * Aborts with subclass specific abortion logic executed if needed. * Note the interrupted status of the thread is cleared by this method. * @throws AbortedException if found necessary. */ protected final void abortIfNeeded() { if (Thread.currentThread().isInterrupted()) { try { abort(); // execute subclass specific abortion logic } catch (IOException e) { LoggerFactory.getLogger(getClass()).debug("FYI", e); } throw AbortedException.builder().build(); } }
Example #6
Source File: SdkFilterInputStream.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * Aborts with subclass specific abortion logic executed if needed. * Note the interrupted status of the thread is cleared by this method. * * @throws AbortedException if found necessary. */ protected final void abortIfNeeded() { if (Thread.currentThread().isInterrupted()) { abort(); // execute subclass specific abortion logic throw AbortedException.builder().build(); } }
Example #7
Source File: ThrowableUtils.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * Same as {@link #failure(Throwable)}, but the given errmsg will be used if * it was wrapped as either an {@link SdkClientException} or * {@link AbortedException}. */ public static RuntimeException failure(Throwable t, String errmsg) { if (t instanceof RuntimeException) { return (RuntimeException) t; } if (t instanceof Error) { throw (Error) t; } return t instanceof InterruptedException ? AbortedException.builder().message(errmsg).cause(t).build() : SdkClientException.builder().message(errmsg).cause(t).build(); }
Example #8
Source File: ThrowableUtils.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * Used to help perform common throw-up with minimal wrapping. */ public static RuntimeException failure(Throwable t) { if (t instanceof RuntimeException) { return (RuntimeException) t; } if (t instanceof Error) { throw (Error) t; } return t instanceof InterruptedException ? AbortedException.builder().cause(t).build() : SdkClientException.builder().cause(t).build(); }
Example #9
Source File: ApiCallTimeoutTrackingStage.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
/** * Determine if an interrupted exception is caused by the api call timeout task * interrupting the current thread or some other task interrupting the thread for another * purpose. * * @return {@link ApiCallTimeoutException} if the {@link InterruptedException} was * caused by the {@link SyncTimeoutTask}. Otherwise re-interrupts the current thread * and returns a {@link AbortedException} wrapping an {@link InterruptedException} */ private RuntimeException handleInterruptedException(RequestExecutionContext context, InterruptedException e) { if (e instanceof SdkInterruptedException) { ((SdkInterruptedException) e).getResponseStream().ifPresent(r -> invokeSafely(r::close)); } if (context.apiCallTimeoutTracker().hasExecuted()) { // Clear the interrupt status Thread.interrupted(); return generateApiCallTimeoutException(context); } Thread.currentThread().interrupt(); return AbortedException.create("Thread was interrupted", e); }
Example #10
Source File: CloudWatchMeterRegistry.java From micrometer with Apache License 2.0 | 5 votes |
void sendMetricData(List<MetricDatum> metricData) throws InterruptedException { PutMetricDataRequest putMetricDataRequest = PutMetricDataRequest.builder() .namespace(config.namespace()) .metricData(metricData) .build(); CountDownLatch latch = new CountDownLatch(1); cloudWatchAsyncClient.putMetricData(putMetricDataRequest).whenCompleteAsync((response, t) -> { if (t != null) { if (t instanceof AbortedException) { logger.warn("sending metric data was aborted: {}", t.getMessage()); } else { logger.error("error sending metric data.", t); } } else { logger.debug("published metric with namespace:{}", putMetricDataRequest.namespace()); } latch.countDown(); }); try { @SuppressWarnings("deprecation") long readTimeoutMillis = config.readTimeout().toMillis(); latch.await(readTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { logger.warn("metrics push to cloudwatch took longer than expected"); throw e; } }
Example #11
Source File: AbortedExceptionClientExecutionTimerIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Test(expected = AbortedException.class) public void clientExecutionTimeoutEnabled_aborted_exception_occurs_timeout_not_expired() throws Exception { when(abortableCallable.call()).thenThrow(AbortedException.builder().build()); execute(httpClient, createMockGetRequest().build()); }
Example #12
Source File: SyncClientHandlerTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Test public void responseTransformerThrowsAbortedException_shouldPropagate() throws Exception { verifyResponseTransformerPropagateException(AbortedException.create("")); }
Example #13
Source File: TimeoutExceptionHandlingStageTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Test public void AbortedException_notCausedByTimeouts_shouldPropagate() throws Exception { when(requestPipeline.execute(any(), any())).thenThrow(AbortedException.create("")); verifyExceptionThrown(AbortedException.class); }
Example #14
Source File: TimeoutExceptionHandlingStageTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Test public void AbortedException_causedByAttemptTimeout_shouldThrowApiCallAttemptTimeoutException() throws Exception { when(apiCallAttemptTimeoutTask.hasExecuted()).thenReturn(true); when(requestPipeline.execute(any(), any())).thenThrow(AbortedException.create("")); verifyExceptionThrown(ApiCallAttemptTimeoutException.class); }
Example #15
Source File: TimeoutExceptionHandlingStageTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Test public void AbortedException_causedByCallTimeout_shouldThrowInterruptedException() throws Exception { when(apiCallTimeoutTask.hasExecuted()).thenReturn(true); when(requestPipeline.execute(any(), any())).thenThrow(AbortedException.create("")); verifyExceptionThrown(InterruptedException.class); }
Example #16
Source File: TimeoutExceptionHandlingStageTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Test public void interruptedException_notCausedByTimeouts_shouldPreserveInterruptFlag() throws Exception { when(requestPipeline.execute(any(), any())).thenThrow(new InterruptedException()); verifyExceptionThrown(AbortedException.class); verifyInterruptStatusPreserved(); }
Example #17
Source File: ApiCallTimeoutTrackingStageTest.java From aws-sdk-java-v2 with Apache License 2.0 | 4 votes |
@Test(expected = AbortedException.class) public void nonTimerInterruption_InterruptedExceptionThrown_interruptFlagIsPreserved() throws Exception { nonTimerInterruption_interruptFlagIsPreserved(new InterruptedException()); }
Example #18
Source File: TimeoutExceptionHandlingStage.java From aws-sdk-java-v2 with Apache License 2.0 | 3 votes |
/** * Take the given exception thrown from the wrapped pipeline and return a more appropriate * timeout related exception based on its type and the the execution status. * * @param context The execution context. * @param e The exception thrown from the inner pipeline. * @return The translated exception. */ private Exception translatePipelineException(RequestExecutionContext context, Exception e) { if (e instanceof InterruptedException || e instanceof IOException || e instanceof AbortedException || Thread.currentThread().isInterrupted()) { return handleTimeoutCausedException(context, e); } return e; }