-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.tex
219 lines (169 loc) · 7.97 KB
/
example.tex
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
\documentclass{minimal}
% Transactiondiagram requires Tikz.
\usepackage{tikz}
% Tikz libraries used by transactiondiagram.
\usetikzlibrary{arrows,backgrounds,calc,decorations.pathmorphing,fit,shapes.geometric,matrix,shapes,patterns,positioning}
\usepackage{transactiondiagram}
\begin{document}
% This is an example showing the basic features.
\begin{tikzpicture}
% Transaction, basically a line starting at point (0,0) and ending at
% point (5,0). It contains four operations.
\draw
% First operation in the transaction. Each operation contains at
% least two nodes. The first one (aop) is the label above the node.
% It says what type of operation this is (here: start).
(0,0) node[aop] {$\mathit{start}_i$}
% The second one is the symbol that represents the operation on the
% line. This is a white circle in the case of dot.
node[dot] {}
% The third node is only present in the first node of each
% transaction and contains the label that is typeset on the left of
% the transaction. It names the transaction as Ti.
node[tid] {$T_i$}
% There is a line from the first to the second oepration, indicated
% --. If -- was not here, there would be no line drawn between the
% operations. The operation will appear 1 unit to the east of the
% first operation. This operation is typical, in that it has two
% nodes.
-- ++(1,0) node[aop] {$r_i(x)u_i$}
node[dot] {}
% The third operation is split into an invocation and a response.
% This means that there will be a separate point for the invocation
% and a separate one for the response. The invocation will be denoted
% on the line as a half circle, so we use inv instead of dot.
% We name the point on the line as in, by giving this label in the
% parentheses.
-- ++(1,0) node[aop] {$w_i(x)v_i$}
node[inv] (in) {}
% The response is one unit to the east of the invocation. We do not
% draw a line between the invocation and the response, because we
% will fill the gap later with a dashed line. The response is also
% a half circle, so we use res instead of dot. We name the point on
% the line as re.
++(1,0) node[aop] {$\to\!\mathit{ok}_i$}
node[res] (re) {}
% We add a note below the last operation.
-- ++(1,0) node[aop] {$\mathit{tryC}_i$}
node[dot] {}
node[not] {this is a note}
;
% Next, we fill the gap between the invocation event at node in and the
% response event at node re using the wait-style line.
\draw[wait] (in) -- (re);
% Another transaction, it starts at point (4,-1), so below and to the east
% of where the previous transaction started.
\draw
(4,-1) node[aop] {$\mathit{start}_j$}
node[dot] {}
node[tid] {$T_j$}
-- ++(1,0) node[aop] {$r_j(x)$}
node[inv] (in2){}
++(1,0) node[aop] {$\to\!v_j$}
node[res] (re2){}
-- ++(1.5,0) node[aop] {$\mathit{tryC}_j$}
node[dot] (ab) {}
;
% A dashed line between two events of a split operation
\draw[wait] (in2) -- (re2);
% We draw a happens-before arrow between the invocation events of the two
% transactions. The line is of class hb and is defined by the command
% \squiggle.
\draw[hb] (in) \squiggle (in2);
% Next we draw another transaction in the same line as the previous one
\draw
(9,-1) node[aop] {$\mathit{start}_j'$}
node[dot] (st) {}
node[tid] {$T_j'$}
-- ++(1,0) node[aop] {$r_j'(x)v_k$}
node[dot] (r) {}
% In this transaction we add a note below the last operation. We use
% mutlinot to split the text into several lines.
-- ++(1,0) node[aop] {$\mathit{tryC}_j'$}
node[dot] (n1) {}
node[not] {\multinot{this is a \\ 2-line note}}
;
% We connect the two transactions by a snaky line from the last operation
% of the first transaction to the first operation of the second
% transaction. The line has class retry.
\draw[retry] (ab) -- (st);
\draw
(2,-2) node[aop] {$\mathit{start}_j$}
node[dot] {}
node[tid] {$T_k$}
-- ++(1,0) node[aop] {$w_k(x)v_k$}
node[inv] (in3){}
++(3.25,0) node[aop] {$\to\!\mathit{ok}_k$}
node[res] (re3){}
% In the third transaction we want the text to be below the point on
% the line, so we change aop to bop.
-- ++(1,0) node[bop] {$\mathit{tryC}_k$}
node[dot] (co) {}
;
\draw[wait] (in3) -- (re3);
% We draw another happens before relation, but this one is inclining rather
% then declining, so we use squiggleup instead of squiggle.
\draw[hb] (co) \squiggleup (r);
% Axis with numbers on it.
\axis{0}{12}{-3}
% Alternatively, just a simple axis with just an arrow:
% \simpleaxis{0}{12}{-3}
\end{tikzpicture}
\vspace{2cm}
% This is an example of using rectangles to indicate stretches of time. It
% shows two transactions, where one is longer than the other, and the rectangle
% is drawn over the longer of the two to emphasise the difference.
\begin{tikzpicture}
% The transaction is pretty ordinary, but we add an unmarked node (without
% any style) and name nodes b0, b1, and b2. The umarked node will give a
% rectangle a place to "attach".
\draw
(0,0) node[bop] {$\mathit{start}_i$}
node[dot] (b0) {}
node[tid] {$T_i$}
-- ++(2,0) node (b1) {}
-- ++(2,0) node[aop] {$r_i(x)u_i$}
node[dot] {}
-- ++(2,0) node[aop] {$w_i(x)v_i$}
node[dot] {}
% The unmarked node.
-- ++(2,0) node[aop] {$\mathit{tryC}_i$}
node[dot] (b2) {}
;
% The first rectangle we mark is going to show the width of the difference
% between the two transactions. Hence we put down a rectangle starting at
% node b0 and ending at b1.
\getrect{b0}{b1}
% The node will be 1cm high and go up. If it were going down it'd
% be defined as {-1cm}{below}.
{1cm}{above}
% The rectangle is defined to be hatched using gray perpendicular
% lines, as per standard tikz magic.
{black, pattern=north west lines, pattern color=gray}
% At the top of the rectangle there are two text labels, one at
% the beginning saying $\delta_1$, and one at the end saying
% $\delta_2$.
{$\delta_1$}{$\delta_2$};
% We also draw a smaller rectangle at the end. Since there is no
% difference at the end, we indicate that by drawing a slim rectangle over
% a sinlge node, b2.
\getslimrect{b2}
{1cm}{above}
{black, pattern=north west lines, pattern color=gray}
{$\delta_3$};
\draw
(2,-1) node[aop] {$\mathit{start}_i$}
node[dot] {}
node[tid] {$T_i'$}
-- ++(2,0) node[aop] {$r_i(x)u_i$}
node[dot] {}
-- ++(2,0) node[aop] {$w_i(x)v_i$}
node[dot] {}
-- ++(2,0) node[aop] {$\mathit{tryC}_i$}
node[dot] {}
;
\axis{0}{9}{-2}
% Alternatively, just a simple axis with just an arrow:
% \simpleaxis{0}{12}{-3}
\end{tikzpicture}
\end{document}