Merge "Declare reconciliation artifacts"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / connection / ConnectionManagerImpl.java
index cd9db49634427e1f93b89c29802f53a7d1a0142e..61d2424a9c2c8d4f5257a3904ce1a7ec33494b68 100644 (file)
@@ -9,7 +9,7 @@
 package org.opendaylight.openflowplugin.impl.connection;
 
 import java.net.InetAddress;
-import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.ExecutorService;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
 import org.opendaylight.openflowplugin.api.OFConstants;
@@ -20,6 +20,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceConnec
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
 import org.opendaylight.openflowplugin.api.openflow.md.core.HandshakeListener;
 import org.opendaylight.openflowplugin.api.openflow.md.core.HandshakeManager;
+import org.opendaylight.openflowplugin.impl.common.DeviceConnectionRateLimiter;
 import org.opendaylight.openflowplugin.impl.connection.listener.ConnectionReadyListenerImpl;
 import org.opendaylight.openflowplugin.impl.connection.listener.HandshakeListenerImpl;
 import org.opendaylight.openflowplugin.impl.connection.listener.OpenflowProtocolListenerInitialImpl;
@@ -30,21 +31,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/**
- *
- */
 public class ConnectionManagerImpl implements ConnectionManager {
 
     private static final Logger LOG = LoggerFactory.getLogger(ConnectionManagerImpl.class);
     private static final boolean BITMAP_NEGOTIATION_ENABLED = true;
     private DeviceConnectedHandler deviceConnectedHandler;
     private final OpenflowProviderConfig config;
-    private final ThreadPoolExecutor threadPool;
+    private final ExecutorService executorService;
+    private final DeviceConnectionRateLimiter deviceConnectionRateLimiter;
     private DeviceDisconnectedHandler deviceDisconnectedHandler;
 
-    public ConnectionManagerImpl(final OpenflowProviderConfig config, final ThreadPoolExecutor threadPool) {
+    public ConnectionManagerImpl(final OpenflowProviderConfig config, final ExecutorService executorService) {
         this.config = config;
-        this.threadPool = threadPool;
+        this.executorService = executorService;
+        this.deviceConnectionRateLimiter = new DeviceConnectionRateLimiter(config);
     }
 
     @Override
@@ -57,7 +57,7 @@ public class ConnectionManagerImpl implements ConnectionManager {
         final HandshakeManager handshakeManager = createHandshakeManager(connectionAdapter, handshakeListener);
 
         LOG.trace("prepare handshake context");
-        HandshakeContext handshakeContext = new HandshakeContextImpl(threadPool, handshakeManager);
+        HandshakeContext handshakeContext = new HandshakeContextImpl(executorService, handshakeManager);
         handshakeListener.setHandshakeContext(handshakeContext);
         connectionContext.setHandshakeContext(handshakeContext);
 
@@ -71,7 +71,7 @@ public class ConnectionManagerImpl implements ConnectionManager {
         connectionAdapter.setMessageListener(ofMessageListener);
 
         final SystemNotificationsListener systemListener = new SystemNotificationsListenerImpl(
-                connectionContext, config.getEchoReplyTimeout().getValue(), threadPool);
+                connectionContext, config.getEchoReplyTimeout().getValue(), executorService);
         connectionAdapter.setSystemListener(systemListener);
 
         LOG.trace("connection ballet finished");
@@ -81,10 +81,8 @@ public class ConnectionManagerImpl implements ConnectionManager {
                                                     final HandshakeListener handshakeListener) {
         HandshakeManagerImpl handshakeManager = new HandshakeManagerImpl(connectionAdapter,
                 OFConstants.VERSION_ORDER.get(0),
-                OFConstants.VERSION_ORDER);
-        handshakeManager.setUseVersionBitmap(BITMAP_NEGOTIATION_ENABLED);
-        handshakeManager.setHandshakeListener(handshakeListener);
-        handshakeManager.setErrorHandler(new ErrorHandlerSimpleImpl());
+                OFConstants.VERSION_ORDER, new ErrorHandlerSimpleImpl(), handshakeListener, BITMAP_NEGOTIATION_ENABLED,
+                deviceConnectionRateLimiter);
 
         return handshakeManager;
     }