Remove old AbstractDataListener
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / mdsal / AuthenticationKeyDataListener.java
1 /*
2  * Copyright (c) 2015 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.implementation.mdsal;
9
10 import java.util.Collection;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
13 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
14 import org.opendaylight.lispflowmapping.interfaces.mapcache.IMappingSystem;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.MappingDatabase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.database.VirtualNetworkIdentifier;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
22
23 /**
24  * DataListener for all AuthenticationKey modification events.
25  *
26  * @author Lorand Jakab
27  *
28  */
29 public class AuthenticationKeyDataListener extends AbstractDataListener<AuthenticationKey> {
30     private static final Logger LOG = LoggerFactory.getLogger(AuthenticationKeyDataListener.class);
31     private IMappingSystem mapSystem;
32
33     public AuthenticationKeyDataListener(DataBroker broker, IMappingSystem mapSystem) {
34         setBroker(broker);
35         setMappingSystem(mapSystem);
36         setPath(InstanceIdentifier.create(MappingDatabase.class).child(VirtualNetworkIdentifier.class)
37                 .child(AuthenticationKey.class));
38         LOG.trace("Registering AuthenticationKey listener.");
39         registerDataChangeListener();
40     }
41
42     @Override
43     public void onDataTreeChanged(Collection<DataTreeModification<AuthenticationKey>> changes) {
44         for (DataTreeModification<AuthenticationKey> change : changes) {
45             final DataObjectModification<AuthenticationKey> mod = change.getRootNode();
46
47             if (ModificationType.DELETE == mod.getModificationType()) {
48                 final AuthenticationKey authKey = mod.getDataBefore();
49
50                 LOG.trace("Received deleted data");
51                 LOG.trace("Key: {}", change.getRootPath().getRootIdentifier());
52                 LOG.trace("Value: {}", authKey);
53
54                 mapSystem.removeAuthenticationKey(authKey.getEid());
55             } else if (ModificationType.WRITE == mod.getModificationType() || ModificationType.SUBTREE_MODIFIED == mod
56                     .getModificationType()) {
57                 if (ModificationType.WRITE == mod.getModificationType()) {
58                     LOG.trace("Received created data");
59                 } else {
60                     LOG.trace("Received updated data");
61                 }
62                 // Process newly created or updated authentication keys
63                 final AuthenticationKey authKey = mod.getDataAfter();
64
65                 LOG.trace("Key: {}", change.getRootPath().getRootIdentifier());
66                 LOG.trace("Value: {}", authKey);
67
68                 mapSystem.addAuthenticationKey(authKey.getEid(), authKey.getMappingAuthkey());
69             } else {
70                 LOG.warn("Ignoring unhandled modification type {}", mod.getModificationType());
71             }
72         }
73     }
74
75     void setMappingSystem(IMappingSystem msmr) {
76         this.mapSystem = msmr;
77     }
78 }