Imported vpnservice as a subtree
[netvirt.git] / vpnservice / fcapsapplication / fcapsapplication-impl / src / main / java / org / opendaylight / vpnservice / fcapsapp / performancecounter / NodeConnectorEventListener.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  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.vpnservice.fcapsapp.performancecounter;
9
10 import org.opendaylight.controller.md.sal.binding.api.*;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
12 import org.opendaylight.yangtools.yang.binding.DataObject;
13 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
14 import java.util.Collection;
15
16 public abstract  class NodeConnectorEventListener <T extends DataObject> implements ClusteredDataTreeChangeListener<T>,AutoCloseable,FlowCapableNodeConnectorCommitter<T> {
17     NodeConnectorEventListener(Class<FlowCapableNodeConnector> flowCapableNodeConnectorClass) {
18     }
19
20     @Override
21     public void onDataTreeChanged(Collection<DataTreeModification<T>> changes) {
22         for (DataTreeModification<T> change : changes) {
23             final InstanceIdentifier<T> key = change.getRootPath().getRootIdentifier();
24             final DataObjectModification<T> mod = change.getRootNode();
25             final InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent =
26                     key.firstIdentifierOf(FlowCapableNodeConnector.class);
27
28             switch (mod.getModificationType()) {
29                 case DELETE:
30                     remove(key, mod.getDataBefore(), nodeConnIdent);
31                     break;
32                 case SUBTREE_MODIFIED:
33                     update(key, mod.getDataBefore(), mod.getDataAfter(), nodeConnIdent);
34                     break;
35                 case WRITE:
36                     if (mod.getDataBefore() == null) {
37                         add(key, mod.getDataAfter(), nodeConnIdent);
38                     } else {
39                         update(key, mod.getDataBefore(), mod.getDataAfter(), nodeConnIdent);
40                     }
41                     break;
42
43
44                 default:
45                     throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
46             }
47         }
48     }
49
50     @Override
51     public void close() throws Exception {
52     }
53 }