Merge "Use ClassToInstanceMap instead of a HashMap"
[openflowplugin.git] / applications / topology-manager / src / main / java / org / opendaylight / openflowplugin / applications / topology / manager / FlowCapableTopologyProvider.java
index 0249510756e19ad912078e8351a457a6f61fc88a..83bcb9f81cc9061c03dfe774bcddb3ae24094b0d 100644 (file)
@@ -7,14 +7,18 @@
  */
 package org.opendaylight.openflowplugin.applications.topology.manager;
 
-import com.google.common.base.Optional;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import java.util.Optional;
 import java.util.concurrent.ExecutionException;
-import javax.annotation.Nonnull;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.apache.aries.blueprint.annotation.service.Reference;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
@@ -31,13 +35,14 @@ import org.opendaylight.yangtools.yang.binding.NotificationListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Singleton
 public class FlowCapableTopologyProvider implements ClusterSingletonService, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(FlowCapableTopologyProvider.class);
     private static final String TOPOLOGY_PROVIDER = "ofp-topology-manager";
     static final String TOPOLOGY_ID = "flow:1";
 
     private final DataBroker dataBroker;
-    private final NotificationProviderService notificationService;
+    private final NotificationService notificationService;
     private final OperationProcessor processor;
     private final ClusterSingletonServiceProvider clusterSingletonServiceProvider;
     private InstanceIdentifier<Topology> topologyPathIID;
@@ -45,10 +50,12 @@ public class FlowCapableTopologyProvider implements ClusterSingletonService, Aut
     private ListenerRegistration<NotificationListener> listenerRegistration;
     private ClusterSingletonServiceRegistration singletonServiceRegistration;
 
-    public FlowCapableTopologyProvider(final DataBroker dataBroker,
-                                       final NotificationProviderService notificationService,
+    @Inject
+    public FlowCapableTopologyProvider(@Reference final DataBroker dataBroker,
+                                       @Reference final NotificationService notificationService,
                                        final OperationProcessor processor,
-                                       final ClusterSingletonServiceProvider clusterSingletonServiceProvider) {
+                                       @Reference final ClusterSingletonServiceProvider
+                                               clusterSingletonServiceProvider) {
         this.dataBroker = dataBroker;
         this.notificationService = notificationService;
         this.processor = processor;
@@ -58,6 +65,7 @@ public class FlowCapableTopologyProvider implements ClusterSingletonService, Aut
     /**
      * Gets called on start of a bundle.
      */
+    @PostConstruct
     public void start() {
         final TopologyKey key = new TopologyKey(new TopologyId(TOPOLOGY_ID));
         this.topologyPathIID = InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, key);
@@ -72,6 +80,7 @@ public class FlowCapableTopologyProvider implements ClusterSingletonService, Aut
     }
 
     @Override
+    @PreDestroy
     public void close() {
         this.transactionChainManager.close();
         if (this.listenerRegistration != null) {
@@ -104,7 +113,6 @@ public class FlowCapableTopologyProvider implements ClusterSingletonService, Aut
         return Futures.immediateFuture(null);
     }
 
-    @Nonnull
     @Override
     public ServiceGroupIdentifier getIdentifier() {
         return ServiceGroupIdentifier.create(TOPOLOGY_PROVIDER);