BUG-1075: ingress back pressure
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / queue / QueueKeeperFactory.java
1 /**
2  * Copyright (c) 2013 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 package org.opendaylight.openflowplugin.openflow.md.queue;
9
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
11
12 /**
13  * factory for {@link QueueKeeper} implementations
14  */
15 public abstract class QueueKeeperFactory {
16     
17     /**
18      * @param sourceRegistrator 
19      * @param capacity blocking queue capacity
20      * @return fair reading implementation of {@link QueueKeeper}
21      */
22     @SuppressWarnings("resource")
23     public static QueueKeeper<OfHeader> createFairQueueKeeper(
24             MessageSourcePollRegistrator<QueueKeeper<OfHeader>> sourceRegistrator, int capacity) {
25         QueueKeeperFairImpl queueKeeper = new QueueKeeperFairImpl();
26         queueKeeper.setCapacity(capacity);
27         queueKeeper.setHarvesterHandle(sourceRegistrator.getHarvesterHandle());
28         queueKeeper.init();
29         
30         AutoCloseable registration = sourceRegistrator.registerMessageSource(queueKeeper);
31         queueKeeper.setPollRegistration(registration);
32         return queueKeeper;
33     }
34 }