@Override public void start() throws IOException { transactionMaintenanceTask = taskExecutor.scheduleWithFixedDelay(() -> { int originalSize = transactions.size(); logger.trace("Transaction maintenance task started."); try { Set<String> transactionIds = transactions.keySet().stream().collect(Collectors.toSet()); transactionIds.stream().filter(tid -> !isTransactionActive(tid)) .forEach(tid -> cancelTransaction(tid)); } catch (Exception e) { // Swallow exception so that this thread can keep working. logger.error("An exception occurred while maintaining transactions", e); } logger.debug("Transaction maintenance task finished. originalSize={}, currentSize={}", originalSize, transactions.size()); }, 0, transactionTtlSec / 2, TimeUnit.SECONDS); }
private Response cancelTransaction(String transactionId, TransactionResultEntity entity) { transactionManager.cancelTransaction(transactionId); entity.setMessage("Transaction has been canceled."); entity.setResponseCode(ResponseCode.CANCEL_TRANSACTION.getCode()); return Response.ok(entity).build(); }
transactionManager.cancelTransaction(transactionId); return responseCreator.handshakeExceptionResponse(e); transactionManager.cancelTransaction(transactionId); return responseCreator.unexpectedErrorResponse(portId, e);
@Override public void start() throws IOException { transactionMaintenanceTask = taskExecutor.scheduleWithFixedDelay(() -> { int originalSize = transactions.size(); logger.trace("Transaction maintenance task started."); try { Set<String> transactionIds = transactions.keySet().stream().collect(Collectors.toSet()); transactionIds.stream().filter(tid -> !isTransactionActive(tid)) .forEach(tid -> cancelTransaction(tid)); } catch (Exception e) { // Swallow exception so that this thread can keep working. logger.error("An exception occurred while maintaining transactions", e); } logger.debug("Transaction maintenance task finished. originalSize={}, currentSize={}", originalSize, transactions.size()); }, 0, transactionTtlSec / 2, TimeUnit.SECONDS); }