c22a81a2203249651294556b449075acbc148b4c
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / queue / QueueKeeper.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 java.util.Collection;
11 import java.util.List;
12 import java.util.Map;
13
14 import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
15 import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator;
16 import org.opendaylight.openflowplugin.openflow.md.core.TranslatorKey;
17
18 /**
19  * This processing mechanism based on queue. Processing consists of 2 steps: translate and publish. 
20  * Proposed workflow (might slightly deviate in implementations):
21  * <ol>
22  * <li>messages of input type are pushed in (via {@link QueueKeeper#push(Object, ConnectionConductor)} and similar)</li>
23  * <li>ticket (executable task) is build upon each pushed message and enqueued</li>
24  * <li>ticket is translated using appropriate translator</li>
25  * <li>ticket is dequeued and result is published by appropriate popListener</li>
26  * </ol>
27  * Message order might be not important, e.g. when speed is of the essence
28  * @param <IN> source type
29  * @param <OUT> result type
30  */
31 public interface QueueKeeper<IN, OUT> {
32     
33     /** type of message enqueue */
34     public enum QueueType {
35         /** ordered processing */
36         DEFAULT,
37         /** unordered processing - bypass fair processing */
38         UNORDERED}
39
40     /**
41      * @param translatorMapping translators for message processing
42      */
43     void setTranslatorMapping(Map<TranslatorKey, Collection<IMDMessageTranslator<IN, List<OUT>>>> translatorMapping);
44
45     /**
46      * enqueue message for processing using {@link QueueType#DEFAULT}
47      * @param message
48      * @param conductor source of message
49      */
50     void push(IN message, ConnectionConductor conductor);
51     
52     /**
53      * enqueue message for processing
54      * @param message
55      * @param conductor source of message
56      * @param queueType - {@link QueueType#DEFAULT} if message order matters, {@link QueueType#UNORDERED} otherwise
57      */
58     void push(IN message, ConnectionConductor conductor, QueueType queueType);
59
60     /**
61      * @param popListenersMapping listeners invoked when processing done
62      */
63     void setPopListenersMapping(Map<Class<? extends OUT>, Collection<PopListener<OUT>>> popListenersMapping);
64 }