Bug 9060: TracingBroker printOpenTransactions
[controller.git] / opendaylight / md-sal / mdsal-trace / dom-impl / src / main / java / org / opendaylight / controller / md / sal / trace / dom / impl / TracingTransactionChain.java
1 /*
2  * Copyright (c) 2017 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 java.util.Objects;
11 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
12 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
13 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
14 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
15 import org.opendaylight.controller.md.sal.trace.closetracker.impl.AbstractCloseTracked;
16 import org.opendaylight.controller.md.sal.trace.closetracker.impl.CloseTrackedRegistry;
17
18 class TracingTransactionChain extends AbstractCloseTracked<TracingTransactionChain> implements DOMTransactionChain {
19
20     private final DOMTransactionChain delegate;
21     private final TracingBroker tracingBroker;
22     private final CloseTrackedRegistry<TracingReadOnlyTransaction> readOnlyTransactionsRegistry;
23     private final CloseTrackedRegistry<TracingWriteTransaction> writeTransactionsRegistry;
24     private final CloseTrackedRegistry<TracingReadWriteTransaction> readWriteTransactionsRegistry;
25
26     TracingTransactionChain(DOMTransactionChain delegate, TracingBroker tracingBroker,
27             CloseTrackedRegistry<TracingTransactionChain> transactionChainsRegistry) {
28         super(transactionChainsRegistry);
29         this.delegate = Objects.requireNonNull(delegate);
30         this.tracingBroker = Objects.requireNonNull(tracingBroker);
31
32         final boolean isDebug = transactionChainsRegistry.isDebugContextEnabled();
33         String pf = "TransactionChain_" + toString();
34         this.readOnlyTransactionsRegistry  = new CloseTrackedRegistry<>(this, pf + "newReadOnlyTransaction", isDebug);
35         this.writeTransactionsRegistry     = new CloseTrackedRegistry<>(this, pf + "newWriteOnlyTransaction", isDebug);
36         this.readWriteTransactionsRegistry = new CloseTrackedRegistry<>(this, pf + "newReadWriteTransaction", isDebug);
37     }
38
39     @Override
40     @SuppressWarnings("resource")
41     public DOMDataReadOnlyTransaction newReadOnlyTransaction() {
42         final DOMDataReadOnlyTransaction tx = delegate.newReadOnlyTransaction();
43         return new TracingReadOnlyTransaction(tx, tracingBroker, readOnlyTransactionsRegistry);
44     }
45
46     @Override
47     public DOMDataReadWriteTransaction newReadWriteTransaction() {
48         return new TracingReadWriteTransaction(delegate.newReadWriteTransaction(), tracingBroker,
49                 readWriteTransactionsRegistry);
50     }
51
52     @Override
53     public DOMDataWriteTransaction newWriteOnlyTransaction() {
54         final DOMDataWriteTransaction tx = delegate.newWriteOnlyTransaction();
55         return new TracingWriteTransaction(tx, tracingBroker, writeTransactionsRegistry);
56     }
57
58     @Override
59     public void close() {
60         delegate.close();
61         super.removeFromTrackedRegistry();
62     }
63
64     public CloseTrackedRegistry<TracingReadOnlyTransaction> getReadOnlyTransactionsRegistry() {
65         return readOnlyTransactionsRegistry;
66     }
67
68     public CloseTrackedRegistry<TracingReadWriteTransaction> getReadWriteTransactionsRegistry() {
69         return readWriteTransactionsRegistry;
70     }
71
72     public CloseTrackedRegistry<TracingWriteTransaction> getWriteTransactionsRegistry() {
73         return writeTransactionsRegistry;
74     }
75 }

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