2 * Copyright (c) 2016, 2017 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.genius.interfacemanager.renderer.ovs.utilities;
11 import java.util.List;
12 import org.opendaylight.genius.utils.batching.ResourceHandler;
13 import org.opendaylight.genius.utils.batching.SubTransaction;
14 import org.opendaylight.genius.utils.batching.SubTransactionImpl;
15 import org.opendaylight.mdsal.binding.api.DataBroker;
16 import org.opendaylight.mdsal.binding.api.WriteTransaction;
17 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 class InterfaceBatchHandler implements ResourceHandler {
22 private final DataBroker dataBroker;
23 private final LogicalDatastoreType dataStoreType;
24 private final int batchSize;
25 private final int batchInterval;
27 InterfaceBatchHandler(DataBroker dataBroker, LogicalDatastoreType dataStoreType, int batchSize, int batchInterval) {
28 this.dataBroker = dataBroker;
29 this.dataStoreType = dataStoreType;
30 this.batchSize = batchSize;
31 this.batchInterval = batchInterval;
35 public void update(WriteTransaction tx, LogicalDatastoreType datastoreType, InstanceIdentifier identifier,
36 Object original, Object update, List<SubTransaction> transactionObjects) {
37 if (update != null && !(update instanceof DataObject)) {
40 if (datastoreType != this.getDatastoreType()) {
43 tx.merge(datastoreType, identifier, (DataObject) update, true);
45 buildSubTransactions(transactionObjects, identifier, update, SubTransaction.UPDATE);
49 public void updateContainer(WriteTransaction tx, LogicalDatastoreType datastoreType, InstanceIdentifier
50 identifier, Object original, Object update, List<SubTransaction> transactionObjects) {
55 public void create(WriteTransaction tx, LogicalDatastoreType datastoreType, InstanceIdentifier identifier,
56 Object data, List<SubTransaction> transactionObjects) {
57 if (data != null && !(data instanceof DataObject)) {
60 if (datastoreType != this.getDatastoreType()) {
63 tx.put(datastoreType, identifier, (DataObject) data, true);
65 buildSubTransactions(transactionObjects, identifier, data, SubTransaction.CREATE);
69 public void delete(WriteTransaction tx, LogicalDatastoreType datastoreType, InstanceIdentifier identifier,
70 Object data, List<SubTransaction> transactionObjects) {
71 if (data != null && !(data instanceof DataObject)) {
74 if (datastoreType != this.getDatastoreType()) {
77 tx.delete(datastoreType, identifier);
79 buildSubTransactions(transactionObjects, identifier, data, SubTransaction.DELETE);
83 public DataBroker getResourceBroker() {
88 public int getBatchSize() {
93 public int getBatchInterval() {
98 public LogicalDatastoreType getDatastoreType() {
99 return this.dataStoreType;
102 private void buildSubTransactions(List<SubTransaction> transactionObjects, InstanceIdentifier identifier,
103 Object data, short subTransactionType) {
105 SubTransaction subTransaction = new SubTransactionImpl();
106 subTransaction.setInstanceIdentifier(identifier);
107 subTransaction.setInstance(data);
108 subTransaction.setAction(subTransactionType);
109 transactionObjects.add(subTransaction);