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.config.yang.bgpcep.data.change.counter;
11 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
12 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.protocol.data.change.counter.TopologyDataChangeCounter;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 public class DataChangeCounterImplModule extends org.opendaylight.controller.config.yang.bgpcep.data.change.counter.AbstractDataChangeCounterImplModule {
24 public DataChangeCounterImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
25 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
26 super(identifier, dependencyResolver);
29 public DataChangeCounterImplModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
30 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
31 final org.opendaylight.controller.config.yang.bgpcep.data.change.counter.DataChangeCounterImplModule oldModule,
32 final java.lang.AutoCloseable oldInstance) {
33 super(identifier, dependencyResolver, oldModule, oldInstance);
37 public void customValidation() {
38 JmxAttributeValidationException.checkNotNull(getCounterId(), "value is not set.", counterIdJmxAttribute);
39 JmxAttributeValidationException.checkNotNull(getTopologyName(), "value is not set.", topologyNameJmxAttribute);
43 public java.lang.AutoCloseable createInstance() {
44 final TopologyDataChangeCounter counter = new TopologyDataChangeCounter(getDataProviderDependency(), getCounterId());
45 final InstanceIdentifier<Topology> topoIId = InstanceIdentifier.builder(NetworkTopology.class)
46 .child(Topology.class, new TopologyKey(new TopologyId(getTopologyName()))).build();
47 final ListenerRegistration<TopologyDataChangeCounter> registration = getDataProviderDependency().registerDataTreeChangeListener(
48 new DataTreeIdentifier<Topology>(LogicalDatastoreType.OPERATIONAL, topoIId), counter);
49 return new DataChangeCounterCloseable(counter, registration);
52 private static final class DataChangeCounterCloseable implements AutoCloseable {
54 private final TopologyDataChangeCounter inner;
55 private final ListenerRegistration<TopologyDataChangeCounter> registration;
57 public DataChangeCounterCloseable(final TopologyDataChangeCounter inner,
58 final ListenerRegistration<TopologyDataChangeCounter> registration) {
60 this.registration = registration;
65 this.registration.close();