Added notification for Flow add/delete/update
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / SwitchConnectionHandlerImpl.java
index 4838666431d95d65c86abe8c3e3cdee23c6d66e0..f571e0094b3a05a0ec8f6b69bbdfde86386529a3 100644 (file)
@@ -9,15 +9,50 @@
 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.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;
 
 /**
  * @author mirehak
  *
  */
 public class SwitchConnectionHandlerImpl implements SwitchConnectionHandler {
+    
+    private ScheduledThreadPoolExecutor spyPool; 
+
+    private QueueKeeperLightImpl queueKeeper;
+    private ErrorHandler errorHandler;
+    private MessageSpy<OfHeader, DataObject> 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();
+        
+        //TODO: implement shutdown invocation upon service stop event
+        spyPool = new ScheduledThreadPoolExecutor(1);
+        spyPool.scheduleAtFixedRate(messageSpy, spyRate, spyRate, TimeUnit.SECONDS);
+    }
 
     @Override
     public boolean accept(InetAddress address) {
@@ -27,8 +62,9 @@ public class SwitchConnectionHandlerImpl implements SwitchConnectionHandler {
 
     @Override
     public void onSwitchConnected(ConnectionAdapter connectionAdapter) {
-        ConnectionConductor conductor = ConnectionConductorFactory.createConductor(connectionAdapter);
-        //TODO:: store conductor
+        ConnectionConductor conductor = ConnectionConductorFactory.createConductor(
+                connectionAdapter, queueKeeper);
+        conductor.setErrorHandler(errorHandler);
     }
 
 }