Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.store.packet.impl; |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | 7f171b2 | 2015-08-21 12:49:08 -0700 | [diff] [blame] | 18 | import com.google.common.collect.Lists; |
Jonathan Hart | fc3f6de | 2016-09-19 17:55:15 -0700 | [diff] [blame] | 19 | import org.onlab.util.KryoNamespace; |
sangyun-han | 9f0af2d | 2016-08-04 13:04:59 +0900 | [diff] [blame] | 20 | import org.onosproject.cfg.ComponentConfigService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.cluster.ClusterService; |
| 22 | import org.onosproject.cluster.NodeId; |
| 23 | import org.onosproject.mastership.MastershipService; |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 24 | import org.onosproject.net.flow.TrafficSelector; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.net.packet.OutboundPacket; |
| 26 | import org.onosproject.net.packet.PacketEvent; |
| 27 | import org.onosproject.net.packet.PacketEvent.Type; |
Jonathan Hart | fc3f6de | 2016-09-19 17:55:15 -0700 | [diff] [blame] | 28 | import org.onosproject.net.packet.PacketPriority; |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 29 | import org.onosproject.net.packet.PacketRequest; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import org.onosproject.net.packet.PacketStore; |
| 31 | import org.onosproject.net.packet.PacketStoreDelegate; |
| 32 | import org.onosproject.store.AbstractStore; |
| 33 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 34 | import org.onosproject.store.cluster.messaging.MessageSubject; |
| 35 | import org.onosproject.store.serializers.KryoNamespaces; |
Jordan Halterman | 8c57a09 | 2018-06-04 14:53:06 -0700 | [diff] [blame] | 36 | import org.onosproject.store.service.ConsistentMultimap; |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 37 | import org.onosproject.store.service.Serializer; |
| 38 | import org.onosproject.store.service.StorageService; |
Jordan Halterman | 8c57a09 | 2018-06-04 14:53:06 -0700 | [diff] [blame] | 39 | import org.onosproject.store.service.Versioned; |
sangyun-han | ad84e0c | 2016-02-19 18:30:03 +0900 | [diff] [blame] | 40 | import org.osgi.service.component.ComponentContext; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 41 | import org.osgi.service.component.annotations.Activate; |
| 42 | import org.osgi.service.component.annotations.Component; |
| 43 | import org.osgi.service.component.annotations.Deactivate; |
| 44 | import org.osgi.service.component.annotations.Modified; |
| 45 | import org.osgi.service.component.annotations.Reference; |
| 46 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 47 | import org.slf4j.Logger; |
| 48 | |
Jordan Halterman | 8c57a09 | 2018-06-04 14:53:06 -0700 | [diff] [blame] | 49 | import java.util.Collection; |
sangyun-han | ad84e0c | 2016-02-19 18:30:03 +0900 | [diff] [blame] | 50 | import java.util.Dictionary; |
Thomas Vachuska | 7f171b2 | 2015-08-21 12:49:08 -0700 | [diff] [blame] | 51 | import java.util.List; |
Jonathan Hart | fc3f6de | 2016-09-19 17:55:15 -0700 | [diff] [blame] | 52 | import java.util.Objects; |
sangyun-han | ad84e0c | 2016-02-19 18:30:03 +0900 | [diff] [blame] | 53 | import java.util.Properties; |
Brian O'Connor | 5eb77c8 | 2015-03-02 18:09:39 -0800 | [diff] [blame] | 54 | import java.util.concurrent.ExecutorService; |
| 55 | import java.util.concurrent.Executors; |
| 56 | |
sangyun-han | ad84e0c | 2016-02-19 18:30:03 +0900 | [diff] [blame] | 57 | import static com.google.common.base.Preconditions.checkArgument; |
| 58 | import static com.google.common.base.Strings.isNullOrEmpty; |
Yuta HIGUCHI | 1624df1 | 2016-07-21 16:54:33 -0700 | [diff] [blame] | 59 | import static java.util.concurrent.Executors.newFixedThreadPool; |
sangyun-han | ad84e0c | 2016-02-19 18:30:03 +0900 | [diff] [blame] | 60 | import static org.onlab.util.Tools.get; |
Brian O'Connor | 5eb77c8 | 2015-03-02 18:09:39 -0800 | [diff] [blame] | 61 | import static org.onlab.util.Tools.groupedThreads; |
| 62 | import static org.slf4j.LoggerFactory.getLogger; |
| 63 | |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 64 | /** |
| 65 | * Distributed packet store implementation allowing packets to be sent to |
| 66 | * remote instances. |
| 67 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 68 | @Component(immediate = true, service = PacketStore.class) |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 69 | public class DistributedPacketStore |
| 70 | extends AbstractStore<PacketEvent, PacketStoreDelegate> |
| 71 | implements PacketStore { |
| 72 | |
| 73 | private final Logger log = getLogger(getClass()); |
| 74 | |
sangyun-han | ad84e0c | 2016-02-19 18:30:03 +0900 | [diff] [blame] | 75 | private static final String FORMAT = "Setting: messageHandlerThreadPoolSize={}"; |
Madan Jampani | 2af244a | 2015-02-22 13:12:01 -0800 | [diff] [blame] | 76 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 77 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Thomas Vachuska | ff96523 | 2015-03-17 14:10:52 -0700 | [diff] [blame] | 78 | protected MastershipService mastershipService; |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 79 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 80 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Thomas Vachuska | ff96523 | 2015-03-17 14:10:52 -0700 | [diff] [blame] | 81 | protected ClusterService clusterService; |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 82 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 83 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Thomas Vachuska | ff96523 | 2015-03-17 14:10:52 -0700 | [diff] [blame] | 84 | protected ClusterCommunicationService communicationService; |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 85 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 86 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 87 | protected StorageService storageService; |
| 88 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 89 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
sangyun-han | 9f0af2d | 2016-08-04 13:04:59 +0900 | [diff] [blame] | 90 | protected ComponentConfigService cfgService; |
| 91 | |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 92 | private PacketRequestTracker tracker; |
| 93 | |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 94 | private static final MessageSubject PACKET_OUT_SUBJECT = |
| 95 | new MessageSubject("packet-out"); |
| 96 | |
Jordan Halterman | 2c83a10 | 2017-08-20 17:11:41 -0700 | [diff] [blame] | 97 | private static final Serializer SERIALIZER = Serializer.using(KryoNamespaces.API); |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 98 | |
Madan Jampani | 2af244a | 2015-02-22 13:12:01 -0800 | [diff] [blame] | 99 | private ExecutorService messageHandlingExecutor; |
| 100 | |
sangyun-han | ad84e0c | 2016-02-19 18:30:03 +0900 | [diff] [blame] | 101 | private static final int DEFAULT_MESSAGE_HANDLER_THREAD_POOL_SIZE = 4; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame^] | 102 | //@Property(name = "messageHandlerThreadPoolSize", intValue = DEFAULT_MESSAGE_HANDLER_THREAD_POOL_SIZE, |
| 103 | // label = "Size of thread pool to assign message handler") |
sangyun-han | ad84e0c | 2016-02-19 18:30:03 +0900 | [diff] [blame] | 104 | private static int messageHandlerThreadPoolSize = DEFAULT_MESSAGE_HANDLER_THREAD_POOL_SIZE; |
| 105 | |
| 106 | private static final int MAX_BACKOFF = 50; |
| 107 | |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 108 | @Activate |
sangyun-han | 9f0af2d | 2016-08-04 13:04:59 +0900 | [diff] [blame] | 109 | public void activate(ComponentContext context) { |
| 110 | cfgService.registerProperties(getClass()); |
| 111 | |
| 112 | modified(context); |
| 113 | |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 114 | messageHandlingExecutor = Executors.newFixedThreadPool( |
sangyun-han | ad84e0c | 2016-02-19 18:30:03 +0900 | [diff] [blame] | 115 | messageHandlerThreadPoolSize, |
HIGUCHI Yuta | d9e0105 | 2016-04-14 09:31:42 -0700 | [diff] [blame] | 116 | groupedThreads("onos/store/packet", "message-handlers", log)); |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 117 | |
Madan Jampani | 01e05fb | 2015-08-13 13:29:36 -0700 | [diff] [blame] | 118 | communicationService.<OutboundPacket>addSubscriber(PACKET_OUT_SUBJECT, |
| 119 | SERIALIZER::decode, |
| 120 | packet -> notifyDelegate(new PacketEvent(Type.EMIT, packet)), |
| 121 | messageHandlingExecutor); |
Madan Jampani | 2af244a | 2015-02-22 13:12:01 -0800 | [diff] [blame] | 122 | |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 123 | tracker = new PacketRequestTracker(); |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 124 | |
Madan Jampani | 2af244a | 2015-02-22 13:12:01 -0800 | [diff] [blame] | 125 | log.info("Started"); |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | @Deactivate |
| 129 | public void deactivate() { |
sangyun-han | 9f0af2d | 2016-08-04 13:04:59 +0900 | [diff] [blame] | 130 | cfgService.unregisterProperties(getClass(), false); |
Madan Jampani | 2af244a | 2015-02-22 13:12:01 -0800 | [diff] [blame] | 131 | communicationService.removeSubscriber(PACKET_OUT_SUBJECT); |
| 132 | messageHandlingExecutor.shutdown(); |
Brian O'Connor | 21b028e | 2015-10-08 22:50:02 -0700 | [diff] [blame] | 133 | tracker = null; |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 134 | log.info("Stopped"); |
| 135 | } |
| 136 | |
sangyun-han | ad84e0c | 2016-02-19 18:30:03 +0900 | [diff] [blame] | 137 | @Modified |
| 138 | public void modified(ComponentContext context) { |
| 139 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 140 | |
| 141 | int newMessageHandlerThreadPoolSize; |
| 142 | |
| 143 | try { |
| 144 | String s = get(properties, "messageHandlerThreadPoolSize"); |
| 145 | |
| 146 | newMessageHandlerThreadPoolSize = |
| 147 | isNullOrEmpty(s) ? messageHandlerThreadPoolSize : Integer.parseInt(s.trim()); |
| 148 | |
| 149 | } catch (NumberFormatException e) { |
| 150 | log.warn(e.getMessage()); |
| 151 | newMessageHandlerThreadPoolSize = messageHandlerThreadPoolSize; |
| 152 | } |
| 153 | |
| 154 | // Any change in the following parameters implies thread pool restart |
| 155 | if (newMessageHandlerThreadPoolSize != messageHandlerThreadPoolSize) { |
| 156 | setMessageHandlerThreadPoolSize(newMessageHandlerThreadPoolSize); |
| 157 | restartMessageHandlerThreadPool(); |
| 158 | } |
| 159 | |
| 160 | log.info(FORMAT, messageHandlerThreadPoolSize); |
| 161 | } |
| 162 | |
| 163 | |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 164 | @Override |
| 165 | public void emit(OutboundPacket packet) { |
| 166 | NodeId myId = clusterService.getLocalNode().id(); |
| 167 | NodeId master = mastershipService.getMasterFor(packet.sendThrough()); |
| 168 | |
Jonathan Hart | 7466d61 | 2014-11-24 17:09:53 -0800 | [diff] [blame] | 169 | if (master == null) { |
| 170 | return; |
| 171 | } |
| 172 | |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 173 | if (myId.equals(master)) { |
| 174 | notifyDelegate(new PacketEvent(Type.EMIT, packet)); |
| 175 | return; |
| 176 | } |
| 177 | |
Madan Jampani | 01e05fb | 2015-08-13 13:29:36 -0700 | [diff] [blame] | 178 | communicationService.unicast(packet, PACKET_OUT_SUBJECT, SERIALIZER::encode, master) |
| 179 | .whenComplete((r, error) -> { |
| 180 | if (error != null) { |
| 181 | log.warn("Failed to send packet-out to {}", master, error); |
| 182 | } |
| 183 | }); |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 184 | } |
| 185 | |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 186 | @Override |
Brian O'Connor | 21b028e | 2015-10-08 22:50:02 -0700 | [diff] [blame] | 187 | public void requestPackets(PacketRequest request) { |
| 188 | tracker.add(request); |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | @Override |
Brian O'Connor | 21b028e | 2015-10-08 22:50:02 -0700 | [diff] [blame] | 192 | public void cancelPackets(PacketRequest request) { |
| 193 | tracker.remove(request); |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | @Override |
Thomas Vachuska | 7f171b2 | 2015-08-21 12:49:08 -0700 | [diff] [blame] | 197 | public List<PacketRequest> existingRequests() { |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 198 | return tracker.requests(); |
| 199 | } |
| 200 | |
Thomas Vachuska | 40e63e6 | 2015-10-13 16:16:20 -0700 | [diff] [blame] | 201 | private final class PacketRequestTracker { |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 202 | |
Jordan Halterman | 8c57a09 | 2018-06-04 14:53:06 -0700 | [diff] [blame] | 203 | private ConsistentMultimap<RequestKey, PacketRequest> requests; |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 204 | |
Thomas Vachuska | 40e63e6 | 2015-10-13 16:16:20 -0700 | [diff] [blame] | 205 | private PacketRequestTracker() { |
Jordan Halterman | 8c57a09 | 2018-06-04 14:53:06 -0700 | [diff] [blame] | 206 | requests = storageService.<RequestKey, PacketRequest>consistentMultimapBuilder() |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 207 | .withName("onos-packet-requests") |
Jonathan Hart | fc3f6de | 2016-09-19 17:55:15 -0700 | [diff] [blame] | 208 | .withSerializer(Serializer.using(KryoNamespace.newBuilder() |
| 209 | .register(KryoNamespaces.API) |
| 210 | .register(RequestKey.class) |
| 211 | .build())) |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 212 | .build(); |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Thomas Vachuska | 40e63e6 | 2015-10-13 16:16:20 -0700 | [diff] [blame] | 215 | private void add(PacketRequest request) { |
Jordan Halterman | 8c57a09 | 2018-06-04 14:53:06 -0700 | [diff] [blame] | 216 | boolean firstRequest = addInternal(request); |
| 217 | if (firstRequest && delegate != null) { |
Thomas Vachuska | 40e63e6 | 2015-10-13 16:16:20 -0700 | [diff] [blame] | 218 | // The instance that makes the first request will push to all devices |
| 219 | delegate.requestPackets(request); |
| 220 | } |
| 221 | } |
| 222 | |
Jordan Halterman | 8c57a09 | 2018-06-04 14:53:06 -0700 | [diff] [blame] | 223 | private boolean addInternal(PacketRequest request) { |
Charles Chan | 4e7de42 | 2018-07-05 16:46:11 -0700 | [diff] [blame] | 224 | return requests.put(key(request), request); |
Thomas Vachuska | 40e63e6 | 2015-10-13 16:16:20 -0700 | [diff] [blame] | 225 | } |
Brian O'Connor | 21b028e | 2015-10-08 22:50:02 -0700 | [diff] [blame] | 226 | |
Thomas Vachuska | 40e63e6 | 2015-10-13 16:16:20 -0700 | [diff] [blame] | 227 | private void remove(PacketRequest request) { |
Jordan Halterman | 8c57a09 | 2018-06-04 14:53:06 -0700 | [diff] [blame] | 228 | boolean removedLast = removeInternal(request); |
| 229 | if (removedLast && delegate != null) { |
Thomas Vachuska | 40e63e6 | 2015-10-13 16:16:20 -0700 | [diff] [blame] | 230 | // The instance that removes the last request will remove from all devices |
| 231 | delegate.cancelPackets(request); |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 232 | } |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Jordan Halterman | 8c57a09 | 2018-06-04 14:53:06 -0700 | [diff] [blame] | 235 | private boolean removeInternal(PacketRequest request) { |
| 236 | Collection<? extends PacketRequest> values = |
| 237 | Versioned.valueOrNull(requests.removeAndGet(key(request), request)); |
| 238 | return values == null || values.isEmpty(); |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Thomas Vachuska | 40e63e6 | 2015-10-13 16:16:20 -0700 | [diff] [blame] | 241 | private List<PacketRequest> requests() { |
Thomas Vachuska | 7f171b2 | 2015-08-21 12:49:08 -0700 | [diff] [blame] | 242 | List<PacketRequest> list = Lists.newArrayList(); |
Jordan Halterman | 8c57a09 | 2018-06-04 14:53:06 -0700 | [diff] [blame] | 243 | requests.values().forEach(v -> list.add(v)); |
Thomas Vachuska | 7f171b2 | 2015-08-21 12:49:08 -0700 | [diff] [blame] | 244 | list.sort((o1, o2) -> o1.priority().priorityValue() - o2.priority().priorityValue()); |
| 245 | return list; |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 246 | } |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 247 | } |
sangyun-han | ad84e0c | 2016-02-19 18:30:03 +0900 | [diff] [blame] | 248 | |
| 249 | /** |
Jonathan Hart | fc3f6de | 2016-09-19 17:55:15 -0700 | [diff] [blame] | 250 | * Creates a new request key from a packet request. |
| 251 | * |
| 252 | * @param request packet request |
| 253 | * @return request key |
| 254 | */ |
| 255 | private static RequestKey key(PacketRequest request) { |
| 256 | return new RequestKey(request.selector(), request.priority()); |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Key of a packet request. |
| 261 | */ |
| 262 | private static final class RequestKey { |
| 263 | private final TrafficSelector selector; |
| 264 | private final PacketPriority priority; |
| 265 | |
| 266 | private RequestKey(TrafficSelector selector, PacketPriority priority) { |
| 267 | this.selector = selector; |
| 268 | this.priority = priority; |
| 269 | } |
| 270 | |
| 271 | @Override |
| 272 | public int hashCode() { |
| 273 | return Objects.hash(selector, priority); |
| 274 | } |
| 275 | |
| 276 | @Override |
| 277 | public boolean equals(Object other) { |
| 278 | if (other == this) { |
| 279 | return true; |
| 280 | } |
| 281 | |
| 282 | if (!(other instanceof RequestKey)) { |
| 283 | return false; |
| 284 | } |
| 285 | |
| 286 | RequestKey that = (RequestKey) other; |
| 287 | |
| 288 | return Objects.equals(selector, that.selector) && |
| 289 | Objects.equals(priority, that.priority); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /** |
sangyun-han | ad84e0c | 2016-02-19 18:30:03 +0900 | [diff] [blame] | 294 | * Sets thread pool size of message handler. |
| 295 | * |
| 296 | * @param poolSize |
| 297 | */ |
| 298 | private void setMessageHandlerThreadPoolSize(int poolSize) { |
| 299 | checkArgument(poolSize >= 0, "Message handler pool size must be 0 or more"); |
| 300 | messageHandlerThreadPoolSize = poolSize; |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Restarts thread pool of message handler. |
| 305 | */ |
| 306 | private void restartMessageHandlerThreadPool() { |
| 307 | ExecutorService prevExecutor = messageHandlingExecutor; |
Yuta HIGUCHI | 1624df1 | 2016-07-21 16:54:33 -0700 | [diff] [blame] | 308 | messageHandlingExecutor = newFixedThreadPool(getMessageHandlerThreadPoolSize(), |
| 309 | groupedThreads("DistPktStore", "messageHandling-%d", log)); |
sangyun-han | ad84e0c | 2016-02-19 18:30:03 +0900 | [diff] [blame] | 310 | prevExecutor.shutdown(); |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * Gets current thread pool size of message handler. |
| 315 | * |
| 316 | * @return messageHandlerThreadPoolSize |
| 317 | */ |
| 318 | private int getMessageHandlerThreadPoolSize() { |
| 319 | return messageHandlerThreadPoolSize; |
| 320 | } |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 321 | } |