X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fforwardingrules-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Ffrm%2Fflow%2FFlowProvider.java;fp=opendaylight%2Fmd-sal%2Fforwardingrules-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Ffrm%2Fflow%2FFlowProvider.java;h=8c248fa264055b615d58bb986b8faaad5d5110b3;hb=3bad057a3d83945a7e23113aacbdba6ba9cb5d97;hp=33db529598dc9115c4dfcb52906f585bcb00313e;hpb=aebab42f1b08f22037ce725fd852d79584d09109;p=controller.git diff --git a/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/flow/FlowProvider.java b/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/flow/FlowProvider.java index 33db529598..8c248fa264 100644 --- a/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/flow/FlowProvider.java +++ b/opendaylight/md-sal/forwardingrules-manager/src/main/java/org/opendaylight/controller/frm/flow/FlowProvider.java @@ -7,9 +7,11 @@ */ package org.opendaylight.controller.frm.flow; -import org.opendaylight.controller.sal.binding.api.data.DataChangeListener; -import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction; -import org.opendaylight.controller.sal.binding.api.data.DataProviderService; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; @@ -17,54 +19,89 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalF import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.base.Preconditions; + +/** + * Flow Provider registers the {@link FlowChangeListener} and it holds all needed + * services for {@link FlowChangeListener}. + * + * @author Vaclav Demcak + * + */ public class FlowProvider implements AutoCloseable { - private final static Logger LOG = LoggerFactory.getLogger(FlowProvider.class); + private static final Logger LOG = LoggerFactory.getLogger(FlowProvider.class); private SalFlowService salFlowService; - private DataProviderService dataService; + private DataBroker dataService; /* DataChangeListener */ - private FlowChangeListener flowDataChangeListener; - ListenerRegistration flowDataChangeListenerRegistration; + private DataChangeListener flowDataChangeListener; + private ListenerRegistration flowDataChangeListenerRegistration; + + /** + * Provider Initialization Phase. + * + * @param DataProviderService dataService + */ + public void init (final DataBroker dataService) { + LOG.info("FRM Flow Config Provider initialization."); + this.dataService = Preconditions.checkNotNull(dataService, "DataProviderService can not be null !"); + } + + /** + * Listener Registration Phase + * + * @param RpcConsumerRegistry rpcRegistry + */ + public void start(final RpcConsumerRegistry rpcRegistry) { + Preconditions.checkArgument(rpcRegistry != null, "RpcConsumerRegistry can not be null !"); + + this.salFlowService = Preconditions.checkNotNull(rpcRegistry.getRpcService(SalFlowService.class), + "RPC SalFlowService not found."); - public void start() { /* Build Path */ - InstanceIdentifierBuilder nodesBuilder = InstanceIdentifier. builder(Nodes.class); - InstanceIdentifierBuilder nodeChild = nodesBuilder. child(Node.class); - InstanceIdentifierBuilder augmentFlowCapNode = nodeChild. augmentation(FlowCapableNode.class); - InstanceIdentifierBuilder tableChild = augmentFlowCapNode.
child(Table.class); - InstanceIdentifierBuilder flowChild = tableChild. child(Flow.class); - final InstanceIdentifier flowDataObjectPath = flowChild.toInstance(); + InstanceIdentifier flowIdentifier = InstanceIdentifier.create(Nodes.class) + .child(Node.class).augmentation(FlowCapableNode.class).child(Table.class).child(Flow.class); /* DataChangeListener registration */ - this.flowDataChangeListener = new FlowChangeListener(this.salFlowService); - this.flowDataChangeListenerRegistration = this.dataService.registerDataChangeListener(flowDataObjectPath, flowDataChangeListener); - LOG.info("Flow Config Provider started."); - } + this.flowDataChangeListener = new FlowChangeListener(FlowProvider.this); + this.flowDataChangeListenerRegistration = + this.dataService.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, + flowIdentifier, flowDataChangeListener, DataChangeScope.SUBTREE); - protected DataModificationTransaction startChange() { - return this.dataService.beginTransaction(); + LOG.info("FRM Flow Config Provider started."); } @Override - public void close() throws Exception { - if(flowDataChangeListenerRegistration != null){ - flowDataChangeListenerRegistration.close(); + public void close() { + LOG.info("FRM Flow Config Provider stopped."); + if (flowDataChangeListenerRegistration != null) { + try { + flowDataChangeListenerRegistration.close(); + } catch (Exception e) { + String errMsg = "Error by stop FRM Flow Config Provider."; + LOG.error(errMsg, e); + throw new IllegalStateException(errMsg, e); + } finally { + flowDataChangeListenerRegistration = null; + } } } - public void setDataService(final DataProviderService dataService) { - this.dataService = dataService; + public DataChangeListener getFlowDataChangeListener() { + return flowDataChangeListener; + } + + public SalFlowService getSalFlowService() { + return salFlowService; } - public void setSalFlowService(final SalFlowService salFlowService) { - this.salFlowService = salFlowService; + public DataBroker getDataService() { + return dataService; } }