@@ -96,15 +96,13 @@ private boolean isAbeforeB(@Nullable Deadline a, @Nullable Deadline b) {
96
96
private ScheduledFuture <?> scheduleDeadlineIfNeeded (
97
97
ScheduledExecutorService scheduler , @ Nullable Deadline deadline ) {
98
98
Deadline contextDeadline = context .getDeadline ();
99
- if (deadline == null && contextDeadline == null ) {
100
- return null ;
101
- }
102
- long remainingNanos = Long .MAX_VALUE ;
103
- if (deadline != null ) {
99
+ String deadlineName ;
100
+ long remainingNanos ;
101
+ if (deadline != null && isAbeforeB (deadline , contextDeadline )) {
102
+ deadlineName = "CallOptions" ;
104
103
remainingNanos = deadline .timeRemaining (NANOSECONDS );
105
- }
106
-
107
- if (contextDeadline != null && contextDeadline .timeRemaining (NANOSECONDS ) < remainingNanos ) {
104
+ } else if (contextDeadline != null ) {
105
+ deadlineName = "Context" ;
108
106
remainingNanos = contextDeadline .timeRemaining (NANOSECONDS );
109
107
if (logger .isLoggable (Level .FINE )) {
110
108
StringBuilder builder =
@@ -121,29 +119,29 @@ private ScheduledFuture<?> scheduleDeadlineIfNeeded(
121
119
}
122
120
logger .fine (builder .toString ());
123
121
}
124
- }
125
-
126
- long seconds = Math .abs (remainingNanos ) / TimeUnit .SECONDS .toNanos (1 );
127
- long nanos = Math .abs (remainingNanos ) % TimeUnit .SECONDS .toNanos (1 );
128
- final StringBuilder buf = new StringBuilder ();
129
- String deadlineName = isAbeforeB (contextDeadline , deadline ) ? "Context" : "CallOptions" ;
130
- if (remainingNanos < 0 ) {
131
- buf .append ("ClientCall started after " );
132
- buf .append (deadlineName );
133
- buf .append (" deadline was exceeded. Deadline has been exceeded for " );
134
122
} else {
135
- buf .append ("Deadline " );
136
- buf .append (deadlineName );
137
- buf .append (" will be exceeded in " );
123
+ return null ;
138
124
}
139
- buf .append (seconds );
140
- buf .append (String .format (Locale .US , ".%09d" , nanos ));
141
- buf .append ("s. " );
142
125
143
126
/* Cancels the call if deadline exceeded prior to the real call being set. */
144
127
class DeadlineExceededRunnable implements Runnable {
145
128
@ Override
146
129
public void run () {
130
+ long seconds = Math .abs (remainingNanos ) / TimeUnit .SECONDS .toNanos (1 );
131
+ long nanos = Math .abs (remainingNanos ) % TimeUnit .SECONDS .toNanos (1 );
132
+ StringBuilder buf = new StringBuilder ();
133
+ if (remainingNanos < 0 ) {
134
+ buf .append ("ClientCall started after " );
135
+ buf .append (deadlineName );
136
+ buf .append (" deadline was exceeded. Deadline has been exceeded for " );
137
+ } else {
138
+ buf .append ("Deadline " );
139
+ buf .append (deadlineName );
140
+ buf .append (" was exceeded after " );
141
+ }
142
+ buf .append (seconds );
143
+ buf .append (String .format (Locale .US , ".%09d" , nanos ));
144
+ buf .append ("s" );
147
145
cancel (
148
146
Status .DEADLINE_EXCEEDED .withDescription (buf .toString ()),
149
147
// We should not cancel the call if the realCall is set because there could be a
0 commit comments