2 * Copyright (c) 2014 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
8 package org.opendaylight.controller.md.sal.binding.impl;
10 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
11 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
12 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction;
13 import org.opendaylight.yangtools.concepts.Delegator;
14 import org.opendaylight.yangtools.concepts.Identifiable;
15 import org.opendaylight.yangtools.yang.binding.DataObject;
16 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import com.google.common.base.Optional;
20 import com.google.common.base.Preconditions;
21 import com.google.common.util.concurrent.Futures;
22 import com.google.common.util.concurrent.ListenableFuture;
25 abstract class AbstractForwardedTransaction<T extends AsyncTransaction<InstanceIdentifier, NormalizedNode<?, ?>>>
26 implements Delegator<T>, Identifiable<Object> {
28 private final T delegate;
29 private final BindingToNormalizedNodeCodec codec;
31 public AbstractForwardedTransaction(final T delegateTx, final BindingToNormalizedNodeCodec codec) {
32 this.delegate = Preconditions.checkNotNull(delegateTx, "Delegate must not be null");
33 this.codec = Preconditions.checkNotNull(codec, "Codec must not be null");
38 public final Object getIdentifier() {
39 return delegate.getIdentifier();
43 public final T getDelegate() {
47 @SuppressWarnings("unchecked")
48 protected final <S extends AsyncTransaction<InstanceIdentifier, NormalizedNode<?, ?>>> S getDelegateChecked(final Class<S> txType) {
49 Preconditions.checkState(txType.isInstance(delegate));
53 protected final BindingToNormalizedNodeCodec getCodec() {
57 protected final ListenableFuture<Optional<DataObject>> doRead(final DOMDataReadTransaction readTx,
58 final LogicalDatastoreType store, final org.opendaylight.yangtools.yang.binding.InstanceIdentifier<?> path) {
59 return Futures.transform(readTx.read(store, codec.toNormalized(path)), codec.deserializeFunction(path));