57
57
* Transports for a single {@link SocketAddress}.
58
58
*/
59
59
@ ThreadSafe
60
- final class TransportSet {
60
+ final class TransportSet implements WithLogId {
61
61
private static final Logger log = Logger .getLogger (TransportSet .class .getName ());
62
-
63
62
private static final ClientTransport SHUTDOWN_TRANSPORT =
64
63
new FailingClientTransport (Status .UNAVAILABLE .withDescription ("TransportSet is shutdown" ));
65
64
@@ -192,7 +191,10 @@ public void run() {
192
191
}
193
192
ManagedClientTransport transport =
194
193
transportFactory .newClientTransport (address , authority );
195
- log .log (Level .FINE , "Created transport {0} for {1}" , new Object [] {transport , address });
194
+ if (log .isLoggable (Level .FINE )) {
195
+ log .log (Level .FINE , "[{0}] Created {1} for {2}" ,
196
+ new Object [] {getLogId (), transport .getLogId (), address });
197
+ }
196
198
transports .add (transport );
197
199
transport .start (new TransportListener (transport , delayedTransport , address ));
198
200
}
@@ -211,6 +213,10 @@ public void run() {
211
213
}
212
214
}
213
215
firstAttempt = false ;
216
+ if (log .isLoggable (Level .FINE )) {
217
+ log .log (Level .FINE , "[{0}] Scheduling connection after {1} ms for {2}" ,
218
+ new Object []{getLogId (), delayMillis , address });
219
+ }
214
220
if (delayMillis <= 0 ) {
215
221
reconnectTask = null ;
216
222
// No back-off this time.
@@ -257,6 +263,11 @@ private void cancelReconnectTask() {
257
263
}
258
264
}
259
265
266
+ @ Override
267
+ public String getLogId () {
268
+ return GrpcUtil .getLogId (this );
269
+ }
270
+
260
271
/** Shared base for both delayed and real transports. */
261
272
private class BaseTransportListener implements ManagedClientTransport .Listener {
262
273
protected final ManagedClientTransport transport ;
@@ -277,6 +288,9 @@ public void transportTerminated() {
277
288
synchronized (lock ) {
278
289
transports .remove (transport );
279
290
if (shutdown && transports .isEmpty ()) {
291
+ if (log .isLoggable (Level .FINE )) {
292
+ log .log (Level .FINE , "[{0}] Terminated" , getLogId ());
293
+ }
280
294
runCallback = true ;
281
295
cancelReconnectTask ();
282
296
}
@@ -301,7 +315,10 @@ public TransportListener(ManagedClientTransport transport,
301
315
302
316
@ Override
303
317
public void transportReady () {
304
- log .log (Level .FINE , "Transport {0} for {1} is ready" , new Object [] {transport , address });
318
+ if (log .isLoggable (Level .FINE )) {
319
+ log .log (Level .FINE , "[{0}] {1} for {2} is ready" ,
320
+ new Object [] {getLogId (), transport .getLogId (), address });
321
+ }
305
322
super .transportReady ();
306
323
boolean savedShutdown ;
307
324
synchronized (lock ) {
@@ -330,8 +347,10 @@ public void transportReady() {
330
347
331
348
@ Override
332
349
public void transportShutdown (Status s ) {
333
- log .log (Level .FINE , "Transport {0} for {1} is being shutdown with {2}" ,
334
- new Object [] {transport , address , s });
350
+ if (log .isLoggable (Level .FINE )) {
351
+ log .log (Level .FINE , "[{0}] {1} for {2} is being shutdown with status {3}" ,
352
+ new Object [] {getLogId (), transport .getLogId (), address , s });
353
+ }
335
354
super .transportShutdown (s );
336
355
synchronized (lock ) {
337
356
if (activeTransport == transport ) {
@@ -353,8 +372,10 @@ public void transportShutdown(Status s) {
353
372
354
373
@ Override
355
374
public void transportTerminated () {
356
- log .log (Level .FINE , "Transport {0} for {1} is terminated" ,
357
- new Object [] {transport , address });
375
+ if (log .isLoggable (Level .FINE )) {
376
+ log .log (Level .FINE , "[{0}] {1} for {2} is terminated" ,
377
+ new Object [] {getLogId (), transport .getLogId (), address });
378
+ }
358
379
super .transportTerminated ();
359
380
Preconditions .checkState (activeTransport != transport ,
360
381
"activeTransport still points to the delayedTransport. "
0 commit comments