MCPcopy Create free account
hub / github.com/grpc/grpc-java / cancel

Method cancel

api/src/context/java/io/grpc/Context.java:813–836  ·  view source on GitHub ↗

Cancel this context and optionally provide a cause (can be null) for the cancellation. This will trigger notification of listeners. It is safe to call this method multiple times. Only the first call will have any effect. Calling cancel(null) is the same as calling #close.

(Throwable cause)

Source from the content-addressed store, hash-verified

811 * {@code false} if the context was already cancelled.
812 */
813 @CanIgnoreReturnValue
814 public boolean cancel(Throwable cause) {
815 boolean triggeredCancel = false;
816 ScheduledFuture<?> localPendingDeadline = null;
817 synchronized (this) {
818 if (!cancelled) {
819 cancelled = true;
820 if (pendingDeadline != null) {
821 // If we have a scheduled cancellation pending attempt to cancel it.
822 localPendingDeadline = pendingDeadline;
823 pendingDeadline = null;
824 }
825 this.cancellationCause = cause;
826 triggeredCancel = true;
827 }
828 }
829 if (localPendingDeadline != null) {
830 localPendingDeadline.cancel(false);
831 }
832 if (triggeredCancel) {
833 notifyAndClearListeners();
834 }
835 return triggeredCancel;
836 }
837
838 /**
839 * Notify all listeners that this context has been cancelled and immediately release

Callers 5

detachAndCancelMethod · 0.95
isCancelledMethod · 0.95
closeMethod · 0.95

Calls 2

cancelMethod · 0.65