Bump odlparent to 5.0.0
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / device / DeviceContextImpl.java
index 6e181f4e2804b18880b54d964424805e2efdf82e..4f660f55b4511420dcd50313d3c5383b1c6c70ae 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -27,10 +27,10 @@ import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
@@ -59,7 +59,6 @@ import org.opendaylight.openflowplugin.common.txchain.TransactionChainManager;
 import org.opendaylight.openflowplugin.extension.api.ConvertorMessageFromOFJava;
 import org.opendaylight.openflowplugin.extension.api.ExtensionConverterProviderKeeper;
 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
-import org.opendaylight.openflowplugin.extension.api.exception.ConversionException;
 import org.opendaylight.openflowplugin.extension.api.path.MessagePath;
 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider;
 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProviderFactory;
@@ -218,7 +217,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
     }
 
     @Override
-    public ReadOnlyTransaction getReadTransaction() {
+    public ReadTransaction getReadTransaction() {
         return dataBroker.newReadOnlyTransaction();
     }
 
@@ -396,7 +395,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
         final OpenflowVersion openflowVersion = OpenflowVersion.get(deviceInfo.getVersion());
 
         // Try to get ingress from match
-        final NodeConnectorRef nodeConnectorRef = Objects.nonNull(packetIn.getIngress())
+        final NodeConnectorRef nodeConnectorRef = packetIn.getIngress() != null
                 ? packetIn.getIngress() : Optional.ofNullable(match)
                 .map(Match::getInPort)
                 .map(nodeConnectorId -> InventoryDataServiceUtil
@@ -472,17 +471,13 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
             }
             // build notification
             final ExperimenterMessageOfChoice messageOfChoice;
-            try {
-                messageOfChoice = messageConverter.convert(vendorData, MessagePath.MESSAGE_NOTIFICATION);
-                final ExperimenterMessageFromDevBuilder experimenterMessageFromDevBld = new
-                        ExperimenterMessageFromDevBuilder()
-                        .setNode(new NodeRef(getDeviceInfo().getNodeInstanceIdentifier()))
-                        .setExperimenterMessageOfChoice(messageOfChoice);
-                // publish
-                notificationPublishService.offerNotification(experimenterMessageFromDevBld.build());
-            } catch (final ConversionException e) {
-                LOG.error("Conversion of experimenter notification failed", e);
-            }
+            messageOfChoice = messageConverter.convert(vendorData, MessagePath.MESSAGE_NOTIFICATION);
+            final ExperimenterMessageFromDevBuilder experimenterMessageFromDevBld = new
+                    ExperimenterMessageFromDevBuilder()
+                    .setNode(new NodeRef(getDeviceInfo().getNodeInstanceIdentifier()))
+                    .setExperimenterMessageOfChoice(messageOfChoice);
+            // publish
+            notificationPublishService.offerNotification(experimenterMessageFromDevBld.build());
         } else {
             LOG.debug("Controller is not owner of the device {}, skipping experimenter message",
                     deviceInfo.getLOGValue());
@@ -496,11 +491,11 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
     public boolean processAlienMessage(final OfHeader message) {
         final Class<? extends DataContainer> implementedInterface = message.getImplementedInterface();
 
-        if (Objects.nonNull(implementedInterface) && org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service
-                .rev130709.PacketInMessage.class.equals(implementedInterface)) {
+        if (org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketInMessage.class
+                .equals(implementedInterface)) {
             final org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709
-                    .PacketInMessage packetInMessage = org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service
-                    .rev130709.PacketInMessage.class.cast(message);
+                    .PacketInMessage packetInMessage = (org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service
+                .rev130709.PacketInMessage) message;
 
             handlePacketInMessage(packetInMessage, implementedInterface, packetInMessage.getMatch());
             return true;
@@ -557,8 +552,8 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
     }
 
     @Override
-    public ListenableFuture<Void> closeServiceInstance() {
-        final ListenableFuture<Void> listenableFuture = initialized.get()
+    public ListenableFuture<?> closeServiceInstance() {
+        final ListenableFuture<?> listenableFuture = initialized.get()
                 ? transactionChainManager.deactivateTransactionManager()
                 : Futures.immediateFuture(null);
 
@@ -595,11 +590,11 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
             deviceFlowRegistry.close();
             deviceMeterRegistry.close();
 
-            final ListenableFuture<Void> txChainShuttingDown = transactionChainManager.shuttingDown();
+            final ListenableFuture<?> txChainShuttingDown = transactionChainManager.shuttingDown();
 
-            Futures.addCallback(txChainShuttingDown, new FutureCallback<Void>() {
+            Futures.addCallback(txChainShuttingDown, new FutureCallback<Object>() {
                 @Override
-                public void onSuccess(@Nullable final Void result) {
+                public void onSuccess(final Object result) {
                     transactionChainManager.close();
                     transactionChainManager = null;
                 }
@@ -663,7 +658,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
                     deviceInfo.toString()));
         }
 
-        final ListenableFuture<List<com.google.common.base.Optional<FlowCapableNode>>> deviceFlowRegistryFill =
+        final ListenableFuture<List<Optional<FlowCapableNode>>> deviceFlowRegistryFill =
                 getDeviceFlowRegistry().fill();
         Futures.addCallback(deviceFlowRegistryFill,
                 new DeviceFlowRegistryCallback(deviceFlowRegistryFill, contextChainMastershipWatcher),
@@ -708,20 +703,19 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
         hasState.set(true);
     }
 
-    private class DeviceFlowRegistryCallback implements FutureCallback<List<com.google.common.base
-            .Optional<FlowCapableNode>>> {
-        private final ListenableFuture<List<com.google.common.base.Optional<FlowCapableNode>>> deviceFlowRegistryFill;
+    private class DeviceFlowRegistryCallback implements FutureCallback<List<Optional<FlowCapableNode>>> {
+        private final ListenableFuture<List<Optional<FlowCapableNode>>> deviceFlowRegistryFill;
         private final ContextChainMastershipWatcher contextChainMastershipWatcher;
 
         DeviceFlowRegistryCallback(
-                ListenableFuture<List<com.google.common.base.Optional<FlowCapableNode>>> deviceFlowRegistryFill,
+                ListenableFuture<List<Optional<FlowCapableNode>>> deviceFlowRegistryFill,
                 ContextChainMastershipWatcher contextChainMastershipWatcher) {
             this.deviceFlowRegistryFill = deviceFlowRegistryFill;
             this.contextChainMastershipWatcher = contextChainMastershipWatcher;
         }
 
         @Override
-        public void onSuccess(@Nullable List<com.google.common.base.Optional<FlowCapableNode>> result) {
+        public void onSuccess(List<Optional<FlowCapableNode>> result) {
             if (LOG.isDebugEnabled()) {
                 // Count all flows we read from datastore for debugging purposes.
                 // This number do not always represent how many flows were actually added
@@ -732,7 +726,8 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
                         .stream()
                         .flatMap(Collection::stream)
                         .filter(Objects::nonNull)
-                        .flatMap(flowCapableNodeOptional -> flowCapableNodeOptional.asSet().stream())
+                        .flatMap(flowCapableNodeOptional
+                            -> com.google.common.base.Optional.fromJavaUtil(flowCapableNodeOptional).asSet().stream())
                         .filter(Objects::nonNull)
                         .filter(flowCapableNode -> Objects.nonNull(flowCapableNode.getTable()))
                         .flatMap(flowCapableNode -> flowCapableNode.getTable().stream())