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.openflowplugin.impl.services.AbstractMultipartService;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
15 import org.opendaylight.yangtools.yang.binding.DataContainer;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public abstract class AbstractMultipartWriter<T extends DataContainer> {
23 private static final Logger LOG = LoggerFactory.getLogger(AbstractMultipartService.class);
25 private final TxFacade txFacade;
26 private final InstanceIdentifier<Node> instanceIdentifier;
28 AbstractMultipartWriter(final TxFacade txFacade, final InstanceIdentifier<Node> instanceIdentifier) {
29 this.txFacade = txFacade;
30 this.instanceIdentifier = instanceIdentifier;
34 * 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
51 * @return instance identifier
53 protected InstanceIdentifier<Node> getInstanceIdentifier() {
54 return instanceIdentifier;
59 * @param dataContainer dataContainer
60 * @param withParents write missing parents if needed (slower)
61 * @return true if we have correct dataContainer type
63 public boolean write(final DataContainer dataContainer, final boolean withParents) {
64 if (getType().isInstance(dataContainer)) {
65 LOG.debug("Writing multipart data of type {} for node {}", getType(), getInstanceIdentifier());
66 storeStatistics(getType().cast(dataContainer), withParents);
70 LOG.debug("Failed to write multipart data of type {} for node {}", getType(), getInstanceIdentifier());
76 * @return type of writer
78 protected abstract Class<T> getType();
82 * @param statistics statistics
83 * @param withParents write missing parents if needed (slower)
85 protected abstract void storeStatistics(final T statistics,
86 final boolean withParents);