52f1dab509b012bdf3de0ce8e5f156946cf76c40
[controller.git] / opendaylight / md-sal / mdsal-trace / dom-impl / src / main / java / org / opendaylight / controller / md / sal / trace / dom / impl / TracingReadWriteTransaction.java
1 /*
2  * Copyright (c) 2016 Red Hat, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.trace.dom.impl;
9
10 import com.google.common.base.Optional;
11 import com.google.common.util.concurrent.CheckedFuture;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.time.Instant;
14 import java.util.Objects;
15 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
18 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
19 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
20 import org.opendaylight.controller.md.sal.trace.closetracker.impl.CloseTracked;
21 import org.opendaylight.controller.md.sal.trace.closetracker.impl.CloseTrackedRegistry;
22 import org.opendaylight.controller.md.sal.trace.closetracker.impl.CloseTrackedTrait;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
26
27 class TracingReadWriteTransaction
28     extends AbstractTracingWriteTransaction
29         implements DOMDataReadWriteTransaction, CloseTracked<TracingReadWriteTransaction> {
30
31     private final CloseTrackedTrait<TracingReadWriteTransaction> closeTracker;
32     private final DOMDataReadWriteTransaction delegate;
33
34     TracingReadWriteTransaction(DOMDataReadWriteTransaction delegate, TracingBroker tracingBroker,
35             CloseTrackedRegistry<TracingReadWriteTransaction> readWriteTransactionsRegistry) {
36         super(delegate, tracingBroker);
37         this.closeTracker = new CloseTrackedTrait<>(readWriteTransactionsRegistry);
38         this.delegate = Objects.requireNonNull(delegate);
39     }
40
41     @Override
42     public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
43                                                             LogicalDatastoreType store, YangInstanceIdentifier yiid) {
44         return delegate.read(store, yiid);
45     }
46
47     @Override
48     public CheckedFuture<Boolean, ReadFailedException> exists(LogicalDatastoreType store, YangInstanceIdentifier yiid) {
49         return delegate.exists(store, yiid);
50     }
51
52     @Override
53     public CheckedFuture<Void, TransactionCommitFailedException> submit() {
54         closeTracker.removeFromTrackedRegistry();
55         return super.submit();
56     }
57
58     @Override
59     public ListenableFuture<RpcResult<TransactionStatus>> commit() {
60         closeTracker.removeFromTrackedRegistry();
61         return super.commit();
62     }
63
64     @Override
65     public boolean cancel() {
66         closeTracker.removeFromTrackedRegistry();
67         return super.cancel();
68     }
69
70     @Override
71     public Instant getObjectCreated() {
72         return closeTracker.getObjectCreated();
73     }
74
75     @Override
76     public StackTraceElement[] getAllocationContextStackTrace() {
77         return closeTracker.getAllocationContextStackTrace();
78     }
79 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.