unifying statistics manager api packages
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / SwitchConnectionHandlerImpl.java
index f571e0094b3a05a0ec8f6b69bbdfde86386529a3..287b605d5524af21e8bde4c24c35c40df7cd3572 100644 (file)
@@ -14,43 +14,45 @@ 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.api.openflow.md.core.ConnectionConductor;
+import org.opendaylight.openflowplugin.api.openflow.md.core.ErrorHandler;
 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
-import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpy;
-import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpyCounterImpl;
-import org.opendaylight.openflowplugin.openflow.md.queue.QueueKeeperLightImpl;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
-import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.openflowplugin.openflow.md.queue.QueueProcessorLightImpl;
+import org.opendaylight.openflowplugin.api.openflow.statistics.MessageSpy;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
 
 /**
- * @author mirehak
- *
+ * basic interconnecting piece between plugin and library 
  */
 public class SwitchConnectionHandlerImpl implements SwitchConnectionHandler {
     
     private ScheduledThreadPoolExecutor spyPool; 
 
-    private QueueKeeperLightImpl queueKeeper;
+    private QueueProcessorLightImpl queueProcessor;
     private ErrorHandler errorHandler;
-    private MessageSpy<OfHeader, DataObject> messageSpy;
+    private MessageSpy<DataContainer> messageSpy;
     private int spyRate = 10;
 
     /**
      *
      */
     public SwitchConnectionHandlerImpl() {
-        messageSpy = new MessageSpyCounterImpl();
-        queueKeeper = new QueueKeeperLightImpl();
-        queueKeeper.setTranslatorMapping(OFSessionUtil.getTranslatorMap());
-        queueKeeper.setPopListenersMapping(OFSessionUtil.getPopListenerMapping());
-        queueKeeper.setMessageSpy(messageSpy);
-        
-        queueKeeper.init();
-
-        errorHandler = new ErrorHandlerQueueImpl();
-        new Thread(errorHandler).start();
+        queueProcessor = new QueueProcessorLightImpl();
         
         //TODO: implement shutdown invocation upon service stop event
         spyPool = new ScheduledThreadPoolExecutor(1);
+    }
+
+    /**
+     * wire all up
+     */
+    public void init() {
+        queueProcessor.setTranslatorMapping(OFSessionUtil.getTranslatorMap());
+        queueProcessor.setPopListenersMapping(OFSessionUtil.getPopListenerMapping());
+        queueProcessor.setMessageSpy(messageSpy);
+        
+        queueProcessor.init();
+        
         spyPool.scheduleAtFixedRate(messageSpy, spyRate, spyRate, TimeUnit.SECONDS);
     }
 
@@ -63,8 +65,22 @@ public class SwitchConnectionHandlerImpl implements SwitchConnectionHandler {
     @Override
     public void onSwitchConnected(ConnectionAdapter connectionAdapter) {
         ConnectionConductor conductor = ConnectionConductorFactory.createConductor(
-                connectionAdapter, queueKeeper);
+                connectionAdapter, queueProcessor);
         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;
+    }
 
 }