Small fix to xsql dependencies
[controller.git] / opendaylight / md-sal / forwardingrules-manager / src / main / java / org / opendaylight / controller / frm / reconil / FlowNodeReconcilProvider.java
1 /**
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.frm.reconil;
10
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;
26
27 import com.google.common.base.Preconditions;
28
29 /**
30  * forwardingrules-manager
31  * org.opendaylight.controller.frm
32  *
33  * FlowNode Reconciliation Provider registers the FlowNodeReconilListener
34  * and it holds all needed services for FlowNodeReconcilListener.
35  *
36  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
37  *
38  * Created: Jun 13, 2014
39  */
40 public class FlowNodeReconcilProvider implements AutoCloseable {
41
42     private static final Logger LOG = LoggerFactory.getLogger(FlowNodeReconcilProvider.class);
43
44     private SalFlowService salFlowService;
45     private SalMeterService salMeterService;
46     private SalGroupService salGroupService;
47     private DataBroker dataService;
48
49     /* DataChangeListener */
50     private DataChangeListener flowNodeReconcilListener;
51     private ListenerRegistration<DataChangeListener> flowNodeReconcilListenerRegistration;
52
53     public void init (final DataBroker dataService) {
54         LOG.info("FRM Flow Node Config Reconcil Provider initialization.");
55
56         this.dataService = Preconditions.checkNotNull(dataService, "DataProviderService can not be null !");
57     }
58
59     public void start( final RpcConsumerRegistry rpcRegistry ) {
60         Preconditions.checkArgument(rpcRegistry != null, "RpcConcumerRegistry can not be null !");
61
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.");
68
69         /* Build Path */
70         InstanceIdentifier<FlowCapableNode> flowCapableNodeIdent =
71                 InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class);
72
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.");
78     }
79
80     @Override
81     public void close() {
82         LOG.info("FRM Flow Node Config Reconcil Provider stopped.");
83         if (flowNodeReconcilListenerRegistration != null) {
84             try {
85                 flowNodeReconcilListenerRegistration.close();
86             } catch (Exception e) {
87                 String errMsg = "Error by stop FRM Flow Node Config Reconcil Provider.";
88                 LOG.error(errMsg, e);
89                 throw new IllegalStateException(errMsg, e);
90             } finally {
91                 flowNodeReconcilListenerRegistration = null;
92             }
93         }
94     }
95
96     public DataChangeListener getFlowNodeReconcilListener() {
97         return flowNodeReconcilListener;
98     }
99
100     public DataBroker getDataService() {
101         return dataService;
102     }
103
104     public SalFlowService getSalFlowService() {
105         return salFlowService;
106     }
107
108     public SalMeterService getSalMeterService() {
109         return salMeterService;
110     }
111
112     public SalGroupService getSalGroupService() {
113         return salGroupService;
114     }
115 }