private void forceCloseOnPendingRequests() { for (MySqlRequest request : requestQueue) { if (request.getRequest().tryCancel()) { request.getFuture().trySetException(new DbSessionClosedException("Connection is closed")); } } }
@Override public DbSessionFuture<Void> rollback() { if (!isInTransaction()) { throw new DbException("No transaction has been started to rollback"); } checkClosed(); synchronized (lock) { final MySqlRequest request = queRequest(MySqlRequests.rollbackTransaction(this)); isInTransaction = false; return (DbSessionFuture<Void>) request.getFuture(); } }
public MySqlRequest dequeRequest() { synchronized (lock) { final MySqlRequest request = requestQueue.poll(); if (logger.isDebugEnabled()) { logger.debug("Dequeued request: {}", request); } if (request.getRequest().wasCancelled()) { if (logger.isDebugEnabled()) { logger.debug("Request has been cancelled: {}", request); } return dequeRequest(); } return request; } }
public MySqlRequest forceQueRequest(MySqlRequest request) { synchronized (lock) { requestQueue.add(request); channel.write(request.getRequest()); return request; } }
@Override public DbFuture<Void> close(CloseMode closeMode) throws DbException { synchronized (lock) { if (null == closeFuture) { final MySqlRequest closeRequest = MySqlRequests.createCloseRequest(this); closeFuture = closeRequest.getFuture(); closeFuture.addListener( new DbListener<Void>() { @Override public void onCompletion(DbFuture<Void> future) { MySqlConnection.this.connectionManager.removeConnection(MySqlConnection.this); } }); if (closeMode == CloseMode.CANCEL_PENDING_OPERATIONS) { forceCloseOnPendingRequests(); } forceQueRequest(closeRequest); return closeFuture; } else { return closeFuture; } } }