Eliminate jsr305 dependencies
[lispflowmapping.git] / mappingservice / neutron / src / main / java / org / opendaylight / lispflowmapping / neutron / intenthandler / listener / service / VbridgeTopologyListenerService.java
1 /*
2  * Copyright (c) 2017 Cisco Systems, Inc.  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 package org.opendaylight.lispflowmapping.neutron.intenthandler.listener.service;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.lispflowmapping.neutron.intenthandler.listener.VbridgeTopologyListener;
12 import org.opendaylight.mdsal.binding.api.DataBroker;
13 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
14 import org.opendaylight.mdsal.binding.api.MountPointService;
15 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.topology.rev160129.TopologyTypesVbridgeAugment;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vbridge.topology.rev160129.network.topology.topology.topology.types.VbridgeTopology;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.TopologyTypes;
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;
25
26 /**
27  * Created by Shakib Ahmed on 1/19/17.
28  */
29 public class VbridgeTopologyListenerService implements AutoCloseable {
30     private static final Logger LOG = LoggerFactory.getLogger(VbridgeTopologyListenerService.class);
31
32     private final ListenerRegistration<VbridgeTopologyListener> listenerRegistration;
33
34     private boolean closed;
35
36     private static final DataTreeIdentifier<VbridgeTopology> TREE_LISTENER_IDENTIFIER =
37             DataTreeIdentifier.create(
38                     LogicalDatastoreType.OPERATIONAL,
39                     InstanceIdentifier.builder(NetworkTopology.class)
40                             .child(Topology.class)
41                             .child(TopologyTypes.class)
42                             .augmentation(TopologyTypesVbridgeAugment.class)
43                             .child(VbridgeTopology.class).build());
44
45     public VbridgeTopologyListenerService(final ListenerRegistration<VbridgeTopologyListener> reg) {
46         this.listenerRegistration = reg;
47         this.closed = false;
48     }
49
50     public static VbridgeTopologyListenerService initialize(final @NonNull DataBroker dataBroker,
51                                                             final @NonNull MountPointService mountPointService) {
52         final ListenerRegistration<VbridgeTopologyListener> reg =
53                 dataBroker.registerDataTreeChangeListener(TREE_LISTENER_IDENTIFIER,
54                         new VbridgeTopologyListener(dataBroker, mountPointService));
55
56         return new VbridgeTopologyListenerService(reg);
57     }
58
59
60     @Override
61     public void close() {
62         if (!closed) {
63
64             final VbridgeTopologyListener listener = listenerRegistration.getInstance();
65
66             listenerRegistration.close();
67             listener.close();
68
69             closed = true;
70         }
71     }
72 }