added unit tests for BarrierProcessor
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / device / BarrierProcessor.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.impl.device;
10
11 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
12 import org.opendaylight.openflowplugin.api.openflow.device.handlers.OutstandingMessageExtractor;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 /**
17  * openflowplugin-impl
18  * org.opendaylight.openflowplugin.impl.device
19  *
20  *
21  *
22  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
23  *
24  * Created: Apr 3, 2015
25  */
26 public class BarrierProcessor {
27
28     private static Logger LOG = LoggerFactory.getLogger(BarrierProcessor.class);
29
30     /**
31      * for all requestContexts from deviceContext cache which are older than barrier (lower barrierXid value) we do: <br>
32      *     <ul>
33      *         <li>remove from cache</li>
34      *         <li>cancel inner future</li>
35      *     </ul>
36      *
37      * @param barrierXid
38      * @param messageExtractor
39      */
40     public static void processOutstandingRequests(final long barrierXid, final OutstandingMessageExtractor messageExtractor) {
41         LOG.trace("processing barrier response [{}]", barrierXid);
42         RequestContext nextRequestContext;
43         while ((nextRequestContext = messageExtractor.extractNextOutstandingMessage(barrierXid)) != null ) {
44             LOG.trace("flushing outstanding request [{}]", nextRequestContext.getXid().getValue());
45             nextRequestContext.getFuture().cancel(false);
46         }
47     }
48 }