1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.ipc;
19
20 import java.io.IOException;
21 import java.lang.reflect.Constructor;
22
23 import org.apache.hadoop.conf.Configuration;
24 import org.apache.hadoop.hbase.DoNotRetryIOException;
25 import org.apache.hadoop.hbase.HBaseConfiguration;
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
27 import org.apache.hadoop.hbase.classification.InterfaceStability;
28 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
29 import org.apache.hadoop.hbase.util.DynamicClassLoader;
30 import org.apache.hadoop.ipc.RemoteException;
31
32
33
34
35
36
37
38 @SuppressWarnings("serial")
39 @InterfaceAudience.Public
40 @InterfaceStability.Evolving
41 @edu.umd.cs.findbugs.annotations.SuppressWarnings(
42 value = "DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED", justification = "None. Address sometime.")
43 public class RemoteWithExtrasException extends RemoteException {
44 private final String hostname;
45 private final int port;
46 private final boolean doNotRetry;
47
48 private final static ClassLoader CLASS_LOADER;
49
50 static {
51 ClassLoader parent = RemoteWithExtrasException.class.getClassLoader();
52 Configuration conf = HBaseConfiguration.create();
53 CLASS_LOADER = new DynamicClassLoader(conf, parent);
54 }
55
56 public RemoteWithExtrasException(String className, String msg, final boolean doNotRetry) {
57 this(className, msg, null, -1, doNotRetry);
58 }
59
60 public RemoteWithExtrasException(String className, String msg, final String hostname,
61 final int port, final boolean doNotRetry) {
62 super(className, msg);
63 this.hostname = hostname;
64 this.port = port;
65 this.doNotRetry = doNotRetry;
66 }
67
68 @Override
69 public IOException unwrapRemoteException() {
70 Class<?> realClass;
71 try {
72
73
74 realClass = Class.forName(getClassName(), false, CLASS_LOADER);
75 } catch (ClassNotFoundException cnfe) {
76 try {
77
78 realClass = Class.forName(getClassName(), false, super.getClass().getClassLoader());
79 } catch (ClassNotFoundException e) {
80 return new DoNotRetryIOException(
81 "Unable to load exception received from server:" + e.getMessage(), this);
82 }
83 }
84 try {
85 return instantiateException(realClass.asSubclass(IOException.class));
86 } catch (Exception e) {
87 return new DoNotRetryIOException(
88 "Unable to instantiate exception received from server:" + e.getMessage(), this);
89 }
90 }
91
92 private IOException instantiateException(Class<? extends IOException> cls) throws Exception {
93 Constructor<? extends IOException> cn = cls.getConstructor(String.class);
94 cn.setAccessible(true);
95 IOException ex = cn.newInstance(this.getMessage());
96 ex.initCause(this);
97 return ex;
98 }
99
100
101
102
103 public String getHostname() {
104 return this.hostname;
105 }
106
107
108
109
110 public int getPort() {
111 return this.port;
112 }
113
114
115
116
117 public boolean isDoNotRetry() {
118 return this.doNotRetry;
119 }
120 }