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.group;
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.group.service.rev130918.SalGroupService;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
20 import org.opendaylight.yangtools.concepts.ListenerRegistration;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import com.google.common.base.Preconditions;
28 * Group Provider registers the {@link GroupChangeListener} and it holds all needed
29 * services for {@link GroupChangeListener}.
31 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
34 public class GroupProvider implements AutoCloseable {
36 private static final Logger LOG = LoggerFactory.getLogger(GroupProvider.class);
38 private SalGroupService salGroupService;
39 private DataBroker dataService;
41 /* DataChangeListener */
42 private DataChangeListener groupDataChangeListener;
43 private ListenerRegistration<DataChangeListener> groupDataChangeListenerRegistration;
46 * Provider Initialization Phase.
48 * @param DataProviderService dataService
50 public void init (final DataBroker dataService) {
51 LOG.info("FRM Group Config Provider initialization.");
52 this.dataService = Preconditions.checkNotNull(dataService, "DataService can not be null !");
56 * Listener Registration Phase
58 * @param RpcConsumerRegistry rpcRegistry
60 public void start(final RpcConsumerRegistry rpcRegistry) {
61 Preconditions.checkArgument(rpcRegistry != null, "RpcConsumerRegistry can not be null !");
63 this.salGroupService = Preconditions.checkNotNull(rpcRegistry.getRpcService(SalGroupService.class),
64 "RPC SalGroupService not found.");
67 InstanceIdentifier<Group> groupIdentifier = InstanceIdentifier.create(Nodes.class)
68 .child(Node.class).augmentation(FlowCapableNode.class).child(Group.class);
70 /* DataChangeListener registration */
71 this.groupDataChangeListener = new GroupChangeListener(GroupProvider.this);
72 this.groupDataChangeListenerRegistration = this.dataService.registerDataChangeListener(
73 LogicalDatastoreType.CONFIGURATION, groupIdentifier, groupDataChangeListener, DataChangeScope.SUBTREE);
75 LOG.info("FRM Group Config Provider started.");
80 LOG.info("FRM Group Config Provider stopped.");
81 if (groupDataChangeListenerRegistration != null) {
83 groupDataChangeListenerRegistration.close();
84 } catch (Exception e) {
85 String errMsg = "Error by stop FRM Group Config Provider.";
87 throw new IllegalStateException(errMsg, e);
89 groupDataChangeListenerRegistration = null;
94 public DataChangeListener getGroupDataChangeListener() {
95 return groupDataChangeListener;
98 public SalGroupService getSalGroupService() {
99 return salGroupService;
102 public DataBroker getDataService() {