Bug 3599 - Li - transaction chain manager should not propagate connection context...
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / OpenFlowPluginProviderImpl.java
index fecf0537f1b9aa32f7a1e91c4adde12edb170fcc..30173363c7d3b36eb39b0beb391f28251ab0b769 100644 (file)
@@ -13,11 +13,19 @@ import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import java.lang.management.ManagementFactory;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectName;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.controller.md.sal.binding.api.NotificationService;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
 import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProvider;
@@ -25,15 +33,19 @@ import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionManager
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
+import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
 import org.opendaylight.openflowplugin.extension.api.ExtensionConverterRegistrator;
 import org.opendaylight.openflowplugin.extension.api.OpenFlowPluginExtensionRegistratorProvider;
 import org.opendaylight.openflowplugin.impl.connection.ConnectionManagerImpl;
 import org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl;
 import org.opendaylight.openflowplugin.impl.rpc.RpcManagerImpl;
 import org.opendaylight.openflowplugin.impl.statistics.StatisticsManagerImpl;
+import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.MessageIntelligenceAgencyImpl;
+import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.MessageIntelligenceAgencyMXBean;
 import org.opendaylight.openflowplugin.impl.util.TranslatorLibraryUtil;
 import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionConverterManager;
 import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionConverterManagerImpl;
+import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.api.types.rev150327.OfpRole;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -43,24 +55,28 @@ import org.slf4j.LoggerFactory;
  */
 public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenFlowPluginExtensionRegistratorProvider {
 
-    protected static final Logger LOG = LoggerFactory.getLogger(OpenFlowPluginProviderImpl.class);
+    private static final Logger LOG = LoggerFactory.getLogger(OpenFlowPluginProviderImpl.class);
+    private static final MessageIntelligenceAgency messageIntelligenceAgency = new MessageIntelligenceAgencyImpl();
 
+    private final int rpcRequestsQuota;
     private DeviceManager deviceManager;
     private RpcManager rpcManager;
     private RpcProviderRegistry rpcProviderRegistry;
     private StatisticsManager statisticsManager;
     private ConnectionManager connectionManager;
-    private NotificationProviderService notificationProviderService;
+    private NotificationService notificationProviderService;
+    private NotificationPublishService notificationPublishService;
 
     private ExtensionConverterManager extensionConverterManager;
 
     private DataBroker dataBroker;
     private OfpRole role;
     private Collection<SwitchConnectionProvider> switchConnectionProviders;
-    private Long rpcRequestsQuota;
+    private boolean switchFeaturesMandatory = false;
 
-    public OpenFlowPluginProviderImpl(final Long rpcRequestsQuota) {
-        this.rpcRequestsQuota = rpcRequestsQuota;
+    public OpenFlowPluginProviderImpl(final long rpcRequestsQuota) {
+        Preconditions.checkArgument(rpcRequestsQuota > 0 && rpcRequestsQuota <= Integer.MAX_VALUE, "rpcRequestQuota has to be in range <1,%s>", Integer.MAX_VALUE);
+        this.rpcRequestsQuota = (int) rpcRequestsQuota;
     }
 
 
@@ -87,6 +103,18 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         });
     }
 
+    public boolean isSwitchFeaturesMandatory() {
+        return switchFeaturesMandatory;
+    }
+
+    public void setSwitchFeaturesMandatory(final boolean switchFeaturesMandatory) {
+        this.switchFeaturesMandatory = switchFeaturesMandatory;
+    }
+
+    public static MessageIntelligenceAgency getMessageIntelligenceAgency() {
+        return OpenFlowPluginProviderImpl.messageIntelligenceAgency;
+    }
+
     @Override
     public void setSwitchConnectionProviders(final Collection<SwitchConnectionProvider> switchConnectionProviders) {
         this.switchConnectionProviders = switchConnectionProviders;
@@ -116,27 +144,57 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         Preconditions.checkNotNull(notificationProviderService, "missing notification provider service");
 
         extensionConverterManager = new ExtensionConverterManagerImpl();
+        // TODO: copied from OpenFlowPluginProvider (Helium) misusesing the old way of distributing extension converters
+        // TODO: rewrite later!
+        OFSessionUtil.getSessionManager().setExtensionConverterProvider(extensionConverterManager);
 
         connectionManager = new ConnectionManagerImpl();
-        deviceManager = new DeviceManagerImpl(dataBroker);
+
+        registerMXBean(messageIntelligenceAgency);
+
+        deviceManager = new DeviceManagerImpl(dataBroker, messageIntelligenceAgency, switchFeaturesMandatory);
         statisticsManager = new StatisticsManagerImpl();
         rpcManager = new RpcManagerImpl(rpcProviderRegistry, rpcRequestsQuota);
 
         connectionManager.setDeviceConnectedHandler(deviceManager);
         deviceManager.setDeviceInitializationPhaseHandler(statisticsManager);
         deviceManager.setNotificationService(this.notificationProviderService);
+        deviceManager.setNotificationPublishService(this.notificationPublishService);
         statisticsManager.setDeviceInitializationPhaseHandler(rpcManager);
         rpcManager.setDeviceInitializationPhaseHandler(deviceManager);
 
         TranslatorLibraryUtil.setBasicTranslatorLibrary(deviceManager);
+        deviceManager.initialize();
+
         startSwitchConnections();
     }
 
+    private static void registerMXBean(final MessageIntelligenceAgency messageIntelligenceAgency) {
+        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+        try {
+            String pathToMxBean = String.format("%s:type=%s",
+                    MessageIntelligenceAgencyMXBean.class.getPackage().getName(),
+                    MessageIntelligenceAgencyMXBean.class.getSimpleName());
+            ObjectName name = new ObjectName(pathToMxBean);
+            mbs.registerMBean(messageIntelligenceAgency, name);
+        } catch (MalformedObjectNameException
+                | NotCompliantMBeanException
+                | MBeanRegistrationException
+                | InstanceAlreadyExistsException e) {
+            LOG.warn("Error registering MBean {}", e);
+        }
+    }
+
     @Override
-    public void setNotificationProviderService(final NotificationProviderService notificationProviderService) {
+    public void setNotificationProviderService(final NotificationService notificationProviderService) {
         this.notificationProviderService = notificationProviderService;
     }
 
+    @Override
+    public void setNotificationPublishService(final NotificationPublishService notificationPublishProviderService) {
+        this.notificationPublishService = notificationPublishProviderService;
+    }
+
     @Override
     public ExtensionConverterRegistrator getExtensionConverterRegistrator() {
         return extensionConverterManager;