com.wallstop-studios.dxmessaging 2.1.3 → 2.1.4
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/.github/workflows/dotnet-tests.yml +2 -2
- package/.github/workflows/prettier-autofix.yml +0 -7
- package/.pre-commit-config.yaml +8 -5
- package/CONTRIBUTING.md +8 -2
- package/Docs/Performance.md +11 -11
- package/Runtime/Core/MessageBus/MessageBus.cs +75 -159
- package/Tests/Runtime/Core/Extensions/MessageBusExtensionsTests.cs +12 -31
- package/Tests/Runtime/Core/OrderingManyRegistrationsTests.cs +683 -0
- package/Tests/Runtime/Core/OrderingManyRegistrationsTests.cs.meta +11 -0
- package/package.json +1 -1
- package/scripts/fix-eol.js +38 -3
|
@@ -16,7 +16,7 @@ jobs:
|
|
|
16
16
|
|
|
17
17
|
steps:
|
|
18
18
|
- name: Checkout
|
|
19
|
-
uses: actions/checkout@
|
|
19
|
+
uses: actions/checkout@v5
|
|
20
20
|
|
|
21
21
|
- name: Setup .NET
|
|
22
22
|
uses: actions/setup-dotnet@v5
|
|
@@ -47,7 +47,7 @@ jobs:
|
|
|
47
47
|
cat artifacts/coverage/Summary.txt
|
|
48
48
|
|
|
49
49
|
- name: Upload coverage report
|
|
50
|
-
uses: actions/upload-artifact@
|
|
50
|
+
uses: actions/upload-artifact@v5
|
|
51
51
|
with:
|
|
52
52
|
name: generator-coverage
|
|
53
53
|
path: artifacts/coverage
|
|
@@ -46,10 +46,6 @@ jobs:
|
|
|
46
46
|
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
|
|
47
47
|
run: npx --yes markdownlint-cli@0.40.0 "**/*.md" "**/*.markdown" --config .markdownlint.json --ignore-path .markdownlintignore --fix
|
|
48
48
|
|
|
49
|
-
- name: Fix EOL/BOM (Dependabot only)
|
|
50
|
-
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
|
|
51
|
-
run: node scripts/fix-eol.js -v
|
|
52
|
-
|
|
53
49
|
- name: Commit formatting changes to PR branch (Dependabot only)
|
|
54
50
|
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login == 'dependabot[bot]' }}
|
|
55
51
|
uses: stefanzweifel/git-auto-commit-action@v7
|
|
@@ -118,9 +114,6 @@ jobs:
|
|
|
118
114
|
- name: Markdownlint (auto-fix)
|
|
119
115
|
run: npx --yes markdownlint-cli@0.40.0 "**/*.md" "**/*.markdown" --config .markdownlint.json --ignore-path .markdownlintignore --fix
|
|
120
116
|
|
|
121
|
-
- name: Fix EOL/BOM
|
|
122
|
-
run: node scripts/fix-eol.js -v
|
|
123
|
-
|
|
124
117
|
- name: Detect changes
|
|
125
118
|
id: changes
|
|
126
119
|
shell: bash
|
package/.pre-commit-config.yaml
CHANGED
|
@@ -57,14 +57,17 @@ repos:
|
|
|
57
57
|
|
|
58
58
|
- repo: local
|
|
59
59
|
hooks:
|
|
60
|
-
- id: eol
|
|
61
|
-
name:
|
|
62
|
-
entry: node scripts/fix-eol.js
|
|
60
|
+
- id: fix-eol
|
|
61
|
+
name: Normalize CRLF and strip BOM
|
|
62
|
+
entry: node scripts/fix-eol.js
|
|
63
63
|
language: system
|
|
64
|
-
pass_filenames: false
|
|
65
64
|
stages:
|
|
66
65
|
- pre-commit
|
|
67
|
-
|
|
66
|
+
pass_filenames: true
|
|
67
|
+
description: Automatically rewrite text files to match CI EOL/BOM policy.
|
|
68
|
+
|
|
69
|
+
- repo: local
|
|
70
|
+
hooks:
|
|
68
71
|
- id: eol-bom-check
|
|
69
72
|
name: Enforce CRLF and no BOM
|
|
70
73
|
entry: node scripts/check-eol.js
|
package/CONTRIBUTING.md
CHANGED
|
@@ -8,7 +8,12 @@ Before committing, please enable our git hooks and local linters so you catch is
|
|
|
8
8
|
- Install hooks: `pre-commit install`
|
|
9
9
|
- Run on all files: `pre-commit run --all-files`
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Line endings: Git already normalizes files to CRLF through `.gitattributes`. Run this once after cloning (especially on Windows) so your working tree matches CI:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
git config core.autocrlf false
|
|
15
|
+
git add --renormalize .
|
|
16
|
+
```
|
|
12
17
|
|
|
13
18
|
What runs locally:
|
|
14
19
|
|
|
@@ -29,5 +34,6 @@ Handy commands:
|
|
|
29
34
|
- Format JSON/.asmdef (manual): `npx prettier@3.6.2 --write "**/*.{json,asmdef}"`
|
|
30
35
|
- Format YAML (all files): `pre-commit run prettier-yaml --all-files`
|
|
31
36
|
- Check YAML formatting + lint: `npm run check:yaml`
|
|
32
|
-
- Fix EOL/BOM issues quickly: `node scripts/fix-eol.js -v`
|
|
33
37
|
- Format C#: `dotnet tool restore && dotnet tool run csharpier format`
|
|
38
|
+
|
|
39
|
+
If you do still need to repair line endings manually (for example, after copying files from an external tool), run `node scripts/fix-eol.js -v` and then re-stage the affected files.
|
package/Docs/Performance.md
CHANGED
|
@@ -14,17 +14,17 @@ See also: [Performance optimizations](./DesignAndArchitecture.md#performance-opt
|
|
|
14
14
|
|
|
15
15
|
| Message Tech | Operations / Second | Allocations? |
|
|
16
16
|
| ------------------------------------------ | ------------------- | ------------ |
|
|
17
|
-
| Unity | 2,
|
|
18
|
-
| DxMessaging (GameObject) - Normal | 8,
|
|
19
|
-
| DxMessaging (Component) - Normal | 8,
|
|
20
|
-
| DxMessaging (GameObject) - No-Copy | 9,
|
|
21
|
-
| DxMessaging (Component) - No-Copy | 9,
|
|
22
|
-
| DxMessaging (Untargeted) - No-Copy |
|
|
23
|
-
| DxMessaging (Untargeted) - Interceptors | 6,
|
|
24
|
-
| DxMessaging (Untargeted) - Post-Processors | 5,
|
|
25
|
-
| Reflexive (One Argument) | 2,
|
|
26
|
-
| Reflexive (Two Arguments) | 2,
|
|
27
|
-
| Reflexive (Three Arguments) | 2,
|
|
17
|
+
| Unity | 2,522,000 | Yes |
|
|
18
|
+
| DxMessaging (GameObject) - Normal | 8,606,000 | No |
|
|
19
|
+
| DxMessaging (Component) - Normal | 8,608,000 | No |
|
|
20
|
+
| DxMessaging (GameObject) - No-Copy | 9,534,000 | No |
|
|
21
|
+
| DxMessaging (Component) - No-Copy | 9,658,000 | No |
|
|
22
|
+
| DxMessaging (Untargeted) - No-Copy | 15,008,000 | No |
|
|
23
|
+
| DxMessaging (Untargeted) - Interceptors | 6,944,000 | No |
|
|
24
|
+
| DxMessaging (Untargeted) - Post-Processors | 5,146,000 | No |
|
|
25
|
+
| Reflexive (One Argument) | 2,822,000 | No |
|
|
26
|
+
| Reflexive (Two Arguments) | 2,370,000 | No |
|
|
27
|
+
| Reflexive (Three Arguments) | 2,342,000 | No |
|
|
28
28
|
|
|
29
29
|
## macOS
|
|
30
30
|
|
|
@@ -47,6 +47,18 @@ namespace DxMessaging.Core.MessageBus
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
private sealed class InterceptorCache<TValue>
|
|
51
|
+
{
|
|
52
|
+
public readonly SortedList<int, List<TValue>> handlers = new();
|
|
53
|
+
public long lastSeenEmissionId;
|
|
54
|
+
|
|
55
|
+
public void Clear()
|
|
56
|
+
{
|
|
57
|
+
handlers.Clear();
|
|
58
|
+
lastSeenEmissionId = 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
50
62
|
private sealed class HandlerCache
|
|
51
63
|
{
|
|
52
64
|
public readonly Dictionary<MessageHandler, int> handlers = new();
|
|
@@ -165,12 +177,9 @@ namespace DxMessaging.Core.MessageBus
|
|
|
165
177
|
private readonly HandlerCache _globalSinks = new();
|
|
166
178
|
|
|
167
179
|
// Interceptors split by category to avoid mixing types
|
|
168
|
-
private readonly MessageCache<
|
|
169
|
-
|
|
170
|
-
private readonly MessageCache<
|
|
171
|
-
new();
|
|
172
|
-
private readonly MessageCache<HandlerCache<int, List<object>>> _broadcastInterceptsByType =
|
|
173
|
-
new();
|
|
180
|
+
private readonly MessageCache<InterceptorCache<object>> _untargetedInterceptsByType = new();
|
|
181
|
+
private readonly MessageCache<InterceptorCache<object>> _targetedInterceptsByType = new();
|
|
182
|
+
private readonly MessageCache<InterceptorCache<object>> _broadcastInterceptsByType = new();
|
|
174
183
|
private readonly Dictionary<object, Dictionary<int, int>> _uniqueInterceptorsAndPriorities =
|
|
175
184
|
new();
|
|
176
185
|
|
|
@@ -367,29 +376,9 @@ namespace DxMessaging.Core.MessageBus
|
|
|
367
376
|
)
|
|
368
377
|
where T : IUntargetedMessage
|
|
369
378
|
{
|
|
370
|
-
|
|
379
|
+
InterceptorCache<object> prioritizedInterceptors =
|
|
371
380
|
_untargetedInterceptsByType.GetOrAdd<T>();
|
|
372
381
|
|
|
373
|
-
if (
|
|
374
|
-
!prioritizedInterceptors.handlers.TryGetValue(
|
|
375
|
-
priority,
|
|
376
|
-
out List<object> interceptors
|
|
377
|
-
)
|
|
378
|
-
)
|
|
379
|
-
{
|
|
380
|
-
prioritizedInterceptors.version++;
|
|
381
|
-
interceptors = new List<object>();
|
|
382
|
-
prioritizedInterceptors.handlers[priority] = interceptors;
|
|
383
|
-
// maintain sorted order
|
|
384
|
-
List<int> order = prioritizedInterceptors.order;
|
|
385
|
-
int idx = 0;
|
|
386
|
-
while (idx < order.Count && order[idx] < priority)
|
|
387
|
-
{
|
|
388
|
-
idx++;
|
|
389
|
-
}
|
|
390
|
-
order.Insert(idx, priority);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
382
|
if (
|
|
394
383
|
!_uniqueInterceptorsAndPriorities.TryGetValue(
|
|
395
384
|
interceptor,
|
|
@@ -401,6 +390,13 @@ namespace DxMessaging.Core.MessageBus
|
|
|
401
390
|
_uniqueInterceptorsAndPriorities[interceptor] = priorityCount;
|
|
402
391
|
}
|
|
403
392
|
|
|
393
|
+
List<object> interceptors;
|
|
394
|
+
if (!prioritizedInterceptors.handlers.TryGetValue(priority, out interceptors))
|
|
395
|
+
{
|
|
396
|
+
interceptors = new List<object>();
|
|
397
|
+
prioritizedInterceptors.handlers.Add(priority, interceptors);
|
|
398
|
+
}
|
|
399
|
+
|
|
404
400
|
if (!priorityCount.TryGetValue(priority, out int count))
|
|
405
401
|
{
|
|
406
402
|
count = 0;
|
|
@@ -464,20 +460,17 @@ namespace DxMessaging.Core.MessageBus
|
|
|
464
460
|
{
|
|
465
461
|
if (_untargetedInterceptsByType.TryGetValue<T>(out prioritizedInterceptors))
|
|
466
462
|
{
|
|
467
|
-
prioritizedInterceptors.version++;
|
|
468
463
|
if (
|
|
469
|
-
prioritizedInterceptors.handlers.TryGetValue(
|
|
464
|
+
prioritizedInterceptors.handlers.TryGetValue(
|
|
465
|
+
priority,
|
|
466
|
+
out List<object> interceptors
|
|
467
|
+
)
|
|
470
468
|
)
|
|
471
469
|
{
|
|
472
470
|
complete = interceptors.Remove(interceptor);
|
|
473
471
|
if (interceptors.Count == 0)
|
|
474
472
|
{
|
|
475
473
|
_ = prioritizedInterceptors.handlers.Remove(priority);
|
|
476
|
-
int removeIdx = prioritizedInterceptors.order.IndexOf(priority);
|
|
477
|
-
if (removeIdx >= 0)
|
|
478
|
-
{
|
|
479
|
-
prioritizedInterceptors.order.RemoveAt(removeIdx);
|
|
480
|
-
}
|
|
481
474
|
}
|
|
482
475
|
}
|
|
483
476
|
}
|
|
@@ -501,29 +494,9 @@ namespace DxMessaging.Core.MessageBus
|
|
|
501
494
|
)
|
|
502
495
|
where T : ITargetedMessage
|
|
503
496
|
{
|
|
504
|
-
|
|
497
|
+
InterceptorCache<object> prioritizedInterceptors =
|
|
505
498
|
_targetedInterceptsByType.GetOrAdd<T>();
|
|
506
499
|
|
|
507
|
-
if (
|
|
508
|
-
!prioritizedInterceptors.handlers.TryGetValue(
|
|
509
|
-
priority,
|
|
510
|
-
out List<object> interceptors
|
|
511
|
-
)
|
|
512
|
-
)
|
|
513
|
-
{
|
|
514
|
-
prioritizedInterceptors.version++;
|
|
515
|
-
interceptors = new List<object>();
|
|
516
|
-
prioritizedInterceptors.handlers[priority] = interceptors;
|
|
517
|
-
// maintain sorted order
|
|
518
|
-
List<int> order = prioritizedInterceptors.order;
|
|
519
|
-
int idx = 0;
|
|
520
|
-
while (idx < order.Count && order[idx] < priority)
|
|
521
|
-
{
|
|
522
|
-
idx++;
|
|
523
|
-
}
|
|
524
|
-
order.Insert(idx, priority);
|
|
525
|
-
}
|
|
526
|
-
|
|
527
500
|
if (
|
|
528
501
|
!_uniqueInterceptorsAndPriorities.TryGetValue(
|
|
529
502
|
interceptor,
|
|
@@ -535,6 +508,13 @@ namespace DxMessaging.Core.MessageBus
|
|
|
535
508
|
_uniqueInterceptorsAndPriorities[interceptor] = priorityCount;
|
|
536
509
|
}
|
|
537
510
|
|
|
511
|
+
List<object> interceptors;
|
|
512
|
+
if (!prioritizedInterceptors.handlers.TryGetValue(priority, out interceptors))
|
|
513
|
+
{
|
|
514
|
+
interceptors = new List<object>();
|
|
515
|
+
prioritizedInterceptors.handlers.Add(priority, interceptors);
|
|
516
|
+
}
|
|
517
|
+
|
|
538
518
|
if (!priorityCount.TryGetValue(priority, out int count))
|
|
539
519
|
{
|
|
540
520
|
count = 0;
|
|
@@ -598,20 +578,17 @@ namespace DxMessaging.Core.MessageBus
|
|
|
598
578
|
{
|
|
599
579
|
if (_targetedInterceptsByType.TryGetValue<T>(out prioritizedInterceptors))
|
|
600
580
|
{
|
|
601
|
-
prioritizedInterceptors.version++;
|
|
602
581
|
if (
|
|
603
|
-
prioritizedInterceptors.handlers.TryGetValue(
|
|
582
|
+
prioritizedInterceptors.handlers.TryGetValue(
|
|
583
|
+
priority,
|
|
584
|
+
out List<object> interceptors
|
|
585
|
+
)
|
|
604
586
|
)
|
|
605
587
|
{
|
|
606
588
|
complete = interceptors.Remove(interceptor);
|
|
607
589
|
if (interceptors.Count == 0)
|
|
608
590
|
{
|
|
609
591
|
_ = prioritizedInterceptors.handlers.Remove(priority);
|
|
610
|
-
int removeIdx = prioritizedInterceptors.order.IndexOf(priority);
|
|
611
|
-
if (removeIdx >= 0)
|
|
612
|
-
{
|
|
613
|
-
prioritizedInterceptors.order.RemoveAt(removeIdx);
|
|
614
|
-
}
|
|
615
592
|
}
|
|
616
593
|
}
|
|
617
594
|
}
|
|
@@ -635,29 +612,9 @@ namespace DxMessaging.Core.MessageBus
|
|
|
635
612
|
)
|
|
636
613
|
where T : IBroadcastMessage
|
|
637
614
|
{
|
|
638
|
-
|
|
615
|
+
InterceptorCache<object> prioritizedInterceptors =
|
|
639
616
|
_broadcastInterceptsByType.GetOrAdd<T>();
|
|
640
617
|
|
|
641
|
-
if (
|
|
642
|
-
!prioritizedInterceptors.handlers.TryGetValue(
|
|
643
|
-
priority,
|
|
644
|
-
out List<object> interceptors
|
|
645
|
-
)
|
|
646
|
-
)
|
|
647
|
-
{
|
|
648
|
-
prioritizedInterceptors.version++;
|
|
649
|
-
interceptors = new List<object>();
|
|
650
|
-
prioritizedInterceptors.handlers[priority] = interceptors;
|
|
651
|
-
// maintain sorted order
|
|
652
|
-
List<int> order = prioritizedInterceptors.order;
|
|
653
|
-
int idx = 0;
|
|
654
|
-
while (idx < order.Count && order[idx] < priority)
|
|
655
|
-
{
|
|
656
|
-
idx++;
|
|
657
|
-
}
|
|
658
|
-
order.Insert(idx, priority);
|
|
659
|
-
}
|
|
660
|
-
|
|
661
618
|
if (
|
|
662
619
|
!_uniqueInterceptorsAndPriorities.TryGetValue(
|
|
663
620
|
interceptor,
|
|
@@ -669,6 +626,13 @@ namespace DxMessaging.Core.MessageBus
|
|
|
669
626
|
_uniqueInterceptorsAndPriorities[interceptor] = priorityCount;
|
|
670
627
|
}
|
|
671
628
|
|
|
629
|
+
List<object> interceptors;
|
|
630
|
+
if (!prioritizedInterceptors.handlers.TryGetValue(priority, out interceptors))
|
|
631
|
+
{
|
|
632
|
+
interceptors = new List<object>();
|
|
633
|
+
prioritizedInterceptors.handlers.Add(priority, interceptors);
|
|
634
|
+
}
|
|
635
|
+
|
|
672
636
|
if (!priorityCount.TryGetValue(priority, out int count))
|
|
673
637
|
{
|
|
674
638
|
count = 0;
|
|
@@ -732,20 +696,17 @@ namespace DxMessaging.Core.MessageBus
|
|
|
732
696
|
{
|
|
733
697
|
if (_broadcastInterceptsByType.TryGetValue<T>(out prioritizedInterceptors))
|
|
734
698
|
{
|
|
735
|
-
prioritizedInterceptors.version++;
|
|
736
699
|
if (
|
|
737
|
-
prioritizedInterceptors.handlers.TryGetValue(
|
|
700
|
+
prioritizedInterceptors.handlers.TryGetValue(
|
|
701
|
+
priority,
|
|
702
|
+
out List<object> interceptors
|
|
703
|
+
)
|
|
738
704
|
)
|
|
739
705
|
{
|
|
740
706
|
complete = interceptors.Remove(interceptor);
|
|
741
707
|
if (interceptors.Count == 0)
|
|
742
708
|
{
|
|
743
709
|
_ = prioritizedInterceptors.handlers.Remove(priority);
|
|
744
|
-
int removeIdx = prioritizedInterceptors.order.IndexOf(priority);
|
|
745
|
-
if (removeIdx >= 0)
|
|
746
|
-
{
|
|
747
|
-
prioritizedInterceptors.order.RemoveAt(removeIdx);
|
|
748
|
-
}
|
|
749
710
|
}
|
|
750
711
|
}
|
|
751
712
|
}
|
|
@@ -3010,39 +2971,24 @@ namespace DxMessaging.Core.MessageBus
|
|
|
3010
2971
|
}
|
|
3011
2972
|
|
|
3012
2973
|
private bool TryGetUntargetedInterceptorCaches<TMessage>(
|
|
3013
|
-
out
|
|
2974
|
+
out SortedList<int, List<object>> interceptorHandlers,
|
|
3014
2975
|
out List<object> interceptorObjects
|
|
3015
2976
|
)
|
|
3016
2977
|
where TMessage : IUntargetedMessage
|
|
3017
2978
|
{
|
|
3018
2979
|
if (
|
|
3019
2980
|
!_untargetedInterceptsByType.TryGetValue<TMessage>(
|
|
3020
|
-
out
|
|
2981
|
+
out InterceptorCache<object> interceptors
|
|
3021
2982
|
)
|
|
3022
2983
|
|| interceptors.handlers.Count == 0
|
|
3023
2984
|
)
|
|
3024
2985
|
{
|
|
3025
|
-
|
|
2986
|
+
interceptorHandlers = default;
|
|
3026
2987
|
interceptorObjects = default;
|
|
3027
2988
|
return false;
|
|
3028
2989
|
}
|
|
3029
2990
|
|
|
3030
|
-
|
|
3031
|
-
if (interceptors.version != interceptors.lastSeenVersion)
|
|
3032
|
-
{
|
|
3033
|
-
interceptorStack.Clear();
|
|
3034
|
-
List<int> keys = interceptors.order;
|
|
3035
|
-
for (int i = 0; i < keys.Count; ++i)
|
|
3036
|
-
{
|
|
3037
|
-
int key = keys[i];
|
|
3038
|
-
if (interceptors.handlers.TryGetValue(key, out List<object> values))
|
|
3039
|
-
{
|
|
3040
|
-
interceptorStack.Add(new KeyValuePair<int, List<object>>(key, values));
|
|
3041
|
-
}
|
|
3042
|
-
}
|
|
3043
|
-
|
|
3044
|
-
interceptors.lastSeenVersion = interceptors.version;
|
|
3045
|
-
}
|
|
2991
|
+
interceptorHandlers = interceptors.handlers;
|
|
3046
2992
|
|
|
3047
2993
|
if (!_innerInterceptorsStack.TryPop(out interceptorObjects))
|
|
3048
2994
|
{
|
|
@@ -3053,39 +2999,24 @@ namespace DxMessaging.Core.MessageBus
|
|
|
3053
2999
|
}
|
|
3054
3000
|
|
|
3055
3001
|
private bool TryGetTargetedInterceptorCaches<TMessage>(
|
|
3056
|
-
out
|
|
3002
|
+
out SortedList<int, List<object>> interceptorHandlers,
|
|
3057
3003
|
out List<object> interceptorObjects
|
|
3058
3004
|
)
|
|
3059
3005
|
where TMessage : ITargetedMessage
|
|
3060
3006
|
{
|
|
3061
3007
|
if (
|
|
3062
3008
|
!_targetedInterceptsByType.TryGetValue<TMessage>(
|
|
3063
|
-
out
|
|
3009
|
+
out InterceptorCache<object> interceptors
|
|
3064
3010
|
)
|
|
3065
3011
|
|| interceptors.handlers.Count == 0
|
|
3066
3012
|
)
|
|
3067
3013
|
{
|
|
3068
|
-
|
|
3014
|
+
interceptorHandlers = default;
|
|
3069
3015
|
interceptorObjects = default;
|
|
3070
3016
|
return false;
|
|
3071
3017
|
}
|
|
3072
3018
|
|
|
3073
|
-
|
|
3074
|
-
if (interceptors.version != interceptors.lastSeenVersion)
|
|
3075
|
-
{
|
|
3076
|
-
interceptorStack.Clear();
|
|
3077
|
-
List<int> keys = interceptors.order;
|
|
3078
|
-
for (int i = 0; i < keys.Count; ++i)
|
|
3079
|
-
{
|
|
3080
|
-
int key = keys[i];
|
|
3081
|
-
if (interceptors.handlers.TryGetValue(key, out List<object> values))
|
|
3082
|
-
{
|
|
3083
|
-
interceptorStack.Add(new KeyValuePair<int, List<object>>(key, values));
|
|
3084
|
-
}
|
|
3085
|
-
}
|
|
3086
|
-
|
|
3087
|
-
interceptors.lastSeenVersion = interceptors.version;
|
|
3088
|
-
}
|
|
3019
|
+
interceptorHandlers = interceptors.handlers;
|
|
3089
3020
|
|
|
3090
3021
|
if (!_innerInterceptorsStack.TryPop(out interceptorObjects))
|
|
3091
3022
|
{
|
|
@@ -3096,39 +3027,24 @@ namespace DxMessaging.Core.MessageBus
|
|
|
3096
3027
|
}
|
|
3097
3028
|
|
|
3098
3029
|
private bool TryGetBroadcastInterceptorCaches<TMessage>(
|
|
3099
|
-
out
|
|
3030
|
+
out SortedList<int, List<object>> interceptorHandlers,
|
|
3100
3031
|
out List<object> interceptorObjects
|
|
3101
3032
|
)
|
|
3102
3033
|
where TMessage : IBroadcastMessage
|
|
3103
3034
|
{
|
|
3104
3035
|
if (
|
|
3105
3036
|
!_broadcastInterceptsByType.TryGetValue<TMessage>(
|
|
3106
|
-
out
|
|
3037
|
+
out InterceptorCache<object> interceptors
|
|
3107
3038
|
)
|
|
3108
3039
|
|| interceptors.handlers.Count == 0
|
|
3109
3040
|
)
|
|
3110
3041
|
{
|
|
3111
|
-
|
|
3042
|
+
interceptorHandlers = default;
|
|
3112
3043
|
interceptorObjects = default;
|
|
3113
3044
|
return false;
|
|
3114
3045
|
}
|
|
3115
3046
|
|
|
3116
|
-
|
|
3117
|
-
if (interceptors.version != interceptors.lastSeenVersion)
|
|
3118
|
-
{
|
|
3119
|
-
interceptorStack.Clear();
|
|
3120
|
-
List<int> keys = interceptors.order;
|
|
3121
|
-
for (int i = 0; i < keys.Count; ++i)
|
|
3122
|
-
{
|
|
3123
|
-
int key = keys[i];
|
|
3124
|
-
if (interceptors.handlers.TryGetValue(key, out List<object> values))
|
|
3125
|
-
{
|
|
3126
|
-
interceptorStack.Add(new KeyValuePair<int, List<object>>(key, values));
|
|
3127
|
-
}
|
|
3128
|
-
}
|
|
3129
|
-
|
|
3130
|
-
interceptors.lastSeenVersion = interceptors.version;
|
|
3131
|
-
}
|
|
3047
|
+
interceptorHandlers = interceptors.handlers;
|
|
3132
3048
|
|
|
3133
3049
|
if (!_innerInterceptorsStack.TryPop(out interceptorObjects))
|
|
3134
3050
|
{
|
|
@@ -3143,7 +3059,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
3143
3059
|
{
|
|
3144
3060
|
if (
|
|
3145
3061
|
!TryGetUntargetedInterceptorCaches<T>(
|
|
3146
|
-
out
|
|
3062
|
+
out SortedList<int, List<object>> interceptorHandlers,
|
|
3147
3063
|
out List<object> interceptorObjects
|
|
3148
3064
|
)
|
|
3149
3065
|
)
|
|
@@ -3153,11 +3069,11 @@ namespace DxMessaging.Core.MessageBus
|
|
|
3153
3069
|
|
|
3154
3070
|
try
|
|
3155
3071
|
{
|
|
3156
|
-
|
|
3072
|
+
IList<List<object>> prioritizedInterceptors = interceptorHandlers.Values;
|
|
3073
|
+
for (int s = 0; s < prioritizedInterceptors.Count; ++s)
|
|
3157
3074
|
{
|
|
3158
|
-
KeyValuePair<int, List<object>> entry = interceptorStack[s];
|
|
3159
3075
|
interceptorObjects.Clear();
|
|
3160
|
-
List<object> interceptors =
|
|
3076
|
+
List<object> interceptors = prioritizedInterceptors[s];
|
|
3161
3077
|
interceptorObjects.AddRange(interceptors);
|
|
3162
3078
|
|
|
3163
3079
|
for (int i = 0; i < interceptorObjects.Count; ++i)
|
|
@@ -3185,7 +3101,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
3185
3101
|
{
|
|
3186
3102
|
if (
|
|
3187
3103
|
!TryGetTargetedInterceptorCaches<T>(
|
|
3188
|
-
out
|
|
3104
|
+
out SortedList<int, List<object>> interceptorHandlers,
|
|
3189
3105
|
out List<object> interceptorObjects
|
|
3190
3106
|
)
|
|
3191
3107
|
)
|
|
@@ -3195,11 +3111,11 @@ namespace DxMessaging.Core.MessageBus
|
|
|
3195
3111
|
|
|
3196
3112
|
try
|
|
3197
3113
|
{
|
|
3198
|
-
|
|
3114
|
+
IList<List<object>> prioritizedInterceptors = interceptorHandlers.Values;
|
|
3115
|
+
for (int s = 0; s < prioritizedInterceptors.Count; ++s)
|
|
3199
3116
|
{
|
|
3200
|
-
KeyValuePair<int, List<object>> entry = interceptorStack[s];
|
|
3201
3117
|
interceptorObjects.Clear();
|
|
3202
|
-
List<object> interceptors =
|
|
3118
|
+
List<object> interceptors = prioritizedInterceptors[s];
|
|
3203
3119
|
interceptorObjects.AddRange(interceptors);
|
|
3204
3120
|
|
|
3205
3121
|
for (int i = 0; i < interceptorObjects.Count; ++i)
|
|
@@ -3227,7 +3143,7 @@ namespace DxMessaging.Core.MessageBus
|
|
|
3227
3143
|
{
|
|
3228
3144
|
if (
|
|
3229
3145
|
!TryGetBroadcastInterceptorCaches<T>(
|
|
3230
|
-
out
|
|
3146
|
+
out SortedList<int, List<object>> interceptorHandlers,
|
|
3231
3147
|
out List<object> interceptorObjects
|
|
3232
3148
|
)
|
|
3233
3149
|
)
|
|
@@ -3237,11 +3153,11 @@ namespace DxMessaging.Core.MessageBus
|
|
|
3237
3153
|
|
|
3238
3154
|
try
|
|
3239
3155
|
{
|
|
3240
|
-
|
|
3156
|
+
IList<List<object>> prioritizedInterceptors = interceptorHandlers.Values;
|
|
3157
|
+
for (int s = 0; s < prioritizedInterceptors.Count; ++s)
|
|
3241
3158
|
{
|
|
3242
|
-
KeyValuePair<int, List<object>> entry = interceptorStack[s];
|
|
3243
3159
|
interceptorObjects.Clear();
|
|
3244
|
-
List<object> interceptors =
|
|
3160
|
+
List<object> interceptors = prioritizedInterceptors[s];
|
|
3245
3161
|
interceptorObjects.AddRange(interceptors);
|
|
3246
3162
|
|
|
3247
3163
|
for (int i = 0; i < interceptorObjects.Count; ++i)
|
|
@@ -33,9 +33,7 @@ namespace DxMessaging.Tests.Runtime.Core.Extensions
|
|
|
33
33
|
MessageHandler handler = new MessageHandler(new InstanceId(10), bus) { active = true };
|
|
34
34
|
MessageRegistrationToken token = MessageRegistrationToken.Create(handler, bus);
|
|
35
35
|
int count = 0;
|
|
36
|
-
_ = token.RegisterUntargeted
|
|
37
|
-
(ref ClassUntargetedMessage _) => count++
|
|
38
|
-
);
|
|
36
|
+
_ = token.RegisterUntargeted((ref ClassUntargetedMessage _) => count++);
|
|
39
37
|
token.Enable();
|
|
40
38
|
|
|
41
39
|
ClassUntargetedMessage message = new ClassUntargetedMessage();
|
|
@@ -52,9 +50,7 @@ namespace DxMessaging.Tests.Runtime.Core.Extensions
|
|
|
52
50
|
MessageHandler handler = new MessageHandler(new InstanceId(20), bus) { active = true };
|
|
53
51
|
MessageRegistrationToken token = MessageRegistrationToken.Create(handler, bus);
|
|
54
52
|
int count = 0;
|
|
55
|
-
_ = token.RegisterUntargeted
|
|
56
|
-
(ref StructUntargetedMessage _) => count++
|
|
57
|
-
);
|
|
53
|
+
_ = token.RegisterUntargeted((ref StructUntargetedMessage _) => count++);
|
|
58
54
|
token.Enable();
|
|
59
55
|
|
|
60
56
|
StructUntargetedMessage message = new StructUntargetedMessage(1);
|
|
@@ -73,7 +69,7 @@ namespace DxMessaging.Tests.Runtime.Core.Extensions
|
|
|
73
69
|
StructInterceptedMessage intercepted = default;
|
|
74
70
|
int postProcessCount = 0;
|
|
75
71
|
|
|
76
|
-
_ = bus.RegisterUntargetedInterceptor
|
|
72
|
+
_ = bus.RegisterUntargetedInterceptor(
|
|
77
73
|
(ref StructInterceptedMessage msg) =>
|
|
78
74
|
{
|
|
79
75
|
msg.Value += 10;
|
|
@@ -81,11 +77,9 @@ namespace DxMessaging.Tests.Runtime.Core.Extensions
|
|
|
81
77
|
}
|
|
82
78
|
);
|
|
83
79
|
|
|
84
|
-
_ = token.RegisterUntargeted
|
|
85
|
-
(ref StructInterceptedMessage msg) => intercepted = msg
|
|
86
|
-
);
|
|
80
|
+
_ = token.RegisterUntargeted((ref StructInterceptedMessage msg) => intercepted = msg);
|
|
87
81
|
|
|
88
|
-
_ = token.RegisterUntargetedPostProcessor
|
|
82
|
+
_ = token.RegisterUntargetedPostProcessor(
|
|
89
83
|
(ref StructInterceptedMessage _) => postProcessCount++
|
|
90
84
|
);
|
|
91
85
|
|
|
@@ -108,9 +102,7 @@ namespace DxMessaging.Tests.Runtime.Core.Extensions
|
|
|
108
102
|
MessageRegistrationToken token = MessageRegistrationToken.Create(handler, bus);
|
|
109
103
|
int busSum = 0;
|
|
110
104
|
|
|
111
|
-
_ = token.RegisterUntargeted
|
|
112
|
-
(ref StructUntargetedMessage msg) => busSum += msg.Value
|
|
113
|
-
);
|
|
105
|
+
_ = token.RegisterUntargeted((ref StructUntargetedMessage msg) => busSum += msg.Value);
|
|
114
106
|
|
|
115
107
|
token.Enable();
|
|
116
108
|
|
|
@@ -132,7 +124,7 @@ namespace DxMessaging.Tests.Runtime.Core.Extensions
|
|
|
132
124
|
MessageRegistrationToken token2 = MessageRegistrationToken.Create(handler2, bus);
|
|
133
125
|
int messageSum = 0;
|
|
134
126
|
|
|
135
|
-
_ = token2.RegisterUntargeted
|
|
127
|
+
_ = token2.RegisterUntargeted(
|
|
136
128
|
(ref StructUntargetedMessage msg) => messageSum += msg.Value
|
|
137
129
|
);
|
|
138
130
|
|
|
@@ -158,10 +150,7 @@ namespace DxMessaging.Tests.Runtime.Core.Extensions
|
|
|
158
150
|
MessageHandler handler = new MessageHandler(new InstanceId(30), bus) { active = true };
|
|
159
151
|
MessageRegistrationToken token = MessageRegistrationToken.Create(handler, bus);
|
|
160
152
|
int count = 0;
|
|
161
|
-
_ = token.RegisterTargeted
|
|
162
|
-
target,
|
|
163
|
-
(ref StructTargetedMessage _) => count++
|
|
164
|
-
);
|
|
153
|
+
_ = token.RegisterTargeted(target, (ref StructTargetedMessage _) => count++);
|
|
165
154
|
token.Enable();
|
|
166
155
|
|
|
167
156
|
StructTargetedMessage message = new StructTargetedMessage(5);
|
|
@@ -180,10 +169,7 @@ namespace DxMessaging.Tests.Runtime.Core.Extensions
|
|
|
180
169
|
MessageHandler handler = new MessageHandler(new InstanceId(40), bus) { active = true };
|
|
181
170
|
MessageRegistrationToken token = MessageRegistrationToken.Create(handler, bus);
|
|
182
171
|
int count = 0;
|
|
183
|
-
_ = token.RegisterBroadcast
|
|
184
|
-
source,
|
|
185
|
-
(ref StructBroadcastMessage _) => count++
|
|
186
|
-
);
|
|
172
|
+
_ = token.RegisterBroadcast(source, (ref StructBroadcastMessage _) => count++);
|
|
187
173
|
token.Enable();
|
|
188
174
|
|
|
189
175
|
StructBroadcastMessage message = new StructBroadcastMessage(7);
|
|
@@ -206,19 +192,14 @@ namespace DxMessaging.Tests.Runtime.Core.Extensions
|
|
|
206
192
|
string broadcast = null;
|
|
207
193
|
string untargeted = null;
|
|
208
194
|
|
|
209
|
-
_ = token.RegisterTargeted
|
|
210
|
-
target,
|
|
211
|
-
(ref StringMessage m) => targeted = m.message
|
|
212
|
-
);
|
|
195
|
+
_ = token.RegisterTargeted(target, (ref StringMessage m) => targeted = m.message);
|
|
213
196
|
|
|
214
|
-
_ = token.RegisterBroadcast
|
|
197
|
+
_ = token.RegisterBroadcast(
|
|
215
198
|
source,
|
|
216
199
|
(ref SourcedStringMessage m) => broadcast = m.message
|
|
217
200
|
);
|
|
218
201
|
|
|
219
|
-
_ = token.RegisterUntargeted
|
|
220
|
-
(ref GlobalStringMessage m) => untargeted = m.message
|
|
221
|
-
);
|
|
202
|
+
_ = token.RegisterUntargeted((ref GlobalStringMessage m) => untargeted = m.message);
|
|
222
203
|
|
|
223
204
|
token.Enable();
|
|
224
205
|
|