Pier Ventre

Fix the side effects introduced by https://gerrit.onosproject.org/#/c/10978/

Change-Id: I88f84f28d9c5243c6ce42c81914b0f87e41bbd3e
...@@ -253,12 +253,38 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -253,12 +253,38 @@ public class FlowObjectiveManager implements FlowObjectiveService {
253 return queued; 253 return queued;
254 } 254 }
255 255
256 - // Retrieves the device pipeline behaviour from the cache. 256 + /**
257 + * Retrieves (if it exists) the device pipeline behaviour from the cache.
258 + * Otherwise it warms the caches and triggers the init method of the Pipeline.
259 + *
260 + * @param deviceId the id of the device associated to the pipeline
261 + * @return the implementation of the Pipeliner behaviour
262 + */
257 private Pipeliner getDevicePipeliner(DeviceId deviceId) { 263 private Pipeliner getDevicePipeliner(DeviceId deviceId) {
258 return pipeliners.computeIfAbsent(deviceId, this::initPipelineHandler); 264 return pipeliners.computeIfAbsent(deviceId, this::initPipelineHandler);
259 } 265 }
260 266
261 /** 267 /**
268 + * Retrieves (if it exists) the device pipeline behaviour from the cache and
269 + * and triggers the init method of the pipeline. Otherwise (DEVICE_ADDED) it warms
270 + * the caches and triggers the init method of the Pipeline. The rationale of this
271 + * method is for managing the scenario of a switch that goes down for a failure
272 + * and goes up after a while.
273 + *
274 + * @param deviceId the id of the device associated to the pipeline
275 + * @return the implementation of the Pipeliner behaviour
276 + */
277 + private Pipeliner getAndInitDevicePipeliner(DeviceId deviceId) {
278 + return pipeliners.compute(deviceId, (deviceIdValue, pipelinerValue) -> {
279 + if (pipelinerValue != null) {
280 + pipelinerValue.init(deviceId, context);
281 + return pipelinerValue;
282 + }
283 + return this.initPipelineHandler(deviceId);
284 + });
285 + }
286 +
287 + /**
262 * Creates and initialize {@link Pipeliner}. 288 * Creates and initialize {@link Pipeliner}.
263 * <p> 289 * <p>
264 * Note: Expected to be called under per-Device lock. 290 * Note: Expected to be called under per-Device lock.
...@@ -315,7 +341,7 @@ public class FlowObjectiveManager implements FlowObjectiveService { ...@@ -315,7 +341,7 @@ public class FlowObjectiveManager implements FlowObjectiveService {
315 event.subject().id()); 341 event.subject().id());
316 if (deviceService.isAvailable(event.subject().id())) { 342 if (deviceService.isAvailable(event.subject().id())) {
317 log.debug("Device is now available {}", event.subject().id()); 343 log.debug("Device is now available {}", event.subject().id());
318 - getDevicePipeliner(event.subject().id()); 344 + getAndInitDevicePipeliner(event.subject().id());
319 } else { 345 } else {
320 log.debug("Device is no longer available {}", event.subject().id()); 346 log.debug("Device is no longer available {}", event.subject().id());
321 } 347 }
......