Bug 9060: TracingBroker printOpenTransactions
[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.util.Objects;
14 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
17 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
18 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
19 import org.opendaylight.controller.md.sal.trace.closetracker.impl.CloseTracked;
20 import org.opendaylight.controller.md.sal.trace.closetracker.impl.CloseTrackedRegistry;
21 import org.opendaylight.controller.md.sal.trace.closetracker.impl.CloseTrackedTrait;
22 import org.opendaylight.yangtools.yang.common.RpcResult;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
25
26 class TracingReadWriteTransaction
27     extends AbstractTracingWriteTransaction
28         implements DOMDataReadWriteTransaction, CloseTracked<TracingReadWriteTransaction> {
29
30     private final CloseTrackedTrait<TracingReadWriteTransaction> closeTracker;
31     private final DOMDataReadWriteTransaction delegate;
32
33     TracingReadWriteTransaction(DOMDataReadWriteTransaction delegate, TracingBroker tracingBroker,
34             CloseTrackedRegistry<TracingReadWriteTransaction> readWriteTransactionsRegistry) {
35         super(delegate, tracingBroker);
36         this.closeTracker = new CloseTrackedTrait<>(readWriteTransactionsRegistry, this);
37         this.delegate = Objects.requireNonNull(delegate);
38     }
39
40     @Override
41     public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
42                                                             LogicalDatastoreType store, YangInstanceIdentifier yiid) {
43         return delegate.read(store, yiid);
44     }
45
46     @Override
47     public CheckedFuture<Boolean, ReadFailedException> exists(LogicalDatastoreType store, YangInstanceIdentifier yiid) {
48         return delegate.exists(store, yiid);
49     }
50
51     @Override
52     public CheckedFuture<Void, TransactionCommitFailedException> submit() {
53         closeTracker.removeFromTrackedRegistry();
54         return super.submit();
55     }
56
57     @Override
58     public ListenableFuture<RpcResult<TransactionStatus>> commit() {
59         closeTracker.removeFromTrackedRegistry();
60         return super.commit();
61     }
62
63     @Override
64     public boolean cancel() {
65         closeTracker.removeFromTrackedRegistry();
66         return super.cancel();
67     }
68
69     @Override
70     public StackTraceElement[] getAllocationContextStackTrace() {
71         return closeTracker.getAllocationContextStackTrace();
72     }
73
74     @Override
75     public CloseTracked<TracingReadWriteTransaction> getRealCloseTracked() {
76         return this;
77     }
78 }

©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.