BUG-542 - adding overall statictics
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / SwitchConnectionHandlerImpl.java
index f26375bf5a28d78f155d841a31574868d064cfcb..50d3bee271044d4f7c4f0e4e2db329b093460020 100644 (file)
@@ -9,32 +9,49 @@
 package org.opendaylight.openflowplugin.openflow.md.core;
 
 import java.net.InetAddress;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
 
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
+import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpy;
 import org.opendaylight.openflowplugin.openflow.md.queue.QueueKeeperLightImpl;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
 
 /**
- * @author mirehak
- *
+ * basic interconnecting piece between plugin and library 
  */
 public class SwitchConnectionHandlerImpl implements SwitchConnectionHandler {
     
-    private QueueKeeperLightImpl<Object> queueKeeper;
+    private ScheduledThreadPoolExecutor spyPool; 
+
+    private QueueKeeperLightImpl queueKeeper;
     private ErrorHandler errorHandler;
+    private MessageSpy<DataContainer> messageSpy;
+    private int spyRate = 10;
 
     /**
-     * 
+     *
      */
     public SwitchConnectionHandlerImpl() {
-        queueKeeper = new QueueKeeperLightImpl<>();
-        queueKeeper.setListenerMapping(OFSessionUtil.getListenersMap());
+        queueKeeper = new QueueKeeperLightImpl();
+        
+        //TODO: implement shutdown invocation upon service stop event
+        spyPool = new ScheduledThreadPoolExecutor(1);
+    }
+
+    /**
+     * wire all up
+     */
+    public void init() {
+        queueKeeper.setTranslatorMapping(OFSessionUtil.getTranslatorMap());
+        queueKeeper.setPopListenersMapping(OFSessionUtil.getPopListenerMapping());
+        queueKeeper.setMessageSpy(messageSpy);
+        
         queueKeeper.init();
-        // TODO: add pop-listeners consuming object processed via queue
-        //queueKeeper.addPopListener(listener);
         
-        errorHandler = new ErrorHandlerQueueImpl();
+        spyPool.scheduleAtFixedRate(messageSpy, spyRate, spyRate, TimeUnit.SECONDS);
     }
 
     @Override
@@ -49,5 +66,19 @@ public class SwitchConnectionHandlerImpl implements SwitchConnectionHandler {
                 connectionAdapter, queueKeeper);
         conductor.setErrorHandler(errorHandler);
     }
+    
+    /**
+     * @param messageSpy the messageSpy to set
+     */
+    public void setMessageSpy(MessageSpy<DataContainer> messageSpy) {
+        this.messageSpy = messageSpy;
+    }
+    
+    /**
+     * @param errorHandler the errorHandler to set
+     */
+    public void setErrorHandler(ErrorHandler errorHandler) {
+        this.errorHandler = errorHandler;
+    }
 
 }