2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.datastore.multipart;
11 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
12 import org.opendaylight.openflowplugin.api.openflow.device.TxFacade;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
14 import org.opendaylight.yangtools.yang.binding.DataContainer;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public abstract class AbstractMultipartWriter<T extends DataContainer> {
22 private static final Logger LOG = LoggerFactory.getLogger(AbstractMultipartWriter.class);
24 private final TxFacade txFacade;
25 private final InstanceIdentifier<Node> instanceIdentifier;
27 AbstractMultipartWriter(final TxFacade txFacade, final InstanceIdentifier<Node> instanceIdentifier) {
28 this.txFacade = txFacade;
29 this.instanceIdentifier = instanceIdentifier;
33 * Creates put operation using provided data in underlying transaction chain.
37 * @param <O> data type
39 protected <O extends DataObject> void writeToTransaction(final InstanceIdentifier<O> path,
41 final boolean withParents) {
43 txFacade.writeToTransactionWithParentsSlow(LogicalDatastoreType.OPERATIONAL, path, data);
45 txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, path, data);
50 * Get instance identifier.
52 * @return instance identifier
54 protected InstanceIdentifier<Node> getInstanceIdentifier() {
55 return instanceIdentifier;
59 * Write dataContainer.
61 * @param dataContainer dataContainer
62 * @param withParents write missing parents if needed (slower)
63 * @return true if we have correct dataContainer type
65 public boolean write(final DataContainer dataContainer, final boolean withParents) {
66 if (getType().isInstance(dataContainer)) {
67 LOG.debug("Writing multipart data of type {} for node {}", getType(), getInstanceIdentifier());
68 storeStatistics(getType().cast(dataContainer), withParents);
72 LOG.debug("Failed to write multipart data of type {} for node {}", getType(), getInstanceIdentifier());
79 * @return type of writer
81 protected abstract Class<T> getType();
86 * @param statistics statistics
87 * @param withParents write missing parents if needed (slower)
89 protected abstract void storeStatistics(T statistics, boolean withParents);