Transaction.java
2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.dianping.cat.message;
import java.util.List;
/**
* <p>
* <code>Transaction</code> is any interesting unit of work that takes time to complete and may fail.
* </p>
*
* <p>
* Basically, all data access across the boundary needs to be logged as a <code>Transaction</code> since it may fail and
* time consuming. For example, URL request, disk IO, JDBC query, search query, HTTP request, 3rd party API call etc.
* </p>
*
* <p>
* Sometime if A needs call B which is owned by another team, although A and B are deployed together without any
* physical boundary. To make the ownership clear, there could be some <code>Transaction</code> logged when A calls B.
* </p>
*
* <p>
* Most of <code>Transaction</code> should be logged in the infrastructure level or framework level, which is
* transparent to the application.
* </p>
*
* <p>
* All CAT message will be constructed as a message tree and send to back-end for further analysis, and for monitoring.
* Only <code>Transaction</code> can be a tree node, all other message will be the tree leaf. The transaction without
* other messages nested is an atomic transaction.
* </p>
*
* @author Frankie Wu
*/
public interface Transaction extends Message {
/**
* Add one nested child message to current transaction.
*
* @param message
* to be added
*/
public Transaction addChild(Message message);
/**
* Get all children message within current transaction.
*
* <p>
* Typically, a <code>Transaction</code> can nest other <code>Transaction</code>s, <code>Event</code>s and
* <code>Heartbeat</code> s, while an <code>Event</code> or <code>Heartbeat</code> can't nest other messages.
* </p>
*
* @return all children messages, empty if there is no nested children.
*/
public List<Message> getChildren();
/**
* How long the transaction took from construction to complete. Time unit is microsecond.
*
* @return duration time in microsecond
*/
public long getDurationInMicros();
/**
* How long the transaction took from construction to complete. Time unit is millisecond.
*
* @return duration time in millisecond
*/
public long getDurationInMillis();
/**
* Has children or not. An atomic transaction does not have any children message.
*
* @return true if child exists, else false.
*/
public boolean hasChildren();
/**
* Check if the transaction is stand-alone or belongs to another one.
*
* @return true if it's an root transaction.
*/
public boolean isStandalone();
}