Bug 1764 - moved Session related interfaces to openflowplugin-api
[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.openflowplugin.api.openflow.md.queue.MessageSourcePollRegistrator;
11 import org.opendaylight.openflowplugin.api.openflow.md.queue.QueueKeeper;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
13
14 /**
15  * factory for {@link org.opendaylight.openflowplugin.api.openflow.md.queue.QueueKeeper} implementations
16  */
17 public abstract class QueueKeeperFactory {
18     
19     /**
20      * @param sourceRegistrator 
21      * @param capacity blocking queue capacity
22      * @return fair reading implementation of {@link org.opendaylight.openflowplugin.api.openflow.md.queue.QueueKeeper} (not registered = not started yet)
23      */
24     public static QueueKeeper<OfHeader> createFairQueueKeeper(
25             MessageSourcePollRegistrator<QueueKeeper<OfHeader>> sourceRegistrator, int capacity) {
26         QueueKeeperFairImpl queueKeeper = new QueueKeeperFairImpl();
27         queueKeeper.setCapacity(capacity);
28         queueKeeper.setHarvesterHandle(sourceRegistrator.getHarvesterHandle());
29         queueKeeper.init();
30         
31         return queueKeeper;
32     }
33
34     /**
35      * register queue by harvester, start processing it. Use {@link QueueKeeperFairImpl#close()} to kill the queue and stop processing. 
36      * @param sourceRegistrator
37      * @param queueKeeper
38      */
39     public static <V> void plugQueue(
40             MessageSourcePollRegistrator<QueueKeeper<V>> sourceRegistrator,
41             QueueKeeper<V> queueKeeper) {
42         AutoCloseable registration = sourceRegistrator.registerMessageSource(queueKeeper);
43         queueKeeper.setPollRegistration(registration);
44     }
45 }