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
8 package org.opendaylight.controller.frm.flow;
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
12 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
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.yangtools.concepts.ListenerRegistration;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import com.google.common.base.Preconditions;
29 * Flow Provider registers the {@link FlowChangeListener} and it holds all needed
30 * services for {@link FlowChangeListener}.
32 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
35 public class FlowProvider implements AutoCloseable {
37 private static final Logger LOG = LoggerFactory.getLogger(FlowProvider.class);
39 private SalFlowService salFlowService;
40 private DataBroker dataService;
42 /* DataChangeListener */
43 private DataChangeListener flowDataChangeListener;
44 private ListenerRegistration<DataChangeListener> flowDataChangeListenerRegistration;
47 * Provider Initialization Phase.
49 * @param DataProviderService dataService
51 public void init (final DataBroker dataService) {
52 LOG.info("FRM Flow Config Provider initialization.");
53 this.dataService = Preconditions.checkNotNull(dataService, "DataProviderService can not be null !");
57 * Listener Registration Phase
59 * @param RpcConsumerRegistry rpcRegistry
61 public void start(final RpcConsumerRegistry rpcRegistry) {
62 Preconditions.checkArgument(rpcRegistry != null, "RpcConsumerRegistry can not be null !");
64 this.salFlowService = Preconditions.checkNotNull(rpcRegistry.getRpcService(SalFlowService.class),
65 "RPC SalFlowService not found.");
68 InstanceIdentifier<Flow> flowIdentifier = InstanceIdentifier.create(Nodes.class)
69 .child(Node.class).augmentation(FlowCapableNode.class).child(Table.class).child(Flow.class);
71 /* DataChangeListener registration */
72 this.flowDataChangeListener = new FlowChangeListener(FlowProvider.this);
73 this.flowDataChangeListenerRegistration =
74 this.dataService.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
75 flowIdentifier, flowDataChangeListener, DataChangeScope.SUBTREE);
77 LOG.info("FRM Flow Config Provider started.");
82 LOG.info("FRM Flow Config Provider stopped.");
83 if (flowDataChangeListenerRegistration != null) {
85 flowDataChangeListenerRegistration.close();
86 } catch (Exception e) {
87 String errMsg = "Error by stop FRM Flow Config Provider.";
89 throw new IllegalStateException(errMsg, e);
91 flowDataChangeListenerRegistration = null;
96 public DataChangeListener getFlowDataChangeListener() {
97 return flowDataChangeListener;
100 public SalFlowService getSalFlowService() {
101 return salFlowService;
104 public DataBroker getDataService() {