Cleaning-up shared executors use of metrics service.
Change-Id: I4293df87cd46e9f22cbdf03cfbced9a21ba85de7
Showing
3 changed files
with
60 additions
and
47 deletions
| ... | @@ -101,7 +101,7 @@ public class CoreManager implements CoreService { | ... | @@ -101,7 +101,7 @@ public class CoreManager implements CoreService { |
| 101 | 101 | ||
| 102 | 102 | ||
| 103 | @Activate | 103 | @Activate |
| 104 | - public void activate() { | 104 | + protected void activate() { |
| 105 | registerApplication(CORE_APP_NAME); | 105 | registerApplication(CORE_APP_NAME); |
| 106 | cfgService.registerProperties(getClass()); | 106 | cfgService.registerProperties(getClass()); |
| 107 | try { | 107 | try { |
| ... | @@ -117,7 +117,7 @@ public class CoreManager implements CoreService { | ... | @@ -117,7 +117,7 @@ public class CoreManager implements CoreService { |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | @Deactivate | 119 | @Deactivate |
| 120 | - public void deactivate() { | 120 | + protected void deactivate() { |
| 121 | cfgService.unregisterProperties(getClass(), false); | 121 | cfgService.unregisterProperties(getClass(), false); |
| 122 | SharedExecutors.shutdown(); | 122 | SharedExecutors.shutdown(); |
| 123 | } | 123 | } |
| ... | @@ -171,7 +171,7 @@ public class CoreManager implements CoreService { | ... | @@ -171,7 +171,7 @@ public class CoreManager implements CoreService { |
| 171 | 171 | ||
| 172 | 172 | ||
| 173 | @Modified | 173 | @Modified |
| 174 | - public void modified(ComponentContext context) { | 174 | + protected void modified(ComponentContext context) { |
| 175 | Dictionary<?, ?> properties = context.getProperties(); | 175 | Dictionary<?, ?> properties = context.getProperties(); |
| 176 | Integer poolSize = Tools.getIntegerProperty(properties, "sharedThreadPoolSize"); | 176 | Integer poolSize = Tools.getIntegerProperty(properties, "sharedThreadPoolSize"); |
| 177 | 177 | ||
| ... | @@ -193,7 +193,7 @@ public class CoreManager implements CoreService { | ... | @@ -193,7 +193,7 @@ public class CoreManager implements CoreService { |
| 193 | Boolean performanceCheck = Tools.isPropertyEnabled(properties, "sharedThreadPerformanceCheck"); | 193 | Boolean performanceCheck = Tools.isPropertyEnabled(properties, "sharedThreadPerformanceCheck"); |
| 194 | if (performanceCheck != null) { | 194 | if (performanceCheck != null) { |
| 195 | calculatePoolPerformance = performanceCheck; | 195 | calculatePoolPerformance = performanceCheck; |
| 196 | - SharedExecutors.setCalculatePoolPerformance(calculatePoolPerformance, metricsService); | 196 | + SharedExecutors.setMetricsService(calculatePoolPerformance ? metricsService : null); |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | log.info("Settings: sharedThreadPoolSize={}, maxEventTimeLimit={}, calculatePoolPerformance={}", | 199 | log.info("Settings: sharedThreadPoolSize={}, maxEventTimeLimit={}, calculatePoolPerformance={}", | ... | ... |
| ... | @@ -112,30 +112,29 @@ class SharedExecutorService implements ExecutorService { | ... | @@ -112,30 +112,29 @@ class SharedExecutorService implements ExecutorService { |
| 112 | Counter taskCounter = new Counter(); | 112 | Counter taskCounter = new Counter(); |
| 113 | taskCounter.reset(); | 113 | taskCounter.reset(); |
| 114 | return executor.submit(() -> { | 114 | return executor.submit(() -> { |
| 115 | - T t = null; | 115 | + T t = null; |
| 116 | - long queueWaitTime = (long) taskCounter.duration(); | 116 | + long queueWaitTime = (long) taskCounter.duration(); |
| 117 | - Class className; | 117 | + Class className; |
| 118 | - if (task instanceof CallableExtended) { | 118 | + if (task instanceof CallableExtended) { |
| 119 | - className = ((CallableExtended) task).getRunnable().getClass(); | 119 | + className = ((CallableExtended) task).getRunnable().getClass(); |
| 120 | - } else { | 120 | + } else { |
| 121 | - className = task.getClass(); | 121 | + className = task.getClass(); |
| 122 | - } | 122 | + } |
| 123 | - if (queueMetrics != null) { | 123 | + if (queueMetrics != null) { |
| 124 | - queueMetrics.update(queueWaitTime, TimeUnit.SECONDS); | 124 | + queueMetrics.update(queueWaitTime, TimeUnit.SECONDS); |
| 125 | - } | 125 | + } |
| 126 | - taskCounter.reset(); | 126 | + taskCounter.reset(); |
| 127 | - try { | 127 | + try { |
| 128 | - t = task.call(); | 128 | + t = task.call(); |
| 129 | - } catch (Exception e) { | 129 | + } catch (Exception e) { |
| 130 | - getLogger(className).error("Uncaught exception on " + className, e); | 130 | + getLogger(className).error("Uncaught exception on " + className, e); |
| 131 | - } | 131 | + } |
| 132 | - long taskwaittime = (long) taskCounter.duration(); | 132 | + long taskwaittime = (long) taskCounter.duration(); |
| 133 | - if (delayMetrics != null) { | 133 | + if (delayMetrics != null) { |
| 134 | - delayMetrics.update(taskwaittime, TimeUnit.SECONDS); | 134 | + delayMetrics.update(taskwaittime, TimeUnit.SECONDS); |
| 135 | - } | 135 | + } |
| 136 | - return t; | 136 | + return t; |
| 137 | - } | 137 | + }); |
| 138 | - ); | ||
| 139 | } | 138 | } |
| 140 | 139 | ||
| 141 | @Override | 140 | @Override |
| ... | @@ -179,20 +178,26 @@ class SharedExecutorService implements ExecutorService { | ... | @@ -179,20 +178,26 @@ class SharedExecutorService implements ExecutorService { |
| 179 | executor.execute(command); | 178 | executor.execute(command); |
| 180 | } | 179 | } |
| 181 | 180 | ||
| 182 | - public void setCalculatePoolPerformance(boolean calculatePoolPerformance, MetricsService metricsSrv) { | 181 | + /** |
| 183 | - this.metricsService = metricsSrv; | 182 | + * Enables or disables calculation of the pool performance metrics. If |
| 184 | - if (calculatePoolPerformance) { | 183 | + * the metrics service is not null metric collection will be enabled; |
| 185 | - if (metricsService != null) { | 184 | + * otherwise it will be disabled. |
| 186 | - executorMetrics = metricsService.registerComponent("SharedExecutor"); | 185 | + * |
| 187 | - MetricsFeature mf = executorMetrics.registerFeature("*"); | 186 | + * @param metricsService optional metric service |
| 188 | - queueMetrics = metricsService.createTimer(executorMetrics, mf, "Queue"); | 187 | + */ |
| 189 | - delayMetrics = metricsService.createTimer(executorMetrics, mf, "Delay"); | 188 | + public void setMetricsService(MetricsService metricsService) { |
| 190 | - } | 189 | + if (this.metricsService == null && metricsService != null) { |
| 191 | - } else { | 190 | + // If metrics service was newly introduced, initialize metrics. |
| 192 | - metricsService = null; | 191 | + executorMetrics = metricsService.registerComponent("SharedExecutor"); |
| 193 | - queueMetrics = null; | 192 | + MetricsFeature mf = executorMetrics.registerFeature("*"); |
| 194 | - delayMetrics = null; | 193 | + queueMetrics = metricsService.createTimer(executorMetrics, mf, "Queue"); |
| 195 | - } | 194 | + delayMetrics = metricsService.createTimer(executorMetrics, mf, "Delay"); |
| 195 | + } else if (this.metricsService != null && metricsService == null) { | ||
| 196 | + // If the metrics service was newly withdrawn, tear-down metrics. | ||
| 197 | + queueMetrics = null; | ||
| 198 | + delayMetrics = null; | ||
| 199 | + } // Otherwise just record the metrics service | ||
| 200 | + this.metricsService = metricsService; | ||
| 196 | } | 201 | } |
| 197 | 202 | ||
| 198 | private Runnable wrap(Runnable command) { | 203 | private Runnable wrap(Runnable command) { |
| ... | @@ -223,8 +228,8 @@ class SharedExecutorService implements ExecutorService { | ... | @@ -223,8 +228,8 @@ class SharedExecutorService implements ExecutorService { |
| 223 | } | 228 | } |
| 224 | 229 | ||
| 225 | /** | 230 | /** |
| 226 | - * CallableExtended class is used to get Runnable Object | 231 | + * CallableExtended class is used to get Runnable Object |
| 227 | - * from Callable Object. | 232 | + * from Callable Object. |
| 228 | */ | 233 | */ |
| 229 | class CallableExtended implements Callable { | 234 | class CallableExtended implements Callable { |
| 230 | 235 | ||
| ... | @@ -232,11 +237,13 @@ class SharedExecutorService implements ExecutorService { | ... | @@ -232,11 +237,13 @@ class SharedExecutorService implements ExecutorService { |
| 232 | 237 | ||
| 233 | /** | 238 | /** |
| 234 | * Wrapper for Callable object . | 239 | * Wrapper for Callable object . |
| 240 | + * | ||
| 235 | * @param runnable Runnable object | 241 | * @param runnable Runnable object |
| 236 | */ | 242 | */ |
| 237 | public CallableExtended(Runnable runnable) { | 243 | public CallableExtended(Runnable runnable) { |
| 238 | this.runnable = runnable; | 244 | this.runnable = runnable; |
| 239 | } | 245 | } |
| 246 | + | ||
| 240 | public Runnable getRunnable() { | 247 | public Runnable getRunnable() { |
| 241 | return runnable; | 248 | return runnable; |
| 242 | } | 249 | } | ... | ... |
| ... | @@ -95,9 +95,15 @@ public final class SharedExecutors { | ... | @@ -95,9 +95,15 @@ public final class SharedExecutors { |
| 95 | "onos-pool-executor-%d"))); | 95 | "onos-pool-executor-%d"))); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | - | 98 | + /** |
| 99 | - public static void setCalculatePoolPerformance(boolean calculatePoolPerformance, MetricsService metricsService) { | 99 | + * Enables or disables calculation of the pool performance metrics. If |
| 100 | - poolThreadExecutor.setCalculatePoolPerformance(calculatePoolPerformance, metricsService); | 100 | + * the metrics service is not null metric collection will be enabled; |
| 101 | + * otherwise it will be disabled. | ||
| 102 | + * | ||
| 103 | + * @param metricsService optional metric service | ||
| 104 | + */ | ||
| 105 | + public static void setMetricsService(MetricsService metricsService) { | ||
| 106 | + poolThreadExecutor.setMetricsService(metricsService); | ||
| 101 | } | 107 | } |
| 102 | 108 | ||
| 103 | /** | 109 | /** | ... | ... |
-
Please register or login to post a comment