Jian Li
Committed by Gerrit Code Review

[ONOS-3528] Enable logging exception for SharedExecutorService

Change-Id: I612d5e844412b2ddca6b848e5f7aae5138999d3f
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onlab.util; 16 package org.onlab.util;
17 17
18 +import com.codahale.metrics.Timer;
18 import org.onlab.metrics.MetricsComponent; 19 import org.onlab.metrics.MetricsComponent;
19 import org.onlab.metrics.MetricsFeature; 20 import org.onlab.metrics.MetricsFeature;
20 import org.onlab.metrics.MetricsService; 21 import org.onlab.metrics.MetricsService;
...@@ -27,8 +28,8 @@ import java.util.concurrent.ExecutorService; ...@@ -27,8 +28,8 @@ import java.util.concurrent.ExecutorService;
27 import java.util.concurrent.Future; 28 import java.util.concurrent.Future;
28 import java.util.concurrent.TimeUnit; 29 import java.util.concurrent.TimeUnit;
29 import java.util.concurrent.TimeoutException; 30 import java.util.concurrent.TimeoutException;
30 -import com.codahale.metrics.Timer;
31 31
32 +import static org.slf4j.LoggerFactory.getLogger;
32 33
33 34
34 /** 35 /**
...@@ -111,11 +112,11 @@ class SharedExecutorService implements ExecutorService { ...@@ -111,11 +112,11 @@ class SharedExecutorService implements ExecutorService {
111 return executor.submit(() -> { 112 return executor.submit(() -> {
112 T t = null; 113 T t = null;
113 long queueWaitTime = (long) taskCounter.duration(); 114 long queueWaitTime = (long) taskCounter.duration();
114 - String className; 115 + Class className;
115 if (task instanceof CallableExtended) { 116 if (task instanceof CallableExtended) {
116 - className = ((CallableExtended) task).getRunnable().getClass().toString(); 117 + className = ((CallableExtended) task).getRunnable().getClass();
117 } else { 118 } else {
118 - className = task.getClass().toString(); 119 + className = task.getClass();
119 } 120 }
120 if (queueMetrics != null) { 121 if (queueMetrics != null) {
121 queueMetrics.update(queueWaitTime, TimeUnit.SECONDS); 122 queueMetrics.update(queueWaitTime, TimeUnit.SECONDS);
...@@ -123,7 +124,9 @@ class SharedExecutorService implements ExecutorService { ...@@ -123,7 +124,9 @@ class SharedExecutorService implements ExecutorService {
123 taskCounter.reset(); 124 taskCounter.reset();
124 try { 125 try {
125 t = task.call(); 126 t = task.call();
126 - } catch (Exception e) { } 127 + } catch (Exception e) {
128 + getLogger(className).error("Uncaught exception on " + className, e);
129 + }
127 long taskwaittime = (long) taskCounter.duration(); 130 long taskwaittime = (long) taskCounter.duration();
128 if (delayMetrics != null) { 131 if (delayMetrics != null) {
129 delayMetrics.update(taskwaittime, TimeUnit.SECONDS); 132 delayMetrics.update(taskwaittime, TimeUnit.SECONDS);
......