http://git-wip-us.apache.org/repos/asf/hbase-site/blob/f6f9d4f3/devapidocs/src-html/org/apache/hadoop/hbase/executor/ExecutorService.TrackingThreadPoolExecutor.html
----------------------------------------------------------------------
diff --git
a/devapidocs/src-html/org/apache/hadoop/hbase/executor/ExecutorService.TrackingThreadPoolExecutor.html
b/devapidocs/src-html/org/apache/hadoop/hbase/executor/ExecutorService.TrackingThreadPoolExecutor.html
index 49f081b..33c9cc0 100644
---
a/devapidocs/src-html/org/apache/hadoop/hbase/executor/ExecutorService.TrackingThreadPoolExecutor.html
+++
b/devapidocs/src-html/org/apache/hadoop/hbase/executor/ExecutorService.TrackingThreadPoolExecutor.html
@@ -35,309 +35,328 @@
<span class="sourceLineNo">027</span>import
java.util.concurrent.BlockingQueue;<a name="line.27"></a>
<span class="sourceLineNo">028</span>import
java.util.concurrent.ConcurrentHashMap;<a name="line.28"></a>
<span class="sourceLineNo">029</span>import
java.util.concurrent.ConcurrentMap;<a name="line.29"></a>
-<span class="sourceLineNo">030</span>import
java.util.concurrent.LinkedBlockingQueue;<a name="line.30"></a>
-<span class="sourceLineNo">031</span>import
java.util.concurrent.ThreadPoolExecutor;<a name="line.31"></a>
-<span class="sourceLineNo">032</span>import java.util.concurrent.TimeUnit;<a
name="line.32"></a>
-<span class="sourceLineNo">033</span>import
java.util.concurrent.atomic.AtomicLong;<a name="line.33"></a>
-<span class="sourceLineNo">034</span><a name="line.34"></a>
-<span class="sourceLineNo">035</span>import
org.apache.yetus.audience.InterfaceAudience;<a name="line.35"></a>
-<span class="sourceLineNo">036</span>import org.slf4j.Logger;<a
name="line.36"></a>
-<span class="sourceLineNo">037</span>import org.slf4j.LoggerFactory;<a
name="line.37"></a>
-<span class="sourceLineNo">038</span>import
org.apache.hadoop.hbase.monitoring.ThreadMonitoring;<a name="line.38"></a>
+<span class="sourceLineNo">030</span>import java.util.concurrent.Executors;<a
name="line.30"></a>
+<span class="sourceLineNo">031</span>import
java.util.concurrent.LinkedBlockingQueue;<a name="line.31"></a>
+<span class="sourceLineNo">032</span>import
java.util.concurrent.ThreadPoolExecutor;<a name="line.32"></a>
+<span class="sourceLineNo">033</span>import java.util.concurrent.TimeUnit;<a
name="line.33"></a>
+<span class="sourceLineNo">034</span>import
java.util.concurrent.atomic.AtomicLong;<a name="line.34"></a>
+<span class="sourceLineNo">035</span>import
org.apache.hadoop.hbase.monitoring.ThreadMonitoring;<a name="line.35"></a>
+<span class="sourceLineNo">036</span>import
org.apache.yetus.audience.InterfaceAudience;<a name="line.36"></a>
+<span class="sourceLineNo">037</span>import org.slf4j.Logger;<a
name="line.37"></a>
+<span class="sourceLineNo">038</span>import org.slf4j.LoggerFactory;<a
name="line.38"></a>
<span class="sourceLineNo">039</span><a name="line.39"></a>
<span class="sourceLineNo">040</span>import
org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;<a
name="line.40"></a>
<span class="sourceLineNo">041</span>import
org.apache.hbase.thirdparty.com.google.common.collect.Lists;<a
name="line.41"></a>
<span class="sourceLineNo">042</span>import
org.apache.hbase.thirdparty.com.google.common.collect.Maps;<a
name="line.42"></a>
-<span class="sourceLineNo">043</span>import
org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;<a
name="line.43"></a>
-<span class="sourceLineNo">044</span><a name="line.44"></a>
-<span class="sourceLineNo">045</span>/**<a name="line.45"></a>
-<span class="sourceLineNo">046</span> * This is a generic executor service.
This component abstracts a<a name="line.46"></a>
-<span class="sourceLineNo">047</span> * threadpool, a queue to which {@link
EventType}s can be submitted,<a name="line.47"></a>
-<span class="sourceLineNo">048</span> * and a
<code>Runnable</code> that handles the object that is added to the
queue.<a name="line.48"></a>
-<span class="sourceLineNo">049</span> *<a name="line.49"></a>
-<span class="sourceLineNo">050</span> * <p>In order to create a new
service, create an instance of this class and<a name="line.50"></a>
-<span class="sourceLineNo">051</span> * then do:
<code>instance.startExecutorService("myService");</code>. When
done<a name="line.51"></a>
-<span class="sourceLineNo">052</span> * call {@link #shutdown()}.<a
name="line.52"></a>
-<span class="sourceLineNo">053</span> *<a name="line.53"></a>
-<span class="sourceLineNo">054</span> * <p>In order to use the service
created above, call<a name="line.54"></a>
-<span class="sourceLineNo">055</span> * {@link #submit(EventHandler)}.<a
name="line.55"></a>
-<span class="sourceLineNo">056</span> */<a name="line.56"></a>
-<span class="sourceLineNo">057</span>@InterfaceAudience.Private<a
name="line.57"></a>
-<span class="sourceLineNo">058</span>public class ExecutorService {<a
name="line.58"></a>
-<span class="sourceLineNo">059</span> private static final Logger LOG =
LoggerFactory.getLogger(ExecutorService.class);<a name="line.59"></a>
-<span class="sourceLineNo">060</span><a name="line.60"></a>
-<span class="sourceLineNo">061</span> // hold the all the executors created
in a map addressable by their names<a name="line.61"></a>
-<span class="sourceLineNo">062</span> private final
ConcurrentHashMap<String, Executor> executorMap = new
ConcurrentHashMap<>();<a name="line.62"></a>
+<span class="sourceLineNo">043</span>import
org.apache.hbase.thirdparty.com.google.common.util.concurrent.ListenableFuture;<a
name="line.43"></a>
+<span class="sourceLineNo">044</span>import
org.apache.hbase.thirdparty.com.google.common.util.concurrent.ListeningScheduledExecutorService;<a
name="line.44"></a>
+<span class="sourceLineNo">045</span>import
org.apache.hbase.thirdparty.com.google.common.util.concurrent.MoreExecutors;<a
name="line.45"></a>
+<span class="sourceLineNo">046</span>import
org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;<a
name="line.46"></a>
+<span class="sourceLineNo">047</span><a name="line.47"></a>
+<span class="sourceLineNo">048</span>/**<a name="line.48"></a>
+<span class="sourceLineNo">049</span> * This is a generic executor service.
This component abstracts a<a name="line.49"></a>
+<span class="sourceLineNo">050</span> * threadpool, a queue to which {@link
EventType}s can be submitted,<a name="line.50"></a>
+<span class="sourceLineNo">051</span> * and a
<code>Runnable</code> that handles the object that is added to the
queue.<a name="line.51"></a>
+<span class="sourceLineNo">052</span> *<a name="line.52"></a>
+<span class="sourceLineNo">053</span> * <p>In order to create a new
service, create an instance of this class and<a name="line.53"></a>
+<span class="sourceLineNo">054</span> * then do:
<code>instance.startExecutorService("myService");</code>. When
done<a name="line.54"></a>
+<span class="sourceLineNo">055</span> * call {@link #shutdown()}.<a
name="line.55"></a>
+<span class="sourceLineNo">056</span> *<a name="line.56"></a>
+<span class="sourceLineNo">057</span> * <p>In order to use the service
created above, call<a name="line.57"></a>
+<span class="sourceLineNo">058</span> * {@link #submit(EventHandler)}.<a
name="line.58"></a>
+<span class="sourceLineNo">059</span> */<a name="line.59"></a>
+<span class="sourceLineNo">060</span>@InterfaceAudience.Private<a
name="line.60"></a>
+<span class="sourceLineNo">061</span>public class ExecutorService {<a
name="line.61"></a>
+<span class="sourceLineNo">062</span> private static final Logger LOG =
LoggerFactory.getLogger(ExecutorService.class);<a name="line.62"></a>
<span class="sourceLineNo">063</span><a name="line.63"></a>
-<span class="sourceLineNo">064</span> // Name of the server hosting this
executor service.<a name="line.64"></a>
-<span class="sourceLineNo">065</span> private final String servername;<a
name="line.65"></a>
+<span class="sourceLineNo">064</span> // hold the all the executors created
in a map addressable by their names<a name="line.64"></a>
+<span class="sourceLineNo">065</span> private final
ConcurrentHashMap<String, Executor> executorMap = new
ConcurrentHashMap<>();<a name="line.65"></a>
<span class="sourceLineNo">066</span><a name="line.66"></a>
-<span class="sourceLineNo">067</span> /**<a name="line.67"></a>
-<span class="sourceLineNo">068</span> * Default constructor.<a
name="line.68"></a>
-<span class="sourceLineNo">069</span> * @param servername Name of the
hosting server.<a name="line.69"></a>
-<span class="sourceLineNo">070</span> */<a name="line.70"></a>
-<span class="sourceLineNo">071</span> public ExecutorService(final String
servername) {<a name="line.71"></a>
-<span class="sourceLineNo">072</span> super();<a name="line.72"></a>
-<span class="sourceLineNo">073</span> this.servername = servername;<a
name="line.73"></a>
-<span class="sourceLineNo">074</span> }<a name="line.74"></a>
-<span class="sourceLineNo">075</span><a name="line.75"></a>
-<span class="sourceLineNo">076</span> /**<a name="line.76"></a>
-<span class="sourceLineNo">077</span> * Start an executor service with a
given name. If there was a service already<a name="line.77"></a>
-<span class="sourceLineNo">078</span> * started with the same name, this
throws a RuntimeException.<a name="line.78"></a>
-<span class="sourceLineNo">079</span> * @param name Name of the service to
start.<a name="line.79"></a>
-<span class="sourceLineNo">080</span> */<a name="line.80"></a>
-<span class="sourceLineNo">081</span> @VisibleForTesting<a name="line.81"></a>
-<span class="sourceLineNo">082</span> public void startExecutorService(String
name, int maxThreads) {<a name="line.82"></a>
-<span class="sourceLineNo">083</span> if (this.executorMap.get(name) !=
null) {<a name="line.83"></a>
-<span class="sourceLineNo">084</span> throw new RuntimeException("An
executor service with the name " + name +<a name="line.84"></a>
-<span class="sourceLineNo">085</span> " is already running!");<a
name="line.85"></a>
-<span class="sourceLineNo">086</span> }<a name="line.86"></a>
-<span class="sourceLineNo">087</span> Executor hbes = new Executor(name,
maxThreads);<a name="line.87"></a>
-<span class="sourceLineNo">088</span> if
(this.executorMap.putIfAbsent(name, hbes) != null) {<a name="line.88"></a>
-<span class="sourceLineNo">089</span> throw new RuntimeException("An
executor service with the name " + name +<a name="line.89"></a>
-<span class="sourceLineNo">090</span> " is already running (2)!");<a
name="line.90"></a>
-<span class="sourceLineNo">091</span> }<a name="line.91"></a>
-<span class="sourceLineNo">092</span> LOG.debug("Starting executor service
name=" + name +<a name="line.92"></a>
-<span class="sourceLineNo">093</span> ", corePoolSize=" +
hbes.threadPoolExecutor.getCorePoolSize() +<a name="line.93"></a>
-<span class="sourceLineNo">094</span> ", maxPoolSize=" +
hbes.threadPoolExecutor.getMaximumPoolSize());<a name="line.94"></a>
-<span class="sourceLineNo">095</span> }<a name="line.95"></a>
-<span class="sourceLineNo">096</span><a name="line.96"></a>
-<span class="sourceLineNo">097</span> boolean isExecutorServiceRunning(String
name) {<a name="line.97"></a>
-<span class="sourceLineNo">098</span> return
this.executorMap.containsKey(name);<a name="line.98"></a>
-<span class="sourceLineNo">099</span> }<a name="line.99"></a>
-<span class="sourceLineNo">100</span><a name="line.100"></a>
-<span class="sourceLineNo">101</span> public void shutdown() {<a
name="line.101"></a>
-<span class="sourceLineNo">102</span> for(Entry<String, Executor>
entry: this.executorMap.entrySet()) {<a name="line.102"></a>
-<span class="sourceLineNo">103</span> List<Runnable> wasRunning =<a
name="line.103"></a>
-<span class="sourceLineNo">104</span>
entry.getValue().threadPoolExecutor.shutdownNow();<a name="line.104"></a>
-<span class="sourceLineNo">105</span> if (!wasRunning.isEmpty()) {<a
name="line.105"></a>
-<span class="sourceLineNo">106</span> LOG.info(entry.getValue() + " had
" + wasRunning + " on shutdown");<a name="line.106"></a>
-<span class="sourceLineNo">107</span> }<a name="line.107"></a>
-<span class="sourceLineNo">108</span> }<a name="line.108"></a>
-<span class="sourceLineNo">109</span> this.executorMap.clear();<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> Executor getExecutor(final ExecutorType
type) {<a name="line.112"></a>
-<span class="sourceLineNo">113</span> return
getExecutor(type.getExecutorName(this.servername));<a name="line.113"></a>
-<span class="sourceLineNo">114</span> }<a name="line.114"></a>
-<span class="sourceLineNo">115</span><a name="line.115"></a>
-<span class="sourceLineNo">116</span> Executor getExecutor(String name) {<a
name="line.116"></a>
-<span class="sourceLineNo">117</span> Executor executor =
this.executorMap.get(name);<a name="line.117"></a>
-<span class="sourceLineNo">118</span> return executor;<a
name="line.118"></a>
-<span class="sourceLineNo">119</span> }<a name="line.119"></a>
-<span class="sourceLineNo">120</span><a name="line.120"></a>
-<span class="sourceLineNo">121</span> @VisibleForTesting<a
name="line.121"></a>
-<span class="sourceLineNo">122</span> public ThreadPoolExecutor
getExecutorThreadPool(final ExecutorType type) {<a name="line.122"></a>
-<span class="sourceLineNo">123</span> return
getExecutor(type).getThreadPoolExecutor();<a name="line.123"></a>
-<span class="sourceLineNo">124</span> }<a name="line.124"></a>
-<span class="sourceLineNo">125</span><a name="line.125"></a>
-<span class="sourceLineNo">126</span> public void startExecutorService(final
ExecutorType type, final int maxThreads) {<a name="line.126"></a>
-<span class="sourceLineNo">127</span> String name =
type.getExecutorName(this.servername);<a name="line.127"></a>
-<span class="sourceLineNo">128</span> if (isExecutorServiceRunning(name))
{<a name="line.128"></a>
-<span class="sourceLineNo">129</span> LOG.debug("Executor service " +
toString() + " already running on " +<a name="line.129"></a>
-<span class="sourceLineNo">130</span> this.servername);<a
name="line.130"></a>
-<span class="sourceLineNo">131</span> return;<a name="line.131"></a>
-<span class="sourceLineNo">132</span> }<a name="line.132"></a>
-<span class="sourceLineNo">133</span> startExecutorService(name,
maxThreads);<a name="line.133"></a>
-<span class="sourceLineNo">134</span> }<a name="line.134"></a>
-<span class="sourceLineNo">135</span><a name="line.135"></a>
-<span class="sourceLineNo">136</span> public void submit(final EventHandler
eh) {<a name="line.136"></a>
-<span class="sourceLineNo">137</span> Executor executor =
getExecutor(eh.getEventType().getExecutorServiceType());<a name="line.137"></a>
-<span class="sourceLineNo">138</span> if (executor == null) {<a
name="line.138"></a>
-<span class="sourceLineNo">139</span> // This happens only when events
are submitted after shutdown() was<a name="line.139"></a>
-<span class="sourceLineNo">140</span> // called, so dropping them should
be "ok" since it means we're<a name="line.140"></a>
-<span class="sourceLineNo">141</span> // shutting down.<a
name="line.141"></a>
-<span class="sourceLineNo">142</span> LOG.error("Cannot submit [" + eh +
"] because the executor is missing." +<a name="line.142"></a>
-<span class="sourceLineNo">143</span> " Is this process shutting
down?");<a name="line.143"></a>
-<span class="sourceLineNo">144</span> } else {<a name="line.144"></a>
-<span class="sourceLineNo">145</span> executor.submit(eh);<a
name="line.145"></a>
-<span class="sourceLineNo">146</span> }<a name="line.146"></a>
-<span class="sourceLineNo">147</span> }<a name="line.147"></a>
-<span class="sourceLineNo">148</span><a name="line.148"></a>
-<span class="sourceLineNo">149</span> public Map<String,
ExecutorStatus> getAllExecutorStatuses() {<a name="line.149"></a>
-<span class="sourceLineNo">150</span> Map<String, ExecutorStatus> ret
= Maps.newHashMap();<a name="line.150"></a>
-<span class="sourceLineNo">151</span> for (Map.Entry<String,
Executor> e : executorMap.entrySet()) {<a name="line.151"></a>
-<span class="sourceLineNo">152</span> ret.put(e.getKey(),
e.getValue().getStatus());<a name="line.152"></a>
+<span class="sourceLineNo">067</span> // Name of the server hosting this
executor service.<a name="line.67"></a>
+<span class="sourceLineNo">068</span> private final String servername;<a
name="line.68"></a>
+<span class="sourceLineNo">069</span><a name="line.69"></a>
+<span class="sourceLineNo">070</span> private final
ListeningScheduledExecutorService delayedSubmitTimer =<a name="line.70"></a>
+<span class="sourceLineNo">071</span>
MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(1, new
ThreadFactoryBuilder()<a name="line.71"></a>
+<span class="sourceLineNo">072</span>
.setDaemon(true).setNameFormat("Event-Executor-Delay-Submit-Timer").build()));<a
name="line.72"></a>
+<span class="sourceLineNo">073</span><a name="line.73"></a>
+<span class="sourceLineNo">074</span> /**<a name="line.74"></a>
+<span class="sourceLineNo">075</span> * Default constructor.<a
name="line.75"></a>
+<span class="sourceLineNo">076</span> * @param servername Name of the
hosting server.<a name="line.76"></a>
+<span class="sourceLineNo">077</span> */<a name="line.77"></a>
+<span class="sourceLineNo">078</span> public ExecutorService(final String
servername) {<a name="line.78"></a>
+<span class="sourceLineNo">079</span> this.servername = servername;<a
name="line.79"></a>
+<span class="sourceLineNo">080</span> }<a name="line.80"></a>
+<span class="sourceLineNo">081</span><a name="line.81"></a>
+<span class="sourceLineNo">082</span> /**<a name="line.82"></a>
+<span class="sourceLineNo">083</span> * Start an executor service with a
given name. If there was a service already<a name="line.83"></a>
+<span class="sourceLineNo">084</span> * started with the same name, this
throws a RuntimeException.<a name="line.84"></a>
+<span class="sourceLineNo">085</span> * @param name Name of the service to
start.<a name="line.85"></a>
+<span class="sourceLineNo">086</span> */<a name="line.86"></a>
+<span class="sourceLineNo">087</span> @VisibleForTesting<a name="line.87"></a>
+<span class="sourceLineNo">088</span> public void startExecutorService(String
name, int maxThreads) {<a name="line.88"></a>
+<span class="sourceLineNo">089</span> if (this.executorMap.get(name) !=
null) {<a name="line.89"></a>
+<span class="sourceLineNo">090</span> throw new RuntimeException("An
executor service with the name " + name +<a name="line.90"></a>
+<span class="sourceLineNo">091</span> " is already running!");<a
name="line.91"></a>
+<span class="sourceLineNo">092</span> }<a name="line.92"></a>
+<span class="sourceLineNo">093</span> Executor hbes = new Executor(name,
maxThreads);<a name="line.93"></a>
+<span class="sourceLineNo">094</span> if
(this.executorMap.putIfAbsent(name, hbes) != null) {<a name="line.94"></a>
+<span class="sourceLineNo">095</span> throw new RuntimeException("An
executor service with the name " + name +<a name="line.95"></a>
+<span class="sourceLineNo">096</span> " is already running (2)!");<a
name="line.96"></a>
+<span class="sourceLineNo">097</span> }<a name="line.97"></a>
+<span class="sourceLineNo">098</span> LOG.debug("Starting executor service
name=" + name +<a name="line.98"></a>
+<span class="sourceLineNo">099</span> ", corePoolSize=" +
hbes.threadPoolExecutor.getCorePoolSize() +<a name="line.99"></a>
+<span class="sourceLineNo">100</span> ", maxPoolSize=" +
hbes.threadPoolExecutor.getMaximumPoolSize());<a name="line.100"></a>
+<span class="sourceLineNo">101</span> }<a name="line.101"></a>
+<span class="sourceLineNo">102</span><a name="line.102"></a>
+<span class="sourceLineNo">103</span> boolean isExecutorServiceRunning(String
name) {<a name="line.103"></a>
+<span class="sourceLineNo">104</span> return
this.executorMap.containsKey(name);<a name="line.104"></a>
+<span class="sourceLineNo">105</span> }<a name="line.105"></a>
+<span class="sourceLineNo">106</span><a name="line.106"></a>
+<span class="sourceLineNo">107</span> public void shutdown() {<a
name="line.107"></a>
+<span class="sourceLineNo">108</span>
this.delayedSubmitTimer.shutdownNow();<a name="line.108"></a>
+<span class="sourceLineNo">109</span> for(Entry<String, Executor>
entry: this.executorMap.entrySet()) {<a name="line.109"></a>
+<span class="sourceLineNo">110</span> List<Runnable> wasRunning =<a
name="line.110"></a>
+<span class="sourceLineNo">111</span>
entry.getValue().threadPoolExecutor.shutdownNow();<a name="line.111"></a>
+<span class="sourceLineNo">112</span> if (!wasRunning.isEmpty()) {<a
name="line.112"></a>
+<span class="sourceLineNo">113</span> LOG.info(entry.getValue() + " had
" + wasRunning + " on shutdown");<a name="line.113"></a>
+<span class="sourceLineNo">114</span> }<a name="line.114"></a>
+<span class="sourceLineNo">115</span> }<a name="line.115"></a>
+<span class="sourceLineNo">116</span> this.executorMap.clear();<a
name="line.116"></a>
+<span class="sourceLineNo">117</span> }<a name="line.117"></a>
+<span class="sourceLineNo">118</span><a name="line.118"></a>
+<span class="sourceLineNo">119</span> Executor getExecutor(final ExecutorType
type) {<a name="line.119"></a>
+<span class="sourceLineNo">120</span> return
getExecutor(type.getExecutorName(this.servername));<a name="line.120"></a>
+<span class="sourceLineNo">121</span> }<a name="line.121"></a>
+<span class="sourceLineNo">122</span><a name="line.122"></a>
+<span class="sourceLineNo">123</span> Executor getExecutor(String name) {<a
name="line.123"></a>
+<span class="sourceLineNo">124</span> Executor executor =
this.executorMap.get(name);<a name="line.124"></a>
+<span class="sourceLineNo">125</span> return executor;<a
name="line.125"></a>
+<span class="sourceLineNo">126</span> }<a name="line.126"></a>
+<span class="sourceLineNo">127</span><a name="line.127"></a>
+<span class="sourceLineNo">128</span> @VisibleForTesting<a
name="line.128"></a>
+<span class="sourceLineNo">129</span> public ThreadPoolExecutor
getExecutorThreadPool(final ExecutorType type) {<a name="line.129"></a>
+<span class="sourceLineNo">130</span> return
getExecutor(type).getThreadPoolExecutor();<a name="line.130"></a>
+<span class="sourceLineNo">131</span> }<a name="line.131"></a>
+<span class="sourceLineNo">132</span><a name="line.132"></a>
+<span class="sourceLineNo">133</span> public void startExecutorService(final
ExecutorType type, final int maxThreads) {<a name="line.133"></a>
+<span class="sourceLineNo">134</span> String name =
type.getExecutorName(this.servername);<a name="line.134"></a>
+<span class="sourceLineNo">135</span> if (isExecutorServiceRunning(name))
{<a name="line.135"></a>
+<span class="sourceLineNo">136</span> LOG.debug("Executor service " +
toString() + " already running on " +<a name="line.136"></a>
+<span class="sourceLineNo">137</span> this.servername);<a
name="line.137"></a>
+<span class="sourceLineNo">138</span> return;<a name="line.138"></a>
+<span class="sourceLineNo">139</span> }<a name="line.139"></a>
+<span class="sourceLineNo">140</span> startExecutorService(name,
maxThreads);<a name="line.140"></a>
+<span class="sourceLineNo">141</span> }<a name="line.141"></a>
+<span class="sourceLineNo">142</span><a name="line.142"></a>
+<span class="sourceLineNo">143</span> public void submit(final EventHandler
eh) {<a name="line.143"></a>
+<span class="sourceLineNo">144</span> Executor executor =
getExecutor(eh.getEventType().getExecutorServiceType());<a name="line.144"></a>
+<span class="sourceLineNo">145</span> if (executor == null) {<a
name="line.145"></a>
+<span class="sourceLineNo">146</span> // This happens only when events
are submitted after shutdown() was<a name="line.146"></a>
+<span class="sourceLineNo">147</span> // called, so dropping them should
be "ok" since it means we're<a name="line.147"></a>
+<span class="sourceLineNo">148</span> // shutting down.<a
name="line.148"></a>
+<span class="sourceLineNo">149</span> LOG.error("Cannot submit [" + eh +
"] because the executor is missing." +<a name="line.149"></a>
+<span class="sourceLineNo">150</span> " Is this process shutting
down?");<a name="line.150"></a>
+<span class="sourceLineNo">151</span> } else {<a name="line.151"></a>
+<span class="sourceLineNo">152</span> executor.submit(eh);<a
name="line.152"></a>
<span class="sourceLineNo">153</span> }<a name="line.153"></a>
-<span class="sourceLineNo">154</span> return ret;<a name="line.154"></a>
-<span class="sourceLineNo">155</span> }<a name="line.155"></a>
-<span class="sourceLineNo">156</span><a name="line.156"></a>
-<span class="sourceLineNo">157</span> /**<a name="line.157"></a>
-<span class="sourceLineNo">158</span> * Executor instance.<a
name="line.158"></a>
-<span class="sourceLineNo">159</span> */<a name="line.159"></a>
-<span class="sourceLineNo">160</span> static class Executor {<a
name="line.160"></a>
-<span class="sourceLineNo">161</span> // how long to retain excess
threads<a name="line.161"></a>
-<span class="sourceLineNo">162</span> static final long
keepAliveTimeInMillis = 1000;<a name="line.162"></a>
-<span class="sourceLineNo">163</span> // the thread pool executor that
services the requests<a name="line.163"></a>
-<span class="sourceLineNo">164</span> final TrackingThreadPoolExecutor
threadPoolExecutor;<a name="line.164"></a>
-<span class="sourceLineNo">165</span> // work queue to use - unbounded
queue<a name="line.165"></a>
-<span class="sourceLineNo">166</span> final BlockingQueue<Runnable> q
= new LinkedBlockingQueue<>();<a name="line.166"></a>
-<span class="sourceLineNo">167</span> private final String name;<a
name="line.167"></a>
-<span class="sourceLineNo">168</span> private static final AtomicLong
seqids = new AtomicLong(0);<a name="line.168"></a>
-<span class="sourceLineNo">169</span> private final long id;<a
name="line.169"></a>
-<span class="sourceLineNo">170</span><a name="line.170"></a>
-<span class="sourceLineNo">171</span> protected Executor(String name, int
maxThreads) {<a name="line.171"></a>
-<span class="sourceLineNo">172</span> this.id =
seqids.incrementAndGet();<a name="line.172"></a>
-<span class="sourceLineNo">173</span> this.name = name;<a
name="line.173"></a>
-<span class="sourceLineNo">174</span> // create the thread pool
executor<a name="line.174"></a>
-<span class="sourceLineNo">175</span> this.threadPoolExecutor = new
TrackingThreadPoolExecutor(<a name="line.175"></a>
-<span class="sourceLineNo">176</span> maxThreads, maxThreads,<a
name="line.176"></a>
-<span class="sourceLineNo">177</span> keepAliveTimeInMillis,
TimeUnit.MILLISECONDS, q);<a name="line.177"></a>
-<span class="sourceLineNo">178</span> // name the threads for this
threadpool<a name="line.178"></a>
-<span class="sourceLineNo">179</span> ThreadFactoryBuilder tfb = new
ThreadFactoryBuilder();<a name="line.179"></a>
-<span class="sourceLineNo">180</span> tfb.setNameFormat(this.name +
"-%d");<a name="line.180"></a>
-<span class="sourceLineNo">181</span> tfb.setDaemon(true);<a
name="line.181"></a>
-<span class="sourceLineNo">182</span>
this.threadPoolExecutor.setThreadFactory(tfb.build());<a name="line.182"></a>
-<span class="sourceLineNo">183</span> }<a name="line.183"></a>
-<span class="sourceLineNo">184</span><a name="line.184"></a>
-<span class="sourceLineNo">185</span> /**<a name="line.185"></a>
-<span class="sourceLineNo">186</span> * Submit the event to the queue for
handling.<a name="line.186"></a>
-<span class="sourceLineNo">187</span> * @param event<a name="line.187"></a>
-<span class="sourceLineNo">188</span> */<a name="line.188"></a>
-<span class="sourceLineNo">189</span> void submit(final EventHandler event)
{<a name="line.189"></a>
-<span class="sourceLineNo">190</span> // If there is a listener for this
type, make sure we call the before<a name="line.190"></a>
-<span class="sourceLineNo">191</span> // and after process methods.<a
name="line.191"></a>
-<span class="sourceLineNo">192</span>
this.threadPoolExecutor.execute(event);<a name="line.192"></a>
-<span class="sourceLineNo">193</span> }<a name="line.193"></a>
-<span class="sourceLineNo">194</span><a name="line.194"></a>
-<span class="sourceLineNo">195</span> TrackingThreadPoolExecutor
getThreadPoolExecutor() {<a name="line.195"></a>
-<span class="sourceLineNo">196</span> return threadPoolExecutor;<a
name="line.196"></a>
-<span class="sourceLineNo">197</span> }<a name="line.197"></a>
-<span class="sourceLineNo">198</span><a name="line.198"></a>
-<span class="sourceLineNo">199</span> @Override<a name="line.199"></a>
-<span class="sourceLineNo">200</span> public String toString() {<a
name="line.200"></a>
-<span class="sourceLineNo">201</span> return getClass().getSimpleName() +
"-" + id + "-" + name;<a name="line.201"></a>
+<span class="sourceLineNo">154</span> }<a name="line.154"></a>
+<span class="sourceLineNo">155</span><a name="line.155"></a>
+<span class="sourceLineNo">156</span> // Submit the handler after the given
delay. Used for retrying.<a name="line.156"></a>
+<span class="sourceLineNo">157</span> public void delayedSubmit(EventHandler
eh, long delay, TimeUnit unit) {<a name="line.157"></a>
+<span class="sourceLineNo">158</span> ListenableFuture<?> future =
delayedSubmitTimer.schedule(() -> submit(eh), delay, unit);<a
name="line.158"></a>
+<span class="sourceLineNo">159</span> future.addListener(() -> {<a
name="line.159"></a>
+<span class="sourceLineNo">160</span> try {<a name="line.160"></a>
+<span class="sourceLineNo">161</span> future.get();<a
name="line.161"></a>
+<span class="sourceLineNo">162</span> } catch (Exception e) {<a
name="line.162"></a>
+<span class="sourceLineNo">163</span> LOG.error("Failed to submit the
event handler {} to executor", eh, e);<a name="line.163"></a>
+<span class="sourceLineNo">164</span> }<a name="line.164"></a>
+<span class="sourceLineNo">165</span> }, MoreExecutors.directExecutor());<a
name="line.165"></a>
+<span class="sourceLineNo">166</span> }<a name="line.166"></a>
+<span class="sourceLineNo">167</span><a name="line.167"></a>
+<span class="sourceLineNo">168</span> public Map<String,
ExecutorStatus> getAllExecutorStatuses() {<a name="line.168"></a>
+<span class="sourceLineNo">169</span> Map<String, ExecutorStatus> ret
= Maps.newHashMap();<a name="line.169"></a>
+<span class="sourceLineNo">170</span> for (Map.Entry<String,
Executor> e : executorMap.entrySet()) {<a name="line.170"></a>
+<span class="sourceLineNo">171</span> ret.put(e.getKey(),
e.getValue().getStatus());<a name="line.171"></a>
+<span class="sourceLineNo">172</span> }<a name="line.172"></a>
+<span class="sourceLineNo">173</span> return ret;<a name="line.173"></a>
+<span class="sourceLineNo">174</span> }<a name="line.174"></a>
+<span class="sourceLineNo">175</span><a name="line.175"></a>
+<span class="sourceLineNo">176</span> /**<a name="line.176"></a>
+<span class="sourceLineNo">177</span> * Executor instance.<a
name="line.177"></a>
+<span class="sourceLineNo">178</span> */<a name="line.178"></a>
+<span class="sourceLineNo">179</span> static class Executor {<a
name="line.179"></a>
+<span class="sourceLineNo">180</span> // how long to retain excess
threads<a name="line.180"></a>
+<span class="sourceLineNo">181</span> static final long
keepAliveTimeInMillis = 1000;<a name="line.181"></a>
+<span class="sourceLineNo">182</span> // the thread pool executor that
services the requests<a name="line.182"></a>
+<span class="sourceLineNo">183</span> final TrackingThreadPoolExecutor
threadPoolExecutor;<a name="line.183"></a>
+<span class="sourceLineNo">184</span> // work queue to use - unbounded
queue<a name="line.184"></a>
+<span class="sourceLineNo">185</span> final BlockingQueue<Runnable> q
= new LinkedBlockingQueue<>();<a name="line.185"></a>
+<span class="sourceLineNo">186</span> private final String name;<a
name="line.186"></a>
+<span class="sourceLineNo">187</span> private static final AtomicLong
seqids = new AtomicLong(0);<a name="line.187"></a>
+<span class="sourceLineNo">188</span> private final long id;<a
name="line.188"></a>
+<span class="sourceLineNo">189</span><a name="line.189"></a>
+<span class="sourceLineNo">190</span> protected Executor(String name, int
maxThreads) {<a name="line.190"></a>
+<span class="sourceLineNo">191</span> this.id =
seqids.incrementAndGet();<a name="line.191"></a>
+<span class="sourceLineNo">192</span> this.name = name;<a
name="line.192"></a>
+<span class="sourceLineNo">193</span> // create the thread pool
executor<a name="line.193"></a>
+<span class="sourceLineNo">194</span> this.threadPoolExecutor = new
TrackingThreadPoolExecutor(<a name="line.194"></a>
+<span class="sourceLineNo">195</span> maxThreads, maxThreads,<a
name="line.195"></a>
+<span class="sourceLineNo">196</span> keepAliveTimeInMillis,
TimeUnit.MILLISECONDS, q);<a name="line.196"></a>
+<span class="sourceLineNo">197</span> // name the threads for this
threadpool<a name="line.197"></a>
+<span class="sourceLineNo">198</span> ThreadFactoryBuilder tfb = new
ThreadFactoryBuilder();<a name="line.198"></a>
+<span class="sourceLineNo">199</span> tfb.setNameFormat(this.name +
"-%d");<a name="line.199"></a>
+<span class="sourceLineNo">200</span> tfb.setDaemon(true);<a
name="line.200"></a>
+<span class="sourceLineNo">201</span>
this.threadPoolExecutor.setThreadFactory(tfb.build());<a name="line.201"></a>
<span class="sourceLineNo">202</span> }<a name="line.202"></a>
<span class="sourceLineNo">203</span><a name="line.203"></a>
-<span class="sourceLineNo">204</span> public ExecutorStatus getStatus() {<a
name="line.204"></a>
-<span class="sourceLineNo">205</span> List<EventHandler>
queuedEvents = Lists.newArrayList();<a name="line.205"></a>
-<span class="sourceLineNo">206</span> for (Runnable r : q) {<a
name="line.206"></a>
-<span class="sourceLineNo">207</span> if (!(r instanceof EventHandler))
{<a name="line.207"></a>
-<span class="sourceLineNo">208</span> LOG.warn("Non-EventHandler " +
r + " queued in " + name);<a name="line.208"></a>
-<span class="sourceLineNo">209</span> continue;<a name="line.209"></a>
-<span class="sourceLineNo">210</span> }<a name="line.210"></a>
-<span class="sourceLineNo">211</span>
queuedEvents.add((EventHandler)r);<a name="line.211"></a>
-<span class="sourceLineNo">212</span> }<a name="line.212"></a>
+<span class="sourceLineNo">204</span> /**<a name="line.204"></a>
+<span class="sourceLineNo">205</span> * Submit the event to the queue for
handling.<a name="line.205"></a>
+<span class="sourceLineNo">206</span> * @param event<a name="line.206"></a>
+<span class="sourceLineNo">207</span> */<a name="line.207"></a>
+<span class="sourceLineNo">208</span> void submit(final EventHandler event)
{<a name="line.208"></a>
+<span class="sourceLineNo">209</span> // If there is a listener for this
type, make sure we call the before<a name="line.209"></a>
+<span class="sourceLineNo">210</span> // and after process methods.<a
name="line.210"></a>
+<span class="sourceLineNo">211</span>
this.threadPoolExecutor.execute(event);<a name="line.211"></a>
+<span class="sourceLineNo">212</span> }<a name="line.212"></a>
<span class="sourceLineNo">213</span><a name="line.213"></a>
-<span class="sourceLineNo">214</span> List<RunningEventStatus>
running = Lists.newArrayList();<a name="line.214"></a>
-<span class="sourceLineNo">215</span> for (Map.Entry<Thread,
Runnable> e :<a name="line.215"></a>
-<span class="sourceLineNo">216</span>
threadPoolExecutor.getRunningTasks().entrySet()) {<a name="line.216"></a>
-<span class="sourceLineNo">217</span> Runnable r = e.getValue();<a
name="line.217"></a>
-<span class="sourceLineNo">218</span> if (!(r instanceof EventHandler))
{<a name="line.218"></a>
-<span class="sourceLineNo">219</span> LOG.warn("Non-EventHandler " +
r + " running in " + name);<a name="line.219"></a>
-<span class="sourceLineNo">220</span> continue;<a name="line.220"></a>
-<span class="sourceLineNo">221</span> }<a name="line.221"></a>
-<span class="sourceLineNo">222</span> running.add(new
RunningEventStatus(e.getKey(), (EventHandler)r));<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> return new ExecutorStatus(this,
queuedEvents, running);<a name="line.225"></a>
-<span class="sourceLineNo">226</span> }<a name="line.226"></a>
-<span class="sourceLineNo">227</span> }<a name="line.227"></a>
-<span class="sourceLineNo">228</span><a name="line.228"></a>
-<span class="sourceLineNo">229</span> /**<a name="line.229"></a>
-<span class="sourceLineNo">230</span> * A subclass of ThreadPoolExecutor
that keeps track of the Runnables that<a name="line.230"></a>
-<span class="sourceLineNo">231</span> * are executing at any given point in
time.<a name="line.231"></a>
-<span class="sourceLineNo">232</span> */<a name="line.232"></a>
-<span class="sourceLineNo">233</span> static class TrackingThreadPoolExecutor
extends ThreadPoolExecutor {<a name="line.233"></a>
-<span class="sourceLineNo">234</span> private ConcurrentMap<Thread,
Runnable> running = Maps.newConcurrentMap();<a name="line.234"></a>
-<span class="sourceLineNo">235</span><a name="line.235"></a>
-<span class="sourceLineNo">236</span> public TrackingThreadPoolExecutor(int
corePoolSize, int maximumPoolSize,<a name="line.236"></a>
-<span class="sourceLineNo">237</span> long keepAliveTime, TimeUnit
unit, BlockingQueue<Runnable> workQueue) {<a name="line.237"></a>
-<span class="sourceLineNo">238</span> super(corePoolSize,
maximumPoolSize, keepAliveTime, unit, workQueue);<a name="line.238"></a>
-<span class="sourceLineNo">239</span> }<a name="line.239"></a>
-<span class="sourceLineNo">240</span><a name="line.240"></a>
-<span class="sourceLineNo">241</span> @Override<a name="line.241"></a>
-<span class="sourceLineNo">242</span> protected void afterExecute(Runnable
r, Throwable t) {<a name="line.242"></a>
-<span class="sourceLineNo">243</span> super.afterExecute(r, t);<a
name="line.243"></a>
-<span class="sourceLineNo">244</span>
running.remove(Thread.currentThread());<a name="line.244"></a>
+<span class="sourceLineNo">214</span> TrackingThreadPoolExecutor
getThreadPoolExecutor() {<a name="line.214"></a>
+<span class="sourceLineNo">215</span> return threadPoolExecutor;<a
name="line.215"></a>
+<span class="sourceLineNo">216</span> }<a name="line.216"></a>
+<span class="sourceLineNo">217</span><a name="line.217"></a>
+<span class="sourceLineNo">218</span> @Override<a name="line.218"></a>
+<span class="sourceLineNo">219</span> public String toString() {<a
name="line.219"></a>
+<span class="sourceLineNo">220</span> return getClass().getSimpleName() +
"-" + id + "-" + name;<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> public ExecutorStatus getStatus() {<a
name="line.223"></a>
+<span class="sourceLineNo">224</span> List<EventHandler>
queuedEvents = Lists.newArrayList();<a name="line.224"></a>
+<span class="sourceLineNo">225</span> for (Runnable r : q) {<a
name="line.225"></a>
+<span class="sourceLineNo">226</span> if (!(r instanceof EventHandler))
{<a name="line.226"></a>
+<span class="sourceLineNo">227</span> LOG.warn("Non-EventHandler " +
r + " queued in " + name);<a name="line.227"></a>
+<span class="sourceLineNo">228</span> continue;<a name="line.228"></a>
+<span class="sourceLineNo">229</span> }<a name="line.229"></a>
+<span class="sourceLineNo">230</span>
queuedEvents.add((EventHandler)r);<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> List<RunningEventStatus>
running = Lists.newArrayList();<a name="line.233"></a>
+<span class="sourceLineNo">234</span> for (Map.Entry<Thread,
Runnable> e :<a name="line.234"></a>
+<span class="sourceLineNo">235</span>
threadPoolExecutor.getRunningTasks().entrySet()) {<a name="line.235"></a>
+<span class="sourceLineNo">236</span> Runnable r = e.getValue();<a
name="line.236"></a>
+<span class="sourceLineNo">237</span> if (!(r instanceof EventHandler))
{<a name="line.237"></a>
+<span class="sourceLineNo">238</span> LOG.warn("Non-EventHandler " +
r + " running in " + name);<a name="line.238"></a>
+<span class="sourceLineNo">239</span> continue;<a name="line.239"></a>
+<span class="sourceLineNo">240</span> }<a name="line.240"></a>
+<span class="sourceLineNo">241</span> running.add(new
RunningEventStatus(e.getKey(), (EventHandler)r));<a name="line.241"></a>
+<span class="sourceLineNo">242</span> }<a name="line.242"></a>
+<span class="sourceLineNo">243</span><a name="line.243"></a>
+<span class="sourceLineNo">244</span> return new ExecutorStatus(this,
queuedEvents, running);<a name="line.244"></a>
<span class="sourceLineNo">245</span> }<a name="line.245"></a>
-<span class="sourceLineNo">246</span><a name="line.246"></a>
-<span class="sourceLineNo">247</span> @Override<a name="line.247"></a>
-<span class="sourceLineNo">248</span> protected void beforeExecute(Thread
t, Runnable r) {<a name="line.248"></a>
-<span class="sourceLineNo">249</span> Runnable oldPut = running.put(t,
r);<a name="line.249"></a>
-<span class="sourceLineNo">250</span> assert oldPut == null :
"inconsistency for thread " + t;<a name="line.250"></a>
-<span class="sourceLineNo">251</span> super.beforeExecute(t, r);<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> /**<a name="line.254"></a>
-<span class="sourceLineNo">255</span> * @return a map of the threads
currently running tasks<a name="line.255"></a>
-<span class="sourceLineNo">256</span> * inside this executor. Each key is
an active thread,<a name="line.256"></a>
-<span class="sourceLineNo">257</span> * and the value is the task that is
currently running.<a name="line.257"></a>
-<span class="sourceLineNo">258</span> * Note that this is not a stable
snapshot of the map.<a name="line.258"></a>
-<span class="sourceLineNo">259</span> */<a name="line.259"></a>
-<span class="sourceLineNo">260</span> public ConcurrentMap<Thread,
Runnable> getRunningTasks() {<a name="line.260"></a>
-<span class="sourceLineNo">261</span> return running;<a
name="line.261"></a>
-<span class="sourceLineNo">262</span> }<a name="line.262"></a>
-<span class="sourceLineNo">263</span> }<a name="line.263"></a>
-<span class="sourceLineNo">264</span><a name="line.264"></a>
-<span class="sourceLineNo">265</span> /**<a name="line.265"></a>
-<span class="sourceLineNo">266</span> * A snapshot of the status of a
particular executor. This includes<a name="line.266"></a>
-<span class="sourceLineNo">267</span> * the contents of the executor's
pending queue, as well as the<a name="line.267"></a>
-<span class="sourceLineNo">268</span> * threads and events currently being
processed.<a name="line.268"></a>
-<span class="sourceLineNo">269</span> *<a name="line.269"></a>
-<span class="sourceLineNo">270</span> * This is a consistent snapshot that
is immutable once constructed.<a name="line.270"></a>
-<span class="sourceLineNo">271</span> */<a name="line.271"></a>
-<span class="sourceLineNo">272</span> public static class ExecutorStatus {<a
name="line.272"></a>
-<span class="sourceLineNo">273</span> final Executor executor;<a
name="line.273"></a>
-<span class="sourceLineNo">274</span> final List<EventHandler>
queuedEvents;<a name="line.274"></a>
-<span class="sourceLineNo">275</span> final List<RunningEventStatus>
running;<a name="line.275"></a>
-<span class="sourceLineNo">276</span><a name="line.276"></a>
-<span class="sourceLineNo">277</span> ExecutorStatus(Executor executor,<a
name="line.277"></a>
-<span class="sourceLineNo">278</span> List<EventHandler>
queuedEvents,<a name="line.278"></a>
-<span class="sourceLineNo">279</span> List<RunningEventStatus>
running) {<a name="line.279"></a>
-<span class="sourceLineNo">280</span> this.executor = executor;<a
name="line.280"></a>
-<span class="sourceLineNo">281</span> this.queuedEvents = queuedEvents;<a
name="line.281"></a>
-<span class="sourceLineNo">282</span> this.running = running;<a
name="line.282"></a>
-<span class="sourceLineNo">283</span> }<a name="line.283"></a>
-<span class="sourceLineNo">284</span><a name="line.284"></a>
-<span class="sourceLineNo">285</span> /**<a name="line.285"></a>
-<span class="sourceLineNo">286</span> * Dump a textual representation of
the executor's status<a name="line.286"></a>
-<span class="sourceLineNo">287</span> * to the given writer.<a
name="line.287"></a>
-<span class="sourceLineNo">288</span> *<a name="line.288"></a>
-<span class="sourceLineNo">289</span> * @param out the stream to write
to<a name="line.289"></a>
-<span class="sourceLineNo">290</span> * @param indent a string prefix for
each line, used for indentation<a name="line.290"></a>
-<span class="sourceLineNo">291</span> */<a name="line.291"></a>
-<span class="sourceLineNo">292</span> public void dumpTo(Writer out, String
indent) throws IOException {<a name="line.292"></a>
-<span class="sourceLineNo">293</span> out.write(indent + "Status for
executor: " + executor + "\n");<a name="line.293"></a>
-<span class="sourceLineNo">294</span> out.write(indent +
"=======================================\n");<a name="line.294"></a>
-<span class="sourceLineNo">295</span> out.write(indent +
queuedEvents.size() + " events queued, " +<a name="line.295"></a>
-<span class="sourceLineNo">296</span> running.size() + "
running\n");<a name="line.296"></a>
-<span class="sourceLineNo">297</span> if (!queuedEvents.isEmpty()) {<a
name="line.297"></a>
-<span class="sourceLineNo">298</span> out.write(indent +
"Queued:\n");<a name="line.298"></a>
-<span class="sourceLineNo">299</span> for (EventHandler e :
queuedEvents) {<a name="line.299"></a>
-<span class="sourceLineNo">300</span> out.write(indent + " " + e +
"\n");<a name="line.300"></a>
-<span class="sourceLineNo">301</span> }<a name="line.301"></a>
-<span class="sourceLineNo">302</span> out.write("\n");<a
name="line.302"></a>
-<span class="sourceLineNo">303</span> }<a name="line.303"></a>
-<span class="sourceLineNo">304</span> if (!running.isEmpty()) {<a
name="line.304"></a>
-<span class="sourceLineNo">305</span> out.write(indent +
"Running:\n");<a name="line.305"></a>
-<span class="sourceLineNo">306</span> for (RunningEventStatus stat :
running) {<a name="line.306"></a>
-<span class="sourceLineNo">307</span> out.write(indent + " Running
on thread '" +<a name="line.307"></a>
-<span class="sourceLineNo">308</span>
stat.threadInfo.getThreadName() +<a name="line.308"></a>
-<span class="sourceLineNo">309</span> "': " + stat.event +
"\n");<a name="line.309"></a>
-<span class="sourceLineNo">310</span>
out.write(ThreadMonitoring.formatThreadInfo(<a name="line.310"></a>
-<span class="sourceLineNo">311</span> stat.threadInfo, indent + "
"));<a name="line.311"></a>
-<span class="sourceLineNo">312</span> out.write("\n");<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> out.flush();<a name="line.315"></a>
-<span class="sourceLineNo">316</span> }<a name="line.316"></a>
-<span class="sourceLineNo">317</span> }<a name="line.317"></a>
-<span class="sourceLineNo">318</span><a name="line.318"></a>
-<span class="sourceLineNo">319</span> /**<a name="line.319"></a>
-<span class="sourceLineNo">320</span> * The status of a particular event
that is in the middle of being<a name="line.320"></a>
-<span class="sourceLineNo">321</span> * handled by an executor.<a
name="line.321"></a>
-<span class="sourceLineNo">322</span> */<a name="line.322"></a>
-<span class="sourceLineNo">323</span> public static class RunningEventStatus
{<a name="line.323"></a>
-<span class="sourceLineNo">324</span> final ThreadInfo threadInfo;<a
name="line.324"></a>
-<span class="sourceLineNo">325</span> final EventHandler event;<a
name="line.325"></a>
-<span class="sourceLineNo">326</span><a name="line.326"></a>
-<span class="sourceLineNo">327</span> public RunningEventStatus(Thread t,
EventHandler event) {<a name="line.327"></a>
-<span class="sourceLineNo">328</span> this.threadInfo =
ThreadMonitoring.getThreadInfo(t);<a name="line.328"></a>
-<span class="sourceLineNo">329</span> this.event = event;<a
name="line.329"></a>
-<span class="sourceLineNo">330</span> }<a name="line.330"></a>
-<span class="sourceLineNo">331</span> }<a name="line.331"></a>
-<span class="sourceLineNo">332</span>}<a name="line.332"></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> * A subclass of ThreadPoolExecutor
that keeps track of the Runnables that<a name="line.249"></a>
+<span class="sourceLineNo">250</span> * are executing at any given point in
time.<a name="line.250"></a>
+<span class="sourceLineNo">251</span> */<a name="line.251"></a>
+<span class="sourceLineNo">252</span> static class TrackingThreadPoolExecutor
extends ThreadPoolExecutor {<a name="line.252"></a>
+<span class="sourceLineNo">253</span> private ConcurrentMap<Thread,
Runnable> running = Maps.newConcurrentMap();<a name="line.253"></a>
+<span class="sourceLineNo">254</span><a name="line.254"></a>
+<span class="sourceLineNo">255</span> public TrackingThreadPoolExecutor(int
corePoolSize, int maximumPoolSize,<a name="line.255"></a>
+<span class="sourceLineNo">256</span> long keepAliveTime, TimeUnit
unit, BlockingQueue<Runnable> workQueue) {<a name="line.256"></a>
+<span class="sourceLineNo">257</span> super(corePoolSize,
maximumPoolSize, keepAliveTime, unit, workQueue);<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> @Override<a name="line.260"></a>
+<span class="sourceLineNo">261</span> protected void afterExecute(Runnable
r, Throwable t) {<a name="line.261"></a>
+<span class="sourceLineNo">262</span> super.afterExecute(r, t);<a
name="line.262"></a>
+<span class="sourceLineNo">263</span>
running.remove(Thread.currentThread());<a name="line.263"></a>
+<span class="sourceLineNo">264</span> }<a name="line.264"></a>
+<span class="sourceLineNo">265</span><a name="line.265"></a>
+<span class="sourceLineNo">266</span> @Override<a name="line.266"></a>
+<span class="sourceLineNo">267</span> protected void beforeExecute(Thread
t, Runnable r) {<a name="line.267"></a>
+<span class="sourceLineNo">268</span> Runnable oldPut = running.put(t,
r);<a name="line.268"></a>
+<span class="sourceLineNo">269</span> assert oldPut == null :
"inconsistency for thread " + t;<a name="line.269"></a>
+<span class="sourceLineNo">270</span> super.beforeExecute(t, r);<a
name="line.270"></a>
+<span class="sourceLineNo">271</span> }<a name="line.271"></a>
+<span class="sourceLineNo">272</span><a name="line.272"></a>
+<span class="sourceLineNo">273</span> /**<a name="line.273"></a>
+<span class="sourceLineNo">274</span> * @return a map of the threads
currently running tasks<a name="line.274"></a>
+<span class="sourceLineNo">275</span> * inside this executor. Each key is
an active thread,<a name="line.275"></a>
+<span class="sourceLineNo">276</span> * and the value is the task that is
currently running.<a name="line.276"></a>
+<span class="sourceLineNo">277</span> * Note that this is not a stable
snapshot of the map.<a name="line.277"></a>
+<span class="sourceLineNo">278</span> */<a name="line.278"></a>
+<span class="sourceLineNo">279</span> public ConcurrentMap<Thread,
Runnable> getRunningTasks() {<a name="line.279"></a>
+<span class="sourceLineNo">280</span> return running;<a
name="line.280"></a>
+<span class="sourceLineNo">281</span> }<a name="line.281"></a>
+<span class="sourceLineNo">282</span> }<a name="line.282"></a>
+<span class="sourceLineNo">283</span><a name="line.283"></a>
+<span class="sourceLineNo">284</span> /**<a name="line.284"></a>
+<span class="sourceLineNo">285</span> * A snapshot of the status of a
particular executor. This includes<a name="line.285"></a>
+<span class="sourceLineNo">286</span> * the contents of the executor's
pending queue, as well as the<a name="line.286"></a>
+<span class="sourceLineNo">287</span> * threads and events currently being
processed.<a name="line.287"></a>
+<span class="sourceLineNo">288</span> *<a name="line.288"></a>
+<span class="sourceLineNo">289</span> * This is a consistent snapshot that
is immutable once constructed.<a name="line.289"></a>
+<span class="sourceLineNo">290</span> */<a name="line.290"></a>
+<span class="sourceLineNo">291</span> public static class ExecutorStatus {<a
name="line.291"></a>
+<span class="sourceLineNo">292</span> final Executor executor;<a
name="line.292"></a>
+<span class="sourceLineNo">293</span> final List<EventHandler>
queuedEvents;<a name="line.293"></a>
+<span class="sourceLineNo">294</span> final List<RunningEventStatus>
running;<a name="line.294"></a>
+<span class="sourceLineNo">295</span><a name="line.295"></a>
+<span class="sourceLineNo">296</span> ExecutorStatus(Executor executor,<a
name="line.296"></a>
+<span class="sourceLineNo">297</span> List<EventHandler>
queuedEvents,<a name="line.297"></a>
+<span class="sourceLineNo">298</span> List<RunningEventStatus>
running) {<a name="line.298"></a>
+<span class="sourceLineNo">299</span> this.executor = executor;<a
name="line.299"></a>
+<span class="sourceLineNo">300</span> this.queuedEvents = queuedEvents;<a
name="line.300"></a>
+<span class="sourceLineNo">301</span> this.running = running;<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> /**<a name="line.304"></a>
+<span class="sourceLineNo">305</span> * Dump a textual representation of
the executor's status<a name="line.305"></a>
+<span class="sourceLineNo">306</span> * to the given writer.<a
name="line.306"></a>
+<span class="sourceLineNo">307</span> *<a name="line.307"></a>
+<span class="sourceLineNo">308</span> * @param out the stream to write
to<a name="line.308"></a>
+<span class="sourceLineNo">309</span> * @param indent a string prefix for
each line, used for indentation<a name="line.309"></a>
+<span class="sourceLineNo">310</span> */<a name="line.310"></a>
+<span class="sourceLineNo">311</span> public void dumpTo(Writer out, String
indent) throws IOException {<a name="line.311"></a>
+<span class="sourceLineNo">312</span> out.write(indent + "Status for
executor: " + executor + "\n");<a name="line.312"></a>
+<span class="sourceLineNo">313</span> out.write(indent +
"=======================================\n");<a name="line.313"></a>
+<span class="sourceLineNo">314</span> out.write(indent +
queuedEvents.size() + " events queued, " +<a name="line.314"></a>
+<span class="sourceLineNo">315</span> running.size() + "
running\n");<a name="line.315"></a>
+<span class="sourceLineNo">316</span> if (!queuedEvents.isEmpty()) {<a
name="line.316"></a>
+<span class="sourceLineNo">317</span> out.write(indent +
"Queued:\n");<a name="line.317"></a>
+<span class="sourceLineNo">318</span> for (EventHandler e :
queuedEvents) {<a name="line.318"></a>
+<span class="sourceLineNo">319</span> out.write(indent + " " + e +
"\n");<a name="line.319"></a>
+<span class="sourceLineNo">320</span> }<a name="line.320"></a>
+<span class="sourceLineNo">321</span> out.write("\n");<a
name="line.321"></a>
+<span class="sourceLineNo">322</span> }<a name="line.322"></a>
+<span class="sourceLineNo">323</span> if (!running.isEmpty()) {<a
name="line.323"></a>
+<span class="sourceLineNo">324</span> out.write(indent +
"Running:\n");<a name="line.324"></a>
+<span class="sourceLineNo">325</span> for (RunningEventStatus stat :
running) {<a name="line.325"></a>
+<span class="sourceLineNo">326</span> out.write(indent + " Running
on thread '" +<a name="line.326"></a>
+<span class="sourceLineNo">327</span>
stat.threadInfo.getThreadName() +<a name="line.327"></a>
+<span class="sourceLineNo">328</span> "': " + stat.event +
"\n");<a name="line.328"></a>
+<span class="sourceLineNo">329</span>
out.write(ThreadMonitoring.formatThreadInfo(<a name="line.329"></a>
+<span class="sourceLineNo">330</span> stat.threadInfo, indent + "
"));<a name="line.330"></a>
+<span class="sourceLineNo">331</span> out.write("\n");<a
name="line.331"></a>
+<span class="sourceLineNo">332</span> }<a name="line.332"></a>
+<span class="sourceLineNo">333</span> }<a name="line.333"></a>
+<span class="sourceLineNo">334</span> out.flush();<a name="line.334"></a>
+<span class="sourceLineNo">335</span> }<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> * The status of a particular event
that is in the middle of being<a name="line.339"></a>
+<span class="sourceLineNo">340</span> * handled by an executor.<a
name="line.340"></a>
+<span class="sourceLineNo">341</span> */<a name="line.341"></a>
+<span class="sourceLineNo">342</span> public static class RunningEventStatus
{<a name="line.342"></a>
+<span class="sourceLineNo">343</span> final ThreadInfo threadInfo;<a
name="line.343"></a>
+<span class="sourceLineNo">344</span> final EventHandler event;<a
name="line.344"></a>
+<span class="sourceLineNo">345</span><a name="line.345"></a>
+<span class="sourceLineNo">346</span> public RunningEventStatus(Thread t,
EventHandler event) {<a name="line.346"></a>
+<span class="sourceLineNo">347</span> this.threadInfo =
ThreadMonitoring.getThreadInfo(t);<a name="line.347"></a>
+<span class="sourceLineNo">348</span> this.event = event;<a
name="line.348"></a>
+<span class="sourceLineNo">349</span> }<a name="line.349"></a>
+<span class="sourceLineNo">350</span> }<a name="line.350"></a>
+<span class="sourceLineNo">351</span>}<a name="line.351"></a>