sangyun-han
Committed by Gerrit Code Review

[ONOS-4004] DistributedStatisticStore and DistributedFlowStatisticStore make configurable

- Using @Property and @Modified annotations
- Fix DistributedPacketStore / DistributedStatisticStore / DistributedFlowStatisticStore

Change-Id: I6c907498496b9f21a8ef13b7badeb24770cb88ff
...@@ -21,6 +21,8 @@ import com.google.common.collect.Sets; ...@@ -21,6 +21,8 @@ import com.google.common.collect.Sets;
21 import org.apache.felix.scr.annotations.Activate; 21 import org.apache.felix.scr.annotations.Activate;
22 import org.apache.felix.scr.annotations.Component; 22 import org.apache.felix.scr.annotations.Component;
23 import org.apache.felix.scr.annotations.Deactivate; 23 import org.apache.felix.scr.annotations.Deactivate;
24 +import org.apache.felix.scr.annotations.Modified;
25 +import org.apache.felix.scr.annotations.Property;
24 import org.apache.felix.scr.annotations.Reference; 26 import org.apache.felix.scr.annotations.Reference;
25 import org.apache.felix.scr.annotations.ReferenceCardinality; 27 import org.apache.felix.scr.annotations.ReferenceCardinality;
26 import org.apache.felix.scr.annotations.Service; 28 import org.apache.felix.scr.annotations.Service;
...@@ -44,14 +46,20 @@ import org.onosproject.store.service.ConsistentMap; ...@@ -44,14 +46,20 @@ import org.onosproject.store.service.ConsistentMap;
44 import org.onosproject.store.service.ConsistentMapException; 46 import org.onosproject.store.service.ConsistentMapException;
45 import org.onosproject.store.service.Serializer; 47 import org.onosproject.store.service.Serializer;
46 import org.onosproject.store.service.StorageService; 48 import org.onosproject.store.service.StorageService;
49 +import org.osgi.service.component.ComponentContext;
47 import org.slf4j.Logger; 50 import org.slf4j.Logger;
48 51
52 +import java.util.Dictionary;
49 import java.util.List; 53 import java.util.List;
54 +import java.util.Properties;
50 import java.util.Set; 55 import java.util.Set;
51 import java.util.concurrent.ExecutorService; 56 import java.util.concurrent.ExecutorService;
52 import java.util.concurrent.Executors; 57 import java.util.concurrent.Executors;
53 import java.util.concurrent.atomic.AtomicBoolean; 58 import java.util.concurrent.atomic.AtomicBoolean;
54 59
60 +import static com.google.common.base.Preconditions.checkArgument;
61 +import static com.google.common.base.Strings.isNullOrEmpty;
62 +import static org.onlab.util.Tools.get;
55 import static org.onlab.util.Tools.groupedThreads; 63 import static org.onlab.util.Tools.groupedThreads;
56 import static org.onlab.util.Tools.retryable; 64 import static org.onlab.util.Tools.retryable;
57 import static org.slf4j.LoggerFactory.getLogger; 65 import static org.slf4j.LoggerFactory.getLogger;
...@@ -68,10 +76,7 @@ public class DistributedPacketStore ...@@ -68,10 +76,7 @@ public class DistributedPacketStore
68 76
69 private final Logger log = getLogger(getClass()); 77 private final Logger log = getLogger(getClass());
70 78
71 - private static final int MAX_BACKOFF = 50; 79 + private static final String FORMAT = "Setting: messageHandlerThreadPoolSize={}";
72 -
73 - // TODO: make this configurable.
74 - private static final int MESSAGE_HANDLER_THREAD_POOL_SIZE = 4;
75 80
76 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 81 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
77 protected MastershipService mastershipService; 82 protected MastershipService mastershipService;
...@@ -102,10 +107,17 @@ public class DistributedPacketStore ...@@ -102,10 +107,17 @@ public class DistributedPacketStore
102 107
103 private ExecutorService messageHandlingExecutor; 108 private ExecutorService messageHandlingExecutor;
104 109
110 + private static final int DEFAULT_MESSAGE_HANDLER_THREAD_POOL_SIZE = 4;
111 + @Property(name = "messageHandlerThreadPoolSize", intValue = DEFAULT_MESSAGE_HANDLER_THREAD_POOL_SIZE,
112 + label = "Size of thread pool to assign message handler")
113 + private static int messageHandlerThreadPoolSize = DEFAULT_MESSAGE_HANDLER_THREAD_POOL_SIZE;
114 +
115 + private static final int MAX_BACKOFF = 50;
116 +
105 @Activate 117 @Activate
106 public void activate() { 118 public void activate() {
107 messageHandlingExecutor = Executors.newFixedThreadPool( 119 messageHandlingExecutor = Executors.newFixedThreadPool(
108 - MESSAGE_HANDLER_THREAD_POOL_SIZE, 120 + messageHandlerThreadPoolSize,
109 groupedThreads("onos/store/packet", "message-handlers")); 121 groupedThreads("onos/store/packet", "message-handlers"));
110 122
111 communicationService.<OutboundPacket>addSubscriber(PACKET_OUT_SUBJECT, 123 communicationService.<OutboundPacket>addSubscriber(PACKET_OUT_SUBJECT,
...@@ -126,6 +138,33 @@ public class DistributedPacketStore ...@@ -126,6 +138,33 @@ public class DistributedPacketStore
126 log.info("Stopped"); 138 log.info("Stopped");
127 } 139 }
128 140
141 + @Modified
142 + public void modified(ComponentContext context) {
143 + Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
144 +
145 + int newMessageHandlerThreadPoolSize;
146 +
147 + try {
148 + String s = get(properties, "messageHandlerThreadPoolSize");
149 +
150 + newMessageHandlerThreadPoolSize =
151 + isNullOrEmpty(s) ? messageHandlerThreadPoolSize : Integer.parseInt(s.trim());
152 +
153 + } catch (NumberFormatException e) {
154 + log.warn(e.getMessage());
155 + newMessageHandlerThreadPoolSize = messageHandlerThreadPoolSize;
156 + }
157 +
158 + // Any change in the following parameters implies thread pool restart
159 + if (newMessageHandlerThreadPoolSize != messageHandlerThreadPoolSize) {
160 + setMessageHandlerThreadPoolSize(newMessageHandlerThreadPoolSize);
161 + restartMessageHandlerThreadPool();
162 + }
163 +
164 + log.info(FORMAT, messageHandlerThreadPoolSize);
165 + }
166 +
167 +
129 @Override 168 @Override
130 public void emit(OutboundPacket packet) { 169 public void emit(OutboundPacket packet) {
131 NodeId myId = clusterService.getLocalNode().id(); 170 NodeId myId = clusterService.getLocalNode().id();
...@@ -239,4 +278,32 @@ public class DistributedPacketStore ...@@ -239,4 +278,32 @@ public class DistributedPacketStore
239 return list; 278 return list;
240 } 279 }
241 } 280 }
281 +
282 + /**
283 + * Sets thread pool size of message handler.
284 + *
285 + * @param poolSize
286 + */
287 + private void setMessageHandlerThreadPoolSize(int poolSize) {
288 + checkArgument(poolSize >= 0, "Message handler pool size must be 0 or more");
289 + messageHandlerThreadPoolSize = poolSize;
290 + }
291 +
292 + /**
293 + * Restarts thread pool of message handler.
294 + */
295 + private void restartMessageHandlerThreadPool() {
296 + ExecutorService prevExecutor = messageHandlingExecutor;
297 + messageHandlingExecutor = Executors.newFixedThreadPool(getMessageHandlerThreadPoolSize());
298 + prevExecutor.shutdown();
299 + }
300 +
301 + /**
302 + * Gets current thread pool size of message handler.
303 + *
304 + * @return messageHandlerThreadPoolSize
305 + */
306 + private int getMessageHandlerThreadPoolSize() {
307 + return messageHandlerThreadPoolSize;
308 + }
242 } 309 }
......
...@@ -20,6 +20,8 @@ import com.google.common.base.Objects; ...@@ -20,6 +20,8 @@ import com.google.common.base.Objects;
20 import org.apache.felix.scr.annotations.Activate; 20 import org.apache.felix.scr.annotations.Activate;
21 import org.apache.felix.scr.annotations.Component; 21 import org.apache.felix.scr.annotations.Component;
22 import org.apache.felix.scr.annotations.Deactivate; 22 import org.apache.felix.scr.annotations.Deactivate;
23 +import org.apache.felix.scr.annotations.Modified;
24 +import org.apache.felix.scr.annotations.Property;
23 import org.apache.felix.scr.annotations.Reference; 25 import org.apache.felix.scr.annotations.Reference;
24 import org.apache.felix.scr.annotations.ReferenceCardinality; 26 import org.apache.felix.scr.annotations.ReferenceCardinality;
25 import org.apache.felix.scr.annotations.Service; 27 import org.apache.felix.scr.annotations.Service;
...@@ -39,18 +41,24 @@ import org.onosproject.net.statistic.FlowStatisticStore; ...@@ -39,18 +41,24 @@ import org.onosproject.net.statistic.FlowStatisticStore;
39 import org.onosproject.store.cluster.messaging.ClusterCommunicationService; 41 import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
40 import org.onosproject.store.serializers.KryoNamespaces; 42 import org.onosproject.store.serializers.KryoNamespaces;
41 import org.onosproject.store.serializers.KryoSerializer; 43 import org.onosproject.store.serializers.KryoSerializer;
44 +import org.osgi.service.component.ComponentContext;
42 import org.slf4j.Logger; 45 import org.slf4j.Logger;
43 46
44 import java.util.Collections; 47 import java.util.Collections;
48 +import java.util.Dictionary;
45 import java.util.HashSet; 49 import java.util.HashSet;
46 import java.util.Map; 50 import java.util.Map;
47 import java.util.Optional; 51 import java.util.Optional;
52 +import java.util.Properties;
48 import java.util.Set; 53 import java.util.Set;
49 import java.util.concurrent.ConcurrentHashMap; 54 import java.util.concurrent.ConcurrentHashMap;
50 import java.util.concurrent.ExecutorService; 55 import java.util.concurrent.ExecutorService;
51 import java.util.concurrent.Executors; 56 import java.util.concurrent.Executors;
52 import java.util.concurrent.TimeUnit; 57 import java.util.concurrent.TimeUnit;
53 58
59 +import static com.google.common.base.Preconditions.checkArgument;
60 +import static com.google.common.base.Strings.isNullOrEmpty;
61 +import static org.onlab.util.Tools.get;
54 import static org.onlab.util.Tools.groupedThreads; 62 import static org.onlab.util.Tools.groupedThreads;
55 import static org.onosproject.store.statistic.impl.StatisticStoreMessageSubjects.GET_CURRENT; 63 import static org.onosproject.store.statistic.impl.StatisticStoreMessageSubjects.GET_CURRENT;
56 import static org.onosproject.store.statistic.impl.StatisticStoreMessageSubjects.GET_PREVIOUS; 64 import static org.onosproject.store.statistic.impl.StatisticStoreMessageSubjects.GET_PREVIOUS;
...@@ -65,8 +73,7 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -65,8 +73,7 @@ import static org.slf4j.LoggerFactory.getLogger;
65 public class DistributedFlowStatisticStore implements FlowStatisticStore { 73 public class DistributedFlowStatisticStore implements FlowStatisticStore {
66 private final Logger log = getLogger(getClass()); 74 private final Logger log = getLogger(getClass());
67 75
68 - // TODO: Make configurable. 76 + private static final String FORMAT = "Setting: messageHandlerThreadPoolSize={}";
69 - private static final int MESSAGE_HANDLER_THREAD_POOL_SIZE = 4;
70 77
71 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 78 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
72 protected MastershipService mastershipService; 79 protected MastershipService mastershipService;
...@@ -97,6 +104,12 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore { ...@@ -97,6 +104,12 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore {
97 private NodeId local; 104 private NodeId local;
98 private ExecutorService messageHandlingExecutor; 105 private ExecutorService messageHandlingExecutor;
99 106
107 + private static final int DEFAULT_MESSAGE_HANDLER_THREAD_POOL_SIZE = 4;
108 + @Property(name = "messageHandlerThreadPoolSize", intValue = DEFAULT_MESSAGE_HANDLER_THREAD_POOL_SIZE,
109 + label = "Size of thread pool to assign message handler")
110 + private static int messageHandlerThreadPoolSize = DEFAULT_MESSAGE_HANDLER_THREAD_POOL_SIZE;
111 +
112 +
100 private static final long STATISTIC_STORE_TIMEOUT_MILLIS = 3000; 113 private static final long STATISTIC_STORE_TIMEOUT_MILLIS = 3000;
101 114
102 @Activate 115 @Activate
...@@ -104,7 +117,7 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore { ...@@ -104,7 +117,7 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore {
104 local = clusterService.getLocalNode().id(); 117 local = clusterService.getLocalNode().id();
105 118
106 messageHandlingExecutor = Executors.newFixedThreadPool( 119 messageHandlingExecutor = Executors.newFixedThreadPool(
107 - MESSAGE_HANDLER_THREAD_POOL_SIZE, 120 + messageHandlerThreadPoolSize,
108 groupedThreads("onos/store/statistic", "message-handlers")); 121 groupedThreads("onos/store/statistic", "message-handlers"));
109 122
110 clusterCommunicator.addSubscriber( 123 clusterCommunicator.addSubscriber(
...@@ -126,6 +139,32 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore { ...@@ -126,6 +139,32 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore {
126 log.info("Stopped"); 139 log.info("Stopped");
127 } 140 }
128 141
142 + @Modified
143 + public void modified(ComponentContext context) {
144 + Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
145 +
146 + int newMessageHandlerThreadPoolSize;
147 +
148 + try {
149 + String s = get(properties, "messageHandlerThreadPoolSize");
150 +
151 + newMessageHandlerThreadPoolSize =
152 + isNullOrEmpty(s) ? messageHandlerThreadPoolSize : Integer.parseInt(s.trim());
153 +
154 + } catch (NumberFormatException e) {
155 + log.warn(e.getMessage());
156 + newMessageHandlerThreadPoolSize = messageHandlerThreadPoolSize;
157 + }
158 +
159 + // Any change in the following parameters implies thread pool restart
160 + if (newMessageHandlerThreadPoolSize != messageHandlerThreadPoolSize) {
161 + setMessageHandlerThreadPoolSize(newMessageHandlerThreadPoolSize);
162 + restartMessageHandlerThreadPool();
163 + }
164 +
165 + log.info(FORMAT, messageHandlerThreadPoolSize);
166 + }
167 +
129 @Override 168 @Override
130 public synchronized void removeFlowStatistic(FlowRule rule) { 169 public synchronized void removeFlowStatistic(FlowRule rule) {
131 ConnectPoint cp = buildConnectPoint(rule); 170 ConnectPoint cp = buildConnectPoint(rule);
...@@ -134,10 +173,16 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore { ...@@ -134,10 +173,16 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore {
134 } 173 }
135 174
136 // remove this rule if present from current map 175 // remove this rule if present from current map
137 - current.computeIfPresent(cp, (c, e) -> { e.remove(rule); return e; }); 176 + current.computeIfPresent(cp, (c, e) -> {
177 + e.remove(rule);
178 + return e;
179 + });
138 180
139 // remove this on if present from previous map 181 // remove this on if present from previous map
140 - previous.computeIfPresent(cp, (c, e) -> { e.remove(rule); return e; }); 182 + previous.computeIfPresent(cp, (c, e) -> {
183 + e.remove(rule);
184 + return e;
185 + });
141 } 186 }
142 187
143 @Override 188 @Override
...@@ -286,4 +331,32 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore { ...@@ -286,4 +331,32 @@ public class DistributedFlowStatisticStore implements FlowStatisticStore {
286 } 331 }
287 return null; 332 return null;
288 } 333 }
334 +
335 + /**
336 + * Sets thread pool size of message handler.
337 + *
338 + * @param poolSize
339 + */
340 + private void setMessageHandlerThreadPoolSize(int poolSize) {
341 + checkArgument(poolSize >= 0, "Message handler pool size must be 0 or more");
342 + messageHandlerThreadPoolSize = poolSize;
343 + }
344 +
345 + /**
346 + * Restarts thread pool of message handler.
347 + */
348 + private void restartMessageHandlerThreadPool() {
349 + ExecutorService prevExecutor = messageHandlingExecutor;
350 + messageHandlingExecutor = Executors.newFixedThreadPool(getMessageHandlerThreadPoolSize());
351 + prevExecutor.shutdown();
352 + }
353 +
354 + /**
355 + * Gets current thread pool size of message handler.
356 + *
357 + * @return messageHandlerThreadPoolSize
358 + */
359 + private int getMessageHandlerThreadPoolSize() {
360 + return messageHandlerThreadPoolSize;
361 + }
289 } 362 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -20,6 +20,8 @@ import com.google.common.collect.Sets; ...@@ -20,6 +20,8 @@ import com.google.common.collect.Sets;
20 import org.apache.felix.scr.annotations.Activate; 20 import org.apache.felix.scr.annotations.Activate;
21 import org.apache.felix.scr.annotations.Component; 21 import org.apache.felix.scr.annotations.Component;
22 import org.apache.felix.scr.annotations.Deactivate; 22 import org.apache.felix.scr.annotations.Deactivate;
23 +import org.apache.felix.scr.annotations.Modified;
24 +import org.apache.felix.scr.annotations.Property;
23 import org.apache.felix.scr.annotations.Reference; 25 import org.apache.felix.scr.annotations.Reference;
24 import org.apache.felix.scr.annotations.ReferenceCardinality; 26 import org.apache.felix.scr.annotations.ReferenceCardinality;
25 import org.apache.felix.scr.annotations.Service; 27 import org.apache.felix.scr.annotations.Service;
...@@ -39,11 +41,14 @@ import org.onosproject.net.statistic.StatisticStore; ...@@ -39,11 +41,14 @@ import org.onosproject.net.statistic.StatisticStore;
39 import org.onosproject.store.cluster.messaging.ClusterCommunicationService; 41 import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
40 import org.onosproject.store.serializers.KryoNamespaces; 42 import org.onosproject.store.serializers.KryoNamespaces;
41 import org.onosproject.store.serializers.KryoSerializer; 43 import org.onosproject.store.serializers.KryoSerializer;
44 +import org.osgi.service.component.ComponentContext;
42 import org.slf4j.Logger; 45 import org.slf4j.Logger;
43 46
44 import java.util.Collections; 47 import java.util.Collections;
48 +import java.util.Dictionary;
45 import java.util.HashSet; 49 import java.util.HashSet;
46 import java.util.Map; 50 import java.util.Map;
51 +import java.util.Properties;
47 import java.util.Set; 52 import java.util.Set;
48 import java.util.concurrent.ConcurrentHashMap; 53 import java.util.concurrent.ConcurrentHashMap;
49 import java.util.concurrent.ExecutorService; 54 import java.util.concurrent.ExecutorService;
...@@ -51,6 +56,9 @@ import java.util.concurrent.Executors; ...@@ -51,6 +56,9 @@ import java.util.concurrent.Executors;
51 import java.util.concurrent.TimeUnit; 56 import java.util.concurrent.TimeUnit;
52 import java.util.concurrent.atomic.AtomicInteger; 57 import java.util.concurrent.atomic.AtomicInteger;
53 58
59 +import static com.google.common.base.Preconditions.checkArgument;
60 +import static com.google.common.base.Strings.isNullOrEmpty;
61 +import static org.onlab.util.Tools.get;
54 import static org.onlab.util.Tools.groupedThreads; 62 import static org.onlab.util.Tools.groupedThreads;
55 import static org.onosproject.store.statistic.impl.StatisticStoreMessageSubjects.GET_CURRENT; 63 import static org.onosproject.store.statistic.impl.StatisticStoreMessageSubjects.GET_CURRENT;
56 import static org.onosproject.store.statistic.impl.StatisticStoreMessageSubjects.GET_PREVIOUS; 64 import static org.onosproject.store.statistic.impl.StatisticStoreMessageSubjects.GET_PREVIOUS;
...@@ -67,8 +75,7 @@ public class DistributedStatisticStore implements StatisticStore { ...@@ -67,8 +75,7 @@ public class DistributedStatisticStore implements StatisticStore {
67 75
68 private final Logger log = getLogger(getClass()); 76 private final Logger log = getLogger(getClass());
69 77
70 - // TODO: Make configurable. 78 + private static final String FORMAT = "Setting: messageHandlerThreadPoolSize={}";
71 - private static final int MESSAGE_HANDLER_THREAD_POOL_SIZE = 4;
72 79
73 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 80 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
74 protected MastershipService mastershipService; 81 protected MastershipService mastershipService;
...@@ -101,13 +108,18 @@ public class DistributedStatisticStore implements StatisticStore { ...@@ -101,13 +108,18 @@ public class DistributedStatisticStore implements StatisticStore {
101 108
102 private ExecutorService messageHandlingExecutor; 109 private ExecutorService messageHandlingExecutor;
103 110
111 + private static final int DEFAULT_MESSAGE_HANDLER_THREAD_POOL_SIZE = 4;
112 + @Property(name = "messageHandlerThreadPoolSize", intValue = DEFAULT_MESSAGE_HANDLER_THREAD_POOL_SIZE,
113 + label = "Size of thread pool to assign message handler")
114 + private static int messageHandlerThreadPoolSize = DEFAULT_MESSAGE_HANDLER_THREAD_POOL_SIZE;
115 +
104 private static final long STATISTIC_STORE_TIMEOUT_MILLIS = 3000; 116 private static final long STATISTIC_STORE_TIMEOUT_MILLIS = 3000;
105 117
106 @Activate 118 @Activate
107 public void activate() { 119 public void activate() {
108 120
109 messageHandlingExecutor = Executors.newFixedThreadPool( 121 messageHandlingExecutor = Executors.newFixedThreadPool(
110 - MESSAGE_HANDLER_THREAD_POOL_SIZE, 122 + messageHandlerThreadPoolSize,
111 groupedThreads("onos/store/statistic", "message-handlers")); 123 groupedThreads("onos/store/statistic", "message-handlers"));
112 124
113 clusterCommunicator.<ConnectPoint, Set<FlowEntry>>addSubscriber(GET_CURRENT, 125 clusterCommunicator.<ConnectPoint, Set<FlowEntry>>addSubscriber(GET_CURRENT,
...@@ -133,6 +145,33 @@ public class DistributedStatisticStore implements StatisticStore { ...@@ -133,6 +145,33 @@ public class DistributedStatisticStore implements StatisticStore {
133 log.info("Stopped"); 145 log.info("Stopped");
134 } 146 }
135 147
148 + @Modified
149 + public void modified(ComponentContext context) {
150 + Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
151 +
152 + int newMessageHandlerThreadPoolSize;
153 +
154 + try {
155 + String s = get(properties, "messageHandlerThreadPoolSize");
156 +
157 + newMessageHandlerThreadPoolSize =
158 + isNullOrEmpty(s) ? messageHandlerThreadPoolSize : Integer.parseInt(s.trim());
159 +
160 + } catch (NumberFormatException e) {
161 + log.warn(e.getMessage());
162 + newMessageHandlerThreadPoolSize = messageHandlerThreadPoolSize;
163 + }
164 +
165 + // Any change in the following parameters implies thread pool restart
166 + if (newMessageHandlerThreadPoolSize != messageHandlerThreadPoolSize) {
167 + setMessageHandlerThreadPoolSize(newMessageHandlerThreadPoolSize);
168 + restartMessageHandlerThreadPool();
169 + }
170 +
171 + log.info(FORMAT, messageHandlerThreadPoolSize);
172 + }
173 +
174 +
136 @Override 175 @Override
137 public void prepareForStatistics(FlowRule rule) { 176 public void prepareForStatistics(FlowRule rule) {
138 ConnectPoint cp = buildConnectPoint(rule); 177 ConnectPoint cp = buildConnectPoint(rule);
...@@ -314,4 +353,32 @@ public class DistributedStatisticStore implements StatisticStore { ...@@ -314,4 +353,32 @@ public class DistributedStatisticStore implements StatisticStore {
314 353
315 } 354 }
316 355
356 + /**
357 + * Sets thread pool size of message handler.
358 + *
359 + * @param poolSize
360 + */
361 + private void setMessageHandlerThreadPoolSize(int poolSize) {
362 + checkArgument(poolSize >= 0, "Message handler pool size must be 0 or more");
363 + messageHandlerThreadPoolSize = poolSize;
364 + }
365 +
366 + /**
367 + * Restarts thread pool of message handler.
368 + */
369 + private void restartMessageHandlerThreadPool() {
370 + ExecutorService prevExecutor = messageHandlingExecutor;
371 + messageHandlingExecutor = Executors.newFixedThreadPool(getMessageHandlerThreadPoolSize());
372 + prevExecutor.shutdown();
373 + }
374 +
375 + /**
376 + * Gets current thread pool size of message handler.
377 + *
378 + * @return messageHandlerThreadPoolSize
379 + */
380 + private int getMessageHandlerThreadPoolSize() {
381 + return messageHandlerThreadPoolSize;
382 + }
383 +
317 } 384 }
......