/** * Call join an unwrap any {@link CompletionException}, expecting the exception to be a {@link RuntimeException}. * @param future The future to join on. * @param <T> The type of result the future will return. * @return The result returned by the future. * @throws RuntimeException If the future fails. */ public static <T> T unwrappedExceptionJoin(CompletableFuture<T> future) { try { return future.join(); } catch (CompletionException e) { throw Throwables.expectRuntimeException( e.getCause() ); } }
throw wrap( Throwables.combine( throwable, otherThrowable ) ); } ) );
@Override public CompletableFuture<BulkResult> execute(ElasticsearchWorkExecutionContext context) { return Futures.create( () -> context.getClient().submit( request ) ) .thenApply( this::generateResult ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchRequestFailed( request, null, Throwables.expectException( throwable ) ); } ) ); }
throw log.unableToInstantiateClass( classToLoad, Throwables.getFirstNonNullMessage( e ), e ); componentDescription, classToLoad, Throwables.getFirstNonNullMessage( e ), e );
throw log.unableToInstantiateClass( classToLoad, Throwables.getFirstNonNullMessage( e ), e ); componentDescription, classToLoad, Throwables.getFirstNonNullMessage( e ), e );
private <T> T execute(ElasticsearchWork<T> work) { try { return Futures.unwrappedExceptionJoin( orchestrator.submit( work ) ); } catch (CompletionException e) { throw Throwables.expectRuntimeException( e ); } } }
@Override public CompletableFuture<BulkResult> execute(ElasticsearchWorkExecutionContext context) { return Futures.create( () -> context.getClient().submit( request ) ) .thenApply( this::generateResult ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchRequestFailed( request, null, Throwables.expectException( throwable ) ); } ) ); }
componentDescription, classToLoad, Throwables.getFirstNonNullMessage( e ), e );
private <T> T execute(ElasticsearchWork<T> work) { try { return Futures.unwrappedExceptionJoin( orchestrator.submit( work ) ); } catch (CompletionException e) { throw Throwables.expectRuntimeException( e ); } } }
@Override public final CompletableFuture<R> execute(ElasticsearchWorkExecutionContext executionContext) { return Futures.create( () -> beforeExecute( executionContext, request ) ) .thenCompose( ignored -> executionContext.getClient().submit( request ) ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchRequestFailed( request, null, Throwables.expectException( throwable ) ); } ) ) .thenCompose( response -> handleResult( executionContext, response ) ); }
componentDescription, classToLoad, Throwables.getFirstNonNullMessage( e ), e );
@Override public final CompletableFuture<R> execute(ElasticsearchWorkExecutionContext executionContext) { return Futures.create( () -> beforeExecute( executionContext, request ) ) .thenCompose( ignored -> executionContext.getClient().submit( request ) ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchRequestFailed( request, null, Throwables.expectException( throwable ) ); } ) ) .thenCompose( response -> handleResult( executionContext, response ) ); }
private CompletableFuture<R> handleResult(ElasticsearchWorkExecutionContext executionContext, ElasticsearchResponse response) { R result; try { resultAssessor.checkSuccess( response ); result = generateResult( executionContext, response ); if ( markIndexDirty ) { executionContext.registerIndexToRefresh( dirtiedIndexName ); } } catch (RuntimeException e) { throw log.elasticsearchRequestFailed( request, response, e ); } return afterSuccess( executionContext ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchRequestFailed( request, response, Throwables.expectException( throwable ) ); } ) ) .thenApply( ignored -> result ); }
private CompletableFuture<R> handleResult(ElasticsearchWorkExecutionContext executionContext, ElasticsearchResponse response) { R result; try { resultAssessor.checkSuccess( response ); result = generateResult( executionContext, response ); if ( markIndexDirty ) { executionContext.registerIndexToRefresh( dirtiedIndexName ); } } catch (RuntimeException e) { throw log.elasticsearchRequestFailed( request, response, e ); } return afterSuccess( executionContext ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchRequestFailed( request, response, Throwables.expectException( throwable ) ); } ) ) .thenApply( ignored -> result ); }
private CompletableFuture<R> handleResult(ElasticsearchWorkExecutionContext executionContext, JsonObject bulkResponseItem) { R result; try { resultAssessor.checkSuccess( bulkResponseItem ); result = generateResult( executionContext, bulkResponseItem ); if ( markIndexDirty ) { executionContext.registerIndexToRefresh( dirtiedIndexName ); } } catch (RuntimeException e) { throw log.elasticsearchBulkedRequestFailed( getBulkableActionMetadata(), bulkResponseItem, e ); } return afterSuccess( executionContext ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchBulkedRequestFailed( getBulkableActionMetadata(), bulkResponseItem, Throwables.expectException( throwable ) ); } ) ) .thenApply( ignored -> result ); }
private CompletableFuture<R> handleResult(ElasticsearchWorkExecutionContext executionContext, JsonObject bulkResponseItem) { R result; try { resultAssessor.checkSuccess( bulkResponseItem ); result = generateResult( executionContext, bulkResponseItem ); if ( markIndexDirty ) { executionContext.registerIndexToRefresh( dirtiedIndexName ); } } catch (RuntimeException e) { throw log.elasticsearchBulkedRequestFailed( getBulkableActionMetadata(), bulkResponseItem, e ); } return afterSuccess( executionContext ) .exceptionally( Futures.handler( throwable -> { throw log.elasticsearchBulkedRequestFailed( getBulkableActionMetadata(), bulkResponseItem, Throwables.expectException( throwable ) ); } ) ) .thenApply( ignored -> result ); }