Source:
private int deleteRecords(DeleteAction deleteAction) throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException, InterruptedException, ParseException, CQLException { final DeleteAction transformDeleteAction = transformDeleteAction(deleteAction); QueryRequest queryRequest = queryFactory.getQuery( transformDeleteAction.getConstraint(), transformDeleteAction.getTypeName()); queryRequest = queryFactory.updateQueryRequestTags( queryRequest, schemaTransformerManager.getTransformerSchemaForId( transformDeleteAction.getTypeName())); int batchCount = 1; int deletedCount = 0; String[] idsToDelete = getNextQueryBatch(queryRequest); CompletionService<DeleteResponse> deleteCompletionService = new ExecutorCompletionService<>(queryExecutor); while (idsToDelete.length > 0) { LOGGER.debug( "Attempting to delete metacards from batch {}.", idsToDelete.length, ++batchCount); final Subject subject = SecurityUtils.getSubject(); for (final String id : idsToDelete) { Callable<DeleteResponse> callable = () -> { try { DeleteRequestImpl deleteRequest = new DeleteRequestImpl(id); return framework.delete(deleteRequest); } catch (IngestException | SourceUnavailableException | CatalogQueryException e) { LOGGER.debug("Unable to delete record: {}", id, e); throw new CswException( "Unable to delete record(s).", CswConstants.TRANSACTION_FAILED, transformDeleteAction.getHandle()); } }; Callable<DeleteResponse> deleteCallable = subject.associateWith(callable); deleteCompletionService.submit(deleteCallable); } for (int i = 0; i < idsToDelete.length; i++) { try { Future<DeleteResponse> completedFuture = deleteCompletionService.take(); try { deletedCount += completedFuture.get().getDeletedMetacards().size(); } catch (ExecutionException | CancellationException e) { LOGGER.debug("Error deleting Metacard", e); throw new CswException( "Unable to delete record(s).", CswConstants.TRANSACTION_FAILED, deleteAction.getHandle()); } } catch (InterruptedException e) { LOGGER.debug("Metacard delete interrupted", e); Thread.currentThread().interrupt(); } } idsToDelete = getNextQueryBatch(queryRequest); } return deletedCount; }

Target:
private int deleteRecords(DeleteAction deleteAction) throws CswException, UnsupportedQueryException { final DeleteAction transformDeleteAction = transformDeleteAction(deleteAction); QueryRequest queryRequest = queryFactory.getQuery( transformDeleteAction.getConstraint(), transformDeleteAction.getTypeName()); queryRequest = queryFactory.updateQueryRequestTags( queryRequest, schemaTransformerManager.getTransformerSchemaForId( transformDeleteAction.getTypeName())); int batchCount = 1; int deletedCount = 0; String[] idsToDelete = getNextQueryBatch(queryRequest); CompletionService<DeleteResponse> deleteCompletionService = new ExecutorCompletionService<>(queryExecutor); while (idsToDelete.length > 0) { LOGGER.debug( "Attempting to delete metacards from batch {}.", idsToDelete.length, ++batchCount); final Subject subject = SecurityUtils.getSubject(); for (final String id : idsToDelete) { Callable<DeleteResponse> callable = () -> { try { DeleteRequestImpl deleteRequest = new DeleteRequestImpl(id); return framework.delete(deleteRequest); } catch (IngestException | SourceUnavailableException | CatalogQueryException e) { LOGGER.debug("Unable to delete record: {}", id, e); throw new CswException( "Unable to delete record(s).", CswConstants.TRANSACTION_FAILED, transformDeleteAction.getHandle()); } }; Callable<DeleteResponse> deleteCallable = subject.associateWith(callable); deleteCompletionService.submit(deleteCallable); } for (int i = 0; i < idsToDelete.length; i++) { try { Future<DeleteResponse> completedFuture = deleteCompletionService.take(); try { deletedCount += completedFuture.get().getDeletedMetacards().size(); } catch (ExecutionException | CancellationException e) { LOGGER.debug("Error deleting Metacard", e); throw new CswException( "Unable to delete record(s).", CswConstants.TRANSACTION_FAILED, deleteAction.getHandle()); } } catch (InterruptedException e) { LOGGER.debug("Metacard delete interrupted", e); Thread.currentThread().interrupt(); break; } } idsToDelete = getNextQueryBatch(queryRequest); } return deletedCount; }