7f26f0dc6a21e7acccfbda792dcc640ff1d5786a
[controller.git] / opendaylight / md-sal / mdsal-trace / cli / src / main / java / org / opendaylight / controller / md / sal / trace / cli / PrintOpenTransactionsCommand.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.cli;
9
10 import org.apache.karaf.shell.api.action.Action;
11 import org.apache.karaf.shell.api.action.Command;
12 import org.apache.karaf.shell.api.action.lifecycle.Reference;
13 import org.apache.karaf.shell.api.action.lifecycle.Service;
14 import org.opendaylight.controller.md.sal.trace.api.TracingDOMDataBroker;
15
16 /**
17  * Karaf CLI command to dump all open transactions.
18  *
19  * @author Michael Vorburger.ch
20  */
21 @Service
22 @Command(scope = "trace", name = "transactions",
23     description = "Show all (still) open transactions; including stack trace of creator, "
24     + "if transaction-debug-context-enabled is true in mdsaltrace_config.xml")
25 public class PrintOpenTransactionsCommand implements Action {
26
27     @Reference
28     private TracingDOMDataBroker tracingDOMDataBroker;
29
30     // NB: Do NOT have a non-default constructor for injection of @Reference
31     // Karaf needs a default constructor to create the command - and it works as is.
32
33     @Override
34     @SuppressWarnings("checkstyle:RegexpSingleLineJava")
35     public Object execute() throws Exception {
36         if (!tracingDOMDataBroker.printOpenTransactions(System.out)) {
37             System.out.println("No open transactions, great!");
38         }
39         return null;
40     }
41
42 }