*/
package org.opendaylight.openflowplugin.applications.topology.manager;
+import static java.util.Objects.requireNonNull;
+
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 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.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.NotificationListener;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
-public class FlowCapableTopologyProvider implements ClusterSingletonService, AutoCloseable {
+@Component(service = { })
+public final 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 NotificationService notificationService;
+ private final InstanceIdentifier<Topology> topologyPathIID;
+ private final TransactionChainManager transactionChainManager;
private final OperationProcessor processor;
- private final ClusterSingletonServiceProvider clusterSingletonServiceProvider;
- private InstanceIdentifier<Topology> topologyPathIID;
- private TransactionChainManager transactionChainManager;
- private ListenerRegistration<NotificationListener> listenerRegistration;
+
+ private Registration listenerRegistration;
private ClusterSingletonServiceRegistration singletonServiceRegistration;
@Inject
+ @Activate
public FlowCapableTopologyProvider(@Reference final DataBroker dataBroker,
- @Reference final NotificationService notificationService,
- final OperationProcessor processor,
- @Reference final ClusterSingletonServiceProvider
- clusterSingletonServiceProvider) {
- this.dataBroker = dataBroker;
- this.notificationService = notificationService;
- this.processor = processor;
- this.clusterSingletonServiceProvider = clusterSingletonServiceProvider;
- }
-
- /**
- * Gets called on start of a bundle.
- */
- @PostConstruct
- public void start() {
+ @Reference final NotificationService notificationService,
+ @Reference final ClusterSingletonServiceProvider clusterSingletonServiceProvider,
+ @Reference final OperationProcessor processor) {
+ this.processor = requireNonNull(processor);
final TopologyKey key = new TopologyKey(new TopologyId(TOPOLOGY_ID));
- this.topologyPathIID = InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, key);
+ topologyPathIID = InstanceIdentifier.create(NetworkTopology.class).child(Topology.class, key);
- final FlowCapableTopologyExporter listener = new FlowCapableTopologyExporter(processor, topologyPathIID);
- this.listenerRegistration = notificationService.registerNotificationListener(listener);
- this.transactionChainManager = new TransactionChainManager(dataBroker, TOPOLOGY_PROVIDER);
- this.transactionChainManager.activateTransactionManager();
- this.transactionChainManager.initialSubmitWriteTransaction();
- this.singletonServiceRegistration = this.clusterSingletonServiceProvider.registerClusterSingletonService(this);
+ listenerRegistration = notificationService.registerCompositeListener(
+ new FlowCapableTopologyExporter(processor, topologyPathIID).toListener());
+ transactionChainManager = new TransactionChainManager(dataBroker, TOPOLOGY_PROVIDER);
+ transactionChainManager.activateTransactionManager();
+ transactionChainManager.initialSubmitWriteTransaction();
+ singletonServiceRegistration = clusterSingletonServiceProvider.registerClusterSingletonService(this);
LOG.info("Topology Manager service started.");
}
- @Override
@PreDestroy
+ @Deactivate
+ @Override
public void close() {
- this.transactionChainManager.close();
- if (this.listenerRegistration != null) {
+ transactionChainManager.close();
+ if (listenerRegistration != null) {
LOG.info("Closing notification listener registration.");
- this.listenerRegistration.close();
- this.listenerRegistration = null;
+ listenerRegistration.close();
+ listenerRegistration = null;
}
- if (this.singletonServiceRegistration != null) {
+ if (singletonServiceRegistration != null) {
LOG.info("Closing clustering singleton service registration.");
- this.singletonServiceRegistration.close();
- this.singletonServiceRegistration = null;
+ singletonServiceRegistration.close();
+ singletonServiceRegistration = null;
}
- LOG.debug("Topology Manager instance is stopped.");
+ LOG.info("Topology Manager instance is stopped.");
}
@Override
return Futures.immediateFuture(null);
}
- @Nonnull
@Override
public ServiceGroupIdentifier getIdentifier() {
return ServiceGroupIdentifier.create(TOPOLOGY_PROVIDER);
private boolean isFlowTopologyExist(final InstanceIdentifier<Topology> path) {
try {
- Optional<Topology> ofTopology = this.transactionChainManager
+ Optional<Topology> ofTopology = transactionChainManager
.readFromTransaction(LogicalDatastoreType.OPERATIONAL, path).get();
LOG.debug("OpenFlow topology exist in the operational data store at {}", path);
if (ofTopology.isPresent()) {