-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Context.cs
299 lines (271 loc) · 10.1 KB
/
Context.cs
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
//-----------------------------------------------------------------------
// <copyright file="Context.cs" company="Akka.NET Project">
// Copyright (C) 2009-2023 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------
using System;
using Akka.Streams.Implementation.Fusing;
namespace Akka.Streams.Stage
{
//[Flags]
//public enum Directive
//{
// AsyncDirective = 1,
// SyncDirective = 2,
// UpstreamDirective = 4 | SyncDirective,
// DownstreamDirective = 8 | SyncDirective,
// TerminationDirective = 16 | SyncDirective,
// // never instantiated
// FreeDirective = UpstreamDirective | DownstreamDirective | TerminationDirective | AsyncDirective
//}
/// <summary>
/// TBD
/// </summary>
public interface IDirective { }
/// <summary>
/// TBD
/// </summary>
public interface IAsyncDirective : IDirective { }
/// <summary>
/// TBD
/// </summary>
public interface ISyncDirective : IDirective { }
/// <summary>
/// TBD
/// </summary>
public interface IUpstreamDirective : ISyncDirective { }
/// <summary>
/// TBD
/// </summary>
public interface IDownstreamDirective : ISyncDirective { }
/// <summary>
/// TBD
/// </summary>
public interface ITerminationDirective : ISyncDirective { }
/// <summary>
/// TBD
/// </summary>
public sealed class FreeDirective : IUpstreamDirective, IDownstreamDirective, ITerminationDirective, IAsyncDirective { }
/// <summary>
/// TBD
/// </summary>
public interface ILifecycleContext
{
/// <summary>
/// Returns the Materializer that was used to materialize this Stage/>.
/// It can be used to materialize sub-flows.
/// </summary>
IMaterializer Materializer { get; }
/// <summary>
/// Returns operation attributes associated with the this Stage
/// </summary>
Attributes Attributes { get; }
}
/// <summary>
/// Passed to the callback methods of <see cref="PushPullStage{TIn,TOut}"/> and <see cref="StatefulStage{TIn,TOut}"/>.
/// </summary>
public interface IContext : ILifecycleContext
{
/// <summary>
/// This returns true after <see cref="AbsorbTermination"/> has been used.
/// </summary>
bool IsFinishing { get; }
/// <summary>
/// Push one element to downstream immediately followed by
/// cancel of upstreams and complete of downstreams.
/// </summary>
/// <param name="element">TBD</param>
/// <returns>TBD</returns>
IDownstreamDirective PushAndFinish(object element);
/// <summary>
/// Push one element to downstreams.
/// </summary>
/// <param name="element">TBD</param>
/// <returns>TBD</returns>
IDownstreamDirective Push(object element);
/// <summary>
/// Request for more elements from upstreams.
/// </summary>
/// <returns>TBD</returns>
IUpstreamDirective Pull();
/// <summary>
/// Cancel upstreams and complete downstreams successfully.
/// </summary>
/// <returns>TBD</returns>
FreeDirective Finish();
FreeDirective Finish(Exception cause);
/// <summary>
/// Cancel upstreams and complete downstreams with failure.
/// </summary>
/// <param name="cause">TBD</param>
/// <returns>TBD</returns>
FreeDirective Fail(Exception cause);
/// <summary>
/// Puts the stage in a finishing state so that
/// final elements can be pushed from onPull.
/// </summary>
/// <returns>TBD</returns>
ITerminationDirective AbsorbTermination();
}
/// <summary>
/// TBD
/// </summary>
/// <typeparam name="TOut">TBD</typeparam>
public interface IContext<in TOut> : IContext
{
/// <summary>
/// Push one element to downstream immediately followed by
/// cancel of upstreams and complete of downstreams.
/// </summary>
/// <param name="element">TBD</param>
/// <returns>TBD</returns>
IDownstreamDirective PushAndFinish(TOut element);
/// <summary>
/// Push one element to downstreams.
/// </summary>
/// <param name="element">TBD</param>
/// <returns>TBD</returns>
IDownstreamDirective Push(TOut element);
}
/// <summary>
/// Passed to the callback methods of <see cref="DetachedStage{TIn,TOut}"/>.
///
/// <see cref="HoldDownstream"/> and <see cref="HoldUpstream"/> stops execution and at the same time putting the stage in a holding state.
/// If the stage is in a holding state it contains one absorbed signal, therefore in
/// this state the only possible command to call is <see cref="PushAndPull"/> which results in two
/// events making the balance right again: 1 hold + 1 external event = 2 external event
/// </summary>
public interface IDetachedContext : IContext
{
/// <summary>
/// This returns true when <see cref="HoldDownstream"/> and <see cref="HoldUpstream"/> has been used
/// and it is reset to false after <see cref="PushAndPull"/>.
/// </summary>
bool IsHoldingBoth { get; }
/// <summary>
/// TBD
/// </summary>
bool IsHoldingUpstream { get; }
/// <summary>
/// TBD
/// </summary>
bool IsHoldingDownstream { get; }
/// <summary>
/// TBD
/// </summary>
/// <param name="element">TBD</param>
/// <returns>TBD</returns>
FreeDirective PushAndPull(object element);
/// <summary>
/// TBD
/// </summary>
/// <returns>TBD</returns>
IUpstreamDirective HoldUpstream();
/// <summary>
/// TBD
/// </summary>
/// <param name="element">TBD</param>
/// <returns>TBD</returns>
IUpstreamDirective HoldUpstreamAndPush(object element);
/// <summary>
/// TBD
/// </summary>
/// <returns>TBD</returns>
IDownstreamDirective HoldDownstream();
/// <summary>
/// TBD
/// </summary>
/// <returns>TBD</returns>
IDownstreamDirective HoldDownstreamAndPull();
}
/// <summary>
/// TBD
/// </summary>
/// <typeparam name="TOut">TBD</typeparam>
public interface IDetachedContext<in TOut> : IDetachedContext, IContext<TOut>
{
/// <summary>
/// TBD
/// </summary>
/// <param name="element">TBD</param>
/// <returns>TBD</returns>
FreeDirective PushAndPull(TOut element);
/// <summary>
/// TBD
/// </summary>
/// <param name="element">TBD</param>
/// <returns>TBD</returns>
IUpstreamDirective HoldUpstreamAndPush(TOut element);
}
/// <summary>
/// TBD
/// </summary>
/// <param name="element">TBD</param>
public delegate void AsyncCallback(object element);
/// <summary>
/// An asynchronous callback holder that is attached to an <see cref="IAsyncContext{TOut,TExt}"/>.
///
/// Invoking will eventually lead to <see cref="GraphInterpreter.OnAsyncInput"/>
/// being called.
///
/// Dispatch an asynchronous notification. This method is thread-safe and
/// may be invoked from external execution contexts.
/// </summary>
/// <typeparam name="T">TBD</typeparam>
/// <param name="element">TBD</param>
public delegate void AsyncCallback<in T>(T element);
/// <summary>
/// This kind of context is available to <see cref="IAsyncContext{TOut,TExt}"/>. It implements the same
/// interface as for <see cref="IDetachedContext"/> with the addition of being able to obtain
/// <see cref="AsyncCallback"/> objects that allow the registration of asynchronous notifications.
/// </summary>
public interface IAsyncContext : IDetachedContext
{
/// <summary>
/// Obtain a callback object that can be used asynchronously to re-enter the
/// current <see cref="IAsyncContext{TOut,TExt}"/> with an asynchronous notification. After the
/// notification has been invoked, eventually <see cref="GraphInterpreter.OnAsyncInput"/>
/// will be called with the given data item.
///
/// This object can be cached and reused within the same <see cref="IAsyncContext{TOut,TExt}"/>.
/// </summary>
/// <returns>TBD</returns>
AsyncCallback GetAsyncCallback();
/// <summary>
/// In response to an asynchronous notification an <see cref="IAsyncContext{TOut,TExt}"/> may choose
/// to neither push nor pull nor terminate, which is represented as this directive.
/// </summary>
/// <returns>TBD</returns>
IAsyncDirective Ignore();
}
/// <summary>
/// TBD
/// </summary>
/// <typeparam name="TOut">TBD</typeparam>
/// <typeparam name="TExt">TBD</typeparam>
public interface IAsyncContext<in TOut, in TExt> : IAsyncContext, IDetachedContext<TOut>
{
/// <summary>
/// Obtain a callback object that can be used asynchronously to re-enter the
/// current <see cref="IAsyncContext{TOut,TExt}"/> with an asynchronous notification. After the
/// notification has been invoked, eventually <see cref="GraphInterpreter.OnAsyncInput"/>
/// will be called with the given data item.
///
/// This object can be cached and reused within the same <see cref="IAsyncContext{TOut,TExt}"/>.
/// </summary>
/// <returns>TBD</returns>
new AsyncCallback<TExt> GetAsyncCallback();
}
/// <summary>
/// TBD
/// </summary>
public interface IBoundaryContext : IContext
{
/// <summary>
/// TBD
/// </summary>
/// <returns>TBD</returns>
FreeDirective Exit();
}
}