http://git-wip-us.apache.org/repos/asf/hbase-site/blob/2777c693/devapidocs/src-html/org/apache/hadoop/hbase/ipc/AbstractRpcClient.AbstractRpcChannel.html
----------------------------------------------------------------------
diff --git 
a/devapidocs/src-html/org/apache/hadoop/hbase/ipc/AbstractRpcClient.AbstractRpcChannel.html
 
b/devapidocs/src-html/org/apache/hadoop/hbase/ipc/AbstractRpcClient.AbstractRpcChannel.html
index 30d5dd8..beacb44 100644
--- 
a/devapidocs/src-html/org/apache/hadoop/hbase/ipc/AbstractRpcClient.AbstractRpcChannel.html
+++ 
b/devapidocs/src-html/org/apache/hadoop/hbase/ipc/AbstractRpcClient.AbstractRpcChannel.html
@@ -109,497 +109,499 @@
 <span class="sourceLineNo">101</span>  private static final 
ScheduledExecutorService IDLE_CONN_SWEEPER = Executors<a name="line.101"></a>
 <span class="sourceLineNo">102</span>      .newScheduledThreadPool(1, 
Threads.newDaemonThreadFactory("Idle-Rpc-Conn-Sweeper"));<a name="line.102"></a>
 <span class="sourceLineNo">103</span><a name="line.103"></a>
-<span class="sourceLineNo">104</span>  protected final static Map&lt;Kind, 
TokenSelector&lt;? extends TokenIdentifier&gt;&gt; TOKEN_HANDLERS = new 
HashMap&lt;&gt;();<a name="line.104"></a>
-<span class="sourceLineNo">105</span><a name="line.105"></a>
-<span class="sourceLineNo">106</span>  static {<a name="line.106"></a>
-<span class="sourceLineNo">107</span>    
TOKEN_HANDLERS.put(Kind.HBASE_AUTH_TOKEN, new AuthenticationTokenSelector());<a 
name="line.107"></a>
-<span class="sourceLineNo">108</span>  }<a name="line.108"></a>
-<span class="sourceLineNo">109</span><a name="line.109"></a>
-<span class="sourceLineNo">110</span>  protected boolean running = true; // if 
client runs<a name="line.110"></a>
+<span class="sourceLineNo">104</span>  
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="MS_MUTABLE_COLLECTION_PKGPROTECT",<a
 name="line.104"></a>
+<span class="sourceLineNo">105</span>      justification="the rest of the 
system which live in the different package can use")<a name="line.105"></a>
+<span class="sourceLineNo">106</span>  protected final static Map&lt;Kind, 
TokenSelector&lt;? extends TokenIdentifier&gt;&gt; TOKEN_HANDLERS = new 
HashMap&lt;&gt;();<a name="line.106"></a>
+<span class="sourceLineNo">107</span><a name="line.107"></a>
+<span class="sourceLineNo">108</span>  static {<a name="line.108"></a>
+<span class="sourceLineNo">109</span>    
TOKEN_HANDLERS.put(Kind.HBASE_AUTH_TOKEN, new AuthenticationTokenSelector());<a 
name="line.109"></a>
+<span class="sourceLineNo">110</span>  }<a name="line.110"></a>
 <span class="sourceLineNo">111</span><a name="line.111"></a>
-<span class="sourceLineNo">112</span>  protected final Configuration conf;<a 
name="line.112"></a>
-<span class="sourceLineNo">113</span>  protected final String clusterId;<a 
name="line.113"></a>
-<span class="sourceLineNo">114</span>  protected final SocketAddress 
localAddr;<a name="line.114"></a>
-<span class="sourceLineNo">115</span>  protected final MetricsConnection 
metrics;<a name="line.115"></a>
-<span class="sourceLineNo">116</span><a name="line.116"></a>
-<span class="sourceLineNo">117</span>  protected final UserProvider 
userProvider;<a name="line.117"></a>
-<span class="sourceLineNo">118</span>  protected final CellBlockBuilder 
cellBlockBuilder;<a name="line.118"></a>
-<span class="sourceLineNo">119</span><a name="line.119"></a>
-<span class="sourceLineNo">120</span>  protected final int 
minIdleTimeBeforeClose; // if the connection is idle for more than this<a 
name="line.120"></a>
-<span class="sourceLineNo">121</span>  // time (in ms), it will be closed at 
any moment.<a name="line.121"></a>
-<span class="sourceLineNo">122</span>  protected final int maxRetries; // the 
max. no. of retries for socket connections<a name="line.122"></a>
-<span class="sourceLineNo">123</span>  protected final long failureSleep; // 
Time to sleep before retry on failure.<a name="line.123"></a>
-<span class="sourceLineNo">124</span>  protected final boolean tcpNoDelay; // 
if T then disable Nagle's Algorithm<a name="line.124"></a>
-<span class="sourceLineNo">125</span>  protected final boolean tcpKeepAlive; 
// if T then use keepalives<a name="line.125"></a>
-<span class="sourceLineNo">126</span>  protected final Codec codec;<a 
name="line.126"></a>
-<span class="sourceLineNo">127</span>  protected final CompressionCodec 
compressor;<a name="line.127"></a>
-<span class="sourceLineNo">128</span>  protected final boolean 
fallbackAllowed;<a name="line.128"></a>
-<span class="sourceLineNo">129</span><a name="line.129"></a>
-<span class="sourceLineNo">130</span>  protected final FailedServers 
failedServers;<a name="line.130"></a>
+<span class="sourceLineNo">112</span>  protected boolean running = true; // if 
client runs<a name="line.112"></a>
+<span class="sourceLineNo">113</span><a name="line.113"></a>
+<span class="sourceLineNo">114</span>  protected final Configuration conf;<a 
name="line.114"></a>
+<span class="sourceLineNo">115</span>  protected final String clusterId;<a 
name="line.115"></a>
+<span class="sourceLineNo">116</span>  protected final SocketAddress 
localAddr;<a name="line.116"></a>
+<span class="sourceLineNo">117</span>  protected final MetricsConnection 
metrics;<a name="line.117"></a>
+<span class="sourceLineNo">118</span><a name="line.118"></a>
+<span class="sourceLineNo">119</span>  protected final UserProvider 
userProvider;<a name="line.119"></a>
+<span class="sourceLineNo">120</span>  protected final CellBlockBuilder 
cellBlockBuilder;<a name="line.120"></a>
+<span class="sourceLineNo">121</span><a name="line.121"></a>
+<span class="sourceLineNo">122</span>  protected final int 
minIdleTimeBeforeClose; // if the connection is idle for more than this<a 
name="line.122"></a>
+<span class="sourceLineNo">123</span>  // time (in ms), it will be closed at 
any moment.<a name="line.123"></a>
+<span class="sourceLineNo">124</span>  protected final int maxRetries; // the 
max. no. of retries for socket connections<a name="line.124"></a>
+<span class="sourceLineNo">125</span>  protected final long failureSleep; // 
Time to sleep before retry on failure.<a name="line.125"></a>
+<span class="sourceLineNo">126</span>  protected final boolean tcpNoDelay; // 
if T then disable Nagle's Algorithm<a name="line.126"></a>
+<span class="sourceLineNo">127</span>  protected final boolean tcpKeepAlive; 
// if T then use keepalives<a name="line.127"></a>
+<span class="sourceLineNo">128</span>  protected final Codec codec;<a 
name="line.128"></a>
+<span class="sourceLineNo">129</span>  protected final CompressionCodec 
compressor;<a name="line.129"></a>
+<span class="sourceLineNo">130</span>  protected final boolean 
fallbackAllowed;<a name="line.130"></a>
 <span class="sourceLineNo">131</span><a name="line.131"></a>
-<span class="sourceLineNo">132</span>  protected final int connectTO;<a 
name="line.132"></a>
-<span class="sourceLineNo">133</span>  protected final int readTO;<a 
name="line.133"></a>
-<span class="sourceLineNo">134</span>  protected final int writeTO;<a 
name="line.134"></a>
-<span class="sourceLineNo">135</span><a name="line.135"></a>
-<span class="sourceLineNo">136</span>  protected final 
PoolMap&lt;ConnectionId, T&gt; connections;<a name="line.136"></a>
+<span class="sourceLineNo">132</span>  protected final FailedServers 
failedServers;<a name="line.132"></a>
+<span class="sourceLineNo">133</span><a name="line.133"></a>
+<span class="sourceLineNo">134</span>  protected final int connectTO;<a 
name="line.134"></a>
+<span class="sourceLineNo">135</span>  protected final int readTO;<a 
name="line.135"></a>
+<span class="sourceLineNo">136</span>  protected final int writeTO;<a 
name="line.136"></a>
 <span class="sourceLineNo">137</span><a name="line.137"></a>
-<span class="sourceLineNo">138</span>  private final AtomicInteger callIdCnt = 
new AtomicInteger(0);<a name="line.138"></a>
+<span class="sourceLineNo">138</span>  protected final 
PoolMap&lt;ConnectionId, T&gt; connections;<a name="line.138"></a>
 <span class="sourceLineNo">139</span><a name="line.139"></a>
-<span class="sourceLineNo">140</span>  private final ScheduledFuture&lt;?&gt; 
cleanupIdleConnectionTask;<a name="line.140"></a>
+<span class="sourceLineNo">140</span>  private final AtomicInteger callIdCnt = 
new AtomicInteger(0);<a name="line.140"></a>
 <span class="sourceLineNo">141</span><a name="line.141"></a>
-<span class="sourceLineNo">142</span>  private int 
maxConcurrentCallsPerServer;<a name="line.142"></a>
+<span class="sourceLineNo">142</span>  private final ScheduledFuture&lt;?&gt; 
cleanupIdleConnectionTask;<a name="line.142"></a>
 <span class="sourceLineNo">143</span><a name="line.143"></a>
-<span class="sourceLineNo">144</span>  private static final 
LoadingCache&lt;InetSocketAddress, AtomicInteger&gt; concurrentCounterCache =<a 
name="line.144"></a>
-<span class="sourceLineNo">145</span>      
CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.HOURS).<a 
name="line.145"></a>
-<span class="sourceLineNo">146</span>          build(new 
CacheLoader&lt;InetSocketAddress, AtomicInteger&gt;() {<a name="line.146"></a>
-<span class="sourceLineNo">147</span>            @Override public 
AtomicInteger load(InetSocketAddress key) throws Exception {<a 
name="line.147"></a>
-<span class="sourceLineNo">148</span>              return new 
AtomicInteger(0);<a name="line.148"></a>
-<span class="sourceLineNo">149</span>            }<a name="line.149"></a>
-<span class="sourceLineNo">150</span>          });<a name="line.150"></a>
-<span class="sourceLineNo">151</span><a name="line.151"></a>
-<span class="sourceLineNo">152</span>  /**<a name="line.152"></a>
-<span class="sourceLineNo">153</span>   * Construct an IPC client for the 
cluster &lt;code&gt;clusterId&lt;/code&gt;<a name="line.153"></a>
-<span class="sourceLineNo">154</span>   * @param conf configuration<a 
name="line.154"></a>
-<span class="sourceLineNo">155</span>   * @param clusterId the cluster id<a 
name="line.155"></a>
-<span class="sourceLineNo">156</span>   * @param localAddr client socket bind 
address.<a name="line.156"></a>
-<span class="sourceLineNo">157</span>   * @param metrics the connection 
metrics<a name="line.157"></a>
-<span class="sourceLineNo">158</span>   */<a name="line.158"></a>
-<span class="sourceLineNo">159</span>  public AbstractRpcClient(Configuration 
conf, String clusterId, SocketAddress localAddr,<a name="line.159"></a>
-<span class="sourceLineNo">160</span>      MetricsConnection metrics) {<a 
name="line.160"></a>
-<span class="sourceLineNo">161</span>    this.userProvider = 
UserProvider.instantiate(conf);<a name="line.161"></a>
-<span class="sourceLineNo">162</span>    this.localAddr = localAddr;<a 
name="line.162"></a>
-<span class="sourceLineNo">163</span>    this.tcpKeepAlive = 
conf.getBoolean("hbase.ipc.client.tcpkeepalive", true);<a name="line.163"></a>
-<span class="sourceLineNo">164</span>    this.clusterId = clusterId != null ? 
clusterId : HConstants.CLUSTER_ID_DEFAULT;<a name="line.164"></a>
-<span class="sourceLineNo">165</span>    this.failureSleep = 
conf.getLong(HConstants.HBASE_CLIENT_PAUSE,<a name="line.165"></a>
-<span class="sourceLineNo">166</span>      
HConstants.DEFAULT_HBASE_CLIENT_PAUSE);<a name="line.166"></a>
-<span class="sourceLineNo">167</span>    this.maxRetries = 
conf.getInt("hbase.ipc.client.connect.max.retries", 0);<a name="line.167"></a>
-<span class="sourceLineNo">168</span>    this.tcpNoDelay = 
conf.getBoolean("hbase.ipc.client.tcpnodelay", true);<a name="line.168"></a>
-<span class="sourceLineNo">169</span>    this.cellBlockBuilder = new 
CellBlockBuilder(conf);<a name="line.169"></a>
-<span class="sourceLineNo">170</span><a name="line.170"></a>
-<span class="sourceLineNo">171</span>    this.minIdleTimeBeforeClose = 
conf.getInt(IDLE_TIME, 120000); // 2 minutes<a name="line.171"></a>
-<span class="sourceLineNo">172</span>    this.conf = conf;<a 
name="line.172"></a>
-<span class="sourceLineNo">173</span>    this.codec = getCodec();<a 
name="line.173"></a>
-<span class="sourceLineNo">174</span>    this.compressor = 
getCompressor(conf);<a name="line.174"></a>
-<span class="sourceLineNo">175</span>    this.fallbackAllowed = 
conf.getBoolean(IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_KEY,<a 
name="line.175"></a>
-<span class="sourceLineNo">176</span>      
IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_DEFAULT);<a name="line.176"></a>
-<span class="sourceLineNo">177</span>    this.failedServers = new 
FailedServers(conf);<a name="line.177"></a>
-<span class="sourceLineNo">178</span>    this.connectTO = 
conf.getInt(SOCKET_TIMEOUT_CONNECT, DEFAULT_SOCKET_TIMEOUT_CONNECT);<a 
name="line.178"></a>
-<span class="sourceLineNo">179</span>    this.readTO = 
conf.getInt(SOCKET_TIMEOUT_READ, DEFAULT_SOCKET_TIMEOUT_READ);<a 
name="line.179"></a>
-<span class="sourceLineNo">180</span>    this.writeTO = 
conf.getInt(SOCKET_TIMEOUT_WRITE, DEFAULT_SOCKET_TIMEOUT_WRITE);<a 
name="line.180"></a>
-<span class="sourceLineNo">181</span>    this.metrics = metrics;<a 
name="line.181"></a>
-<span class="sourceLineNo">182</span>    this.maxConcurrentCallsPerServer = 
conf.getInt(<a name="line.182"></a>
-<span class="sourceLineNo">183</span>        
HConstants.HBASE_CLIENT_PERSERVER_REQUESTS_THRESHOLD,<a name="line.183"></a>
-<span class="sourceLineNo">184</span>        
HConstants.DEFAULT_HBASE_CLIENT_PERSERVER_REQUESTS_THRESHOLD);<a 
name="line.184"></a>
-<span class="sourceLineNo">185</span><a name="line.185"></a>
-<span class="sourceLineNo">186</span>    this.connections = new 
PoolMap&lt;&gt;(getPoolType(conf), getPoolSize(conf));<a name="line.186"></a>
+<span class="sourceLineNo">144</span>  private int 
maxConcurrentCallsPerServer;<a name="line.144"></a>
+<span class="sourceLineNo">145</span><a name="line.145"></a>
+<span class="sourceLineNo">146</span>  private static final 
LoadingCache&lt;InetSocketAddress, AtomicInteger&gt; concurrentCounterCache =<a 
name="line.146"></a>
+<span class="sourceLineNo">147</span>      
CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.HOURS).<a 
name="line.147"></a>
+<span class="sourceLineNo">148</span>          build(new 
CacheLoader&lt;InetSocketAddress, AtomicInteger&gt;() {<a name="line.148"></a>
+<span class="sourceLineNo">149</span>            @Override public 
AtomicInteger load(InetSocketAddress key) throws Exception {<a 
name="line.149"></a>
+<span class="sourceLineNo">150</span>              return new 
AtomicInteger(0);<a name="line.150"></a>
+<span class="sourceLineNo">151</span>            }<a name="line.151"></a>
+<span class="sourceLineNo">152</span>          });<a name="line.152"></a>
+<span class="sourceLineNo">153</span><a name="line.153"></a>
+<span class="sourceLineNo">154</span>  /**<a name="line.154"></a>
+<span class="sourceLineNo">155</span>   * Construct an IPC client for the 
cluster &lt;code&gt;clusterId&lt;/code&gt;<a name="line.155"></a>
+<span class="sourceLineNo">156</span>   * @param conf configuration<a 
name="line.156"></a>
+<span class="sourceLineNo">157</span>   * @param clusterId the cluster id<a 
name="line.157"></a>
+<span class="sourceLineNo">158</span>   * @param localAddr client socket bind 
address.<a name="line.158"></a>
+<span class="sourceLineNo">159</span>   * @param metrics the connection 
metrics<a name="line.159"></a>
+<span class="sourceLineNo">160</span>   */<a name="line.160"></a>
+<span class="sourceLineNo">161</span>  public AbstractRpcClient(Configuration 
conf, String clusterId, SocketAddress localAddr,<a name="line.161"></a>
+<span class="sourceLineNo">162</span>      MetricsConnection metrics) {<a 
name="line.162"></a>
+<span class="sourceLineNo">163</span>    this.userProvider = 
UserProvider.instantiate(conf);<a name="line.163"></a>
+<span class="sourceLineNo">164</span>    this.localAddr = localAddr;<a 
name="line.164"></a>
+<span class="sourceLineNo">165</span>    this.tcpKeepAlive = 
conf.getBoolean("hbase.ipc.client.tcpkeepalive", true);<a name="line.165"></a>
+<span class="sourceLineNo">166</span>    this.clusterId = clusterId != null ? 
clusterId : HConstants.CLUSTER_ID_DEFAULT;<a name="line.166"></a>
+<span class="sourceLineNo">167</span>    this.failureSleep = 
conf.getLong(HConstants.HBASE_CLIENT_PAUSE,<a name="line.167"></a>
+<span class="sourceLineNo">168</span>      
HConstants.DEFAULT_HBASE_CLIENT_PAUSE);<a name="line.168"></a>
+<span class="sourceLineNo">169</span>    this.maxRetries = 
conf.getInt("hbase.ipc.client.connect.max.retries", 0);<a name="line.169"></a>
+<span class="sourceLineNo">170</span>    this.tcpNoDelay = 
conf.getBoolean("hbase.ipc.client.tcpnodelay", true);<a name="line.170"></a>
+<span class="sourceLineNo">171</span>    this.cellBlockBuilder = new 
CellBlockBuilder(conf);<a name="line.171"></a>
+<span class="sourceLineNo">172</span><a name="line.172"></a>
+<span class="sourceLineNo">173</span>    this.minIdleTimeBeforeClose = 
conf.getInt(IDLE_TIME, 120000); // 2 minutes<a name="line.173"></a>
+<span class="sourceLineNo">174</span>    this.conf = conf;<a 
name="line.174"></a>
+<span class="sourceLineNo">175</span>    this.codec = getCodec();<a 
name="line.175"></a>
+<span class="sourceLineNo">176</span>    this.compressor = 
getCompressor(conf);<a name="line.176"></a>
+<span class="sourceLineNo">177</span>    this.fallbackAllowed = 
conf.getBoolean(IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_KEY,<a 
name="line.177"></a>
+<span class="sourceLineNo">178</span>      
IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_DEFAULT);<a name="line.178"></a>
+<span class="sourceLineNo">179</span>    this.failedServers = new 
FailedServers(conf);<a name="line.179"></a>
+<span class="sourceLineNo">180</span>    this.connectTO = 
conf.getInt(SOCKET_TIMEOUT_CONNECT, DEFAULT_SOCKET_TIMEOUT_CONNECT);<a 
name="line.180"></a>
+<span class="sourceLineNo">181</span>    this.readTO = 
conf.getInt(SOCKET_TIMEOUT_READ, DEFAULT_SOCKET_TIMEOUT_READ);<a 
name="line.181"></a>
+<span class="sourceLineNo">182</span>    this.writeTO = 
conf.getInt(SOCKET_TIMEOUT_WRITE, DEFAULT_SOCKET_TIMEOUT_WRITE);<a 
name="line.182"></a>
+<span class="sourceLineNo">183</span>    this.metrics = metrics;<a 
name="line.183"></a>
+<span class="sourceLineNo">184</span>    this.maxConcurrentCallsPerServer = 
conf.getInt(<a name="line.184"></a>
+<span class="sourceLineNo">185</span>        
HConstants.HBASE_CLIENT_PERSERVER_REQUESTS_THRESHOLD,<a name="line.185"></a>
+<span class="sourceLineNo">186</span>        
HConstants.DEFAULT_HBASE_CLIENT_PERSERVER_REQUESTS_THRESHOLD);<a 
name="line.186"></a>
 <span class="sourceLineNo">187</span><a name="line.187"></a>
-<span class="sourceLineNo">188</span>    this.cleanupIdleConnectionTask = 
IDLE_CONN_SWEEPER.scheduleAtFixedRate(new Runnable() {<a name="line.188"></a>
+<span class="sourceLineNo">188</span>    this.connections = new 
PoolMap&lt;&gt;(getPoolType(conf), getPoolSize(conf));<a name="line.188"></a>
 <span class="sourceLineNo">189</span><a name="line.189"></a>
-<span class="sourceLineNo">190</span>      @Override<a name="line.190"></a>
-<span class="sourceLineNo">191</span>      public void run() {<a 
name="line.191"></a>
-<span class="sourceLineNo">192</span>        cleanupIdleConnections();<a 
name="line.192"></a>
-<span class="sourceLineNo">193</span>      }<a name="line.193"></a>
-<span class="sourceLineNo">194</span>    }, minIdleTimeBeforeClose, 
minIdleTimeBeforeClose, TimeUnit.MILLISECONDS);<a name="line.194"></a>
-<span class="sourceLineNo">195</span><a name="line.195"></a>
-<span class="sourceLineNo">196</span>    if (LOG.isDebugEnabled()) {<a 
name="line.196"></a>
-<span class="sourceLineNo">197</span>      LOG.debug("Codec=" + this.codec + 
", compressor=" + this.compressor + ", tcpKeepAlive="<a name="line.197"></a>
-<span class="sourceLineNo">198</span>          + this.tcpKeepAlive + ", 
tcpNoDelay=" + this.tcpNoDelay + ", connectTO=" + this.connectTO<a 
name="line.198"></a>
-<span class="sourceLineNo">199</span>          + ", readTO=" + this.readTO + 
", writeTO=" + this.writeTO + ", minIdleTimeBeforeClose="<a name="line.199"></a>
-<span class="sourceLineNo">200</span>          + this.minIdleTimeBeforeClose + 
", maxRetries=" + this.maxRetries + ", fallbackAllowed="<a name="line.200"></a>
-<span class="sourceLineNo">201</span>          + this.fallbackAllowed + ", 
bind address="<a name="line.201"></a>
-<span class="sourceLineNo">202</span>          + (this.localAddr != null ? 
this.localAddr : "null"));<a name="line.202"></a>
-<span class="sourceLineNo">203</span>    }<a name="line.203"></a>
-<span class="sourceLineNo">204</span>  }<a name="line.204"></a>
-<span class="sourceLineNo">205</span><a name="line.205"></a>
-<span class="sourceLineNo">206</span>  private void cleanupIdleConnections() 
{<a name="line.206"></a>
-<span class="sourceLineNo">207</span>    long closeBeforeTime = 
EnvironmentEdgeManager.currentTime() - minIdleTimeBeforeClose;<a 
name="line.207"></a>
-<span class="sourceLineNo">208</span>    synchronized (connections) {<a 
name="line.208"></a>
-<span class="sourceLineNo">209</span>      for (T conn : connections.values()) 
{<a name="line.209"></a>
-<span class="sourceLineNo">210</span>        // Remove connection if it has 
not been chosen by anyone for more than maxIdleTime, and the<a 
name="line.210"></a>
-<span class="sourceLineNo">211</span>        // connection itself has already 
shutdown. The latter check is because we may still<a name="line.211"></a>
-<span class="sourceLineNo">212</span>        // have some pending calls on 
connection so we should not shutdown the connection outside.<a 
name="line.212"></a>
-<span class="sourceLineNo">213</span>        // The connection itself will 
disconnect if there is no pending call for maxIdleTime.<a name="line.213"></a>
-<span class="sourceLineNo">214</span>        if (conn.getLastTouched() &lt; 
closeBeforeTime &amp;&amp; !conn.isActive()) {<a name="line.214"></a>
-<span class="sourceLineNo">215</span>          if (LOG.isTraceEnabled()) 
LOG.trace("Cleanup idle connection to " + conn.remoteId().address);<a 
name="line.215"></a>
-<span class="sourceLineNo">216</span>          
connections.removeValue(conn.remoteId(), conn);<a name="line.216"></a>
-<span class="sourceLineNo">217</span>          conn.cleanupConnection();<a 
name="line.217"></a>
-<span class="sourceLineNo">218</span>        }<a name="line.218"></a>
-<span class="sourceLineNo">219</span>      }<a name="line.219"></a>
-<span class="sourceLineNo">220</span>    }<a name="line.220"></a>
-<span class="sourceLineNo">221</span>  }<a name="line.221"></a>
-<span class="sourceLineNo">222</span><a name="line.222"></a>
-<span class="sourceLineNo">223</span>  @VisibleForTesting<a 
name="line.223"></a>
-<span class="sourceLineNo">224</span>  public static String 
getDefaultCodec(final Configuration c) {<a name="line.224"></a>
-<span class="sourceLineNo">225</span>    // If 
"hbase.client.default.rpc.codec" is empty string -- you can't set it to null 
because<a name="line.225"></a>
-<span class="sourceLineNo">226</span>    // Configuration will complain -- 
then no default codec (and we'll pb everything). Else<a name="line.226"></a>
-<span class="sourceLineNo">227</span>    // default is KeyValueCodec<a 
name="line.227"></a>
-<span class="sourceLineNo">228</span>    return c.get(DEFAULT_CODEC_CLASS, 
KeyValueCodec.class.getCanonicalName());<a name="line.228"></a>
-<span class="sourceLineNo">229</span>  }<a name="line.229"></a>
-<span class="sourceLineNo">230</span><a name="line.230"></a>
-<span class="sourceLineNo">231</span>  /**<a name="line.231"></a>
-<span class="sourceLineNo">232</span>   * Encapsulate the ugly casting and 
RuntimeException conversion in private method.<a name="line.232"></a>
-<span class="sourceLineNo">233</span>   * @return Codec to use on this 
client.<a name="line.233"></a>
-<span class="sourceLineNo">234</span>   */<a name="line.234"></a>
-<span class="sourceLineNo">235</span>  Codec getCodec() {<a 
name="line.235"></a>
-<span class="sourceLineNo">236</span>    // For NO CODEC, 
"hbase.client.rpc.codec" must be configured with empty string AND<a 
name="line.236"></a>
-<span class="sourceLineNo">237</span>    // "hbase.client.default.rpc.codec" 
also -- because default is to do cell block encoding.<a name="line.237"></a>
-<span class="sourceLineNo">238</span>    String className = 
conf.get(HConstants.RPC_CODEC_CONF_KEY, getDefaultCodec(this.conf));<a 
name="line.238"></a>
-<span class="sourceLineNo">239</span>    if (className == null || 
className.length() == 0) {<a name="line.239"></a>
-<span class="sourceLineNo">240</span>      return null;<a name="line.240"></a>
-<span class="sourceLineNo">241</span>    }<a name="line.241"></a>
-<span class="sourceLineNo">242</span>    try {<a name="line.242"></a>
-<span class="sourceLineNo">243</span>      return (Codec) 
Class.forName(className).newInstance();<a name="line.243"></a>
-<span class="sourceLineNo">244</span>    } catch (Exception e) {<a 
name="line.244"></a>
-<span class="sourceLineNo">245</span>      throw new RuntimeException("Failed 
getting codec " + className, e);<a name="line.245"></a>
-<span class="sourceLineNo">246</span>    }<a name="line.246"></a>
-<span class="sourceLineNo">247</span>  }<a name="line.247"></a>
-<span class="sourceLineNo">248</span><a name="line.248"></a>
-<span class="sourceLineNo">249</span>  @Override<a name="line.249"></a>
-<span class="sourceLineNo">250</span>  public boolean hasCellBlockSupport() 
{<a name="line.250"></a>
-<span class="sourceLineNo">251</span>    return this.codec != null;<a 
name="line.251"></a>
-<span class="sourceLineNo">252</span>  }<a name="line.252"></a>
-<span class="sourceLineNo">253</span><a name="line.253"></a>
-<span class="sourceLineNo">254</span>  // for writing tests that want to throw 
exception when connecting.<a name="line.254"></a>
-<span class="sourceLineNo">255</span>  @VisibleForTesting<a 
name="line.255"></a>
-<span class="sourceLineNo">256</span>  boolean isTcpNoDelay() {<a 
name="line.256"></a>
-<span class="sourceLineNo">257</span>    return tcpNoDelay;<a 
name="line.257"></a>
-<span class="sourceLineNo">258</span>  }<a name="line.258"></a>
-<span class="sourceLineNo">259</span><a name="line.259"></a>
-<span class="sourceLineNo">260</span>  /**<a name="line.260"></a>
-<span class="sourceLineNo">261</span>   * Encapsulate the ugly casting and 
RuntimeException conversion in private method.<a name="line.261"></a>
-<span class="sourceLineNo">262</span>   * @param conf configuration<a 
name="line.262"></a>
-<span class="sourceLineNo">263</span>   * @return The compressor to use on 
this client.<a name="line.263"></a>
-<span class="sourceLineNo">264</span>   */<a name="line.264"></a>
-<span class="sourceLineNo">265</span>  private static CompressionCodec 
getCompressor(final Configuration conf) {<a name="line.265"></a>
-<span class="sourceLineNo">266</span>    String className = 
conf.get("hbase.client.rpc.compressor", null);<a name="line.266"></a>
-<span class="sourceLineNo">267</span>    if (className == null || 
className.isEmpty()) {<a name="line.267"></a>
-<span class="sourceLineNo">268</span>      return null;<a name="line.268"></a>
-<span class="sourceLineNo">269</span>    }<a name="line.269"></a>
-<span class="sourceLineNo">270</span>    try {<a name="line.270"></a>
-<span class="sourceLineNo">271</span>      return (CompressionCodec) 
Class.forName(className).newInstance();<a name="line.271"></a>
-<span class="sourceLineNo">272</span>    } catch (Exception e) {<a 
name="line.272"></a>
-<span class="sourceLineNo">273</span>      throw new RuntimeException("Failed 
getting compressor " + className, e);<a name="line.273"></a>
-<span class="sourceLineNo">274</span>    }<a name="line.274"></a>
-<span class="sourceLineNo">275</span>  }<a name="line.275"></a>
-<span class="sourceLineNo">276</span><a name="line.276"></a>
-<span class="sourceLineNo">277</span>  /**<a name="line.277"></a>
-<span class="sourceLineNo">278</span>   * Return the pool type specified in 
the configuration, which must be set to either<a name="line.278"></a>
-<span class="sourceLineNo">279</span>   * {@link 
org.apache.hadoop.hbase.util.PoolMap.PoolType#RoundRobin} or<a 
name="line.279"></a>
-<span class="sourceLineNo">280</span>   * {@link 
org.apache.hadoop.hbase.util.PoolMap.PoolType#ThreadLocal}, otherwise default 
to the<a name="line.280"></a>
-<span class="sourceLineNo">281</span>   * former. For applications with many 
user threads, use a small round-robin pool. For applications<a 
name="line.281"></a>
-<span class="sourceLineNo">282</span>   * with few user threads, you may want 
to try using a thread-local pool. In any case, the number<a name="line.282"></a>
-<span class="sourceLineNo">283</span>   * of {@link 
org.apache.hadoop.hbase.ipc.RpcClient} instances should not exceed the 
operating<a name="line.283"></a>
-<span class="sourceLineNo">284</span>   * system's hard limit on the number of 
connections.<a name="line.284"></a>
-<span class="sourceLineNo">285</span>   * @param config configuration<a 
name="line.285"></a>
-<span class="sourceLineNo">286</span>   * @return either a {@link 
org.apache.hadoop.hbase.util.PoolMap.PoolType#RoundRobin} or<a 
name="line.286"></a>
-<span class="sourceLineNo">287</span>   *         {@link 
org.apache.hadoop.hbase.util.PoolMap.PoolType#ThreadLocal}<a 
name="line.287"></a>
-<span class="sourceLineNo">288</span>   */<a name="line.288"></a>
-<span class="sourceLineNo">289</span>  private static PoolMap.PoolType 
getPoolType(Configuration config) {<a name="line.289"></a>
-<span class="sourceLineNo">290</span>    return 
PoolMap.PoolType.valueOf(config.get(HConstants.HBASE_CLIENT_IPC_POOL_TYPE),<a 
name="line.290"></a>
-<span class="sourceLineNo">291</span>      PoolMap.PoolType.RoundRobin, 
PoolMap.PoolType.ThreadLocal);<a name="line.291"></a>
-<span class="sourceLineNo">292</span>  }<a name="line.292"></a>
-<span class="sourceLineNo">293</span><a name="line.293"></a>
-<span class="sourceLineNo">294</span>  /**<a name="line.294"></a>
-<span class="sourceLineNo">295</span>   * Return the pool size specified in 
the configuration, which is applicable only if the pool type<a 
name="line.295"></a>
-<span class="sourceLineNo">296</span>   * is {@link 
org.apache.hadoop.hbase.util.PoolMap.PoolType#RoundRobin}.<a 
name="line.296"></a>
-<span class="sourceLineNo">297</span>   * @param config configuration<a 
name="line.297"></a>
-<span class="sourceLineNo">298</span>   * @return the maximum pool size<a 
name="line.298"></a>
-<span class="sourceLineNo">299</span>   */<a name="line.299"></a>
-<span class="sourceLineNo">300</span>  private static int 
getPoolSize(Configuration config) {<a name="line.300"></a>
-<span class="sourceLineNo">301</span>    return 
config.getInt(HConstants.HBASE_CLIENT_IPC_POOL_SIZE, 1);<a name="line.301"></a>
-<span class="sourceLineNo">302</span>  }<a name="line.302"></a>
-<span class="sourceLineNo">303</span><a name="line.303"></a>
-<span class="sourceLineNo">304</span>  private int nextCallId() {<a 
name="line.304"></a>
-<span class="sourceLineNo">305</span>    int id, next;<a name="line.305"></a>
-<span class="sourceLineNo">306</span>    do {<a name="line.306"></a>
-<span class="sourceLineNo">307</span>      id = callIdCnt.get();<a 
name="line.307"></a>
-<span class="sourceLineNo">308</span>      next = id &lt; Integer.MAX_VALUE ? 
id + 1 : 0;<a name="line.308"></a>
-<span class="sourceLineNo">309</span>    } while (!callIdCnt.compareAndSet(id, 
next));<a name="line.309"></a>
-<span class="sourceLineNo">310</span>    return id;<a name="line.310"></a>
-<span class="sourceLineNo">311</span>  }<a name="line.311"></a>
-<span class="sourceLineNo">312</span><a name="line.312"></a>
-<span class="sourceLineNo">313</span>  /**<a name="line.313"></a>
-<span class="sourceLineNo">314</span>   * Make a blocking call. Throws 
exceptions if there are network problems or if the remote code<a 
name="line.314"></a>
-<span class="sourceLineNo">315</span>   * threw an exception.<a 
name="line.315"></a>
-<span class="sourceLineNo">316</span>   * @param ticket Be careful which 
ticket you pass. A new user will mean a new Connection.<a name="line.316"></a>
-<span class="sourceLineNo">317</span>   *          {@link 
UserProvider#getCurrent()} makes a new instance of User each time so will be 
a<a name="line.317"></a>
-<span class="sourceLineNo">318</span>   *          new Connection each time.<a 
name="line.318"></a>
-<span class="sourceLineNo">319</span>   * @return A pair with the Message 
response and the Cell data (if any).<a name="line.319"></a>
-<span class="sourceLineNo">320</span>   */<a name="line.320"></a>
-<span class="sourceLineNo">321</span>  private Message 
callBlockingMethod(Descriptors.MethodDescriptor md, HBaseRpcController hrc,<a 
name="line.321"></a>
-<span class="sourceLineNo">322</span>      Message param, Message returnType, 
final User ticket, final InetSocketAddress isa)<a name="line.322"></a>
-<span class="sourceLineNo">323</span>      throws ServiceException {<a 
name="line.323"></a>
-<span class="sourceLineNo">324</span>    BlockingRpcCallback&lt;Message&gt; 
done = new BlockingRpcCallback&lt;&gt;();<a name="line.324"></a>
-<span class="sourceLineNo">325</span>    callMethod(md, hrc, param, 
returnType, ticket, isa, done);<a name="line.325"></a>
-<span class="sourceLineNo">326</span>    Message val;<a name="line.326"></a>
-<span class="sourceLineNo">327</span>    try {<a name="line.327"></a>
-<span class="sourceLineNo">328</span>      val = done.get();<a 
name="line.328"></a>
-<span class="sourceLineNo">329</span>    } catch (IOException e) {<a 
name="line.329"></a>
-<span class="sourceLineNo">330</span>      throw new ServiceException(e);<a 
name="line.330"></a>
-<span class="sourceLineNo">331</span>    }<a name="line.331"></a>
-<span class="sourceLineNo">332</span>    if (hrc.failed()) {<a 
name="line.332"></a>
-<span class="sourceLineNo">333</span>      throw new 
ServiceException(hrc.getFailed());<a name="line.333"></a>
-<span class="sourceLineNo">334</span>    } else {<a name="line.334"></a>
-<span class="sourceLineNo">335</span>      return val;<a name="line.335"></a>
-<span class="sourceLineNo">336</span>    }<a name="line.336"></a>
-<span class="sourceLineNo">337</span>  }<a name="line.337"></a>
-<span class="sourceLineNo">338</span><a name="line.338"></a>
-<span class="sourceLineNo">339</span>  /**<a name="line.339"></a>
-<span class="sourceLineNo">340</span>   * Get a connection from the pool, or 
create a new one and add it to the pool. Connections to a<a name="line.340"></a>
-<span class="sourceLineNo">341</span>   * given host/port are reused.<a 
name="line.341"></a>
-<span class="sourceLineNo">342</span>   */<a name="line.342"></a>
-<span class="sourceLineNo">343</span>  private T getConnection(ConnectionId 
remoteId) throws IOException {<a name="line.343"></a>
-<span class="sourceLineNo">344</span>    if 
(failedServers.isFailedServer(remoteId.getAddress())) {<a name="line.344"></a>
-<span class="sourceLineNo">345</span>      if (LOG.isDebugEnabled()) {<a 
name="line.345"></a>
-<span class="sourceLineNo">346</span>        LOG.debug("Not trying to connect 
to " + remoteId.address<a name="line.346"></a>
-<span class="sourceLineNo">347</span>            + " this server is in the 
failed servers list");<a name="line.347"></a>
-<span class="sourceLineNo">348</span>      }<a name="line.348"></a>
-<span class="sourceLineNo">349</span>      throw new FailedServerException(<a 
name="line.349"></a>
-<span class="sourceLineNo">350</span>          "This server is in the failed 
servers list: " + remoteId.address);<a name="line.350"></a>
-<span class="sourceLineNo">351</span>    }<a name="line.351"></a>
-<span class="sourceLineNo">352</span>    T conn;<a name="line.352"></a>
-<span class="sourceLineNo">353</span>    synchronized (connections) {<a 
name="line.353"></a>
-<span class="sourceLineNo">354</span>      if (!running) {<a 
name="line.354"></a>
-<span class="sourceLineNo">355</span>        throw new 
StoppedRpcClientException();<a name="line.355"></a>
-<span class="sourceLineNo">356</span>      }<a name="line.356"></a>
-<span class="sourceLineNo">357</span>      conn = connections.get(remoteId);<a 
name="line.357"></a>
-<span class="sourceLineNo">358</span>      if (conn == null) {<a 
name="line.358"></a>
-<span class="sourceLineNo">359</span>        conn = 
createConnection(remoteId);<a name="line.359"></a>
-<span class="sourceLineNo">360</span>        connections.put(remoteId, 
conn);<a name="line.360"></a>
-<span class="sourceLineNo">361</span>      }<a name="line.361"></a>
-<span class="sourceLineNo">362</span>      
conn.setLastTouched(EnvironmentEdgeManager.currentTime());<a 
name="line.362"></a>
-<span class="sourceLineNo">363</span>    }<a name="line.363"></a>
-<span class="sourceLineNo">364</span>    return conn;<a name="line.364"></a>
-<span class="sourceLineNo">365</span>  }<a name="line.365"></a>
-<span class="sourceLineNo">366</span><a name="line.366"></a>
-<span class="sourceLineNo">367</span>  /**<a name="line.367"></a>
-<span class="sourceLineNo">368</span>   * Not connected.<a name="line.368"></a>
-<span class="sourceLineNo">369</span>   */<a name="line.369"></a>
-<span class="sourceLineNo">370</span>  protected abstract T 
createConnection(ConnectionId remoteId) throws IOException;<a 
name="line.370"></a>
-<span class="sourceLineNo">371</span><a name="line.371"></a>
-<span class="sourceLineNo">372</span>  private void onCallFinished(Call call, 
HBaseRpcController hrc, InetSocketAddress addr,<a name="line.372"></a>
-<span class="sourceLineNo">373</span>      RpcCallback&lt;Message&gt; 
callback) {<a name="line.373"></a>
-<span class="sourceLineNo">374</span>    
call.callStats.setCallTimeMs(EnvironmentEdgeManager.currentTime() - 
call.getStartTime());<a name="line.374"></a>
-<span class="sourceLineNo">375</span>    if (metrics != null) {<a 
name="line.375"></a>
-<span class="sourceLineNo">376</span>      metrics.updateRpc(call.md, 
call.param, call.callStats);<a name="line.376"></a>
-<span class="sourceLineNo">377</span>    }<a name="line.377"></a>
-<span class="sourceLineNo">378</span>    if (LOG.isTraceEnabled()) {<a 
name="line.378"></a>
-<span class="sourceLineNo">379</span>      LOG.trace(<a name="line.379"></a>
-<span class="sourceLineNo">380</span>        "Call: " + call.md.getName() + ", 
callTime: " + call.callStats.getCallTimeMs() + "ms");<a name="line.380"></a>
-<span class="sourceLineNo">381</span>    }<a name="line.381"></a>
-<span class="sourceLineNo">382</span>    if (call.error != null) {<a 
name="line.382"></a>
-<span class="sourceLineNo">383</span>      if (call.error instanceof 
RemoteException) {<a name="line.383"></a>
-<span class="sourceLineNo">384</span>        call.error.fillInStackTrace();<a 
name="line.384"></a>
-<span class="sourceLineNo">385</span>        hrc.setFailed(call.error);<a 
name="line.385"></a>
-<span class="sourceLineNo">386</span>      } else {<a name="line.386"></a>
-<span class="sourceLineNo">387</span>        hrc.setFailed(wrapException(addr, 
call.error));<a name="line.387"></a>
-<span class="sourceLineNo">388</span>      }<a name="line.388"></a>
-<span class="sourceLineNo">389</span>      callback.run(null);<a 
name="line.389"></a>
-<span class="sourceLineNo">390</span>    } else {<a name="line.390"></a>
-<span class="sourceLineNo">391</span>      hrc.setDone(call.cells);<a 
name="line.391"></a>
-<span class="sourceLineNo">392</span>      callback.run(call.response);<a 
name="line.392"></a>
-<span class="sourceLineNo">393</span>    }<a name="line.393"></a>
-<span class="sourceLineNo">394</span>  }<a name="line.394"></a>
-<span class="sourceLineNo">395</span><a name="line.395"></a>
-<span class="sourceLineNo">396</span>  private void callMethod(final 
Descriptors.MethodDescriptor md, final HBaseRpcController hrc,<a 
name="line.396"></a>
-<span class="sourceLineNo">397</span>      final Message param, Message 
returnType, final User ticket, final InetSocketAddress addr,<a 
name="line.397"></a>
-<span class="sourceLineNo">398</span>      final RpcCallback&lt;Message&gt; 
callback) {<a name="line.398"></a>
-<span class="sourceLineNo">399</span>    final MetricsConnection.CallStats cs 
= MetricsConnection.newCallStats();<a name="line.399"></a>
-<span class="sourceLineNo">400</span>    
cs.setStartTime(EnvironmentEdgeManager.currentTime());<a name="line.400"></a>
-<span class="sourceLineNo">401</span>    final AtomicInteger counter = 
concurrentCounterCache.getUnchecked(addr);<a name="line.401"></a>
-<span class="sourceLineNo">402</span>    Call call = new Call(nextCallId(), 
md, param, hrc.cellScanner(), returnType,<a name="line.402"></a>
-<span class="sourceLineNo">403</span>        hrc.getCallTimeout(), 
hrc.getPriority(), new RpcCallback&lt;Call&gt;() {<a name="line.403"></a>
-<span class="sourceLineNo">404</span>          @Override<a name="line.404"></a>
-<span class="sourceLineNo">405</span>          public void run(Call call) {<a 
name="line.405"></a>
-<span class="sourceLineNo">406</span>            counter.decrementAndGet();<a 
name="line.406"></a>
-<span class="sourceLineNo">407</span>            onCallFinished(call, hrc, 
addr, callback);<a name="line.407"></a>
-<span class="sourceLineNo">408</span>          }<a name="line.408"></a>
-<span class="sourceLineNo">409</span>        }, cs);<a name="line.409"></a>
-<span class="sourceLineNo">410</span>    ConnectionId remoteId = new 
ConnectionId(ticket, md.getService().getName(), addr);<a name="line.410"></a>
-<span class="sourceLineNo">411</span>    int count = 
counter.incrementAndGet();<a name="line.411"></a>
-<span class="sourceLineNo">412</span>    try {<a name="line.412"></a>
-<span class="sourceLineNo">413</span>      if (count &gt; 
maxConcurrentCallsPerServer) {<a name="line.413"></a>
-<span class="sourceLineNo">414</span>        throw new 
ServerTooBusyException(addr, count);<a name="line.414"></a>
-<span class="sourceLineNo">415</span>      }<a name="line.415"></a>
-<span class="sourceLineNo">416</span>      T connection = 
getConnection(remoteId);<a name="line.416"></a>
-<span class="sourceLineNo">417</span>      connection.sendRequest(call, 
hrc);<a name="line.417"></a>
-<span class="sourceLineNo">418</span>    } catch (Exception e) {<a 
name="line.418"></a>
-<span class="sourceLineNo">419</span>      call.setException(toIOE(e));<a 
name="line.419"></a>
-<span class="sourceLineNo">420</span>    }<a name="line.420"></a>
-<span class="sourceLineNo">421</span>  }<a name="line.421"></a>
-<span class="sourceLineNo">422</span><a name="line.422"></a>
-<span class="sourceLineNo">423</span>  private InetSocketAddress 
createAddr(ServerName sn) throws UnknownHostException {<a name="line.423"></a>
-<span class="sourceLineNo">424</span>    InetSocketAddress addr = new 
InetSocketAddress(sn.getHostname(), sn.getPort());<a name="line.424"></a>
-<span class="sourceLineNo">425</span>    if (addr.isUnresolved()) {<a 
name="line.425"></a>
-<span class="sourceLineNo">426</span>      throw new UnknownHostException("can 
not resolve " + sn.getServerName());<a name="line.426"></a>
-<span class="sourceLineNo">427</span>    }<a name="line.427"></a>
-<span class="sourceLineNo">428</span>    return addr;<a name="line.428"></a>
-<span class="sourceLineNo">429</span>  }<a name="line.429"></a>
-<span class="sourceLineNo">430</span><a name="line.430"></a>
-<span class="sourceLineNo">431</span>  /**<a name="line.431"></a>
-<span class="sourceLineNo">432</span>   * Interrupt the connections to the 
given ip:port server. This should be called if the server is<a 
name="line.432"></a>
-<span class="sourceLineNo">433</span>   * known as actually dead. This will 
not prevent current operation to be retried, and, depending<a 
name="line.433"></a>
-<span class="sourceLineNo">434</span>   * on their own behavior, they may 
retry on the same server. This can be a feature, for example at<a 
name="line.434"></a>
-<span class="sourceLineNo">435</span>   * startup. In any case, they're likely 
to get connection refused (if the process died) or no<a name="line.435"></a>
-<span class="sourceLineNo">436</span>   * route to host: i.e. their next 
retries should be faster and with a safe exception.<a name="line.436"></a>
-<span class="sourceLineNo">437</span>   */<a name="line.437"></a>
-<span class="sourceLineNo">438</span>  @Override<a name="line.438"></a>
-<span class="sourceLineNo">439</span>  public void 
cancelConnections(ServerName sn) {<a name="line.439"></a>
-<span class="sourceLineNo">440</span>    synchronized (connections) {<a 
name="line.440"></a>
-<span class="sourceLineNo">441</span>      for (T connection : 
connections.values()) {<a name="line.441"></a>
-<span class="sourceLineNo">442</span>        ConnectionId remoteId = 
connection.remoteId();<a name="line.442"></a>
-<span class="sourceLineNo">443</span>        if (remoteId.address.getPort() == 
sn.getPort()<a name="line.443"></a>
-<span class="sourceLineNo">444</span>            &amp;&amp; 
remoteId.address.getHostName().equals(sn.getHostname())) {<a 
name="line.444"></a>
-<span class="sourceLineNo">445</span>          LOG.info("The server on " + 
sn.toString() + " is dead - stopping the connection "<a name="line.445"></a>
-<span class="sourceLineNo">446</span>              + connection.remoteId);<a 
name="line.446"></a>
-<span class="sourceLineNo">447</span>          
connections.removeValue(remoteId, connection);<a name="line.447"></a>
-<span class="sourceLineNo">448</span>          connection.shutdown();<a 
name="line.448"></a>
-<span class="sourceLineNo">449</span>        }<a name="line.449"></a>
-<span class="sourceLineNo">450</span>      }<a name="line.450"></a>
-<span class="sourceLineNo">451</span>    }<a name="line.451"></a>
-<span class="sourceLineNo">452</span>  }<a name="line.452"></a>
-<span class="sourceLineNo">453</span>  /**<a name="line.453"></a>
-<span class="sourceLineNo">454</span>   * Configure an hbase rpccontroller<a 
name="line.454"></a>
-<span class="sourceLineNo">455</span>   * @param controller to configure<a 
name="line.455"></a>
-<span class="sourceLineNo">456</span>   * @param channelOperationTimeout 
timeout for operation<a name="line.456"></a>
-<span class="sourceLineNo">457</span>   * @return configured controller<a 
name="line.457"></a>
-<span class="sourceLineNo">458</span>   */<a name="line.458"></a>
-<span class="sourceLineNo">459</span>  static HBaseRpcController 
configureHBaseRpcController(<a name="line.459"></a>
-<span class="sourceLineNo">460</span>      RpcController controller, int 
channelOperationTimeout) {<a name="line.460"></a>
-<span class="sourceLineNo">461</span>    HBaseRpcController hrc;<a 
name="line.461"></a>
-<span class="sourceLineNo">462</span>    if (controller != null &amp;&amp; 
controller instanceof HBaseRpcController) {<a name="line.462"></a>
-<span class="sourceLineNo">463</span>      hrc = (HBaseRpcController) 
controller;<a name="line.463"></a>
-<span class="sourceLineNo">464</span>      if (!hrc.hasCallTimeout()) {<a 
name="line.464"></a>
-<span class="sourceLineNo">465</span>        
hrc.setCallTimeout(channelOperationTimeout);<a name="line.465"></a>
-<span class="sourceLineNo">466</span>      }<a name="line.466"></a>
-<span class="sourceLineNo">467</span>    } else {<a name="line.467"></a>
-<span class="sourceLineNo">468</span>      hrc = new 
HBaseRpcControllerImpl();<a name="line.468"></a>
-<span class="sourceLineNo">469</span>      
hrc.setCallTimeout(channelOperationTimeout);<a name="line.469"></a>
-<span class="sourceLineNo">470</span>    }<a name="line.470"></a>
-<span class="sourceLineNo">471</span>    return hrc;<a name="line.471"></a>
-<span class="sourceLineNo">472</span>  }<a name="line.472"></a>
-<span class="sourceLineNo">473</span><a name="line.473"></a>
-<span class="sourceLineNo">474</span>  protected abstract void 
closeInternal();<a name="line.474"></a>
+<span class="sourceLineNo">190</span>    this.cleanupIdleConnectionTask = 
IDLE_CONN_SWEEPER.scheduleAtFixedRate(new Runnable() {<a name="line.190"></a>
+<span class="sourceLineNo">191</span><a name="line.191"></a>
+<span class="sourceLineNo">192</span>      @Override<a name="line.192"></a>
+<span class="sourceLineNo">193</span>      public void run() {<a 
name="line.193"></a>
+<span class="sourceLineNo">194</span>        cleanupIdleConnections();<a 
name="line.194"></a>
+<span class="sourceLineNo">195</span>      }<a name="line.195"></a>
+<span class="sourceLineNo">196</span>    }, minIdleTimeBeforeClose, 
minIdleTimeBeforeClose, TimeUnit.MILLISECONDS);<a name="line.196"></a>
+<span class="sourceLineNo">197</span><a name="line.197"></a>
+<span class="sourceLineNo">198</span>    if (LOG.isDebugEnabled()) {<a 
name="line.198"></a>
+<span class="sourceLineNo">199</span>      LOG.debug("Codec=" + this.codec + 
", compressor=" + this.compressor + ", tcpKeepAlive="<a name="line.199"></a>
+<span class="sourceLineNo">200</span>          + this.tcpKeepAlive + ", 
tcpNoDelay=" + this.tcpNoDelay + ", connectTO=" + this.connectTO<a 
name="line.200"></a>
+<span class="sourceLineNo">201</span>          + ", readTO=" + this.readTO + 
", writeTO=" + this.writeTO + ", minIdleTimeBeforeClose="<a name="line.201"></a>
+<span class="sourceLineNo">202</span>          + this.minIdleTimeBeforeClose + 
", maxRetries=" + this.maxRetries + ", fallbackAllowed="<a name="line.202"></a>
+<span class="sourceLineNo">203</span>          + this.fallbackAllowed + ", 
bind address="<a name="line.203"></a>
+<span class="sourceLineNo">204</span>          + (this.localAddr != null ? 
this.localAddr : "null"));<a name="line.204"></a>
+<span class="sourceLineNo">205</span>    }<a name="line.205"></a>
+<span class="sourceLineNo">206</span>  }<a name="line.206"></a>
+<span class="sourceLineNo">207</span><a name="line.207"></a>
+<span class="sourceLineNo">208</span>  private void cleanupIdleConnections() 
{<a name="line.208"></a>
+<span class="sourceLineNo">209</span>    long closeBeforeTime = 
EnvironmentEdgeManager.currentTime() - minIdleTimeBeforeClose;<a 
name="line.209"></a>
+<span class="sourceLineNo">210</span>    synchronized (connections) {<a 
name="line.210"></a>
+<span class="sourceLineNo">211</span>      for (T conn : connections.values()) 
{<a name="line.211"></a>
+<span class="sourceLineNo">212</span>        // Remove connection if it has 
not been chosen by anyone for more than maxIdleTime, and the<a 
name="line.212"></a>
+<span class="sourceLineNo">213</span>        // connection itself has already 
shutdown. The latter check is because we may still<a name="line.213"></a>
+<span class="sourceLineNo">214</span>        // have some pending calls on 
connection so we should not shutdown the connection outside.<a 
name="line.214"></a>
+<span class="sourceLineNo">215</span>        // The connection itself will 
disconnect if there is no pending call for maxIdleTime.<a name="line.215"></a>
+<span class="sourceLineNo">216</span>        if (conn.getLastTouched() &lt; 
closeBeforeTime &amp;&amp; !conn.isActive()) {<a name="line.216"></a>
+<span class="sourceLineNo">217</span>          if (LOG.isTraceEnabled()) 
LOG.trace("Cleanup idle connection to " + conn.remoteId().address);<a 
name="line.217"></a>
+<span class="sourceLineNo">218</span>          
connections.removeValue(conn.remoteId(), conn);<a name="line.218"></a>
+<span class="sourceLineNo">219</span>          conn.cleanupConnection();<a 
name="line.219"></a>
+<span class="sourceLineNo">220</span>        }<a name="line.220"></a>
+<span class="sourceLineNo">221</span>      }<a name="line.221"></a>
+<span class="sourceLineNo">222</span>    }<a name="line.222"></a>
+<span class="sourceLineNo">223</span>  }<a name="line.223"></a>
+<span class="sourceLineNo">224</span><a name="line.224"></a>
+<span class="sourceLineNo">225</span>  @VisibleForTesting<a 
name="line.225"></a>
+<span class="sourceLineNo">226</span>  public static String 
getDefaultCodec(final Configuration c) {<a name="line.226"></a>
+<span class="sourceLineNo">227</span>    // If 
"hbase.client.default.rpc.codec" is empty string -- you can't set it to null 
because<a name="line.227"></a>
+<span class="sourceLineNo">228</span>    // Configuration will complain -- 
then no default codec (and we'll pb everything). Else<a name="line.228"></a>
+<span class="sourceLineNo">229</span>    // default is KeyValueCodec<a 
name="line.229"></a>
+<span class="sourceLineNo">230</span>    return c.get(DEFAULT_CODEC_CLASS, 
KeyValueCodec.class.getCanonicalName());<a name="line.230"></a>
+<span class="sourceLineNo">231</span>  }<a name="line.231"></a>
+<span class="sourceLineNo">232</span><a name="line.232"></a>
+<span class="sourceLineNo">233</span>  /**<a name="line.233"></a>
+<span class="sourceLineNo">234</span>   * Encapsulate the ugly casting and 
RuntimeException conversion in private method.<a name="line.234"></a>
+<span class="sourceLineNo">235</span>   * @return Codec to use on this 
client.<a name="line.235"></a>
+<span class="sourceLineNo">236</span>   */<a name="line.236"></a>
+<span class="sourceLineNo">237</span>  Codec getCodec() {<a 
name="line.237"></a>
+<span class="sourceLineNo">238</span>    // For NO CODEC, 
"hbase.client.rpc.codec" must be configured with empty string AND<a 
name="line.238"></a>
+<span class="sourceLineNo">239</span>    // "hbase.client.default.rpc.codec" 
also -- because default is to do cell block encoding.<a name="line.239"></a>
+<span class="sourceLineNo">240</span>    String className = 
conf.get(HConstants.RPC_CODEC_CONF_KEY, getDefaultCodec(this.conf));<a 
name="line.240"></a>
+<span class="sourceLineNo">241</span>    if (className == null || 
className.length() == 0) {<a name="line.241"></a>
+<span class="sourceLineNo">242</span>      return null;<a name="line.242"></a>
+<span class="sourceLineNo">243</span>    }<a name="line.243"></a>
+<span class="sourceLineNo">244</span>    try {<a name="line.244"></a>
+<span class="sourceLineNo">245</span>      return (Codec) 
Class.forName(className).newInstance();<a name="line.245"></a>
+<span class="sourceLineNo">246</span>    } catch (Exception e) {<a 
name="line.246"></a>
+<span class="sourceLineNo">247</span>      throw new RuntimeException("Failed 
getting codec " + className, e);<a name="line.247"></a>
+<span class="sourceLineNo">248</span>    }<a name="line.248"></a>
+<span class="sourceLineNo">249</span>  }<a name="line.249"></a>
+<span class="sourceLineNo">250</span><a name="line.250"></a>
+<span class="sourceLineNo">251</span>  @Override<a name="line.251"></a>
+<span class="sourceLineNo">252</span>  public boolean hasCellBlockSupport() 
{<a name="line.252"></a>
+<span class="sourceLineNo">253</span>    return this.codec != null;<a 
name="line.253"></a>
+<span class="sourceLineNo">254</span>  }<a name="line.254"></a>
+<span class="sourceLineNo">255</span><a name="line.255"></a>
+<span class="sourceLineNo">256</span>  // for writing tests that want to throw 
exception when connecting.<a name="line.256"></a>
+<span class="sourceLineNo">257</span>  @VisibleForTesting<a 
name="line.257"></a>
+<span class="sourceLineNo">258</span>  boolean isTcpNoDelay() {<a 
name="line.258"></a>
+<span class="sourceLineNo">259</span>    return tcpNoDelay;<a 
name="line.259"></a>
+<span class="sourceLineNo">260</span>  }<a name="line.260"></a>
+<span class="sourceLineNo">261</span><a name="line.261"></a>
+<span class="sourceLineNo">262</span>  /**<a name="line.262"></a>
+<span class="sourceLineNo">263</span>   * Encapsulate the ugly casting and 
RuntimeException conversion in private method.<a name="line.263"></a>
+<span class="sourceLineNo">264</span>   * @param conf configuration<a 
name="line.264"></a>
+<span class="sourceLineNo">265</span>   * @return The compressor to use on 
this client.<a name="line.265"></a>
+<span class="sourceLineNo">266</span>   */<a name="line.266"></a>
+<span class="sourceLineNo">267</span>  private static CompressionCodec 
getCompressor(final Configuration conf) {<a name="line.267"></a>
+<span class="sourceLineNo">268</span>    String className = 
conf.get("hbase.client.rpc.compressor", null);<a name="line.268"></a>
+<span class="sourceLineNo">269</span>    if (className == null || 
className.isEmpty()) {<a name="line.269"></a>
+<span class="sourceLineNo">270</span>      return null;<a name="line.270"></a>
+<span class="sourceLineNo">271</span>    }<a name="line.271"></a>
+<span class="sourceLineNo">272</span>    try {<a name="line.272"></a>
+<span class="sourceLineNo">273</span>      return (CompressionCodec) 
Class.forName(className).newInstance();<a name="line.273"></a>
+<span class="sourceLineNo">274</span>    } catch (Exception e) {<a 
name="line.274"></a>
+<span class="sourceLineNo">275</span>      throw new RuntimeException("Failed 
getting compressor " + className, e);<a name="line.275"></a>
+<span class="sourceLineNo">276</span>    }<a name="line.276"></a>
+<span class="sourceLineNo">277</span>  }<a name="line.277"></a>
+<span class="sourceLineNo">278</span><a name="line.278"></a>
+<span class="sourceLineNo">279</span>  /**<a name="line.279"></a>
+<span class="sourceLineNo">280</span>   * Return the pool type specified in 
the configuration, which must be set to either<a name="line.280"></a>
+<span class="sourceLineNo">281</span>   * {@link 
org.apache.hadoop.hbase.util.PoolMap.PoolType#RoundRobin} or<a 
name="line.281"></a>
+<span class="sourceLineNo">282</span>   * {@link 
org.apache.hadoop.hbase.util.PoolMap.PoolType#ThreadLocal}, otherwise default 
to the<a name="line.282"></a>
+<span class="sourceLineNo">283</span>   * former. For applications with many 
user threads, use a small round-robin pool. For applications<a 
name="line.283"></a>
+<span class="sourceLineNo">284</span>   * with few user threads, you may want 
to try using a thread-local pool. In any case, the number<a name="line.284"></a>
+<span class="sourceLineNo">285</span>   * of {@link 
org.apache.hadoop.hbase.ipc.RpcClient} instances should not exceed the 
operating<a name="line.285"></a>
+<span class="sourceLineNo">286</span>   * system's hard limit on the number of 
connections.<a name="line.286"></a>
+<span class="sourceLineNo">287</span>   * @param config configuration<a 
name="line.287"></a>
+<span class="sourceLineNo">288</span>   * @return either a {@link 
org.apache.hadoop.hbase.util.PoolMap.PoolType#RoundRobin} or<a 
name="line.288"></a>
+<span class="sourceLineNo">289</span>   *         {@link 
org.apache.hadoop.hbase.util.PoolMap.PoolType#ThreadLocal}<a 
name="line.289"></a>
+<span class="sourceLineNo">290</span>   */<a name="line.290"></a>
+<span class="sourceLineNo">291</span>  private static PoolMap.PoolType 
getPoolType(Configuration config) {<a name="line.291"></a>
+<span class="sourceLineNo">292</span>    return 
PoolMap.PoolType.valueOf(config.get(HConstants.HBASE_CLIENT_IPC_POOL_TYPE),<a 
name="line.292"></a>
+<span class="sourceLineNo">293</span>      PoolMap.PoolType.RoundRobin, 
PoolMap.PoolType.ThreadLocal);<a name="line.293"></a>
+<span class="sourceLineNo">294</span>  }<a name="line.294"></a>
+<span class="sourceLineNo">295</span><a name="line.295"></a>
+<span class="sourceLineNo">296</span>  /**<a name="line.296"></a>
+<span class="sourceLineNo">297</span>   * Return the pool size specified in 
the configuration, which is applicable only if the pool type<a 
name="line.297"></a>
+<span class="sourceLineNo">298</span>   * is {@link 
org.apache.hadoop.hbase.util.PoolMap.PoolType#RoundRobin}.<a 
name="line.298"></a>
+<span class="sourceLineNo">299</span>   * @param config configuration<a 
name="line.299"></a>
+<span class="sourceLineNo">300</span>   * @return the maximum pool size<a 
name="line.300"></a>
+<span class="sourceLineNo">301</span>   */<a name="line.301"></a>
+<span class="sourceLineNo">302</span>  private static int 
getPoolSize(Configuration config) {<a name="line.302"></a>
+<span class="sourceLineNo">303</span>    return 
config.getInt(HConstants.HBASE_CLIENT_IPC_POOL_SIZE, 1);<a name="line.303"></a>
+<span class="sourceLineNo">304</span>  }<a name="line.304"></a>
+<span class="sourceLineNo">305</span><a name="line.305"></a>
+<span class="sourceLineNo">306</span>  private int nextCallId() {<a 
name="line.306"></a>
+<span class="sourceLineNo">307</span>    int id, next;<a name="line.307"></a>
+<span class="sourceLineNo">308</span>    do {<a name="line.308"></a>
+<span class="sourceLineNo">309</span>      id = callIdCnt.get();<a 
name="line.309"></a>
+<span class="sourceLineNo">310</span>      next = id &lt; Integer.MAX_VALUE ? 
id + 1 : 0;<a name="line.310"></a>
+<span class="sourceLineNo">311</span>    } while (!callIdCnt.compareAndSet(id, 
next));<a name="line.311"></a>
+<span class="sourceLineNo">312</span>    return id;<a name="line.312"></a>
+<span class="sourceLineNo">313</span>  }<a name="line.313"></a>
+<span class="sourceLineNo">314</span><a name="line.314"></a>
+<span class="sourceLineNo">315</span>  /**<a name="line.315"></a>
+<span class="sourceLineNo">316</span>   * Make a blocking call. Throws 
exceptions if there are network problems or if the remote code<a 
name="line.316"></a>
+<span class="sourceLineNo">317</span>   * threw an exception.<a 
name="line.317"></a>
+<span class="sourceLineNo">318</span>   * @param ticket Be careful which 
ticket you pass. A new user will mean a new Connection.<a name="line.318"></a>
+<span class="sourceLineNo">319</span>   *          {@link 
UserProvider#getCurrent()} makes a new instance of User each time so will be 
a<a name="line.319"></a>
+<span class="sourceLineNo">320</span>   *          new Connection each time.<a 
name="line.320"></a>
+<span class="sourceLineNo">321</span>   * @return A pair with the Message 
response and the Cell data (if any).<a name="line.321"></a>
+<span class="sourceLineNo">322</span>   */<a name="line.322"></a>
+<span class="sourceLineNo">323</span>  private Message 
callBlockingMethod(Descriptors.MethodDescriptor md, HBaseRpcController hrc,<a 
name="line.323"></a>
+<span class="sourceLineNo">324</span>      Message param, Message returnType, 
final User ticket, final InetSocketAddress isa)<a name="line.324"></a>
+<span class="sourceLineNo">325</span>      throws ServiceException {<a 
name="line.325"></a>
+<span class="sourceLineNo">326</span>    BlockingRpcCallback&lt;Message&gt; 
done = new BlockingRpcCallback&lt;&gt;();<a name="line.326"></a>
+<span class="sourceLineNo">327</span>    callMethod(md, hrc, param, 
returnType, ticket, isa, done);<a name="line.327"></a>
+<span class="sourceLineNo">328</span>    Message val;<a name="line.328"></a>
+<span class="sourceLineNo">329</span>    try {<a name="line.329"></a>
+<span class="sourceLineNo">330</span>      val = done.get();<a 
name="line.330"></a>
+<span class="sourceLineNo">331</span>    } catch (IOException e) {<a 
name="line.331"></a>
+<span class="sourceLineNo">332</span>      throw new ServiceException(e);<a 
name="line.332"></a>
+<span class="sourceLineNo">333</span>    }<a name="line.333"></a>
+<span class="sourceLineNo">334</span>    if (hrc.failed()) {<a 
name="line.334"></a>
+<span class="sourceLineNo">335</span>      throw new 
ServiceException(hrc.getFailed());<a name="line.335"></a>
+<span class="sourceLineNo">336</span>    } else {<a name="line.336"></a>
+<span class="sourceLineNo">337</span>      return val;<a name="line.337"></a>
+<span class="sourceLineNo">338</span>    }<a name="line.338"></a>
+<span class="sourceLineNo">339</span>  }<a name="line.339"></a>
+<span class="sourceLineNo">340</span><a name="line.340"></a>
+<span class="sourceLineNo">341</span>  /**<a name="line.341"></a>
+<span class="sourceLineNo">342</span>   * Get a connection from the pool, or 
create a new one and add it to the pool. Connections to a<a name="line.342"></a>
+<span class="sourceLineNo">343</span>   * given host/port are reused.<a 
name="line.343"></a>
+<span class="sourceLineNo">344</span>   */<a name="line.344"></a>
+<span class="sourceLineNo">345</span>  private T getConnection(ConnectionId 
remoteId) throws IOException {<a name="line.345"></a>
+<span class="sourceLineNo">346</span>    if 
(failedServers.isFailedServer(remoteId.getAddress())) {<a name="line.346"></a>
+<span class="sourceLineNo">347</span>      if (LOG.isDebugEnabled()) {<a 
name="line.347"></a>
+<span class="sourceLineNo">348</span>        LOG.debug("Not trying to connect 
to " + remoteId.address<a name="line.348"></a>
+<span class="sourceLineNo">349</span>            + " this server is in the 
failed servers list");<a name="line.349"></a>
+<span class="sourceLineNo">350</span>      }<a name="line.350"></a>
+<span class="sourceLineNo">351</span>      throw new FailedServerException(<a 
name="line.351"></a>
+<span class="sourceLineNo">352</span>          "This server is in the failed 
servers list: " + remoteId.address);<a name="line.352"></a>
+<span class="sourceLineNo">353</span>    }<a name="line.353"></a>
+<span class="sourceLineNo">354</span>    T conn;<a name="line.354"></a>
+<span class="sourceLineNo">355</span>    synchronized (connections) {<a 
name="line.355"></a>
+<span class="sourceLineNo">356</span>      if (!running) {<a 
name="line.356"></a>
+<span class="sourceLineNo">357</span>        throw new 
StoppedRpcClientException();<a name="line.357"></a>
+<span class="sourceLineNo">358</span>      }<a name="line.358"></a>
+<span class="sourceLineNo">359</span>      conn = connections.get(remoteId);<a 
name="line.359"></a>
+<span class="sourceLineNo">360</span>      if (conn == null) {<a 
name="line.360"></a>
+<span class="sourceLineNo">361</span>        conn = 
createConnection(remoteId);<a name="line.361"></a>
+<span class="sourceLineNo">362</span>        connections.put(remoteId, 
conn);<a name="line.362"></a>
+<span class="sourceLineNo">363</span>      }<a name="line.363"></a>
+<span class="sourceLineNo">364</span>      
conn.setLastTouched(EnvironmentEdgeManager.currentTime());<a 
name="line.364"></a>
+<span class="sourceLineNo">365</span>    }<a name="line.365"></a>
+<span class="sourceLineNo">366</span>    return conn;<a name="line.366"></a>
+<span class="sourceLineNo">367</span>  }<a name="line.367"></a>
+<span class="sourceLineNo">368</span><a name="line.368"></a>
+<span class="sourceLineNo">369</span>  /**<a name="line.369"></a>
+<span class="sourceLineNo">370</span>   * Not connected.<a name="line.370"></a>
+<span class="sourceLineNo">371</span>   */<a name="line.371"></a>
+<span class="sourceLineNo">372</span>  protected abstract T 
createConnection(ConnectionId remoteId) throws IOException;<a 
name="line.372"></a>
+<span class="sourceLineNo">373</span><a name="line.373"></a>
+<span class="sourceLineNo">374</span>  private void onCallFinished(Call call, 
HBaseRpcController hrc, InetSocketAddress addr,<a name="line.374"></a>
+<span class="sourceLineNo">375</span>      RpcCallback&lt;Message&gt; 
callback) {<a name="line.375"></a>
+<span class="sourceLineNo">376</span>    
call.callStats.setCallTimeMs(EnvironmentEdgeManager.currentTime() - 
call.getStartTime());<a name="line.376"></a>
+<span class="sourceLineNo">377</span>    if (metrics != null) {<a 
name="line.377"></a>
+<span class="sourceLineNo">378</span>      metrics.updateRpc(call.md, 
call.param, call.callStats);<a name="line.378"></a>
+<span class="sourceLineNo">379</span>    }<a name="line.379"></a>
+<span class="sourceLineNo">380</span>    if (LOG.isTraceEnabled()) {<a 
name="line.380"></a>
+<span class="sourceLineNo">381</span>      LOG.trace(<a name="line.381"></a>
+<span class="sourceLineNo">382</span>        "Call: " + call.md.getName() + ", 
callTime: " + call.callStats.getCallTimeMs() + "ms");<a name="line.382"></a>
+<span class="sourceLineNo">383</span>    }<a name="line.383"></a>
+<span class="sourceLineNo">384</span>    if (call.error != null) {<a 
name="line.384"></a>
+<span class="sourceLineNo">385</span>      if (call.error instanceof 
RemoteException) {<a name="line.385"></a>
+<span class="sourceLineNo">386</span>        call.error.fillInStackTrace();<a 
name="line.386"></a>
+<span class="sourceLineNo">387</span>        hrc.setFailed(call.error);<a 
name="line.387"></a>
+<span class="sourceLineNo">388</span>      } else {<a name="line.388"></a>
+<span class="sourceLineNo">389</span>        hrc.setFailed(wrapException(addr, 
call.error));<a name="line.389"></a>
+<span class="sourceLineNo">390</span>      }<a name="line.390"></a>
+<span class="sourceLineNo">391</span>      callback.run(null);<a 
name="line.391"></a>
+<span class="sourceLineNo">392</span>    } else {<a name="line.392"></a>
+<span class="sourceLineNo">393</span>      hrc.setDone(call.cells);<a 
name="line.393"></a>
+<span class="sourceLineNo">394</span>      callback.run(call.response);<a 
name="line.394"></a>
+<span class="sourceLineNo">395</span>    }<a name="line.395"></a>
+<span class="sourceLineNo">396</span>  }<a name="line.396"></a>
+<span class="sourceLineNo">397</span><a name="line.397"></a>
+<span class="sourceLineNo">398</span>  private void callMethod(final 
Descriptors.MethodDescriptor md, final HBaseRpcController hrc,<a 
name="line.398"></a>
+<span class="sourceLineNo">399</span>      final Message param, Message 
returnType, final User ticket, final InetSocketAddress addr,<a 
name="line.399"></a>
+<span class="sourceLineNo">400</span>      final RpcCallback&lt;Message&gt; 
callback) {<a name="line.400"></a>
+<span class="sourceLineNo">401</span>    final MetricsConnection.CallStats cs 
= MetricsConnection.newCallStats();<a name="line.401"></a>
+<span class="sourceLineNo">402</span>    
cs.setStartTime(EnvironmentEdgeManager.currentTime());<a name="line.402"></a>
+<span class="sourceLineNo">403</span>    final AtomicInteger counter = 
concurrentCounterCache.getUnchecked(addr);<a name="line.403"></a>
+<span class="sourceLineNo">404</span>    Call call = new Call(nextCallId(), 
md, param, hrc.cellScanner(), returnType,<a name="line.404"></a>
+<span class="sourceLineNo">405</span>        hrc.getCallTimeout(), 
hrc.getPriority(), new RpcCallback&lt;Call&gt;() {<a name="line.405"></a>
+<span class="sourceLineNo">406</span>          @Override<a name="line.406"></a>
+<span class="sourceLineNo">407</span>          public void run(Call call) {<a 
name="line.407"></a>
+<span class="sourceLineNo">408</span>            counter.decrementAndGet();<a 
name="line.408"></a>
+<span class="sourceLineNo">409</span>            onCallFinished(call, hrc, 
addr, callback);<a name="line.409"></a>
+<span class="sourceLineNo">410</span>          }<a name="line.410"></a>
+<span class="sourceLineNo">411</span>        }, cs);<a name="line.411"></a>
+<span class="sourceLineNo">412</span>    ConnectionId remoteId = new 
ConnectionId(ticket, md.getService().getName(), addr);<a name="line.412"></a>
+<span class="sourceLineNo">413</span>    int count = 
counter.incrementAndGet();<a name="line.413"></a>
+<span class="sourceLineNo">414</span>    try {<a name="line.414"></a>
+<span class="sourceLineNo">415</span>      if (count &gt; 
maxConcurrentCallsPerServer) {<a name="line.415"></a>
+<span class="sourceLineNo">416</span>        throw new 
ServerTooBusyException(addr, count);<a name="line.416"></a>
+<span class="sourceLineNo">417</span>      }<a name="line.417"></a>
+<span class="sourceLineNo">418</span>      T connection = 
getConnection(remoteId);<a name="line.418"></a>
+<span class="sourceLineNo">419</span>      connection.sendRequest(call, 
hrc);<a name="line.419"></a>
+<span class="sourceLineNo">420</span>    } catch (Exception e) {<a 
name="line.420"></a>
+<span class="sourceLineNo">421</span>      call.setException(toIOE(e));<a 
name="line.421"></a>
+<span class="sourceLineNo">422</span>    }<a name="line.422"></a>
+<span class="sourceLineNo">423</span>  }<a name="line.423"></a>
+<span class="sourceLineNo">424</span><a name="line.424"></a>
+<span class="sourceLineNo">425</span>  private InetSocketAddress 
createAddr(ServerName sn) throws UnknownHostException {<a name="line.425"></a>
+<span class="sourceLineNo">426</span>    InetSocketAddress addr = new 
InetSocketAddress(sn.getHostname(), sn.getPort());<a name="line.426"></a>
+<span class="sourceLineNo">427</span>    if (addr.isUnresolved()) {<a 
name="line.427"></a>
+<span class="sourceLineNo">428</span>      throw new UnknownHostException("can 
not resolve " + sn.getServerName());<a name="line.428"></a>
+<span class="sourceLineNo">429</span>    }<a name="line.429"></a>
+<span class="sourceLineNo">430</span>    return addr;<a name="line.430"></a>
+<span class="sourceLineNo">431</span>  }<a name="line.431"></a>
+<span class="sourceLineNo">432</span><a name="line.432"></a>
+<span class="sourceLineNo">433</span>  /**<a name="line.433"></a>
+<span class="sourceLineNo">434</span>   * Interrupt the connections to the 
given ip:port server. This should be called if the server is<a 
name="line.434"></a>
+<span class="sourceLineNo">435</span>   * known as actually dead. This will 
not prevent current operation to be retried, and, depending<a 
name="line.435"></a>
+<span class="sourceLineNo">436</span>   * on their own behavior, they may 
retry on the same server. This can be a feature, for example at<a 
name="line.436"></a>
+<span class="sourceLineNo">437</span>   * startup. In any case, they're likely 
to get connection refused (if the process died) or no<a name="line.437"></a>
+<span class="sourceLineNo">438</span>   * route to host: i.e. their next 
retries should be faster and with a safe exception.<a name="line.438"></a>
+<span class="sourceLineNo">439</span>   */<a name="line.439"></a>
+<span class="sourceLineNo">440</span>  @Override<a name="line.440"></a>
+<span class="sourceLineNo">441</span>  public void 
cancelConnections(ServerName sn) {<a name="line.441"></a>
+<span class="sourceLineNo">442</span>    synchronized (connections) {<a 
name="line.442"></a>
+<span class="sourceLineNo">443</span>      for (T connection : 
connections.values()) {<a name="line.443"></a>
+<span class="sourceLineNo">444</span>        ConnectionId remoteId = 
connection.remoteId();<a name="line.444"></a>
+<span class="sourceLineNo">445</span>        if (remoteId.address.getPort() == 
sn.getPort()<a name="line.445"></a>
+<span class="sourceLineNo">446</span>            &amp;&amp; 
remoteId.address.getHostName().equals(sn.getHostname())) {<a 
name="line.446"></a>
+<span class="sourceLineNo">447</span>          LOG.info("The server on " + 
sn.toString() + " is dead - stopping the connection "<a name="line.447"></a>
+<span class="sourceLineNo">448</span>              + connection.remoteId);<a 
name="line.448"></a>
+<span class="sourceLineNo">449</span>          
connections.removeValue(remoteId, connection);<a name="line.449"></a>
+<span class="sourceLineNo">450</span>          connection.shutdown();<a 
name="line.450"></a>
+<span class="sourceLineNo">451</span>        }<a name="line.451"></a>
+<span class="sourceLineNo">452</span>      }<a name="line.452"></a>
+<span class="sourceLineNo">453</span>    }<a name="line.453"></a>
+<span class="sourceLineNo">454</span>  }<a name="line.454"></a>
+<span class="sourceLineNo">455</span>  /**<a name="line.455"></a>
+<span class="sourceLineNo">456</span>   * Configure an hbase rpccontroller<a 
name="line.456"></a>
+<span class="sourceLineNo">457</span>   * @param controller to configure<a 
name="line.457"></a>
+<span class="sourceLineNo">458</span>   * @param channelOperationTimeout 
timeout for operation<a name="line.458"></a>
+<span class="sourceLineNo">459</span>   * @return configured controller<a 
name="line.459"></a>
+<span class="sourceLineNo">460</span>   */<a name="line.460"></a>
+<span class="sourceLineNo">461</span>  static HBaseRpcController 
configureHBaseRpcController(<a name="line.461"></a>
+<span class="sourceLineNo">462</span>      RpcController controller, int 
channelOperationTimeout) {<a name="line.462"></a>
+<span class="sourceLineNo">463</span>    HBaseRpcController hrc;<a 
name="line.463"></a>
+<span class="sourceLineNo">464</span>    if (controller != null &amp;&amp; 
controller instanceof HBaseRpcController) {<a name="line.464"></a>
+<span class="sourceLineNo">465</span>      hrc = (HBaseRpcController) 
controller;<a name="line.465"></a>
+<span class="sourceLineNo">466</span>      if (!hrc.hasCallTimeout()) {<a 
name="line.466"></a>
+<span class="sourceLineNo">467</span>        
hrc.setCallTimeout(channelOperationTimeout);<a name="line.467"></a>
+<span class="sourceLineNo">468</span>      }<a name="line.468"></a>
+<span class="sourceLineNo">469</span>    } else {<a name="line.469"></a>
+<span class="sourceLineNo">470</span>      hrc = new 
HBaseRpcControllerImpl();<a name="line.470"></a>
+<span class="sourceLineNo">471</span>      
hrc.setCallTimeout(channelOperationTimeout);<a name="line.471"></a>
+<span class="sourceLineNo">472</span>    }<a name="line.472"></a>
+<span class="sourceLineNo">473</span>    return hrc;<a name="line.473"></a>
+<span class="sourceLineNo">474</span>  }<a name="line.474"></a>
 <span class="sourceLineNo">475</span><a name="line.475"></a>
-<span class="sourceLineNo">476</span>  @Override<a name="line.476"></a>
-<span class="sourceLineNo">477</span>  public void close() {<a 
name="line.477"></a>
-<span class="sourceLineNo">478</span>    if (LOG.isDebugEnabled()) {<a 
name="line.478"></a>
-<span class="sourceLineNo">479</span>      LOG.debug("Stopping rpc client");<a 
name="line.479"></a>
-<span class="sourceLineNo">480</span>    }<a name="line.480"></a>
-<span class="sourceLineNo">481</span>    Collection&lt;T&gt; connToClose;<a 
name="line.481"></a>
-<span class="sourceLineNo">482</span>    synchronized (connections) {<a 
name="line.482"></a>
-<span class="sourceLineNo">483</span>      if (!running) {<a 
name="line.483"></a>
-<span class="sourceLineNo">484</span>        return;<a name="line.484"></a>
-<span class="sourceLineNo">485</span>      }<a name="line.485"></a>
-<span class="sourceLineNo">486</span>      running = false;<a 
name="line.486"></a>
-<span class="sourceLineNo">487</span>      connToClose = 
connections.values();<a name="line.487"></a>
-<span class="sourceLineNo">488</span>      connections.clear();<a 
name="line.488"></a>
-<span class="sourceLineNo">489</span>    }<a name="line.489"></a>
-<span class="sourceLineNo">490</span>    
cleanupIdleConnectionTask.cancel(true);<a name="line.490"></a>
-<span class="sourceLineNo">491</span>    for (T conn : connToClose) {<a 
name="line.491"></a>
-<span class="sourceLineNo">492</span>      conn.shutdown();<a 
name="line.492"></a>
-<span class="sourceLineNo">493</span>    }<a name="line.493"></a>
-<span class="sourceLineNo">494</span>    closeInternal();<a 
name="line.494"></a>
-<span class="sourceLineNo">495</span>    for (T conn : connToClose) {<a 
name="line.495"></a>
-<span class="sourceLineNo">496</span>      conn.cleanupConnection();<a 
name="line.496"></a>
-<span class="sourceLineNo">497</span>    }<a name="line.497"></a>
-<span class="sourceLineNo">498</span>  }<a name="line.498"></a>
-<span class="sourceLineNo">499</span><a name="line.499"></a>
-<span class="sourceLineNo">500</span>  @Override<a name="line.500"></a>
-<span class="sourceLineNo">501</span>  public BlockingRpcChannel 
createBlockingRpcChannel(final ServerName sn, final User ticket,<a 
name="line.501"></a>
-<span class="sourceLineNo">502</span>      int rpcTimeout) throws 
UnknownHostException {<a name="line.502"></a>
-<span class="sourceLineNo">503</span>    return new 
BlockingRpcChannelImplementation(this, createAddr(sn), ticket, rpcTimeout);<a 
name="line.503"></a>
-<span class="sourceLineNo">504</span>  }<a name="line.504"></a>
-<span class="sourceLineNo">505</span><a name="line.505"></a>
-<span class="sourceLineNo">506</span>  @Override<a name="line.506"></a>
-<span class="sourceLineNo">507</span>  public RpcChannel 
createRpcChannel(ServerName sn, User user, int rpcTimeout)<a 
name="line.507"></a>
-<span class="sourceLineNo">508</span>      throws UnknownHostException {<a 
name="line.508"></a>
-<span class="sourceLineNo">509</span>    return new 
RpcChannelImplementation(this, createAddr(sn), user, rpcTimeout);<a 
name="line.509"></a>
-<span class="sourceLineNo">510</span>  }<a name="line.510"></a>
-<span class="sourceLineNo">511</span><a name="line.511"></a>
-<span class="sourceLineNo">512</span>  private static class AbstractRpcChannel 
{<a name="line.512"></a>
+<span class="sourceLineNo">476</span>  protected abstract void 
closeInternal();<a name="line.476"></a>
+<span class="sourceLineNo">477</span><a name="line.477"></a>
+<span class="sourceLineNo">478</span>  @Override<a name="line.478"></a>
+<span class="sourceLineNo">479</span>  public void close() {<a 
name="line.479"></a>
+<span class="sourceLineNo">480</span>    if (LOG.isDebugEnabled()) {<a 
name="line.480"></a>
+<span class="sourceLineNo">481</span>      LOG.debug("Stopping rpc client");<a 
name="line.481"></a>
+<span class="sourceLineNo">482</span>    }<a name="line.482"></a>
+<span class="sourceLineNo">483</span>    Collection&lt;T&gt; connToClose;<a 
name="line.483"></a>
+<span class="sourceLineNo">484</span>    synchronized (connections) {<a 
name="line.484"></a>
+<span class="sourceLineNo">485</span>      if (!running) {<a 
name="line.485"></a>
+<span class="sourceLineNo">486</span>        return;<a name="line.486"></a>
+<span class="sourceLineNo">487</span>      }<a name="line.487"></a>
+<span class="sourceLineNo">488</span>      running = false;<a 
name="line.488"></a>
+<span class="sourceLineNo">489</span>      connToClose = 
connections.values();<a name="line.489"></a>
+<span class="sourceLineNo">490</span>      connections.clear();<a 
name="line.490"></a>
+<span class="sourceLineNo">491</span>    }<a name="line.491"></a>
+<span class="sourceLineNo">492</span>    
cleanupIdleConnectionTask.cancel(true);<a name="line.492"></a>
+<span class="sourceLineNo">493</span>    for (T conn : connToClose) {<a 
name="line.493"></a>
+<span class="sourceLineNo">494</span>      conn.shutdown();<a 
name="line.494"></a>
+<span class="sourceLineNo">495</span>    }<a name="line.495"></a>
+<span class="sourceLineNo">496</span>    closeInternal();<a 
name="line.496"></a>
+<span class="sourceLineNo">497</span>    for (T conn : connToClose) {<a 
name="line.497"></a>
+<span class="sourceLineNo">498</span>      conn.cleanupConnection();<a 
name="line.498"></a>
+<span class="sourceLineNo">499</span>    }<a name="line.499"></a>
+<span class="sourceLineNo">500</span>  }<a name="line.500"></a>
+<span class="sourceLineNo">501</span><a name="line.501"></a>
+<span class="sourceLineNo">502</span>  @Override<a name="line.502"></a>
+<span class="sourceLineNo">503</span>  public BlockingRpcChannel 
createBlockingRpcChannel(final ServerName sn, final User ticket,<a 
name="line.503"></a>
+<span class="sourceLineNo">504</span>      int rpcTimeout) throws 
UnknownHostException {<a name="line.504"></a>
+<span class="sourceLineNo">505</span>    return new 
BlockingRpcChannelImplementation(this, createAddr(sn), ticket, rpcTimeout);<a 
name="line.505"></a>
+<span class="sourceLineNo">506</span>  }<a name="line.506"></a>
+<span class="sourceLineNo">507</span><a name="line.507"></a>
+<span class="sourceLineNo">508</span>  @Override<a name="line.508"></a>
+<span class="sourceLineNo">509</span>  public RpcChannel 
createRpcChannel(ServerName sn, User user, int rpcTimeout)<a 
name="line.509"></a>
+<span class="sourceLineNo">510</span>      throws UnknownHostException {<a 
name="line.510"></a>
+<span class="sourceLineNo">511</span>    return new 
RpcChannelImplementation(this, createAddr(sn), user, rpcTimeout);<a 
name="line.511"></a>
+<span class="sourceLineNo">512</span>  }<a name="line.512"></a>
 <span class="sourceLineNo">513</span><a name="line.513"></a>
-<span class="sourceLineNo">514</span>    protected final InetSocketAddress 
addr;<a name="line.514"></a>
+<span class="sourceLineNo">514</span>  private static class AbstractRpcChannel 
{<a name="line.514"></a>
 <span class="sourceLineNo">515</span><a name="line.515"></a>
-<span class="sourceLineNo">516</span>    protected final 
AbstractRpcClient&lt;?&gt; rpcClient;<a name="line.516"></a>
+<span class="sourceLineNo">516</span>    protected final InetSocketAddress 
addr;<a name="line.516"></a>
 <span class="sourceLineNo">517</span><a name="line.517"></a>
-<span class="sourceLineNo">518</span>    protected final User ticket;<a 
name="line.518"></a>
+<span class="sourceLineNo">518</span>    protected final 
AbstractRpcClient&lt;?&gt; rpcClient;<a name="line.518"></a>
 <span class="sourceLineNo">519</span><a name="line.519"></a>
-<span class="sourceLineNo">520</span>    protected final int rpcTimeout;<a 
name="line.520"></a>
+<span class="sourceLineNo">520</span>    protected final User ticket;<a 
name="line.520"></a>
 <span class="sourceLineNo">521</span><a name="line.521"></a>
-<span class="sourceLineNo">522</span>    protected 
AbstractRpcChannel(AbstractRpcClient&lt;?&gt; rpcClient, InetSocketAddress 
addr,<a name="line.522"></a>
-<span class="sourceLineNo">523</span>        User ticket, int rpcTimeout) {<a 
name="line.523"></a>
-<span class="sourceLineNo">524</span>      this.addr = addr;<a 
name="line.524"></a>
-<span class="sourceLineNo">525</span>      this.rpcClient = rpcClient;<a 
name="line.525"></a>
-<span class="sourceLineNo">526</span>      this.ticket = ticket;<a 
name="line.526"></a>
-<span class="sourceLineNo">527</span>      this.rpcTimeout = rpcTimeout;<a 
name="line.527"></a>
-<span class="sourceLineNo">528</span>    }<a name="line.528"></a>
-<span class="sourceLineNo">529</span><a name="line.529"></a>
-<span class="sourceLineNo">530</span>    /**<a name="line.530"></a>
-<span class="sourceLineNo">531</span>     * Configure an rpc controller<a 
name="line.531"></a>
-<span class="sourceLineNo">532</span>     * @param controller to configure<a 
name="line.532"></a>
-<span class="sourceLineNo">533</span>     * @return configured rpc 
controller<a name="line.533"></a>
-<span class="sourceLineNo">534</span>     */<a name="line.534"></a>
-<span class="sourceLineNo">535</span>    protected HBaseRpcController 
configureRpcController(RpcController controller) {<a name="line.535"></a>
-<span class="sourceLineNo">536</span>      HBaseRpcController hrc;<a 
name="line.536"></a>
-<span class="sourceLineNo">537</span>      // TODO: Ideally we should not use 
an RpcController other than HBaseRpcController at client<a name="line.537"></a>
-<span class="sourceLineNo">538</span>      // side. And now we may use 
ServerRpcController.<a name="line.538"></a>
-<span class="sourceLineNo">539</span>      if (controller != null &amp;&amp; 
controller instanceof HBaseRpcController) {<a name="line.539"></a>
-<span class="sourceLineNo">540</span>        hrc = (HBaseRpcController) 
controller;<a name="line.540"></a>
-<span class="sourceLineNo">541</span>        if (!hrc.hasCallTimeout()) {<a 
name="line.541"></a>
-<span class="sourceLineNo">542</span>          
hrc.setCallTimeout(rpcTimeout);<a name="line.542"></a>
-<span class="sourceLineNo">543</span>        }<a name="line.543"></a>
-<span class="sourceLineNo">544</span>      } else {<a name="line.544"></a>
-<span class="sourceLineNo">545</span>        hrc = new 
HBaseRpcControllerImpl();<a name="line.545"></a>
-<span class="sourceLineNo">546</span>        hrc.setCallTimeout(rpcTimeout);<a 
name="line.546"></a>
-<span class="sourceLineNo">547</span>      }<a name="line.547"></a>
-<span class="sourceLineNo">548</span>      return hrc;<a name="line.548"></a>
-<span class="sourceLineNo">549</span>    }<a name="line.549"></a>
-<span class="sourceLineNo">550</span>  }<a name="line.550"></a>
-<span class="sourceLineNo">551</span><a name="line.551"></a>
-<span class="sourceLineNo">552</span>  /**<a name="line.552"></a>
-<span class="sourceLineNo">553</span>   * Blocking rpc channel that goes via 
hbase rpc.<a name="line.553"></a>
-<span class="sourceLineNo">554</span>   */<a name="line.554"></a>
-<span class="sourceLineNo">555</span>  @VisibleForTesting<a 
name="line.555"></a>
-<span class="sourceLineNo">556</span>  public static class 
BlockingRpcChannelImplementation extends AbstractRpcChannel<a 
name="line.556"></a>
-<span class="sourceLineNo">557</span>      implements BlockingRpcChannel {<a 
name="line.557"></a>
-<span class="sourceLineNo">558</span><a name="line.558"></a>
-<span class="sourceLineNo">559</span>    protected 
BlockingRpcChannelImplementation(AbstractRpcClient&lt;?&gt; rpcClient,<a 
name="line.559"></a>
-<span class="sourceLineNo">560</span>        InetSocketAddress addr, User 
ticket, int rpcTimeout) {<a name="line.560"></a>
-<span class="sourceLineNo">561</span>      super(rpcClient, addr, ticket, 
rpcTimeout);<a name="line.561"></a>
-<span class="sourceLineNo">562</span>    }<a name="line.562"></a>
-<span class="sourceLineNo">563</span><a name="line.563"></a>
-<span class="sourceLineNo">564</span>    @Override<a name="line.564"></a>
-<span class="sourceLineNo">565</span>    public Message 
callBlockingMethod(Descriptors.MethodDescriptor md, RpcController controller,<a 
name="line.565"></a>
-<span class="sourceLineNo">566</span>        Message param, Message 
returnType) throws ServiceException {<a name="line.566"></a>
-<span class="sourceLineNo">567</span>      return 
rpcClient.callBlockingMethod(md, configureRpcController(controller),<a 
name="line.567"></a>
-<span class="sourceLineNo">568</span>        param, returnType, ticket, 
addr);<a name="line.568"></a>
-<span class="sourceLineNo">569</span>    }<a name="line.569"></a>
-<span class="sourceLineNo">570</span>  }<a name="line.570"></a>
-<span class="sourceLineNo">571</span><a name="line.571"></a>
-<span class="sourceLineNo">572</span>  /**<a name="line.572"></a>
-<span class="sourceLineNo">573</span>   * Async rpc channel that goes via 
hbase rpc.<a name="line.573"></a>
-<span class="sourceLineNo">574</span>   */<a name="line.574"></a>
-<span class="sourceLineNo">575</span>  public static class 
RpcChannelImplementation extends

<TRUNCATED>

Reply via email to