2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.frm.reconil;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
22 import org.opendaylight.yangtools.concepts.ListenerRegistration;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 import com.google.common.base.Preconditions;
30 * forwardingrules-manager
31 * org.opendaylight.controller.frm
33 * FlowNode Reconciliation Provider registers the FlowNodeReconilListener
34 * and it holds all needed services for FlowNodeReconcilListener.
36 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
38 * Created: Jun 13, 2014
40 public class FlowNodeReconcilProvider implements AutoCloseable {
42 private static final Logger LOG = LoggerFactory.getLogger(FlowNodeReconcilProvider.class);
44 private SalFlowService salFlowService;
45 private SalMeterService salMeterService;
46 private SalGroupService salGroupService;
47 private DataBroker dataService;
49 /* DataChangeListener */
50 private DataChangeListener flowNodeReconcilListener;
51 private ListenerRegistration<DataChangeListener> flowNodeReconcilListenerRegistration;
53 public void init (final DataBroker dataService) {
54 LOG.info("FRM Flow Node Config Reconcil Provider initialization.");
56 this.dataService = Preconditions.checkNotNull(dataService, "DataProviderService can not be null !");
59 public void start( final RpcConsumerRegistry rpcRegistry ) {
60 Preconditions.checkArgument(rpcRegistry != null, "RpcConcumerRegistry can not be null !");
62 this.salFlowService = Preconditions.checkNotNull(rpcRegistry.getRpcService(SalFlowService.class),
63 "RPC SalFlowService not found.");
64 this.salMeterService = Preconditions.checkNotNull(rpcRegistry.getRpcService(SalMeterService.class),
65 "RPC SalMeterService not found.");
66 this.salGroupService = Preconditions.checkNotNull(rpcRegistry.getRpcService(SalGroupService.class),
67 "RPC SalGroupService not found.");
70 InstanceIdentifier<FlowCapableNode> flowCapableNodeIdent =
71 InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class);
73 /* ReconcilNotificationListener registration */
74 this.flowNodeReconcilListener = new FlowNodeReconcilListener(FlowNodeReconcilProvider.this);
75 this.flowNodeReconcilListenerRegistration = this.dataService.registerDataChangeListener(
76 LogicalDatastoreType.OPERATIONAL, flowCapableNodeIdent, flowNodeReconcilListener, DataChangeScope.BASE);
77 LOG.info("FRM Flow Node Config Reconcil Provider started.");
82 LOG.info("FRM Flow Node Config Reconcil Provider stopped.");
83 if (flowNodeReconcilListenerRegistration != null) {
85 flowNodeReconcilListenerRegistration.close();
86 } catch (Exception e) {
87 String errMsg = "Error by stop FRM Flow Node Config Reconcil Provider.";
89 throw new IllegalStateException(errMsg, e);
91 flowNodeReconcilListenerRegistration = null;
96 public DataChangeListener getFlowNodeReconcilListener() {
97 return flowNodeReconcilListener;
100 public DataBroker getDataService() {
104 public SalFlowService getSalFlowService() {
105 return salFlowService;
108 public SalMeterService getSalMeterService() {
109 return salMeterService;
112 public SalGroupService getSalGroupService() {
113 return salGroupService;