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.openflowplugin.applications.frm.ForwardingRulesManager;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 public abstract class AbstractNodeConnectorCommitter<T extends DataObject>
22 implements FlowCapableNodeConnectorCommitter<T> {
23 private final ForwardingRulesManager provider;
25 private final Class<T> clazz;
27 public AbstractNodeConnectorCommitter(ForwardingRulesManager provider, Class<T> clazz) {
28 this.provider = Preconditions.checkNotNull(provider, "ForwardingRulesManager can not be null!");
29 this.clazz = Preconditions.checkNotNull(clazz, "Class can not be null!");
33 public void onDataTreeChanged(Collection<DataTreeModification<T>> changes) {
34 Preconditions.checkNotNull(changes, "Changes may not be null!");
36 for (DataTreeModification<T> change : changes) {
37 final InstanceIdentifier<T> key = change.getRootPath().getRootIdentifier();
38 final DataObjectModification<T> mod = change.getRootNode();
39 final InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent =
40 key.firstIdentifierOf(FlowCapableNodeConnector.class);
42 if (preConfigurationCheck(nodeConnIdent)) {
43 switch (mod.getModificationType()) {
45 remove(key, mod.getDataBefore(), nodeConnIdent);
47 case SUBTREE_MODIFIED:
48 update(key, mod.getDataBefore(), mod.getDataAfter(), nodeConnIdent);
51 if (mod.getDataBefore() == null) {
52 add(key, mod.getDataAfter(), nodeConnIdent);
54 update(key, mod.getDataBefore(), mod.getDataAfter(), nodeConnIdent);
58 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
65 * Method return wildCardPath for Listener registration
66 * and for identify the correct KeyInstanceIdentifier from data.
68 protected abstract InstanceIdentifier<T> getWildCardPath();
70 private boolean preConfigurationCheck(final InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent) {
71 Preconditions.checkNotNull(nodeConnIdent, "FlowCapableNodeConnector ident can not be null!");