public void cancel ( Exception reason ) { // IMPROVEMENT: need to rework how syncs on the future.complete() work. We really should be // syncing here, so we don't do the channel.cancel if the request is processing // future.complete() on another thread at the same time. Should just do a quick // sync, check the future.complete flag, then process only if !complete. That will // also mean we can remove a bunch of redundant checks for complete, but we need to check all // the paths carefully. if ( this . channel == null ) { return ; } synchronized ( this . completedSemaphore ) { if ( ! this . completed ) { try { // this ends up calling future.completed() this . channel . cancel ( this , reason ) ; } catch ( Exception e ) { // Simply swallow the exception } // end try } else { if ( this . channel . readFuture != null ) { this . channel . readFuture . setCancelInProgress ( 0 ) ; } if ( this . channel . writeFuture != null ) { this . channel . writeFuture . setCancelInProgress ( 0 ) ; } } } }
Attempts to cancel the operation represented by the AsyncFuture . Cancellation will not succeed if the operation is already complete .