BUG-4084: Li:Save flows in operational based on barrier success
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / rpc / listener / ItemLifecycleListenerImpl.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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
9 package org.opendaylight.openflowplugin.impl.rpc.listener;
10
11 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
12 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
13 import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.opendaylight.yangtools.yang.binding.Identifiable;
16 import org.opendaylight.yangtools.yang.binding.Identifier;
17 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
18
19 /**
20  * General implementation of {@link ItemLifecycleListener} - keeping of DS/operational reflection up-to-date
21  */
22 public class ItemLifecycleListenerImpl implements ItemLifecycleListener {
23
24     private final DeviceContext deviceContext;
25
26     public ItemLifecycleListenerImpl(DeviceContext deviceContext) {
27         this.deviceContext = deviceContext;
28     }
29
30     @Override
31     public <I extends Identifiable<K> & DataObject, K extends Identifier<I>> void onAdded(KeyedInstanceIdentifier<I, K> itemPath, I itemBody) {
32         deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, itemPath, itemBody);
33         deviceContext.submitTransaction();
34     }
35
36     @Override
37     public <I extends Identifiable<K> & DataObject, K extends Identifier<I>> void onRemoved(KeyedInstanceIdentifier<I, K> itemPath) {
38         deviceContext.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, itemPath);
39         deviceContext.submitTransaction();
40     }
41 }