From 24e0f734efdafca6b8cc1ffce7767d0d6bce9fae Mon Sep 17 00:00:00 2001 From: Michal Rehak Date: Mon, 26 May 2014 17:22:22 +0200 Subject: [PATCH] BUG-1074: add javadoc for QueueKeeper - added javadoc for QueueKeeper and QueueKeeperImpl Change-Id: I5cf4d5c2798766435985bb9a93c45b07e18d4d8b Signed-off-by: Michal Rehak --- .../openflow/md/queue/QueueKeeper.java | 29 ++++++++++++++----- .../md/queue/QueueKeeperLightImpl.java | 26 ++++++++++++++++- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/QueueKeeper.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/QueueKeeper.java index 94f8bb5c86..c22a81a220 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/QueueKeeper.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/QueueKeeper.java @@ -16,34 +16,49 @@ import org.opendaylight.openflowplugin.openflow.md.core.IMDMessageTranslator; import org.opendaylight.openflowplugin.openflow.md.core.TranslatorKey; /** - * @author mirehak + * This processing mechanism based on queue. Processing consists of 2 steps: translate and publish. + * Proposed workflow (might slightly deviate in implementations): + *
    + *
  1. messages of input type are pushed in (via {@link QueueKeeper#push(Object, ConnectionConductor)} and similar)
  2. + *
  3. ticket (executable task) is build upon each pushed message and enqueued
  4. + *
  5. ticket is translated using appropriate translator
  6. + *
  7. ticket is dequeued and result is published by appropriate popListener
  8. + *
+ * Message order might be not important, e.g. when speed is of the essence * @param source type * @param result type */ public interface QueueKeeper { - public enum QueueType {DEFAULT, UNORDERED} + /** type of message enqueue */ + public enum QueueType { + /** ordered processing */ + DEFAULT, + /** unordered processing - bypass fair processing */ + UNORDERED} /** - * @param translatorMapping + * @param translatorMapping translators for message processing */ void setTranslatorMapping(Map>>> translatorMapping); /** + * enqueue message for processing using {@link QueueType#DEFAULT} * @param message - * @param conductor + * @param conductor source of message */ void push(IN message, ConnectionConductor conductor); /** + * enqueue message for processing * @param message - * @param conductor - * @param ordered - true if message order matters, false otherwise + * @param conductor source of message + * @param queueType - {@link QueueType#DEFAULT} if message order matters, {@link QueueType#UNORDERED} otherwise */ void push(IN message, ConnectionConductor conductor, QueueType queueType); /** - * @param popListenersMapping the popListenersMapping to set + * @param popListenersMapping listeners invoked when processing done */ void setPopListenersMapping(Map, Collection>> popListenersMapping); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/QueueKeeperLightImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/QueueKeeperLightImpl.java index 99c7c016cf..04a7ad78e9 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/QueueKeeperLightImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/QueueKeeperLightImpl.java @@ -12,6 +12,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ScheduledThreadPoolExecutor; @@ -26,8 +27,31 @@ import org.opendaylight.yangtools.yang.binding.DataObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + /** - * @author mirehak + * {@link QueueKeeper} implementation focused to keep order and use up mutiple threads for translation phase. + *
+ * There is internal thread pool of limited size ({@link QueueKeeperLightImpl#setPoolSize(int)}) + * dedicated to translation. Then there is singleThreadPool dedicated to publishing (via popListeners) + *
+ * Workflow: + *
    + *
  1. upon message push ticket is created and enqueued
  2. + *
  3. available threads from internal pool translate the massage wrapped in ticket
  4. + *
  5. when translation of particular message is finished, result is set in future result of wrapping ticket
    + * (order of tickets in queue is not touched during translate) + *
  6. + *
  7. at the end of queue there is {@link TicketFinisher} running in singleThreadPool and for each ticket it does: + *
      + *
    1. invoke blocking {@link BlockingQueue#take()} method in order to get the oldest ticket
    2. + *
    3. invoke blocking {@link Future#get()} on the dequeued ticket
    4. + *
    5. as soon as the result of translation is available, appropriate popListener is invoked
    6. + *
    + * and this way the order of messages is preserved and also multiple threads are used by translating + *
  8. + *
+ * + * */ public class QueueKeeperLightImpl implements QueueKeeper { -- 2.36.6