1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.client;
20
21 import org.apache.hadoop.hbase.classification.InterfaceAudience;
22 import org.apache.hadoop.hbase.classification.InterfaceStability;
23
24 import java.io.IOException;
25 import java.util.Date;
26 import java.util.List;
27
28
29
30
31
32 @InterfaceAudience.Public
33 @InterfaceStability.Stable
34 public class RetriesExhaustedException extends IOException {
35 private static final long serialVersionUID = 1876775844L;
36
37 public RetriesExhaustedException(final String msg) {
38 super(msg);
39 }
40
41 public RetriesExhaustedException(final String msg, final IOException e) {
42 super(msg, e);
43 }
44
45
46
47
48 @InterfaceAudience.Private
49 public static class ThrowableWithExtraContext {
50 private final Throwable t;
51 private final long when;
52 private final String extras;
53
54 public ThrowableWithExtraContext(final Throwable t, final long when,
55 final String extras) {
56 this.t = t;
57 this.when = when;
58 this.extras = extras;
59 }
60
61 @Override
62 public String toString() {
63 return new Date(this.when).toString() + ", " + extras + ", " + t.toString();
64 }
65 }
66
67
68
69
70
71
72
73
74 public RetriesExhaustedException(final String callableVitals, int numTries,
75 List<Throwable> exceptions) {
76 super(getMessage(callableVitals, numTries, exceptions));
77 }
78
79
80
81
82
83
84 @InterfaceAudience.Private
85 public RetriesExhaustedException(final int numTries,
86 final List<ThrowableWithExtraContext> exceptions) {
87 super(getMessage(numTries, exceptions),
88 (exceptions != null && !exceptions.isEmpty() ?
89 exceptions.get(exceptions.size() - 1).t : null));
90 }
91
92 private static String getMessage(String callableVitals, int numTries,
93 List<Throwable> exceptions) {
94 StringBuilder buffer = new StringBuilder("Failed contacting ");
95 buffer.append(callableVitals);
96 buffer.append(" after ");
97 buffer.append(numTries + 1);
98 buffer.append(" attempts.\nExceptions:\n");
99 for (Throwable t : exceptions) {
100 buffer.append(t.toString());
101 buffer.append("\n");
102 }
103 return buffer.toString();
104 }
105
106 private static String getMessage(final int numTries,
107 final List<ThrowableWithExtraContext> exceptions) {
108 StringBuilder buffer = new StringBuilder("Failed after attempts=");
109 buffer.append(numTries + 1);
110 buffer.append(", exceptions:\n");
111 for (ThrowableWithExtraContext t : exceptions) {
112 buffer.append(t.toString());
113 buffer.append("\n");
114 }
115 return buffer.toString();
116 }
117 }