com.wallstop-studios.dxmessaging 2.0.0-rc12 → 2.0.0-rc13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +63 -63
- package/.github/workflows/npm-publish.yml +66 -0
- package/CHANGELOG.md.meta +7 -7
- package/Editor/Analyzers/Microsoft.CodeAnalysis.CSharp.dll.meta +33 -33
- package/Editor/Analyzers/Microsoft.CodeAnalysis.dll.meta +33 -33
- package/Editor/Analyzers/System.Reflection.Metadata.dll.meta +33 -33
- package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll.meta +71 -71
- package/Editor/Analyzers.meta +8 -8
- package/Editor/SetupCscRsp.cs +162 -162
- package/Editor/SetupCscRsp.cs.meta +2 -2
- package/Editor/WallstopStudios.DxMessaging.Editor.asmdef +17 -17
- package/Editor/WallstopStudios.DxMessaging.Editor.asmdef.meta +7 -7
- package/Editor.meta +8 -8
- package/LICENSE.md +6 -6
- package/LICENSE.md.meta +7 -7
- package/README.md +387 -364
- package/README.md.meta +7 -7
- package/Runtime/Core/Attributes/DxAutoMessageTypeAttribute.cs +7 -7
- package/Runtime/Core/Attributes/DxAutoMessageTypeAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs +7 -7
- package/Runtime/Core/Attributes/DxBroadcastMessageAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs +7 -7
- package/Runtime/Core/Attributes/DxTargetedMessageAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs +7 -7
- package/Runtime/Core/Attributes/DxUntargetedMessageAttribute.cs.meta +2 -2
- package/Runtime/Core/Attributes.meta +2 -2
- package/Runtime/Core/Extensions/MessageExtensions.cs +342 -342
- package/Runtime/Core/Extensions/MessageExtensions.cs.meta +11 -11
- package/Runtime/Core/Extensions.meta +8 -8
- package/Runtime/Core/IMessage.cs +12 -12
- package/Runtime/Core/IMessage.cs.meta +11 -11
- package/Runtime/Core/InstanceId.cs +149 -149
- package/Runtime/Core/InstanceId.cs.meta +11 -11
- package/Runtime/Core/MessageBus/IMessageBus.cs +309 -309
- package/Runtime/Core/MessageBus/IMessageBus.cs.meta +11 -11
- package/Runtime/Core/MessageBus/MessageBus.cs +2243 -2084
- package/Runtime/Core/MessageBus/MessageBus.cs.meta +11 -11
- package/Runtime/Core/MessageBus/MessagingRegistration.cs +105 -105
- package/Runtime/Core/MessageBus/MessagingRegistration.cs.meta +11 -11
- package/Runtime/Core/MessageBus/RegistrationLog.cs +111 -111
- package/Runtime/Core/MessageBus/RegistrationLog.cs.meta +11 -11
- package/Runtime/Core/MessageBus.meta +8 -8
- package/Runtime/Core/MessageHandler.cs +2778 -2759
- package/Runtime/Core/MessageHandler.cs.meta +11 -11
- package/Runtime/Core/MessageRegistrationHandle.cs +110 -110
- package/Runtime/Core/MessageRegistrationHandle.cs.meta +11 -11
- package/Runtime/Core/MessageRegistrationToken.cs +1234 -1234
- package/Runtime/Core/MessageRegistrationToken.cs.meta +11 -11
- package/Runtime/Core/Messages/IBroadcastMessage.cs +27 -27
- package/Runtime/Core/Messages/IBroadcastMessage.cs.meta +11 -11
- package/Runtime/Core/Messages/ITargetedMessage.cs +27 -27
- package/Runtime/Core/Messages/ITargetedMessage.cs.meta +11 -11
- package/Runtime/Core/Messages/IUntargetedMessage.cs +27 -27
- package/Runtime/Core/Messages/IUntargetedMessage.cs.meta +11 -11
- package/Runtime/Core/Messages.meta +8 -8
- package/Runtime/Core/MessagingDebug.cs +70 -70
- package/Runtime/Core/MessagingDebug.cs.meta +11 -11
- package/Runtime/Core.meta +8 -8
- package/Runtime/Unity/MessageAwareComponent.cs +77 -77
- package/Runtime/Unity/MessageAwareComponent.cs.meta +11 -11
- package/Runtime/Unity/MessagingComponent.cs +99 -99
- package/Runtime/Unity/MessagingComponent.cs.meta +11 -11
- package/Runtime/Unity.meta +8 -8
- package/Runtime/WallstopStudios.DxMessaging.asmdef +15 -15
- package/Runtime.meta +8 -8
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoMessageTypeGenerator.cs +92 -92
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoMessageTypeGenerator.cs.meta +11 -11
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxBroadcastMessageGenerator.cs +94 -94
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxBroadcastMessageGenerator.cs.meta +2 -2
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxTargetedMessageGenerator.cs +94 -94
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxTargetedMessageGenerator.cs.meta +2 -2
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxUntargetedMessageGenerator.cs +94 -94
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxUntargetedMessageGenerator.cs.meta +2 -2
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj +21 -21
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.csproj.meta +7 -7
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators.meta +8 -8
- package/SourceGenerators.meta +8 -8
- package/Tests/Runtime/Benchmarks/PerformanceTests.cs +373 -310
- package/Tests/Runtime/Benchmarks/PerformanceTests.cs.meta +11 -11
- package/Tests/Runtime/Benchmarks.meta +8 -8
- package/Tests/Runtime/Core/BroadcastTests.cs +899 -899
- package/Tests/Runtime/Core/GlobalAcceptAllTests.cs +190 -190
- package/Tests/Runtime/Core/GlobalAcceptAllTests.cs.meta +11 -11
- package/Tests/Runtime/Core/MessagingTestBase.cs +185 -185
- package/Tests/Runtime/Core/MessagingTestBase.cs.meta +11 -11
- package/Tests/Runtime/Core/NominalTests.cs +1740 -1740
- package/Tests/Runtime/Core/PostProcessorTests.cs +1236 -1236
- package/Tests/Runtime/Core/PostProcessorTests.cs.meta +11 -11
- package/Tests/Runtime/Core/RegistrationTests.cs +1266 -1266
- package/Tests/Runtime/Core/RegistrationTests.cs.meta +11 -11
- package/Tests/Runtime/Core/TargetedTests.cs +888 -888
- package/Tests/Runtime/Core/TargetedTests.cs.meta +11 -11
- package/Tests/Runtime/Core/UntargetedTests.cs +272 -272
- package/Tests/Runtime/Core/UntargetedTests.cs.meta +11 -11
- package/Tests/Runtime/Scripts/Components/EmptyMessageAwareComponent.cs +9 -9
- package/Tests/Runtime/Scripts/Components/EmptyMessageAwareComponent.cs.meta +11 -11
- package/Tests/Runtime/Scripts/Components/SimpleMessageAwareComponent.cs +186 -186
- package/Tests/Runtime/Scripts/Messages/ComplexTargetedMessage.cs +30 -30
- package/Tests/Runtime/Scripts/Messages/SimpleBroadcastMessage.cs +8 -8
- package/Tests/Runtime/Scripts/Messages/SimpleTargetedMessage.cs +8 -8
- package/Tests/Runtime/Scripts/Messages/SimpleUntargetedMessage.cs +8 -8
- package/Tests/Runtime/WallstopStudios.DxMessaging.Tests.Runtime.csproj.meta +7 -7
- package/Tests.meta +8 -8
- package/Third Party Notices.md.meta +7 -7
- package/package.json +36 -36
- package/package.json.meta +7 -7
|
@@ -1,2084 +1,2243 @@
|
|
|
1
|
-
namespace DxMessaging.Core.MessageBus
|
|
2
|
-
{
|
|
3
|
-
using System;
|
|
4
|
-
using System.Collections.Generic;
|
|
5
|
-
using System.
|
|
6
|
-
using
|
|
7
|
-
using
|
|
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
|
-
private
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
private readonly
|
|
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
|
-
int priority = 0
|
|
246
|
-
)
|
|
247
|
-
where T :
|
|
248
|
-
{
|
|
249
|
-
return
|
|
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
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
)
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
)
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
.
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
&&
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
{
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
{
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
case
|
|
794
|
-
{
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
case
|
|
846
|
-
{
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
return;
|
|
1186
|
-
}
|
|
1187
|
-
default:
|
|
1188
|
-
{
|
|
1189
|
-
List<MessageHandler> messageHandlers = GetOrAddMessageHandlerStack(
|
|
1190
|
-
handlers.Keys
|
|
1191
|
-
);
|
|
1192
|
-
try
|
|
1193
|
-
{
|
|
1194
|
-
foreach (MessageHandler handler in messageHandlers)
|
|
1195
|
-
{
|
|
1196
|
-
handler.
|
|
1197
|
-
ref source,
|
|
1198
|
-
ref typedMessage,
|
|
1199
|
-
this,
|
|
1200
|
-
priority
|
|
1201
|
-
);
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
finally
|
|
1205
|
-
{
|
|
1206
|
-
_messageHandlers.Push(messageHandlers);
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
break;
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
private void
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
return;
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
{
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
)
|
|
1339
|
-
{
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
{
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
{
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
);
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
ref
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
)
|
|
1763
|
-
where
|
|
1764
|
-
{
|
|
1765
|
-
if (
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
);
|
|
1849
|
-
}
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
)
|
|
1884
|
-
{
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
{
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
1
|
+
namespace DxMessaging.Core.MessageBus
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Collections.Generic;
|
|
5
|
+
using System.Reflection;
|
|
6
|
+
using Messages;
|
|
7
|
+
using static IMessageBus;
|
|
8
|
+
|
|
9
|
+
/// <summary>
|
|
10
|
+
/// Instanced MessageBus for use cases where you want distinct islands of MessageBuses.
|
|
11
|
+
/// </summary>
|
|
12
|
+
public sealed class MessageBus : IMessageBus
|
|
13
|
+
{
|
|
14
|
+
public int RegisteredTargeted
|
|
15
|
+
{
|
|
16
|
+
get
|
|
17
|
+
{
|
|
18
|
+
int count = 0;
|
|
19
|
+
foreach (
|
|
20
|
+
KeyValuePair<
|
|
21
|
+
Type,
|
|
22
|
+
Dictionary<InstanceId, SortedList<int, SortedList<MessageHandler, int>>>
|
|
23
|
+
> entry in _targetedSinks
|
|
24
|
+
)
|
|
25
|
+
{
|
|
26
|
+
count += entry.Value.Count;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return count;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public int RegisteredBroadcast
|
|
34
|
+
{
|
|
35
|
+
get
|
|
36
|
+
{
|
|
37
|
+
int count = 0;
|
|
38
|
+
foreach (var entry in _broadcastSinks)
|
|
39
|
+
{
|
|
40
|
+
count += entry.Value.Count;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return count;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public int RegisteredUntargeted
|
|
48
|
+
{
|
|
49
|
+
get
|
|
50
|
+
{
|
|
51
|
+
int count = 0;
|
|
52
|
+
foreach (var entry in _sinks)
|
|
53
|
+
{
|
|
54
|
+
count += entry.Value.Count;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return count;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private static readonly Type MessageBusType = typeof(MessageBus);
|
|
62
|
+
|
|
63
|
+
// For use with re-broadcasting to generic methods
|
|
64
|
+
private static readonly object[] ReflectionMethodArgumentsCache = new object[2];
|
|
65
|
+
|
|
66
|
+
private const BindingFlags ReflectionHelperBindingFlags =
|
|
67
|
+
BindingFlags.Static | BindingFlags.NonPublic;
|
|
68
|
+
|
|
69
|
+
private delegate void FastUntargetedBroadcast<T>(ref T message)
|
|
70
|
+
where T : IUntargetedMessage;
|
|
71
|
+
private delegate void FastTargetedBroadcast<T>(ref InstanceId target, ref T message)
|
|
72
|
+
where T : ITargetedMessage;
|
|
73
|
+
private delegate void FastSourcedBroadcast<T>(ref InstanceId target, ref T message)
|
|
74
|
+
where T : IBroadcastMessage;
|
|
75
|
+
|
|
76
|
+
public RegistrationLog Log => _log;
|
|
77
|
+
|
|
78
|
+
private readonly Dictionary<Type, SortedList<int, SortedList<MessageHandler, int>>> _sinks =
|
|
79
|
+
new();
|
|
80
|
+
private readonly Dictionary<
|
|
81
|
+
Type,
|
|
82
|
+
Dictionary<InstanceId, SortedList<int, SortedList<MessageHandler, int>>>
|
|
83
|
+
> _targetedSinks = new();
|
|
84
|
+
|
|
85
|
+
private readonly Dictionary<
|
|
86
|
+
Type,
|
|
87
|
+
Dictionary<InstanceId, SortedList<int, SortedList<MessageHandler, int>>>
|
|
88
|
+
> _broadcastSinks = new();
|
|
89
|
+
private readonly Dictionary<
|
|
90
|
+
Type,
|
|
91
|
+
SortedList<int, SortedList<MessageHandler, int>>
|
|
92
|
+
> _postProcessingSinks = new();
|
|
93
|
+
private readonly Dictionary<
|
|
94
|
+
Type,
|
|
95
|
+
Dictionary<InstanceId, SortedList<int, SortedList<MessageHandler, int>>>
|
|
96
|
+
> _postProcessingTargetedSinks = new();
|
|
97
|
+
private readonly Dictionary<
|
|
98
|
+
Type,
|
|
99
|
+
Dictionary<InstanceId, SortedList<int, SortedList<MessageHandler, int>>>
|
|
100
|
+
> _postProcessingBroadcastSinks = new();
|
|
101
|
+
private readonly Dictionary<
|
|
102
|
+
Type,
|
|
103
|
+
SortedList<int, SortedList<MessageHandler, int>>
|
|
104
|
+
> _postProcessingTargetedWithoutTargetingSinks = new();
|
|
105
|
+
private readonly Dictionary<
|
|
106
|
+
Type,
|
|
107
|
+
SortedList<int, SortedList<MessageHandler, int>>
|
|
108
|
+
> _postProcessingBroadcastWithoutSourceSinks = new();
|
|
109
|
+
private readonly SortedList<MessageHandler, int> _globalSinks = new();
|
|
110
|
+
private readonly Dictionary<Type, SortedList<int, List<object>>> _interceptsByType = new();
|
|
111
|
+
private readonly Dictionary<object, Dictionary<int, int>> _uniqueInterceptorsAndPriorities =
|
|
112
|
+
new();
|
|
113
|
+
|
|
114
|
+
private readonly Dictionary<Type, object> _broadcastMethodsByType = new();
|
|
115
|
+
|
|
116
|
+
private readonly RegistrationLog _log = new();
|
|
117
|
+
|
|
118
|
+
// These are used so we aren't allocating as much every time we send messages
|
|
119
|
+
private readonly Stack<List<MessageHandler>> _messageHandlers = new();
|
|
120
|
+
private readonly Stack<
|
|
121
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>>
|
|
122
|
+
> _sortedHandlers = new();
|
|
123
|
+
private readonly Stack<List<List<object>>> _interceptors = new();
|
|
124
|
+
private readonly Stack<List<object>> _innerInterceptorsStack = new();
|
|
125
|
+
|
|
126
|
+
public Action RegisterUntargeted<T>(MessageHandler messageHandler, int priority = 0)
|
|
127
|
+
where T : IUntargetedMessage
|
|
128
|
+
{
|
|
129
|
+
return InternalRegisterUntargeted<T>(
|
|
130
|
+
messageHandler,
|
|
131
|
+
_sinks,
|
|
132
|
+
RegistrationMethod.Untargeted,
|
|
133
|
+
priority
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public Action RegisterTargeted<T>(
|
|
138
|
+
InstanceId target,
|
|
139
|
+
MessageHandler messageHandler,
|
|
140
|
+
int priority = 0
|
|
141
|
+
)
|
|
142
|
+
where T : ITargetedMessage
|
|
143
|
+
{
|
|
144
|
+
return InternalRegisterWithContext<T>(
|
|
145
|
+
target,
|
|
146
|
+
messageHandler,
|
|
147
|
+
_targetedSinks,
|
|
148
|
+
RegistrationMethod.Targeted,
|
|
149
|
+
priority
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public Action RegisterSourcedBroadcast<T>(
|
|
154
|
+
InstanceId source,
|
|
155
|
+
MessageHandler messageHandler,
|
|
156
|
+
int priority = 0
|
|
157
|
+
)
|
|
158
|
+
where T : IBroadcastMessage
|
|
159
|
+
{
|
|
160
|
+
return InternalRegisterWithContext<T>(
|
|
161
|
+
source,
|
|
162
|
+
messageHandler,
|
|
163
|
+
_broadcastSinks,
|
|
164
|
+
RegistrationMethod.Broadcast,
|
|
165
|
+
priority
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public Action RegisterSourcedBroadcastWithoutSource<T>(
|
|
170
|
+
MessageHandler messageHandler,
|
|
171
|
+
int priority = 0
|
|
172
|
+
)
|
|
173
|
+
where T : IBroadcastMessage
|
|
174
|
+
{
|
|
175
|
+
return InternalRegisterUntargeted<T>(
|
|
176
|
+
messageHandler,
|
|
177
|
+
_sinks,
|
|
178
|
+
RegistrationMethod.BroadcastWithoutSource,
|
|
179
|
+
priority
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
public Action RegisterTargetedWithoutTargeting<T>(
|
|
184
|
+
MessageHandler messageHandler,
|
|
185
|
+
int priority = 0
|
|
186
|
+
)
|
|
187
|
+
where T : ITargetedMessage
|
|
188
|
+
{
|
|
189
|
+
return InternalRegisterUntargeted<T>(
|
|
190
|
+
messageHandler,
|
|
191
|
+
_sinks,
|
|
192
|
+
RegistrationMethod.TargetedWithoutTargeting,
|
|
193
|
+
priority
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
public Action RegisterGlobalAcceptAll(MessageHandler messageHandler)
|
|
198
|
+
{
|
|
199
|
+
int count = _globalSinks.GetValueOrDefault(messageHandler, 0);
|
|
200
|
+
|
|
201
|
+
Type type = typeof(IMessage);
|
|
202
|
+
_globalSinks[messageHandler] = count + 1;
|
|
203
|
+
_log.Log(
|
|
204
|
+
new MessagingRegistration(
|
|
205
|
+
messageHandler.owner,
|
|
206
|
+
type,
|
|
207
|
+
RegistrationType.Register,
|
|
208
|
+
RegistrationMethod.GlobalAcceptAll
|
|
209
|
+
)
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
return () =>
|
|
213
|
+
{
|
|
214
|
+
_log.Log(
|
|
215
|
+
new MessagingRegistration(
|
|
216
|
+
messageHandler.owner,
|
|
217
|
+
type,
|
|
218
|
+
RegistrationType.Deregister,
|
|
219
|
+
RegistrationMethod.GlobalAcceptAll
|
|
220
|
+
)
|
|
221
|
+
);
|
|
222
|
+
if (!_globalSinks.TryGetValue(messageHandler, out count))
|
|
223
|
+
{
|
|
224
|
+
MessagingDebug.Log(
|
|
225
|
+
LogLevel.Error,
|
|
226
|
+
"Received over-deregistration of GlobalAcceptAll for MessageHandler {0}. Check to make sure you're not calling (de)registration multiple times.",
|
|
227
|
+
messageHandler
|
|
228
|
+
);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (count <= 1)
|
|
233
|
+
{
|
|
234
|
+
_ = _globalSinks.Remove(messageHandler);
|
|
235
|
+
}
|
|
236
|
+
else
|
|
237
|
+
{
|
|
238
|
+
_globalSinks[messageHandler] = count - 1;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
public Action RegisterUntargetedInterceptor<T>(
|
|
244
|
+
UntargetedInterceptor<T> interceptor,
|
|
245
|
+
int priority = 0
|
|
246
|
+
)
|
|
247
|
+
where T : IUntargetedMessage
|
|
248
|
+
{
|
|
249
|
+
return RegisterInterceptor<T>(interceptor, priority);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public Action RegisterTargetedInterceptor<T>(
|
|
253
|
+
TargetedInterceptor<T> interceptor,
|
|
254
|
+
int priority = 0
|
|
255
|
+
)
|
|
256
|
+
where T : ITargetedMessage
|
|
257
|
+
{
|
|
258
|
+
return RegisterInterceptor<T>(interceptor, priority);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
public Action RegisterBroadcastInterceptor<T>(
|
|
262
|
+
BroadcastInterceptor<T> interceptor,
|
|
263
|
+
int priority = 0
|
|
264
|
+
)
|
|
265
|
+
where T : IBroadcastMessage
|
|
266
|
+
{
|
|
267
|
+
return RegisterInterceptor<T>(interceptor, priority);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
public Action RegisterUntargetedPostProcessor<T>(
|
|
271
|
+
MessageHandler messageHandler,
|
|
272
|
+
int priority = 0
|
|
273
|
+
)
|
|
274
|
+
where T : IUntargetedMessage
|
|
275
|
+
{
|
|
276
|
+
return InternalRegisterUntargeted<T>(
|
|
277
|
+
messageHandler,
|
|
278
|
+
_postProcessingSinks,
|
|
279
|
+
RegistrationMethod.UntargetedPostProcessor,
|
|
280
|
+
priority
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
public Action RegisterTargetedPostProcessor<T>(
|
|
285
|
+
InstanceId target,
|
|
286
|
+
MessageHandler messageHandler,
|
|
287
|
+
int priority = 0
|
|
288
|
+
)
|
|
289
|
+
where T : ITargetedMessage
|
|
290
|
+
{
|
|
291
|
+
return InternalRegisterWithContext<T>(
|
|
292
|
+
target,
|
|
293
|
+
messageHandler,
|
|
294
|
+
_postProcessingTargetedSinks,
|
|
295
|
+
RegistrationMethod.TargetedPostProcessor,
|
|
296
|
+
priority
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
public Action RegisterTargetedWithoutTargetingPostProcessor<T>(
|
|
301
|
+
MessageHandler messageHandler,
|
|
302
|
+
int priority = 0
|
|
303
|
+
)
|
|
304
|
+
where T : ITargetedMessage
|
|
305
|
+
{
|
|
306
|
+
return InternalRegisterUntargeted<T>(
|
|
307
|
+
messageHandler,
|
|
308
|
+
_postProcessingTargetedWithoutTargetingSinks,
|
|
309
|
+
RegistrationMethod.TargetedWithoutTargetingPostProcessor,
|
|
310
|
+
priority
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
public Action RegisterBroadcastPostProcessor<T>(
|
|
315
|
+
InstanceId source,
|
|
316
|
+
MessageHandler messageHandler,
|
|
317
|
+
int priority = 0
|
|
318
|
+
)
|
|
319
|
+
where T : IBroadcastMessage
|
|
320
|
+
{
|
|
321
|
+
return InternalRegisterWithContext<T>(
|
|
322
|
+
source,
|
|
323
|
+
messageHandler,
|
|
324
|
+
_postProcessingBroadcastSinks,
|
|
325
|
+
RegistrationMethod.BroadcastPostProcessor,
|
|
326
|
+
priority
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
public Action RegisterBroadcastWithoutSourcePostProcessor<T>(
|
|
331
|
+
MessageHandler messageHandler,
|
|
332
|
+
int priority = 0
|
|
333
|
+
)
|
|
334
|
+
where T : IBroadcastMessage
|
|
335
|
+
{
|
|
336
|
+
return InternalRegisterUntargeted<T>(
|
|
337
|
+
messageHandler,
|
|
338
|
+
_postProcessingBroadcastWithoutSourceSinks,
|
|
339
|
+
RegistrationMethod.BroadcastWithoutSourcePostProcessor,
|
|
340
|
+
priority
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
private Action RegisterInterceptor<T>(object interceptor, int priority)
|
|
345
|
+
where T : IMessage
|
|
346
|
+
{
|
|
347
|
+
Type type = typeof(T);
|
|
348
|
+
if (
|
|
349
|
+
!_interceptsByType.TryGetValue(
|
|
350
|
+
type,
|
|
351
|
+
out SortedList<int, List<object>> prioritizedInterceptors
|
|
352
|
+
)
|
|
353
|
+
)
|
|
354
|
+
{
|
|
355
|
+
prioritizedInterceptors = new SortedList<int, List<object>>();
|
|
356
|
+
_interceptsByType[type] = prioritizedInterceptors;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (!prioritizedInterceptors.TryGetValue(priority, out List<object> interceptors))
|
|
360
|
+
{
|
|
361
|
+
interceptors = new List<object>();
|
|
362
|
+
prioritizedInterceptors[priority] = interceptors;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (
|
|
366
|
+
!_uniqueInterceptorsAndPriorities.TryGetValue(
|
|
367
|
+
interceptor,
|
|
368
|
+
out Dictionary<int, int> priorityCount
|
|
369
|
+
)
|
|
370
|
+
)
|
|
371
|
+
{
|
|
372
|
+
priorityCount = new Dictionary<int, int>();
|
|
373
|
+
_uniqueInterceptorsAndPriorities[interceptor] = priorityCount;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (!priorityCount.TryGetValue(priority, out int count))
|
|
377
|
+
{
|
|
378
|
+
count = 0;
|
|
379
|
+
interceptors.Add(interceptor);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
priorityCount[priority] = count + 1;
|
|
383
|
+
|
|
384
|
+
_log.Log(
|
|
385
|
+
new MessagingRegistration(
|
|
386
|
+
InstanceId.EmptyId,
|
|
387
|
+
type,
|
|
388
|
+
RegistrationType.Register,
|
|
389
|
+
RegistrationMethod.Interceptor
|
|
390
|
+
)
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
return () =>
|
|
394
|
+
{
|
|
395
|
+
_log.Log(
|
|
396
|
+
new MessagingRegistration(
|
|
397
|
+
InstanceId.EmptyId,
|
|
398
|
+
type,
|
|
399
|
+
RegistrationType.Deregister,
|
|
400
|
+
RegistrationMethod.Interceptor
|
|
401
|
+
)
|
|
402
|
+
);
|
|
403
|
+
bool removed = false;
|
|
404
|
+
if (_uniqueInterceptorsAndPriorities.TryGetValue(interceptor, out priorityCount))
|
|
405
|
+
{
|
|
406
|
+
if (priorityCount.TryGetValue(priority, out count))
|
|
407
|
+
{
|
|
408
|
+
if (1 < count)
|
|
409
|
+
{
|
|
410
|
+
priorityCount[priority] = count - 1;
|
|
411
|
+
}
|
|
412
|
+
else
|
|
413
|
+
{
|
|
414
|
+
removed = true;
|
|
415
|
+
_ = priorityCount.Remove(priority);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (priorityCount.Count <= 0)
|
|
420
|
+
{
|
|
421
|
+
_uniqueInterceptorsAndPriorities.Remove(interceptor);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
else
|
|
425
|
+
{
|
|
426
|
+
MessagingDebug.Log(
|
|
427
|
+
LogLevel.Error,
|
|
428
|
+
"Received over-deregistration of Interceptor {0}. Check to make sure you're not calling (de)registration multiple times.",
|
|
429
|
+
interceptor
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
bool complete = false;
|
|
434
|
+
if (removed)
|
|
435
|
+
{
|
|
436
|
+
if (
|
|
437
|
+
_interceptsByType.TryGetValue(type, out prioritizedInterceptors)
|
|
438
|
+
&& prioritizedInterceptors.TryGetValue(priority, out interceptors)
|
|
439
|
+
)
|
|
440
|
+
{
|
|
441
|
+
complete = interceptors.Remove(interceptor);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
if (!complete)
|
|
445
|
+
{
|
|
446
|
+
MessagingDebug.Log(
|
|
447
|
+
LogLevel.Error,
|
|
448
|
+
"Received over-deregistration of Interceptor {0}. Check to make sure you're not calling (de)registration multiple times.",
|
|
449
|
+
interceptor
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
public void UntypedUntargetedBroadcast(IUntargetedMessage typedMessage)
|
|
457
|
+
{
|
|
458
|
+
Type messageType = typedMessage.MessageType;
|
|
459
|
+
if (!_broadcastMethodsByType.TryGetValue(messageType, out object untargetedMethod))
|
|
460
|
+
{
|
|
461
|
+
// ReSharper disable once PossibleNullReferenceException
|
|
462
|
+
MethodInfo broadcastMethod = MessageBusType
|
|
463
|
+
.GetMethod(nameof(UntargetedBroadcast))
|
|
464
|
+
.MakeGenericMethod(messageType);
|
|
465
|
+
// ReSharper disable once PossibleNullReferenceException
|
|
466
|
+
MethodInfo helperMethod = MessageBusType
|
|
467
|
+
.GetMethod(
|
|
468
|
+
nameof(UntargetedBroadcastReflectionHelper),
|
|
469
|
+
ReflectionHelperBindingFlags
|
|
470
|
+
)
|
|
471
|
+
.MakeGenericMethod(messageType);
|
|
472
|
+
|
|
473
|
+
ReflectionMethodArgumentsCache[0] = this;
|
|
474
|
+
ReflectionMethodArgumentsCache[1] = broadcastMethod;
|
|
475
|
+
untargetedMethod = helperMethod.Invoke(null, ReflectionMethodArgumentsCache);
|
|
476
|
+
_broadcastMethodsByType[messageType] = untargetedMethod;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
Action<IUntargetedMessage> broadcast = (Action<IUntargetedMessage>)untargetedMethod;
|
|
480
|
+
broadcast.Invoke(typedMessage);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
public void UntargetedBroadcast<TMessage>(ref TMessage typedMessage)
|
|
484
|
+
where TMessage : IUntargetedMessage
|
|
485
|
+
{
|
|
486
|
+
Type type = typeof(TMessage);
|
|
487
|
+
if (!RunUntargetedInterceptors(type, ref typedMessage))
|
|
488
|
+
{
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (0 < _globalSinks.Count)
|
|
493
|
+
{
|
|
494
|
+
IUntargetedMessage untargetedMessage = typedMessage;
|
|
495
|
+
BroadcastGlobalUntargeted(ref untargetedMessage);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
bool foundAnyHandlers = InternalUntargetedBroadcast(ref typedMessage, type);
|
|
499
|
+
|
|
500
|
+
if (
|
|
501
|
+
_postProcessingSinks.TryGetValue(
|
|
502
|
+
type,
|
|
503
|
+
out SortedList<int, SortedList<MessageHandler, int>> sortedHandlers
|
|
504
|
+
)
|
|
505
|
+
&& 0 < sortedHandlers.Count
|
|
506
|
+
)
|
|
507
|
+
{
|
|
508
|
+
foundAnyHandlers = true;
|
|
509
|
+
if (sortedHandlers.Count == 1)
|
|
510
|
+
{
|
|
511
|
+
RunUntargetedPostProcessing(
|
|
512
|
+
ref typedMessage,
|
|
513
|
+
sortedHandlers.Keys[0],
|
|
514
|
+
sortedHandlers.Values[0]
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
else
|
|
518
|
+
{
|
|
519
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
520
|
+
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
521
|
+
try
|
|
522
|
+
{
|
|
523
|
+
foreach (
|
|
524
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList
|
|
525
|
+
)
|
|
526
|
+
{
|
|
527
|
+
RunUntargetedPostProcessing(ref typedMessage, entry.Key, entry.Value);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
finally
|
|
531
|
+
{
|
|
532
|
+
_sortedHandlers.Push(handlerList);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
if (!foundAnyHandlers)
|
|
538
|
+
{
|
|
539
|
+
MessagingDebug.Log(
|
|
540
|
+
LogLevel.Info,
|
|
541
|
+
"Could not find a matching untargeted broadcast handler for Message: {0}.",
|
|
542
|
+
typedMessage
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
private void RunUntargetedPostProcessing<TMessage>(
|
|
548
|
+
ref TMessage typedMessage,
|
|
549
|
+
int priority,
|
|
550
|
+
SortedList<MessageHandler, int> handlers
|
|
551
|
+
)
|
|
552
|
+
where TMessage : IUntargetedMessage
|
|
553
|
+
{
|
|
554
|
+
switch (handlers.Count)
|
|
555
|
+
{
|
|
556
|
+
case <= 0:
|
|
557
|
+
{
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
case 1:
|
|
561
|
+
{
|
|
562
|
+
MessageHandler handler = handlers.Keys[0];
|
|
563
|
+
handler.HandleUntargetedPostProcessing(ref typedMessage, this, priority);
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
default:
|
|
567
|
+
{
|
|
568
|
+
List<MessageHandler> messageHandlers = GetOrAddMessageHandlerStack(
|
|
569
|
+
handlers.Keys
|
|
570
|
+
);
|
|
571
|
+
try
|
|
572
|
+
{
|
|
573
|
+
foreach (MessageHandler handler in messageHandlers)
|
|
574
|
+
{
|
|
575
|
+
handler.HandleUntargetedPostProcessing(
|
|
576
|
+
ref typedMessage,
|
|
577
|
+
this,
|
|
578
|
+
priority
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
finally
|
|
583
|
+
{
|
|
584
|
+
_messageHandlers.Push(messageHandlers);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
break;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
public void UntypedTargetedBroadcast(InstanceId target, ITargetedMessage typedMessage)
|
|
593
|
+
{
|
|
594
|
+
Type messageType = typedMessage.MessageType;
|
|
595
|
+
if (!_broadcastMethodsByType.TryGetValue(messageType, out object targetedMethod))
|
|
596
|
+
{
|
|
597
|
+
// ReSharper disable once PossibleNullReferenceException
|
|
598
|
+
MethodInfo broadcastMethod = MessageBusType
|
|
599
|
+
.GetMethod(nameof(TargetedBroadcast))
|
|
600
|
+
.MakeGenericMethod(messageType);
|
|
601
|
+
// ReSharper disable once PossibleNullReferenceException
|
|
602
|
+
MethodInfo helperMethod = MessageBusType
|
|
603
|
+
.GetMethod(
|
|
604
|
+
nameof(TargetedBroadcastReflectionHelper),
|
|
605
|
+
ReflectionHelperBindingFlags
|
|
606
|
+
)
|
|
607
|
+
.MakeGenericMethod(messageType);
|
|
608
|
+
|
|
609
|
+
ReflectionMethodArgumentsCache[0] = this;
|
|
610
|
+
ReflectionMethodArgumentsCache[1] = broadcastMethod;
|
|
611
|
+
targetedMethod = helperMethod.Invoke(null, ReflectionMethodArgumentsCache);
|
|
612
|
+
_broadcastMethodsByType[messageType] = targetedMethod;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
Action<InstanceId, ITargetedMessage> broadcast =
|
|
616
|
+
(Action<InstanceId, ITargetedMessage>)targetedMethod;
|
|
617
|
+
broadcast.Invoke(target, typedMessage);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
public void TargetedBroadcast<TMessage>(ref InstanceId target, ref TMessage typedMessage)
|
|
621
|
+
where TMessage : ITargetedMessage
|
|
622
|
+
{
|
|
623
|
+
Type type = typeof(TMessage);
|
|
624
|
+
if (!RunTargetedInterceptors(type, ref typedMessage, ref target))
|
|
625
|
+
{
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
if (0 < _globalSinks.Count)
|
|
630
|
+
{
|
|
631
|
+
ITargetedMessage targetedMessage = typedMessage;
|
|
632
|
+
BroadcastGlobalTargeted(ref target, ref targetedMessage);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
bool foundAnyHandlers = false;
|
|
636
|
+
if (
|
|
637
|
+
_targetedSinks.TryGetValue(
|
|
638
|
+
type,
|
|
639
|
+
out Dictionary<
|
|
640
|
+
InstanceId,
|
|
641
|
+
SortedList<int, SortedList<MessageHandler, int>>
|
|
642
|
+
> targetedHandlers
|
|
643
|
+
)
|
|
644
|
+
&& targetedHandlers.TryGetValue(
|
|
645
|
+
target,
|
|
646
|
+
out SortedList<int, SortedList<MessageHandler, int>> sortedHandlers
|
|
647
|
+
)
|
|
648
|
+
&& 0 < sortedHandlers.Count
|
|
649
|
+
)
|
|
650
|
+
{
|
|
651
|
+
foundAnyHandlers = true;
|
|
652
|
+
if (sortedHandlers.Count == 1)
|
|
653
|
+
{
|
|
654
|
+
RunTargetedBroadcast(
|
|
655
|
+
ref target,
|
|
656
|
+
ref typedMessage,
|
|
657
|
+
sortedHandlers.Keys[0],
|
|
658
|
+
sortedHandlers.Values[0]
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
else
|
|
662
|
+
{
|
|
663
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
664
|
+
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
665
|
+
try
|
|
666
|
+
{
|
|
667
|
+
foreach (
|
|
668
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList
|
|
669
|
+
)
|
|
670
|
+
{
|
|
671
|
+
RunTargetedBroadcast(
|
|
672
|
+
ref target,
|
|
673
|
+
ref typedMessage,
|
|
674
|
+
entry.Key,
|
|
675
|
+
entry.Value
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
finally
|
|
680
|
+
{
|
|
681
|
+
_sortedHandlers.Push(handlerList);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
_ = InternalTargetedWithoutTargetingBroadcast(ref target, ref typedMessage, type);
|
|
687
|
+
|
|
688
|
+
if (
|
|
689
|
+
_postProcessingTargetedSinks.TryGetValue(type, out targetedHandlers)
|
|
690
|
+
&& targetedHandlers.TryGetValue(target, out sortedHandlers)
|
|
691
|
+
&& 0 < sortedHandlers.Count
|
|
692
|
+
)
|
|
693
|
+
{
|
|
694
|
+
foundAnyHandlers = true;
|
|
695
|
+
if (sortedHandlers.Count == 1)
|
|
696
|
+
{
|
|
697
|
+
RunTargetedPostProcessing(
|
|
698
|
+
ref target,
|
|
699
|
+
ref typedMessage,
|
|
700
|
+
sortedHandlers.Keys[0],
|
|
701
|
+
sortedHandlers.Values[0]
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
else
|
|
705
|
+
{
|
|
706
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
707
|
+
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
708
|
+
try
|
|
709
|
+
{
|
|
710
|
+
foreach (
|
|
711
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList
|
|
712
|
+
)
|
|
713
|
+
{
|
|
714
|
+
RunTargetedPostProcessing(
|
|
715
|
+
ref target,
|
|
716
|
+
ref typedMessage,
|
|
717
|
+
entry.Key,
|
|
718
|
+
entry.Value
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
finally
|
|
723
|
+
{
|
|
724
|
+
_sortedHandlers.Push(handlerList);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
if (
|
|
730
|
+
_postProcessingTargetedWithoutTargetingSinks.TryGetValue(type, out sortedHandlers)
|
|
731
|
+
&& 0 < sortedHandlers.Count
|
|
732
|
+
)
|
|
733
|
+
{
|
|
734
|
+
if (sortedHandlers.Count == 1)
|
|
735
|
+
{
|
|
736
|
+
RunTargetedWithoutTargetingPostProcessing(
|
|
737
|
+
ref target,
|
|
738
|
+
ref typedMessage,
|
|
739
|
+
sortedHandlers.Keys[0],
|
|
740
|
+
sortedHandlers.Values[0]
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
else
|
|
744
|
+
{
|
|
745
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
746
|
+
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
747
|
+
try
|
|
748
|
+
{
|
|
749
|
+
foreach (
|
|
750
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList
|
|
751
|
+
)
|
|
752
|
+
{
|
|
753
|
+
RunTargetedWithoutTargetingPostProcessing(
|
|
754
|
+
ref target,
|
|
755
|
+
ref typedMessage,
|
|
756
|
+
entry.Key,
|
|
757
|
+
entry.Value
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
finally
|
|
762
|
+
{
|
|
763
|
+
_sortedHandlers.Push(handlerList);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
if (!foundAnyHandlers)
|
|
769
|
+
{
|
|
770
|
+
MessagingDebug.Log(
|
|
771
|
+
LogLevel.Info,
|
|
772
|
+
"Could not find a matching targeted broadcast handler for Id: {0}, Message: {1}.",
|
|
773
|
+
target,
|
|
774
|
+
typedMessage
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
private void RunTargetedWithoutTargetingPostProcessing<TMessage>(
|
|
780
|
+
ref InstanceId target,
|
|
781
|
+
ref TMessage typedMessage,
|
|
782
|
+
int priority,
|
|
783
|
+
SortedList<MessageHandler, int> handlers
|
|
784
|
+
)
|
|
785
|
+
where TMessage : ITargetedMessage
|
|
786
|
+
{
|
|
787
|
+
switch (handlers.Count)
|
|
788
|
+
{
|
|
789
|
+
case <= 0:
|
|
790
|
+
{
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
case 1:
|
|
794
|
+
{
|
|
795
|
+
MessageHandler handler = handlers.Keys[0];
|
|
796
|
+
handler.HandleTargetedWithoutTargetingPostProcessing(
|
|
797
|
+
ref target,
|
|
798
|
+
ref typedMessage,
|
|
799
|
+
this,
|
|
800
|
+
priority
|
|
801
|
+
);
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
default:
|
|
805
|
+
{
|
|
806
|
+
List<MessageHandler> messageHandlers = GetOrAddMessageHandlerStack(
|
|
807
|
+
handlers.Keys
|
|
808
|
+
);
|
|
809
|
+
try
|
|
810
|
+
{
|
|
811
|
+
foreach (MessageHandler handler in messageHandlers)
|
|
812
|
+
{
|
|
813
|
+
handler.HandleTargetedWithoutTargetingPostProcessing(
|
|
814
|
+
ref target,
|
|
815
|
+
ref typedMessage,
|
|
816
|
+
this,
|
|
817
|
+
priority
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
finally
|
|
822
|
+
{
|
|
823
|
+
_messageHandlers.Push(messageHandlers);
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
break;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
private void RunTargetedPostProcessing<TMessage>(
|
|
832
|
+
ref InstanceId target,
|
|
833
|
+
ref TMessage typedMessage,
|
|
834
|
+
int priority,
|
|
835
|
+
SortedList<MessageHandler, int> handlers
|
|
836
|
+
)
|
|
837
|
+
where TMessage : ITargetedMessage
|
|
838
|
+
{
|
|
839
|
+
switch (handlers.Count)
|
|
840
|
+
{
|
|
841
|
+
case <= 0:
|
|
842
|
+
{
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
case 1:
|
|
846
|
+
{
|
|
847
|
+
MessageHandler handler = handlers.Keys[0];
|
|
848
|
+
handler.HandleTargetedPostProcessing(
|
|
849
|
+
ref target,
|
|
850
|
+
ref typedMessage,
|
|
851
|
+
this,
|
|
852
|
+
priority
|
|
853
|
+
);
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
default:
|
|
857
|
+
{
|
|
858
|
+
List<MessageHandler> messageHandlers = GetOrAddMessageHandlerStack(
|
|
859
|
+
handlers.Keys
|
|
860
|
+
);
|
|
861
|
+
try
|
|
862
|
+
{
|
|
863
|
+
foreach (MessageHandler handler in messageHandlers)
|
|
864
|
+
{
|
|
865
|
+
handler.HandleTargetedPostProcessing(
|
|
866
|
+
ref target,
|
|
867
|
+
ref typedMessage,
|
|
868
|
+
this,
|
|
869
|
+
priority
|
|
870
|
+
);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
finally
|
|
874
|
+
{
|
|
875
|
+
_messageHandlers.Push(messageHandlers);
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
break;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
private void RunTargetedBroadcast<TMessage>(
|
|
884
|
+
ref InstanceId target,
|
|
885
|
+
ref TMessage typedMessage,
|
|
886
|
+
int priority,
|
|
887
|
+
SortedList<MessageHandler, int> handlers
|
|
888
|
+
)
|
|
889
|
+
where TMessage : ITargetedMessage
|
|
890
|
+
{
|
|
891
|
+
switch (handlers.Count)
|
|
892
|
+
{
|
|
893
|
+
case <= 0:
|
|
894
|
+
{
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
case 1:
|
|
898
|
+
{
|
|
899
|
+
MessageHandler handler = handlers.Keys[0];
|
|
900
|
+
handler.HandleTargeted(ref target, ref typedMessage, this, priority);
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
default:
|
|
904
|
+
{
|
|
905
|
+
List<MessageHandler> messageHandlers = GetOrAddMessageHandlerStack(
|
|
906
|
+
handlers.Keys
|
|
907
|
+
);
|
|
908
|
+
try
|
|
909
|
+
{
|
|
910
|
+
foreach (MessageHandler handler in messageHandlers)
|
|
911
|
+
{
|
|
912
|
+
handler.HandleTargeted(ref target, ref typedMessage, this, priority);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
finally
|
|
916
|
+
{
|
|
917
|
+
_messageHandlers.Push(messageHandlers);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
break;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
public void UntypedSourcedBroadcast(InstanceId source, IBroadcastMessage typedMessage)
|
|
926
|
+
{
|
|
927
|
+
Type messageType = typedMessage.MessageType;
|
|
928
|
+
if (
|
|
929
|
+
!_broadcastMethodsByType.TryGetValue(messageType, out object sourcedBroadcastMethod)
|
|
930
|
+
)
|
|
931
|
+
{
|
|
932
|
+
// ReSharper disable once PossibleNullReferenceException
|
|
933
|
+
MethodInfo broadcastMethod = MessageBusType
|
|
934
|
+
.GetMethod(nameof(SourcedBroadcast))
|
|
935
|
+
.MakeGenericMethod(messageType);
|
|
936
|
+
// ReSharper disable once PossibleNullReferenceException
|
|
937
|
+
MethodInfo helperMethod = MessageBusType
|
|
938
|
+
.GetMethod(
|
|
939
|
+
nameof(SourcedBroadcastReflectionHelper),
|
|
940
|
+
ReflectionHelperBindingFlags
|
|
941
|
+
)
|
|
942
|
+
.MakeGenericMethod(messageType);
|
|
943
|
+
|
|
944
|
+
ReflectionMethodArgumentsCache[0] = this;
|
|
945
|
+
ReflectionMethodArgumentsCache[1] = broadcastMethod;
|
|
946
|
+
sourcedBroadcastMethod = helperMethod.Invoke(null, ReflectionMethodArgumentsCache);
|
|
947
|
+
|
|
948
|
+
_broadcastMethodsByType[messageType] = sourcedBroadcastMethod;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
Action<InstanceId, IBroadcastMessage> broadcast =
|
|
952
|
+
(Action<InstanceId, IBroadcastMessage>)sourcedBroadcastMethod;
|
|
953
|
+
broadcast.Invoke(source, typedMessage);
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
public void SourcedBroadcast<TMessage>(ref InstanceId source, ref TMessage typedMessage)
|
|
957
|
+
where TMessage : IBroadcastMessage
|
|
958
|
+
{
|
|
959
|
+
Type type = typeof(TMessage);
|
|
960
|
+
if (!RunBroadcastInterceptors(type, ref typedMessage, ref source))
|
|
961
|
+
{
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
if (0 < _globalSinks.Count)
|
|
966
|
+
{
|
|
967
|
+
IBroadcastMessage broadcastMessage = typedMessage;
|
|
968
|
+
BroadcastGlobalSourcedBroadcast(ref source, ref broadcastMessage);
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
bool foundAnyHandlers = false;
|
|
972
|
+
if (
|
|
973
|
+
_broadcastSinks.TryGetValue(
|
|
974
|
+
type,
|
|
975
|
+
out Dictionary<
|
|
976
|
+
InstanceId,
|
|
977
|
+
SortedList<int, SortedList<MessageHandler, int>>
|
|
978
|
+
> broadcastHandlers
|
|
979
|
+
)
|
|
980
|
+
&& broadcastHandlers.TryGetValue(
|
|
981
|
+
source,
|
|
982
|
+
out SortedList<int, SortedList<MessageHandler, int>> sortedHandlers
|
|
983
|
+
)
|
|
984
|
+
&& 0 < sortedHandlers.Count
|
|
985
|
+
)
|
|
986
|
+
{
|
|
987
|
+
foundAnyHandlers = true;
|
|
988
|
+
if (sortedHandlers.Count == 1)
|
|
989
|
+
{
|
|
990
|
+
RunBroadcast(
|
|
991
|
+
ref source,
|
|
992
|
+
ref typedMessage,
|
|
993
|
+
sortedHandlers.Keys[0],
|
|
994
|
+
sortedHandlers.Values[0]
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
else
|
|
998
|
+
{
|
|
999
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
1000
|
+
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
1001
|
+
try
|
|
1002
|
+
{
|
|
1003
|
+
foreach (
|
|
1004
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList
|
|
1005
|
+
)
|
|
1006
|
+
{
|
|
1007
|
+
RunBroadcast(ref source, ref typedMessage, entry.Key, entry.Value);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
finally
|
|
1011
|
+
{
|
|
1012
|
+
_sortedHandlers.Push(handlerList);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
_ = InternalBroadcastWithoutSource(ref source, ref typedMessage, type);
|
|
1018
|
+
|
|
1019
|
+
if (
|
|
1020
|
+
_postProcessingBroadcastSinks.TryGetValue(type, out broadcastHandlers)
|
|
1021
|
+
&& broadcastHandlers.TryGetValue(source, out sortedHandlers)
|
|
1022
|
+
&& 0 < sortedHandlers.Count
|
|
1023
|
+
)
|
|
1024
|
+
{
|
|
1025
|
+
foundAnyHandlers = true;
|
|
1026
|
+
if (sortedHandlers.Count == 1)
|
|
1027
|
+
{
|
|
1028
|
+
RunBroadcastPostProcessing(
|
|
1029
|
+
ref source,
|
|
1030
|
+
ref typedMessage,
|
|
1031
|
+
sortedHandlers.Keys[0],
|
|
1032
|
+
sortedHandlers.Values[0]
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
else
|
|
1036
|
+
{
|
|
1037
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
1038
|
+
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
1039
|
+
try
|
|
1040
|
+
{
|
|
1041
|
+
foreach (
|
|
1042
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList
|
|
1043
|
+
)
|
|
1044
|
+
{
|
|
1045
|
+
RunBroadcastPostProcessing(
|
|
1046
|
+
ref source,
|
|
1047
|
+
ref typedMessage,
|
|
1048
|
+
entry.Key,
|
|
1049
|
+
entry.Value
|
|
1050
|
+
);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
finally
|
|
1054
|
+
{
|
|
1055
|
+
_sortedHandlers.Push(handlerList);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
if (
|
|
1061
|
+
_postProcessingBroadcastWithoutSourceSinks.TryGetValue(type, out sortedHandlers)
|
|
1062
|
+
&& 0 < sortedHandlers.Count
|
|
1063
|
+
)
|
|
1064
|
+
{
|
|
1065
|
+
if (sortedHandlers.Count == 1)
|
|
1066
|
+
{
|
|
1067
|
+
RunBroadcastWithoutSourcePostProcessing(
|
|
1068
|
+
ref source,
|
|
1069
|
+
ref typedMessage,
|
|
1070
|
+
sortedHandlers.Keys[0],
|
|
1071
|
+
sortedHandlers.Values[0]
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
else
|
|
1075
|
+
{
|
|
1076
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
1077
|
+
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
1078
|
+
try
|
|
1079
|
+
{
|
|
1080
|
+
foreach (
|
|
1081
|
+
KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList
|
|
1082
|
+
)
|
|
1083
|
+
{
|
|
1084
|
+
RunBroadcastWithoutSourcePostProcessing(
|
|
1085
|
+
ref source,
|
|
1086
|
+
ref typedMessage,
|
|
1087
|
+
entry.Key,
|
|
1088
|
+
entry.Value
|
|
1089
|
+
);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
finally
|
|
1093
|
+
{
|
|
1094
|
+
_sortedHandlers.Push(handlerList);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
if (!foundAnyHandlers)
|
|
1100
|
+
{
|
|
1101
|
+
MessagingDebug.Log(
|
|
1102
|
+
LogLevel.Info,
|
|
1103
|
+
"Could not find a matching sourced broadcast handler for Id: {0}, Message: {1}.",
|
|
1104
|
+
source,
|
|
1105
|
+
typedMessage
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
private void RunBroadcastWithoutSourcePostProcessing<TMessage>(
|
|
1111
|
+
ref InstanceId source,
|
|
1112
|
+
ref TMessage typedMessage,
|
|
1113
|
+
int priority,
|
|
1114
|
+
SortedList<MessageHandler, int> handlers
|
|
1115
|
+
)
|
|
1116
|
+
where TMessage : IBroadcastMessage
|
|
1117
|
+
{
|
|
1118
|
+
switch (handlers.Count)
|
|
1119
|
+
{
|
|
1120
|
+
case <= 0:
|
|
1121
|
+
{
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
case 1:
|
|
1125
|
+
{
|
|
1126
|
+
MessageHandler handler = handlers.Keys[0];
|
|
1127
|
+
handler.HandleSourcedBroadcastWithoutSourcePostProcessing(
|
|
1128
|
+
ref source,
|
|
1129
|
+
ref typedMessage,
|
|
1130
|
+
this,
|
|
1131
|
+
priority
|
|
1132
|
+
);
|
|
1133
|
+
return;
|
|
1134
|
+
}
|
|
1135
|
+
default:
|
|
1136
|
+
{
|
|
1137
|
+
List<MessageHandler> messageHandlers = GetOrAddMessageHandlerStack(
|
|
1138
|
+
handlers.Keys
|
|
1139
|
+
);
|
|
1140
|
+
try
|
|
1141
|
+
{
|
|
1142
|
+
foreach (MessageHandler handler in messageHandlers)
|
|
1143
|
+
{
|
|
1144
|
+
handler.HandleSourcedBroadcastWithoutSourcePostProcessing(
|
|
1145
|
+
ref source,
|
|
1146
|
+
ref typedMessage,
|
|
1147
|
+
this,
|
|
1148
|
+
priority
|
|
1149
|
+
);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
finally
|
|
1153
|
+
{
|
|
1154
|
+
_messageHandlers.Push(messageHandlers);
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
break;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
private void RunBroadcastPostProcessing<TMessage>(
|
|
1163
|
+
ref InstanceId source,
|
|
1164
|
+
ref TMessage typedMessage,
|
|
1165
|
+
int priority,
|
|
1166
|
+
SortedList<MessageHandler, int> handlers
|
|
1167
|
+
)
|
|
1168
|
+
where TMessage : IBroadcastMessage
|
|
1169
|
+
{
|
|
1170
|
+
switch (handlers.Count)
|
|
1171
|
+
{
|
|
1172
|
+
case <= 0:
|
|
1173
|
+
{
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
case 1:
|
|
1177
|
+
{
|
|
1178
|
+
MessageHandler handler = handlers.Keys[0];
|
|
1179
|
+
handler.HandleSourcedBroadcastPostProcessing(
|
|
1180
|
+
ref source,
|
|
1181
|
+
ref typedMessage,
|
|
1182
|
+
this,
|
|
1183
|
+
priority
|
|
1184
|
+
);
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
default:
|
|
1188
|
+
{
|
|
1189
|
+
List<MessageHandler> messageHandlers = GetOrAddMessageHandlerStack(
|
|
1190
|
+
handlers.Keys
|
|
1191
|
+
);
|
|
1192
|
+
try
|
|
1193
|
+
{
|
|
1194
|
+
foreach (MessageHandler handler in messageHandlers)
|
|
1195
|
+
{
|
|
1196
|
+
handler.HandleSourcedBroadcastPostProcessing(
|
|
1197
|
+
ref source,
|
|
1198
|
+
ref typedMessage,
|
|
1199
|
+
this,
|
|
1200
|
+
priority
|
|
1201
|
+
);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
finally
|
|
1205
|
+
{
|
|
1206
|
+
_messageHandlers.Push(messageHandlers);
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
break;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
private void RunBroadcast<TMessage>(
|
|
1215
|
+
ref InstanceId source,
|
|
1216
|
+
ref TMessage typedMessage,
|
|
1217
|
+
int priority,
|
|
1218
|
+
SortedList<MessageHandler, int> handlers
|
|
1219
|
+
)
|
|
1220
|
+
where TMessage : IBroadcastMessage
|
|
1221
|
+
{
|
|
1222
|
+
switch (handlers.Count)
|
|
1223
|
+
{
|
|
1224
|
+
case <= 0:
|
|
1225
|
+
{
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
case 1:
|
|
1229
|
+
{
|
|
1230
|
+
MessageHandler handler = handlers.Keys[0];
|
|
1231
|
+
handler.HandleSourcedBroadcast(ref source, ref typedMessage, this, priority);
|
|
1232
|
+
return;
|
|
1233
|
+
}
|
|
1234
|
+
default:
|
|
1235
|
+
{
|
|
1236
|
+
List<MessageHandler> messageHandlers = GetOrAddMessageHandlerStack(
|
|
1237
|
+
handlers.Keys
|
|
1238
|
+
);
|
|
1239
|
+
try
|
|
1240
|
+
{
|
|
1241
|
+
foreach (MessageHandler handler in messageHandlers)
|
|
1242
|
+
{
|
|
1243
|
+
handler.HandleSourcedBroadcast(
|
|
1244
|
+
ref source,
|
|
1245
|
+
ref typedMessage,
|
|
1246
|
+
this,
|
|
1247
|
+
priority
|
|
1248
|
+
);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
finally
|
|
1252
|
+
{
|
|
1253
|
+
_messageHandlers.Push(messageHandlers);
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
break;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
private void BroadcastGlobalUntargeted(ref IUntargetedMessage message)
|
|
1262
|
+
{
|
|
1263
|
+
switch (_globalSinks.Count)
|
|
1264
|
+
{
|
|
1265
|
+
case <= 0:
|
|
1266
|
+
{
|
|
1267
|
+
return;
|
|
1268
|
+
}
|
|
1269
|
+
case 1:
|
|
1270
|
+
{
|
|
1271
|
+
MessageHandler handler = _globalSinks.Keys[0];
|
|
1272
|
+
handler.HandleGlobalUntargetedMessage(ref message, this);
|
|
1273
|
+
return;
|
|
1274
|
+
}
|
|
1275
|
+
default:
|
|
1276
|
+
{
|
|
1277
|
+
List<MessageHandler> messageHandlers = GetOrAddMessageHandlerStack(
|
|
1278
|
+
_globalSinks.Keys
|
|
1279
|
+
);
|
|
1280
|
+
try
|
|
1281
|
+
{
|
|
1282
|
+
foreach (MessageHandler handler in messageHandlers)
|
|
1283
|
+
{
|
|
1284
|
+
handler.HandleGlobalUntargetedMessage(ref message, this);
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
finally
|
|
1288
|
+
{
|
|
1289
|
+
_messageHandlers.Push(messageHandlers);
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
break;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
private void BroadcastGlobalTargeted(ref InstanceId target, ref ITargetedMessage message)
|
|
1298
|
+
{
|
|
1299
|
+
switch (_globalSinks.Count)
|
|
1300
|
+
{
|
|
1301
|
+
case <= 0:
|
|
1302
|
+
{
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
case 1:
|
|
1306
|
+
{
|
|
1307
|
+
MessageHandler handler = _globalSinks.Keys[0];
|
|
1308
|
+
handler.HandleGlobalTargetedMessage(ref target, ref message, this);
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
default:
|
|
1312
|
+
{
|
|
1313
|
+
List<MessageHandler> messageHandlers = GetOrAddMessageHandlerStack(
|
|
1314
|
+
_globalSinks.Keys
|
|
1315
|
+
);
|
|
1316
|
+
try
|
|
1317
|
+
{
|
|
1318
|
+
foreach (MessageHandler handler in messageHandlers)
|
|
1319
|
+
{
|
|
1320
|
+
handler.HandleGlobalTargetedMessage(ref target, ref message, this);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
finally
|
|
1324
|
+
{
|
|
1325
|
+
_messageHandlers.Push(messageHandlers);
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
break;
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
private void BroadcastGlobalSourcedBroadcast(
|
|
1334
|
+
ref InstanceId source,
|
|
1335
|
+
ref IBroadcastMessage message
|
|
1336
|
+
)
|
|
1337
|
+
{
|
|
1338
|
+
switch (_globalSinks.Count)
|
|
1339
|
+
{
|
|
1340
|
+
case <= 0:
|
|
1341
|
+
{
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
case 1:
|
|
1345
|
+
{
|
|
1346
|
+
MessageHandler handler = _globalSinks.Keys[0];
|
|
1347
|
+
handler.HandleGlobalSourcedBroadcastMessage(ref source, ref message, this);
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1350
|
+
default:
|
|
1351
|
+
{
|
|
1352
|
+
List<MessageHandler> messageHandlers = GetOrAddMessageHandlerStack(
|
|
1353
|
+
_globalSinks.Keys
|
|
1354
|
+
);
|
|
1355
|
+
try
|
|
1356
|
+
{
|
|
1357
|
+
foreach (MessageHandler handler in messageHandlers)
|
|
1358
|
+
{
|
|
1359
|
+
handler.HandleGlobalSourcedBroadcastMessage(
|
|
1360
|
+
ref source,
|
|
1361
|
+
ref message,
|
|
1362
|
+
this
|
|
1363
|
+
);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
finally
|
|
1367
|
+
{
|
|
1368
|
+
_messageHandlers.Push(messageHandlers);
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
break;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
private bool TryGetInterceptorCaches(
|
|
1377
|
+
Type type,
|
|
1378
|
+
out List<List<object>> interceptorStack,
|
|
1379
|
+
out List<object> interceptorObjects
|
|
1380
|
+
)
|
|
1381
|
+
{
|
|
1382
|
+
if (
|
|
1383
|
+
!_interceptsByType.TryGetValue(type, out SortedList<int, List<object>> interceptors)
|
|
1384
|
+
|| interceptors.Count <= 0
|
|
1385
|
+
)
|
|
1386
|
+
{
|
|
1387
|
+
interceptorStack = default;
|
|
1388
|
+
interceptorObjects = default;
|
|
1389
|
+
return false;
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
if (!_interceptors.TryPop(out interceptorStack))
|
|
1393
|
+
{
|
|
1394
|
+
interceptorStack = new List<List<object>>(interceptors.Values);
|
|
1395
|
+
}
|
|
1396
|
+
else
|
|
1397
|
+
{
|
|
1398
|
+
interceptorStack.Clear();
|
|
1399
|
+
switch (interceptors.Values)
|
|
1400
|
+
{
|
|
1401
|
+
case List<List<object>> list:
|
|
1402
|
+
{
|
|
1403
|
+
foreach (List<object> interceptor in list)
|
|
1404
|
+
{
|
|
1405
|
+
interceptorStack.Add(interceptor);
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
break;
|
|
1409
|
+
}
|
|
1410
|
+
case List<object>[] array:
|
|
1411
|
+
{
|
|
1412
|
+
foreach (List<object> interceptor in array)
|
|
1413
|
+
{
|
|
1414
|
+
interceptorStack.Add(interceptor);
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
break;
|
|
1418
|
+
}
|
|
1419
|
+
default:
|
|
1420
|
+
{
|
|
1421
|
+
// ReSharper disable once ForCanBeConvertedToForeach
|
|
1422
|
+
// ReSharper disable once LoopCanBeConvertedToQuery
|
|
1423
|
+
for (int i = 0; i < interceptors.Values.Count; i++)
|
|
1424
|
+
{
|
|
1425
|
+
List<object> interceptor = interceptors.Values[i];
|
|
1426
|
+
interceptorStack.Add(interceptor);
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
break;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
if (!_innerInterceptorsStack.TryPop(out interceptorObjects))
|
|
1435
|
+
{
|
|
1436
|
+
interceptorObjects = new List<object>();
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
return true;
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
private bool RunUntargetedInterceptors<T>(Type type, ref T message)
|
|
1443
|
+
where T : IUntargetedMessage
|
|
1444
|
+
{
|
|
1445
|
+
if (
|
|
1446
|
+
!TryGetInterceptorCaches(
|
|
1447
|
+
type,
|
|
1448
|
+
out List<List<object>> interceptorStack,
|
|
1449
|
+
out List<object> interceptorObjects
|
|
1450
|
+
)
|
|
1451
|
+
)
|
|
1452
|
+
{
|
|
1453
|
+
return true;
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
try
|
|
1457
|
+
{
|
|
1458
|
+
foreach (List<object> stack in interceptorStack)
|
|
1459
|
+
{
|
|
1460
|
+
interceptorObjects.Clear();
|
|
1461
|
+
foreach (object interceptor in stack)
|
|
1462
|
+
{
|
|
1463
|
+
interceptorObjects.Add(interceptor);
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
foreach (object transformer in interceptorObjects)
|
|
1467
|
+
{
|
|
1468
|
+
if (transformer is not UntargetedInterceptor<T> typedTransformer)
|
|
1469
|
+
{
|
|
1470
|
+
continue;
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
if (!typedTransformer(ref message))
|
|
1474
|
+
{
|
|
1475
|
+
return false;
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
finally
|
|
1481
|
+
{
|
|
1482
|
+
_interceptors.Push(interceptorStack);
|
|
1483
|
+
_innerInterceptorsStack.Push(interceptorObjects);
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
return true;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
private bool RunTargetedInterceptors<T>(Type type, ref T message, ref InstanceId target)
|
|
1490
|
+
where T : ITargetedMessage
|
|
1491
|
+
{
|
|
1492
|
+
if (
|
|
1493
|
+
!TryGetInterceptorCaches(
|
|
1494
|
+
type,
|
|
1495
|
+
out List<List<object>> interceptorStack,
|
|
1496
|
+
out List<object> interceptorObjects
|
|
1497
|
+
)
|
|
1498
|
+
)
|
|
1499
|
+
{
|
|
1500
|
+
return true;
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
try
|
|
1504
|
+
{
|
|
1505
|
+
foreach (List<object> stack in interceptorStack)
|
|
1506
|
+
{
|
|
1507
|
+
interceptorObjects.Clear();
|
|
1508
|
+
foreach (object interceptor in stack)
|
|
1509
|
+
{
|
|
1510
|
+
interceptorObjects.Add(interceptor);
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
foreach (object transformer in interceptorObjects)
|
|
1514
|
+
{
|
|
1515
|
+
if (transformer is not TargetedInterceptor<T> typedTransformer)
|
|
1516
|
+
{
|
|
1517
|
+
continue;
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
if (!typedTransformer(ref target, ref message))
|
|
1521
|
+
{
|
|
1522
|
+
return false;
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
finally
|
|
1528
|
+
{
|
|
1529
|
+
_interceptors.Push(interceptorStack);
|
|
1530
|
+
_innerInterceptorsStack.Push(interceptorObjects);
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
return true;
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
private bool RunBroadcastInterceptors<T>(Type type, ref T message, ref InstanceId source)
|
|
1537
|
+
where T : IBroadcastMessage
|
|
1538
|
+
{
|
|
1539
|
+
if (
|
|
1540
|
+
!TryGetInterceptorCaches(
|
|
1541
|
+
type,
|
|
1542
|
+
out List<List<object>> interceptorStack,
|
|
1543
|
+
out List<object> interceptorObjects
|
|
1544
|
+
)
|
|
1545
|
+
)
|
|
1546
|
+
{
|
|
1547
|
+
return true;
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
try
|
|
1551
|
+
{
|
|
1552
|
+
foreach (List<object> stack in interceptorStack)
|
|
1553
|
+
{
|
|
1554
|
+
interceptorObjects.Clear();
|
|
1555
|
+
foreach (object interceptor in stack)
|
|
1556
|
+
{
|
|
1557
|
+
interceptorObjects.Add(interceptor);
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
foreach (object transformer in interceptorObjects)
|
|
1561
|
+
{
|
|
1562
|
+
if (transformer is not BroadcastInterceptor<T> typedTransformer)
|
|
1563
|
+
{
|
|
1564
|
+
continue;
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
if (!typedTransformer(ref source, ref message))
|
|
1568
|
+
{
|
|
1569
|
+
return false;
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
finally
|
|
1575
|
+
{
|
|
1576
|
+
_interceptors.Push(interceptorStack);
|
|
1577
|
+
_innerInterceptorsStack.Push(interceptorObjects);
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
return true;
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
private bool InternalUntargetedBroadcast<TMessage>(ref TMessage message, Type type)
|
|
1584
|
+
where TMessage : IMessage
|
|
1585
|
+
{
|
|
1586
|
+
if (
|
|
1587
|
+
!_sinks.TryGetValue(
|
|
1588
|
+
type,
|
|
1589
|
+
out SortedList<int, SortedList<MessageHandler, int>> sortedHandlers
|
|
1590
|
+
)
|
|
1591
|
+
|| sortedHandlers.Count <= 0
|
|
1592
|
+
)
|
|
1593
|
+
{
|
|
1594
|
+
return false;
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
if (sortedHandlers.Count == 1)
|
|
1598
|
+
{
|
|
1599
|
+
RunUntargetedBroadcast(
|
|
1600
|
+
ref message,
|
|
1601
|
+
sortedHandlers.Keys[0],
|
|
1602
|
+
sortedHandlers.Values[0]
|
|
1603
|
+
);
|
|
1604
|
+
return true;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
1608
|
+
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
1609
|
+
try
|
|
1610
|
+
{
|
|
1611
|
+
foreach (KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList)
|
|
1612
|
+
{
|
|
1613
|
+
RunUntargetedBroadcast(ref message, entry.Key, entry.Value);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
finally
|
|
1617
|
+
{
|
|
1618
|
+
_sortedHandlers.Push(handlerList);
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
return true;
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
private void RunUntargetedBroadcast<TMessage>(
|
|
1625
|
+
ref TMessage message,
|
|
1626
|
+
int priority,
|
|
1627
|
+
SortedList<MessageHandler, int> handlers
|
|
1628
|
+
)
|
|
1629
|
+
where TMessage : IMessage
|
|
1630
|
+
{
|
|
1631
|
+
switch (handlers.Count)
|
|
1632
|
+
{
|
|
1633
|
+
case <= 0:
|
|
1634
|
+
{
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
case 1:
|
|
1638
|
+
{
|
|
1639
|
+
MessageHandler handler = handlers.Keys[0];
|
|
1640
|
+
handler.HandleUntargetedMessage(ref message, this, priority);
|
|
1641
|
+
return;
|
|
1642
|
+
}
|
|
1643
|
+
default:
|
|
1644
|
+
{
|
|
1645
|
+
List<MessageHandler> messageHandlers = GetOrAddMessageHandlerStack(
|
|
1646
|
+
handlers.Keys
|
|
1647
|
+
);
|
|
1648
|
+
try
|
|
1649
|
+
{
|
|
1650
|
+
foreach (MessageHandler handler in messageHandlers)
|
|
1651
|
+
{
|
|
1652
|
+
handler.HandleUntargetedMessage(ref message, this, priority);
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
finally
|
|
1656
|
+
{
|
|
1657
|
+
_messageHandlers.Push(messageHandlers);
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
break;
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
private bool InternalTargetedWithoutTargetingBroadcast<TMessage>(
|
|
1666
|
+
ref InstanceId target,
|
|
1667
|
+
ref TMessage message,
|
|
1668
|
+
Type type
|
|
1669
|
+
)
|
|
1670
|
+
where TMessage : ITargetedMessage
|
|
1671
|
+
{
|
|
1672
|
+
if (
|
|
1673
|
+
!_sinks.TryGetValue(
|
|
1674
|
+
type,
|
|
1675
|
+
out SortedList<int, SortedList<MessageHandler, int>> sortedHandlers
|
|
1676
|
+
)
|
|
1677
|
+
|| sortedHandlers.Count <= 0
|
|
1678
|
+
)
|
|
1679
|
+
{
|
|
1680
|
+
return false;
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
if (sortedHandlers.Count == 1)
|
|
1684
|
+
{
|
|
1685
|
+
RunTargetedWithoutTargeting(
|
|
1686
|
+
ref target,
|
|
1687
|
+
ref message,
|
|
1688
|
+
sortedHandlers.Keys[0],
|
|
1689
|
+
sortedHandlers.Values[0]
|
|
1690
|
+
);
|
|
1691
|
+
return true;
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
1695
|
+
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
1696
|
+
try
|
|
1697
|
+
{
|
|
1698
|
+
foreach (KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList)
|
|
1699
|
+
{
|
|
1700
|
+
RunTargetedWithoutTargeting(ref target, ref message, entry.Key, entry.Value);
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
finally
|
|
1704
|
+
{
|
|
1705
|
+
_sortedHandlers.Push(handlerList);
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
return true;
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
private void RunTargetedWithoutTargeting<TMessage>(
|
|
1712
|
+
ref InstanceId target,
|
|
1713
|
+
ref TMessage message,
|
|
1714
|
+
int priority,
|
|
1715
|
+
SortedList<MessageHandler, int> handlers
|
|
1716
|
+
)
|
|
1717
|
+
where TMessage : ITargetedMessage
|
|
1718
|
+
{
|
|
1719
|
+
switch (handlers.Count)
|
|
1720
|
+
{
|
|
1721
|
+
case <= 0:
|
|
1722
|
+
{
|
|
1723
|
+
return;
|
|
1724
|
+
}
|
|
1725
|
+
case 1:
|
|
1726
|
+
{
|
|
1727
|
+
MessageHandler handler = handlers.Keys[0];
|
|
1728
|
+
handler.HandleTargetedWithoutTargeting(ref target, ref message, this, priority);
|
|
1729
|
+
return;
|
|
1730
|
+
}
|
|
1731
|
+
default:
|
|
1732
|
+
{
|
|
1733
|
+
List<MessageHandler> messageHandlers = GetOrAddMessageHandlerStack(
|
|
1734
|
+
handlers.Keys
|
|
1735
|
+
);
|
|
1736
|
+
try
|
|
1737
|
+
{
|
|
1738
|
+
foreach (MessageHandler handler in messageHandlers)
|
|
1739
|
+
{
|
|
1740
|
+
handler.HandleTargetedWithoutTargeting(
|
|
1741
|
+
ref target,
|
|
1742
|
+
ref message,
|
|
1743
|
+
this,
|
|
1744
|
+
priority
|
|
1745
|
+
);
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
finally
|
|
1749
|
+
{
|
|
1750
|
+
_messageHandlers.Push(messageHandlers);
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
break;
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
private bool InternalBroadcastWithoutSource<TMessage>(
|
|
1759
|
+
ref InstanceId source,
|
|
1760
|
+
ref TMessage message,
|
|
1761
|
+
Type type
|
|
1762
|
+
)
|
|
1763
|
+
where TMessage : IBroadcastMessage
|
|
1764
|
+
{
|
|
1765
|
+
if (
|
|
1766
|
+
!_sinks.TryGetValue(
|
|
1767
|
+
type,
|
|
1768
|
+
out SortedList<int, SortedList<MessageHandler, int>> sortedHandlers
|
|
1769
|
+
)
|
|
1770
|
+
|| sortedHandlers.Count <= 0
|
|
1771
|
+
)
|
|
1772
|
+
{
|
|
1773
|
+
return false;
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
if (sortedHandlers.Count == 1)
|
|
1777
|
+
{
|
|
1778
|
+
RunBroadcastWithoutSource(
|
|
1779
|
+
ref source,
|
|
1780
|
+
ref message,
|
|
1781
|
+
sortedHandlers.Keys[0],
|
|
1782
|
+
sortedHandlers.Values[0]
|
|
1783
|
+
);
|
|
1784
|
+
return true;
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
List<KeyValuePair<int, SortedList<MessageHandler, int>>> handlerList =
|
|
1788
|
+
GetOrAddMessageHandlerStack(sortedHandlers);
|
|
1789
|
+
try
|
|
1790
|
+
{
|
|
1791
|
+
foreach (KeyValuePair<int, SortedList<MessageHandler, int>> entry in handlerList)
|
|
1792
|
+
{
|
|
1793
|
+
RunBroadcastWithoutSource(ref source, ref message, entry.Key, entry.Value);
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
finally
|
|
1797
|
+
{
|
|
1798
|
+
_sortedHandlers.Push(handlerList);
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
return true;
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
private void RunBroadcastWithoutSource<TMessage>(
|
|
1805
|
+
ref InstanceId source,
|
|
1806
|
+
ref TMessage message,
|
|
1807
|
+
int priority,
|
|
1808
|
+
SortedList<MessageHandler, int> handlers
|
|
1809
|
+
)
|
|
1810
|
+
where TMessage : IBroadcastMessage
|
|
1811
|
+
{
|
|
1812
|
+
switch (handlers.Count)
|
|
1813
|
+
{
|
|
1814
|
+
case <= 0:
|
|
1815
|
+
{
|
|
1816
|
+
return;
|
|
1817
|
+
}
|
|
1818
|
+
case 1:
|
|
1819
|
+
{
|
|
1820
|
+
MessageHandler handler = handlers.Keys[0];
|
|
1821
|
+
handler.HandleSourcedBroadcastWithoutSource(
|
|
1822
|
+
ref source,
|
|
1823
|
+
ref message,
|
|
1824
|
+
this,
|
|
1825
|
+
priority
|
|
1826
|
+
);
|
|
1827
|
+
return;
|
|
1828
|
+
}
|
|
1829
|
+
default:
|
|
1830
|
+
{
|
|
1831
|
+
List<MessageHandler> messageHandlers = GetOrAddMessageHandlerStack(
|
|
1832
|
+
handlers.Keys
|
|
1833
|
+
);
|
|
1834
|
+
try
|
|
1835
|
+
{
|
|
1836
|
+
foreach (MessageHandler handler in messageHandlers)
|
|
1837
|
+
{
|
|
1838
|
+
handler.HandleSourcedBroadcastWithoutSource(
|
|
1839
|
+
ref source,
|
|
1840
|
+
ref message,
|
|
1841
|
+
this,
|
|
1842
|
+
priority
|
|
1843
|
+
);
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
finally
|
|
1847
|
+
{
|
|
1848
|
+
_messageHandlers.Push(messageHandlers);
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
break;
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
private Action InternalRegisterUntargeted<T>(
|
|
1857
|
+
MessageHandler messageHandler,
|
|
1858
|
+
Dictionary<Type, SortedList<int, SortedList<MessageHandler, int>>> sinks,
|
|
1859
|
+
RegistrationMethod registrationMethod,
|
|
1860
|
+
int priority
|
|
1861
|
+
)
|
|
1862
|
+
where T : IMessage
|
|
1863
|
+
{
|
|
1864
|
+
if (messageHandler == null)
|
|
1865
|
+
{
|
|
1866
|
+
throw new ArgumentNullException(nameof(messageHandler));
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
InstanceId handlerOwnerId = messageHandler.owner;
|
|
1870
|
+
Type type = typeof(T);
|
|
1871
|
+
|
|
1872
|
+
if (
|
|
1873
|
+
!sinks.TryGetValue(
|
|
1874
|
+
type,
|
|
1875
|
+
out SortedList<int, SortedList<MessageHandler, int>> handlers
|
|
1876
|
+
)
|
|
1877
|
+
)
|
|
1878
|
+
{
|
|
1879
|
+
handlers = new SortedList<int, SortedList<MessageHandler, int>>();
|
|
1880
|
+
sinks[type] = handlers;
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
if (!handlers.TryGetValue(priority, out SortedList<MessageHandler, int> handler))
|
|
1884
|
+
{
|
|
1885
|
+
handler = new SortedList<MessageHandler, int>();
|
|
1886
|
+
handlers[priority] = handler;
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
int count = handler.GetValueOrDefault(messageHandler, 0);
|
|
1890
|
+
|
|
1891
|
+
handler[messageHandler] = count + 1;
|
|
1892
|
+
_log.Log(
|
|
1893
|
+
new MessagingRegistration(
|
|
1894
|
+
handlerOwnerId,
|
|
1895
|
+
type,
|
|
1896
|
+
RegistrationType.Register,
|
|
1897
|
+
registrationMethod
|
|
1898
|
+
)
|
|
1899
|
+
);
|
|
1900
|
+
|
|
1901
|
+
return () =>
|
|
1902
|
+
{
|
|
1903
|
+
_log.Log(
|
|
1904
|
+
new MessagingRegistration(
|
|
1905
|
+
handlerOwnerId,
|
|
1906
|
+
type,
|
|
1907
|
+
RegistrationType.Deregister,
|
|
1908
|
+
registrationMethod
|
|
1909
|
+
)
|
|
1910
|
+
);
|
|
1911
|
+
if (
|
|
1912
|
+
!sinks.TryGetValue(type, out handlers)
|
|
1913
|
+
|| !handlers.TryGetValue(priority, out handler)
|
|
1914
|
+
|| !handler.TryGetValue(messageHandler, out count)
|
|
1915
|
+
)
|
|
1916
|
+
{
|
|
1917
|
+
MessagingDebug.Log(
|
|
1918
|
+
LogLevel.Error,
|
|
1919
|
+
"Received over-deregistration of {0} for {1}. Check to make sure you're not calling (de)registration multiple times.",
|
|
1920
|
+
type,
|
|
1921
|
+
messageHandler
|
|
1922
|
+
);
|
|
1923
|
+
return;
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
if (count <= 1)
|
|
1927
|
+
{
|
|
1928
|
+
bool complete = handler.Remove(messageHandler);
|
|
1929
|
+
|
|
1930
|
+
if (handler.Count <= 0)
|
|
1931
|
+
{
|
|
1932
|
+
_ = handlers.Remove(priority);
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
if (handlers.Count <= 0)
|
|
1936
|
+
{
|
|
1937
|
+
_ = sinks.Remove(type);
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
if (!complete)
|
|
1941
|
+
{
|
|
1942
|
+
MessagingDebug.Log(
|
|
1943
|
+
LogLevel.Error,
|
|
1944
|
+
"Received over-deregistration of {0} for {1}. Check to make sure you're not calling (de)registration multiple times.",
|
|
1945
|
+
type,
|
|
1946
|
+
messageHandler
|
|
1947
|
+
);
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
else
|
|
1951
|
+
{
|
|
1952
|
+
handler[messageHandler] = count - 1;
|
|
1953
|
+
}
|
|
1954
|
+
};
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
private Action InternalRegisterWithContext<T>(
|
|
1958
|
+
InstanceId context,
|
|
1959
|
+
MessageHandler messageHandler,
|
|
1960
|
+
Dictionary<
|
|
1961
|
+
Type,
|
|
1962
|
+
Dictionary<InstanceId, SortedList<int, SortedList<MessageHandler, int>>>
|
|
1963
|
+
> sinks,
|
|
1964
|
+
RegistrationMethod registrationMethod,
|
|
1965
|
+
int priority
|
|
1966
|
+
)
|
|
1967
|
+
{
|
|
1968
|
+
if (messageHandler == null)
|
|
1969
|
+
{
|
|
1970
|
+
throw new ArgumentNullException(nameof(messageHandler));
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
Type type = typeof(T);
|
|
1974
|
+
if (
|
|
1975
|
+
!sinks.TryGetValue(
|
|
1976
|
+
type,
|
|
1977
|
+
out Dictionary<
|
|
1978
|
+
InstanceId,
|
|
1979
|
+
SortedList<int, SortedList<MessageHandler, int>>
|
|
1980
|
+
> broadcastHandlers
|
|
1981
|
+
)
|
|
1982
|
+
)
|
|
1983
|
+
{
|
|
1984
|
+
broadcastHandlers =
|
|
1985
|
+
new Dictionary<InstanceId, SortedList<int, SortedList<MessageHandler, int>>>();
|
|
1986
|
+
sinks[type] = broadcastHandlers;
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
if (
|
|
1990
|
+
!broadcastHandlers.TryGetValue(
|
|
1991
|
+
context,
|
|
1992
|
+
out SortedList<int, SortedList<MessageHandler, int>> handlers
|
|
1993
|
+
)
|
|
1994
|
+
)
|
|
1995
|
+
{
|
|
1996
|
+
handlers = new SortedList<int, SortedList<MessageHandler, int>>();
|
|
1997
|
+
broadcastHandlers[context] = handlers;
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
if (!handlers.TryGetValue(priority, out SortedList<MessageHandler, int> handler))
|
|
2001
|
+
{
|
|
2002
|
+
handler = new SortedList<MessageHandler, int>();
|
|
2003
|
+
handlers[priority] = handler;
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
int count = handler.GetValueOrDefault(messageHandler, 0);
|
|
2007
|
+
|
|
2008
|
+
handler[messageHandler] = count + 1;
|
|
2009
|
+
_log.Log(
|
|
2010
|
+
new MessagingRegistration(
|
|
2011
|
+
context,
|
|
2012
|
+
type,
|
|
2013
|
+
RegistrationType.Register,
|
|
2014
|
+
registrationMethod
|
|
2015
|
+
)
|
|
2016
|
+
);
|
|
2017
|
+
|
|
2018
|
+
return () =>
|
|
2019
|
+
{
|
|
2020
|
+
_log.Log(
|
|
2021
|
+
new MessagingRegistration(
|
|
2022
|
+
context,
|
|
2023
|
+
type,
|
|
2024
|
+
RegistrationType.Deregister,
|
|
2025
|
+
registrationMethod
|
|
2026
|
+
)
|
|
2027
|
+
);
|
|
2028
|
+
if (
|
|
2029
|
+
!sinks.TryGetValue(type, out broadcastHandlers)
|
|
2030
|
+
|| !broadcastHandlers.TryGetValue(context, out handlers)
|
|
2031
|
+
|| !handlers.TryGetValue(priority, out handler)
|
|
2032
|
+
|| !handler.TryGetValue(messageHandler, out count)
|
|
2033
|
+
)
|
|
2034
|
+
{
|
|
2035
|
+
MessagingDebug.Log(
|
|
2036
|
+
LogLevel.Error,
|
|
2037
|
+
"Received over-deregistration of {0} for {1}. Check to make sure you're not calling (de)registration multiple times.",
|
|
2038
|
+
type,
|
|
2039
|
+
messageHandler
|
|
2040
|
+
);
|
|
2041
|
+
return;
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
if (count <= 1)
|
|
2045
|
+
{
|
|
2046
|
+
bool complete = handler.Remove(messageHandler);
|
|
2047
|
+
if (handler.Count <= 0)
|
|
2048
|
+
{
|
|
2049
|
+
_ = handlers.Remove(priority);
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2052
|
+
if (handlers.Count <= 0)
|
|
2053
|
+
{
|
|
2054
|
+
_ = broadcastHandlers.Remove(context);
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
if (broadcastHandlers.Count <= 0)
|
|
2058
|
+
{
|
|
2059
|
+
_ = sinks.Remove(type);
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
if (!complete)
|
|
2063
|
+
{
|
|
2064
|
+
MessagingDebug.Log(
|
|
2065
|
+
LogLevel.Error,
|
|
2066
|
+
"Received over-deregistration of {0} for {1}. Check to make sure you're not calling (de)registration multiple times.",
|
|
2067
|
+
type,
|
|
2068
|
+
messageHandler
|
|
2069
|
+
);
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
else
|
|
2073
|
+
{
|
|
2074
|
+
handler[messageHandler] = count - 1;
|
|
2075
|
+
}
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
private List<
|
|
2080
|
+
KeyValuePair<int, SortedList<MessageHandler, int>>
|
|
2081
|
+
> GetOrAddMessageHandlerStack(
|
|
2082
|
+
IEnumerable<KeyValuePair<int, SortedList<MessageHandler, int>>> handlers
|
|
2083
|
+
)
|
|
2084
|
+
{
|
|
2085
|
+
if (
|
|
2086
|
+
!_sortedHandlers.TryPop(
|
|
2087
|
+
out List<KeyValuePair<int, SortedList<MessageHandler, int>>> messageHandlers
|
|
2088
|
+
)
|
|
2089
|
+
)
|
|
2090
|
+
{
|
|
2091
|
+
return new List<KeyValuePair<int, SortedList<MessageHandler, int>>>(handlers);
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
messageHandlers.Clear();
|
|
2095
|
+
if (handlers is SortedList<int, SortedList<MessageHandler, int>> sortedList)
|
|
2096
|
+
{
|
|
2097
|
+
for (int i = 0; i < sortedList.Count; ++i)
|
|
2098
|
+
{
|
|
2099
|
+
messageHandlers.Add(
|
|
2100
|
+
new KeyValuePair<int, SortedList<MessageHandler, int>>(
|
|
2101
|
+
sortedList.Keys[i],
|
|
2102
|
+
sortedList.Values[i]
|
|
2103
|
+
)
|
|
2104
|
+
);
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
else
|
|
2108
|
+
{
|
|
2109
|
+
messageHandlers.AddRange(handlers);
|
|
2110
|
+
}
|
|
2111
|
+
return messageHandlers;
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
private List<MessageHandler> GetOrAddMessageHandlerStack(
|
|
2115
|
+
IEnumerable<MessageHandler> handlers
|
|
2116
|
+
)
|
|
2117
|
+
{
|
|
2118
|
+
if (!_messageHandlers.TryPop(out List<MessageHandler> messageHandlers))
|
|
2119
|
+
{
|
|
2120
|
+
return new List<MessageHandler>(handlers);
|
|
2121
|
+
}
|
|
2122
|
+
|
|
2123
|
+
messageHandlers.Clear();
|
|
2124
|
+
// Try to avoid allocations if at all possible
|
|
2125
|
+
switch (handlers)
|
|
2126
|
+
{
|
|
2127
|
+
case List<MessageHandler> list:
|
|
2128
|
+
{
|
|
2129
|
+
foreach (MessageHandler handler in list)
|
|
2130
|
+
{
|
|
2131
|
+
messageHandlers.Add(handler);
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
break;
|
|
2135
|
+
}
|
|
2136
|
+
case MessageHandler[] array:
|
|
2137
|
+
{
|
|
2138
|
+
foreach (MessageHandler handler in array)
|
|
2139
|
+
{
|
|
2140
|
+
messageHandlers.Add(handler);
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
break;
|
|
2144
|
+
}
|
|
2145
|
+
case IList<MessageHandler> interfaceList:
|
|
2146
|
+
{
|
|
2147
|
+
for (int i = 0; i < interfaceList.Count; ++i)
|
|
2148
|
+
{
|
|
2149
|
+
messageHandlers.Add(interfaceList[i]);
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
break;
|
|
2153
|
+
}
|
|
2154
|
+
case HashSet<MessageHandler> set:
|
|
2155
|
+
{
|
|
2156
|
+
foreach (MessageHandler handler in set)
|
|
2157
|
+
{
|
|
2158
|
+
messageHandlers.Add(handler);
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2161
|
+
break;
|
|
2162
|
+
}
|
|
2163
|
+
default:
|
|
2164
|
+
{
|
|
2165
|
+
messageHandlers.AddRange(handlers);
|
|
2166
|
+
break;
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
return messageHandlers;
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
// https://blogs.msmvps.com/jonskeet/2008/08/09/making-reflection-fly-and-exploring-delegates/
|
|
2174
|
+
private static Action<IUntargetedMessage> UntargetedBroadcastReflectionHelper<T>(
|
|
2175
|
+
IMessageBus messageBus,
|
|
2176
|
+
MethodInfo methodInfo
|
|
2177
|
+
)
|
|
2178
|
+
where T : IUntargetedMessage
|
|
2179
|
+
{
|
|
2180
|
+
FastUntargetedBroadcast<T> untargetedBroadcast =
|
|
2181
|
+
(FastUntargetedBroadcast<T>)
|
|
2182
|
+
Delegate.CreateDelegate(
|
|
2183
|
+
typeof(FastUntargetedBroadcast<T>),
|
|
2184
|
+
messageBus,
|
|
2185
|
+
methodInfo
|
|
2186
|
+
);
|
|
2187
|
+
|
|
2188
|
+
return UntypedBroadcast;
|
|
2189
|
+
|
|
2190
|
+
void UntypedBroadcast(IUntargetedMessage message)
|
|
2191
|
+
{
|
|
2192
|
+
T typedMessage = (T)message;
|
|
2193
|
+
untargetedBroadcast(ref typedMessage);
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
private static Action<InstanceId, ITargetedMessage> TargetedBroadcastReflectionHelper<T>(
|
|
2198
|
+
IMessageBus messageBus,
|
|
2199
|
+
MethodInfo methodInfo
|
|
2200
|
+
)
|
|
2201
|
+
where T : ITargetedMessage
|
|
2202
|
+
{
|
|
2203
|
+
FastTargetedBroadcast<T> targetedBroadcast =
|
|
2204
|
+
(FastTargetedBroadcast<T>)
|
|
2205
|
+
Delegate.CreateDelegate(
|
|
2206
|
+
typeof(FastTargetedBroadcast<T>),
|
|
2207
|
+
messageBus,
|
|
2208
|
+
methodInfo
|
|
2209
|
+
);
|
|
2210
|
+
|
|
2211
|
+
return UntypedBroadcast;
|
|
2212
|
+
|
|
2213
|
+
void UntypedBroadcast(InstanceId target, ITargetedMessage message)
|
|
2214
|
+
{
|
|
2215
|
+
T typedMessage = (T)message;
|
|
2216
|
+
targetedBroadcast(ref target, ref typedMessage);
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
|
|
2220
|
+
private static Action<InstanceId, IBroadcastMessage> SourcedBroadcastReflectionHelper<T>(
|
|
2221
|
+
IMessageBus messageBus,
|
|
2222
|
+
MethodInfo methodInfo
|
|
2223
|
+
)
|
|
2224
|
+
where T : IBroadcastMessage
|
|
2225
|
+
{
|
|
2226
|
+
FastSourcedBroadcast<T> sourcedBroadcast =
|
|
2227
|
+
(FastSourcedBroadcast<T>)
|
|
2228
|
+
Delegate.CreateDelegate(
|
|
2229
|
+
typeof(FastSourcedBroadcast<T>),
|
|
2230
|
+
messageBus,
|
|
2231
|
+
methodInfo
|
|
2232
|
+
);
|
|
2233
|
+
|
|
2234
|
+
return UntypedBroadcast;
|
|
2235
|
+
|
|
2236
|
+
void UntypedBroadcast(InstanceId target, IBroadcastMessage message)
|
|
2237
|
+
{
|
|
2238
|
+
T typedMessage = (T)message;
|
|
2239
|
+
sourcedBroadcast(ref target, ref typedMessage);
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
}
|