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 public AbstractNodeConnectorCommitter(ForwardingRulesManager provider) {
26 this.provider = Preconditions.checkNotNull(provider, "ForwardingRulesManager can not be null!");
30 public void onDataTreeChanged(Collection<DataTreeModification<T>> changes) {
31 Preconditions.checkNotNull(changes, "Changes may not be null!");
33 for (DataTreeModification<T> change : changes) {
34 final InstanceIdentifier<T> key = change.getRootPath().getRootIdentifier();
35 final DataObjectModification<T> mod = change.getRootNode();
36 final InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent = key
37 .firstIdentifierOf(FlowCapableNodeConnector.class);
39 if (preConfigurationCheck(nodeConnIdent)) {
40 switch (mod.getModificationType()) {
42 remove(key, mod.getDataBefore(), nodeConnIdent);
44 case SUBTREE_MODIFIED:
45 update(key, mod.getDataBefore(), mod.getDataAfter(), nodeConnIdent);
48 if (mod.getDataBefore() == null) {
49 add(key, mod.getDataAfter(), nodeConnIdent);
51 update(key, mod.getDataBefore(), mod.getDataAfter(), nodeConnIdent);
55 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
62 * Method return wildCardPath for Listener registration and for identify the
63 * correct KeyInstanceIdentifier from data.
65 protected abstract InstanceIdentifier<T> getWildCardPath();
67 private boolean preConfigurationCheck(final InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent) {
68 Preconditions.checkNotNull(nodeConnIdent, "FlowCapableNodeConnector ident can not be null!");