Thomas Vachuska

Cleaning-up shared executors use of metrics service.

Change-Id: I4293df87cd46e9f22cbdf03cfbced9a21ba85de7
...@@ -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={}",
......
...@@ -134,8 +134,7 @@ class SharedExecutorService implements ExecutorService { ...@@ -134,8 +134,7 @@ class SharedExecutorService implements ExecutorService {
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.
185 + *
186 + * @param metricsService optional metric service
187 + */
188 + public void setMetricsService(MetricsService metricsService) {
189 + if (this.metricsService == null && metricsService != null) {
190 + // If metrics service was newly introduced, initialize metrics.
186 executorMetrics = metricsService.registerComponent("SharedExecutor"); 191 executorMetrics = metricsService.registerComponent("SharedExecutor");
187 MetricsFeature mf = executorMetrics.registerFeature("*"); 192 MetricsFeature mf = executorMetrics.registerFeature("*");
188 queueMetrics = metricsService.createTimer(executorMetrics, mf, "Queue"); 193 queueMetrics = metricsService.createTimer(executorMetrics, mf, "Queue");
189 delayMetrics = metricsService.createTimer(executorMetrics, mf, "Delay"); 194 delayMetrics = metricsService.createTimer(executorMetrics, mf, "Delay");
190 - } 195 + } else if (this.metricsService != null && metricsService == null) {
191 - } else { 196 + // If the metrics service was newly withdrawn, tear-down metrics.
192 - metricsService = null;
193 queueMetrics = null; 197 queueMetrics = null;
194 delayMetrics = null; 198 delayMetrics = null;
195 - } 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) {
...@@ -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 /**
......