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