HDFS-13664. Refactor ConfiguredFailoverProxyProvider to make inheritance easier. Contributed by Chao Sun.

(cherry picked from commit fba1c42adc)
This commit is contained in:
Chao Sun 2018-06-08 16:36:42 -07:00 committed by Konstantin V Shvachko
parent 63c20f9021
commit d827ffe245
1 changed files with 7 additions and 3 deletions

View File

@ -52,11 +52,11 @@ public class ConfiguredFailoverProxyProvider<T> extends
protected final Configuration conf; protected final Configuration conf;
protected final List<AddressRpcProxyPair<T>> proxies = protected final List<AddressRpcProxyPair<T>> proxies =
new ArrayList<AddressRpcProxyPair<T>>(); new ArrayList<AddressRpcProxyPair<T>>();
private final UserGroupInformation ugi; protected final UserGroupInformation ugi;
protected final Class<T> xface; protected final Class<T> xface;
private int currentProxyIndex = 0; private int currentProxyIndex = 0;
private final HAProxyFactory<T> factory; protected final HAProxyFactory<T> factory;
public ConfiguredFailoverProxyProvider(Configuration conf, URI uri, public ConfiguredFailoverProxyProvider(Configuration conf, URI uri,
Class<T> xface, HAProxyFactory<T> factory) { Class<T> xface, HAProxyFactory<T> factory) {
@ -122,6 +122,10 @@ public class ConfiguredFailoverProxyProvider<T> extends
@Override @Override
public synchronized ProxyInfo<T> getProxy() { public synchronized ProxyInfo<T> getProxy() {
AddressRpcProxyPair<T> current = proxies.get(currentProxyIndex); AddressRpcProxyPair<T> current = proxies.get(currentProxyIndex);
return getProxy(current);
}
protected ProxyInfo<T> getProxy(AddressRpcProxyPair<T> current) {
if (current.namenode == null) { if (current.namenode == null) {
try { try {
current.namenode = factory.createProxy(conf, current.namenode = factory.createProxy(conf,
@ -147,7 +151,7 @@ public class ConfiguredFailoverProxyProvider<T> extends
* A little pair object to store the address and connected RPC proxy object to * A little pair object to store the address and connected RPC proxy object to
* an NN. Note that {@link AddressRpcProxyPair#namenode} may be null. * an NN. Note that {@link AddressRpcProxyPair#namenode} may be null.
*/ */
private static class AddressRpcProxyPair<T> { protected static class AddressRpcProxyPair<T> {
public final InetSocketAddress address; public final InetSocketAddress address;
public T namenode; public T namenode;