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
8 package org.opendaylight.mdsal.binding.javav2.dom.adapter.spi;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static com.google.common.base.Preconditions.checkState;
12 import static java.util.Objects.requireNonNull;
14 import com.google.common.annotations.Beta;
15 import com.google.common.util.concurrent.FluentFuture;
16 import com.google.common.util.concurrent.MoreExecutors;
17 import java.util.Optional;
18 import javax.annotation.Nonnull;
19 import org.opendaylight.mdsal.binding.javav2.dom.codec.impl.BindingToNormalizedNodeCodec;
20 import org.opendaylight.mdsal.binding.javav2.spec.base.InstanceIdentifier;
21 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
22 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
23 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
24 import org.opendaylight.mdsal.dom.api.DOMDataTreeTransaction;
25 import org.opendaylight.yangtools.concepts.Delegator;
26 import org.opendaylight.yangtools.concepts.Identifiable;
29 * Abstract class for forwards transaction and codec for serialize/deserialize DOM and Binding data.
31 * @param <T> type of asynchronous transaction
34 public abstract class AbstractForwardedTransaction<T extends DOMDataTreeTransaction>
35 implements Delegator<T>, Identifiable<Object> {
37 private final T delegate;
38 private final BindingToNormalizedNodeCodec codec;
40 public AbstractForwardedTransaction(final T delegateTx, final BindingToNormalizedNodeCodec codec) {
41 this.delegate = requireNonNull(delegateTx, "Delegate must not be null");
42 this.codec = requireNonNull(codec, "Codec must not be null");
47 public final Object getIdentifier() {
48 return delegate.getIdentifier();
52 public final T getDelegate() {
56 @SuppressWarnings("unchecked")
57 protected final <S extends DOMDataTreeTransaction> S getDelegateChecked(final Class<S> txType) {
58 checkState(txType.isInstance(delegate));
62 protected final BindingToNormalizedNodeCodec getCodec() {
66 protected final <D extends TreeNode> FluentFuture<Optional<D>> doRead(
67 final DOMDataTreeReadTransaction readTx, final LogicalDatastoreType store,
68 final InstanceIdentifier<D> path) {
69 checkArgument(!path.isWildcarded(), "Invalid read of wildcarded path %s", path);
71 return readTx.read(store, codec.toYangInstanceIdentifierBlocking(path))
72 .transform(codec.deserializeFunction(path)::apply, MoreExecutors.directExecutor());