19
19
package org .apache .hadoop .hbase .client ;
20
20
21
21
import java .io .IOException ;
22
- import java .util .Date ;
22
+ import java .time .Instant ;
23
+ import java .time .format .DateTimeFormatter ;
23
24
import java .util .List ;
25
+ import java .util .StringJoiner ;
24
26
27
+ import org .apache .commons .lang3 .StringUtils ;
25
28
import org .apache .yetus .audience .InterfaceAudience ;
26
29
27
30
/**
@@ -41,24 +44,34 @@ public RetriesExhaustedException(final String msg, final IOException e) {
41
44
}
42
45
43
46
/**
44
- * Datastructure that allows adding more info around Throwable incident.
47
+ * Data structure that allows adding more info around Throwable incident.
45
48
*/
46
49
@ InterfaceAudience .Private
47
50
public static class ThrowableWithExtraContext {
48
- private final Throwable t ;
49
- private final long when ;
51
+ private final Throwable throwable ;
52
+ private final long whenAsEpochMilli ;
50
53
private final String extras ;
51
54
52
- public ThrowableWithExtraContext (final Throwable t , final long when ,
55
+ public ThrowableWithExtraContext (final Throwable throwable , final long whenAsEpochMilli ,
53
56
final String extras ) {
54
- this .t = t ;
55
- this .when = when ;
57
+ this .throwable = throwable ;
58
+ this .whenAsEpochMilli = whenAsEpochMilli ;
56
59
this .extras = extras ;
57
60
}
58
61
59
62
@ Override
60
63
public String toString () {
61
- return new Date (this .when ).toString () + ", " + extras + ", " + t .toString ();
64
+ final StringJoiner joiner = new StringJoiner (", " );
65
+ if (whenAsEpochMilli != 0 ) {
66
+ joiner .add (DateTimeFormatter .ISO_INSTANT .format (Instant .ofEpochMilli (whenAsEpochMilli )));
67
+ }
68
+ if (StringUtils .isNotEmpty (extras )) {
69
+ joiner .add (extras );
70
+ }
71
+ if (throwable != null ) {
72
+ joiner .add (throwable .toString ());
73
+ }
74
+ return joiner .toString ();
62
75
}
63
76
}
64
77
@@ -83,7 +96,7 @@ public RetriesExhaustedException(final String callableVitals, int numTries,
83
96
public RetriesExhaustedException (final int numRetries ,
84
97
final List <ThrowableWithExtraContext > exceptions ) {
85
98
super (getMessage (numRetries , exceptions ),
86
- exceptions .isEmpty ()? null : exceptions .get (exceptions .size () - 1 ).t );
99
+ exceptions .isEmpty ()? null : exceptions .get (exceptions .size () - 1 ).throwable );
87
100
}
88
101
89
102
private static String getMessage (String callableVitals , int numTries ,
0 commit comments