2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.openflowplugin.applications.frm.impl;
11 import com.google.common.base.Preconditions;
12 import java.util.Collection;
13 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
14 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
15 import org.opendaylight.openflowplugin.applications.frm.FlowCapableNodeConnectorCommitter;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 public abstract class AbstractNodeConnectorCommitter<T extends DataObject>
21 implements FlowCapableNodeConnectorCommitter<T> {
24 public void onDataTreeChanged(Collection<DataTreeModification<T>> changes) {
25 Preconditions.checkNotNull(changes, "Changes may not be null!");
27 for (DataTreeModification<T> change : changes) {
28 final InstanceIdentifier<T> key = change.getRootPath().getRootIdentifier();
29 final DataObjectModification<T> mod = change.getRootNode();
30 final InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent = key
31 .firstIdentifierOf(FlowCapableNodeConnector.class);
33 if (preConfigurationCheck(nodeConnIdent)) {
34 switch (mod.getModificationType()) {
36 remove(key, mod.getDataBefore(), nodeConnIdent);
38 case SUBTREE_MODIFIED:
39 update(key, mod.getDataBefore(), mod.getDataAfter(), nodeConnIdent);
42 if (mod.getDataBefore() == null) {
43 add(key, mod.getDataAfter(), nodeConnIdent);
45 update(key, mod.getDataBefore(), mod.getDataAfter(), nodeConnIdent);
49 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
56 * Method return wildCardPath for Listener registration and for identify the
57 * correct KeyInstanceIdentifier from data.
59 protected abstract InstanceIdentifier<T> getWildCardPath();
61 private boolean preConfigurationCheck(final InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent) {
62 Preconditions.checkNotNull(nodeConnIdent, "FlowCapableNodeConnector ident can not be null!");