2 * Copyright (c) 2015 Cisco Systems, Inc. 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.impl.rpc.listener;
11 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
12 import org.opendaylight.openflowplugin.api.openflow.device.TxFacade;
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 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * General implementation of {@link ItemLifecycleListener} - keeping of DS/operational reflection up-to-date
24 public class ItemLifecycleListenerImpl implements ItemLifecycleListener {
26 private static final Logger LOG = LoggerFactory.getLogger(ItemLifecycleListenerImpl.class);
27 private static final String NOT_ABLE_TO_WRITE_TO_TRANSACTION = "Not able to write to transaction: ";
29 private final TxFacade txFacade;
31 public ItemLifecycleListenerImpl(final TxFacade txFacade) {
32 this.txFacade = txFacade;
36 public <I extends Identifiable<K> & DataObject, K extends Identifier<I>> void onAdded(KeyedInstanceIdentifier<I, K> itemPath, I itemBody) {
38 txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, itemPath, itemBody);
39 txFacade.submitTransaction();
40 } catch (Exception e) {
41 LOG.warn(NOT_ABLE_TO_WRITE_TO_TRANSACTION, e);
46 public <I extends Identifiable<K> & DataObject, K extends Identifier<I>> void onRemoved(KeyedInstanceIdentifier<I, K> itemPath) {
48 txFacade.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, itemPath);
49 txFacade.submitTransaction();
50 } catch (Exception e) {
51 LOG.warn(NOT_ABLE_TO_WRITE_TO_TRANSACTION, e);
56 public <I extends Identifiable<K> & DataObject, K extends Identifier<I>> void onUpdated(KeyedInstanceIdentifier<I, K> itemPath, I itemBody) {
58 txFacade.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, itemPath);
59 txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, itemPath, itemBody);
60 txFacade.submitTransaction();
61 } catch (Exception e) {
62 LOG.warn(NOT_ABLE_TO_WRITE_TO_TRANSACTION, e);