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