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 com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import com.google.common.util.concurrent.CheckedFuture;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.MoreExecutors;
15 import org.opendaylight.controller.md.sal.common.api.MappingCheckedFuture;
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
19 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction;
20 import org.opendaylight.yangtools.concepts.Delegator;
21 import org.opendaylight.yangtools.concepts.Identifiable;
22 import org.opendaylight.yangtools.yang.binding.DataObject;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
28 abstract class AbstractForwardedTransaction<T extends AsyncTransaction<YangInstanceIdentifier, NormalizedNode<?, ?>>>
29 implements Delegator<T>, Identifiable<Object> {
31 private final T delegate;
32 private final BindingToNormalizedNodeCodec codec;
34 AbstractForwardedTransaction(final T delegateTx, final BindingToNormalizedNodeCodec codec) {
35 this.delegate = Preconditions.checkNotNull(delegateTx, "Delegate must not be null");
36 this.codec = Preconditions.checkNotNull(codec, "Codec must not be null");
41 public final Object getIdentifier() {
42 return delegate.getIdentifier();
46 public final T getDelegate() {
50 @SuppressWarnings("unchecked")
51 protected final <S extends AsyncTransaction<YangInstanceIdentifier, NormalizedNode<?, ?>>>
52 S getDelegateChecked(final Class<S> txType) {
53 Preconditions.checkState(txType.isInstance(delegate));
57 protected final BindingToNormalizedNodeCodec getCodec() {
61 protected final <D extends DataObject> CheckedFuture<Optional<D>, ReadFailedException> doRead(
62 final DOMDataReadTransaction readTx, final LogicalDatastoreType store,
63 final InstanceIdentifier<D> path) {
64 Preconditions.checkArgument(!path.isWildcarded(), "Invalid read of wildcarded path %s", path);
66 return MappingCheckedFuture.create(
67 Futures.transform(readTx.read(store, codec.toYangInstanceIdentifierBlocking(path)),
68 result -> Optional.fromJavaUtil(codec.deserializeFunction(path).apply(result.toJavaUtil())),
69 MoreExecutors.directExecutor()),
70 ReadFailedException.MAPPER);
73 protected final CheckedFuture<Boolean, ReadFailedException> doExists(
74 final DOMDataReadTransaction readTx, final LogicalDatastoreType store,
75 final InstanceIdentifier<?> path) {
76 Preconditions.checkArgument(!path.isWildcarded(), "Invalid read of wildcarded path %s", path);
78 return MappingCheckedFuture.create(readTx.exists(store, codec.toYangInstanceIdentifierBlocking(path)),
79 ReadFailedException.MAPPER);