-
Notifications
You must be signed in to change notification settings - Fork 8
[On Hold] Feature steam improvements and Extract streaming from GAgentBase. #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arg-foo
wants to merge
16
commits into
dev
Choose a base branch
from
feature-steam-auric
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
183b76a
feat: add EventDispatcherWorkerGrain to dispatch events to children.
eanzhao b6d8772
merge branch fix/plugins
eanzhao ca9c50e
feat: add a new stream for children on GAgentBase.
eanzhao caf0120
resolve conflicts with dev.
eanzhao b76ea1b
feat: add EventPubGrain.
eanzhao 6b45438
feat: framework of event pub grains
eanzhao 7cd23b3
fix test cases.
eanzhao e188a82
resolve conflicts with dev and fix test cases.
eanzhao ecb43ab
feat: add test cases for register & unregister.
eanzhao 411dea0
Go
loning 766bfc0
Update TestGrainFactory.cs
loning 7d2802e
resolve conflicts with dev.
eanzhao 420ac33
feat: add logs to new grains.
eanzhao d3c547a
resolve conflicts with dev.
eanzhao d8700e9
feat: register StateDispatcher as transient.
eanzhao 9884fba
Update AevatarGAgentConstants.cs
eanzhao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| namespace Aevatar.Core.Abstractions; | ||
|
|
||
| public static class AevatarCoreStreamConfig | ||
| { | ||
| public static string Prefix { get; private set; } = AevatarCoreConstants.DefaultStreamNamespace; | ||
|
|
||
| public static void Initialize(string? prefix) | ||
| { | ||
| if (prefix != null) | ||
| { | ||
| Prefix = prefix; | ||
| } | ||
| } | ||
| } | ||
16 changes: 16 additions & 0 deletions
16
src/Aevatar.Core.Abstractions/EventPublish/IEventPubChildrenGroupGrain.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| namespace Aevatar.Core.Abstractions.EventPublish; | ||
|
|
||
| using Orleans.Concurrency; | ||
|
|
||
| public interface IEventPubChildrenGroupGrain : IGrainWithIntegerCompoundKey | ||
| { | ||
| Task DownwardsEventAsync(EventWrapperBase eventWrapper); | ||
| Task UpwardsEventAsync(EventWrapperBase eventWrapper); | ||
| Task AddChildAsync(GrainId childGrainId); | ||
| Task AddManyChildAsync(List<GrainId> childrenGrainIds); | ||
| Task RemoveChildAsync(GrainId childId); | ||
| [ReadOnly] | ||
| Task<List<GrainId>> GetChildrenAsync(); | ||
| [ReadOnly] | ||
| Task<int> GetChildrenCountAsync(); | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/Aevatar.Core.Abstractions/EventPublish/IStreamCoordinatorGrain.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| using Orleans.Concurrency; | ||
|
|
||
| namespace Aevatar.Core.Abstractions.EventPublish; | ||
|
|
||
| public interface IStreamCoordinatorGrain : IGrainWithStringKey | ||
| { | ||
| Task<bool> SetParentAsync(GrainId parentGrainId); | ||
| Task ClearParentAsync(GrainId parentGrainId); | ||
| Task SetGroupIndexAsync(int groupIndex); | ||
| [ReadOnly] | ||
| Task<int> GetGroupIndexAsync(); | ||
| [ReadOnly] | ||
| Task<GrainId> GetParentAsync(); | ||
| Task<int> RegisterChildAsync(GrainId childGrainId); | ||
| Task<int> RegisterManyChildAsync(List<GrainId> childrenGrainIds); | ||
| Task UnregisterChildAsync(GrainId childGrainId); | ||
| [ReadOnly] | ||
| Task<List<GrainId>> GetChildrenAsync(); | ||
| Task PublishEventAsync(EventWrapperBase eventWrapper); | ||
| Task DownwardsEventAsync(EventWrapperBase eventWrapper); | ||
| Task UpwardsEventAsync(EventWrapperBase eventWrapper); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
src/Aevatar.Core/EventPublish/EventPubChildrenGroupGrain.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| using Aevatar.Core.Abstractions; | ||
| using Aevatar.Core.Abstractions.EventPublish; | ||
| using Aevatar.Core.Extensions; | ||
| using Microsoft.Extensions.Logging; | ||
| using Newtonsoft.Json; | ||
| using Orleans.EventSourcing; | ||
| using Orleans.Providers; | ||
| using Orleans.Streams; | ||
| using Orleans.Concurrency; | ||
|
|
||
| namespace Aevatar.Core.EventPublish; | ||
|
|
||
| [GenerateSerializer] | ||
| public class EventPubChildrenGroupState : StateBase | ||
| { | ||
| [Id(0)] public List<GrainId> Children { get; set; } = new(); | ||
| [Id(1)] public int ChildrenCount { get; set; } | ||
| } | ||
|
|
||
| [GenerateSerializer] | ||
| public class EventPubChildrenGroupStateLogEvent : StateLogEventBase<EventPubChildrenGroupStateLogEvent>; | ||
|
|
||
| [StorageProvider(ProviderName = "PubSubStore")] | ||
| [LogConsistencyProvider(ProviderName = "LogStorage")] | ||
| [Reentrant] | ||
| public class EventPubChildrenGroupGrain : | ||
| JournaledGrain<EventPubChildrenGroupState, StateLogEventBase<EventPubChildrenGroupStateLogEvent>>, | ||
| IEventPubChildrenGroupGrain | ||
| { | ||
| private readonly ILogger<EventPubChildrenGroupGrain> _logger; | ||
| private readonly IStreamProvider _streamProvider; | ||
|
|
||
| public EventPubChildrenGroupGrain(ILogger<EventPubChildrenGroupGrain> logger) | ||
| { | ||
| _logger = logger; | ||
| _streamProvider = this.GetStreamProvider(AevatarCoreConstants.StreamProvider); | ||
| } | ||
|
|
||
| public async Task DownwardsEventAsync(EventWrapperBase eventWrapper) | ||
| { | ||
| _logger.LogInformation("[{grainId}] Starting DownwardsEventAsync for Event: {eventWrapper}", | ||
| this.GetGrainId().ToString(), | ||
| JsonConvert.SerializeObject(eventWrapper)); | ||
|
|
||
| foreach (var childGrainId in State.Children) | ||
| { | ||
| var stream = _streamProvider.GetEventWrapperBaseStream(childGrainId.ToString()); | ||
| await stream.OnNextAsync(eventWrapper); | ||
| } | ||
| } | ||
|
|
||
| public async Task UpwardsEventAsync(EventWrapperBase eventWrapper) | ||
| { | ||
| _logger.LogInformation("[{grainId}] Starting UpwardsEventAsync for Event: {eventWrapper}", | ||
| this.GetGrainId().ToString(), | ||
| JsonConvert.SerializeObject(eventWrapper)); | ||
|
|
||
| var stream = _streamProvider.GetEventWrapperBaseStream(this.GetPrimaryKeyString()); | ||
| await stream.OnNextAsync(eventWrapper); | ||
| } | ||
|
|
||
| public async Task AddChildAsync(GrainId childGrainId) | ||
| { | ||
| _logger.LogInformation("[{grainId}] Adding child GrainId: {GrainId}", this.GetGrainId().ToString(), | ||
| childGrainId); | ||
|
|
||
| RaiseEvent(new AddChildStateLogEvent { ChildId = childGrainId }); | ||
| await ConfirmEvents(); | ||
| } | ||
|
|
||
| public async Task AddManyChildAsync(List<GrainId> childrenGrainIds) | ||
| { | ||
| _logger.LogInformation("[{grainId}] Adding multiple children GrainIds: {childrenGrainIds}", | ||
| this.GetGrainId().ToString(), string.Join(", ", childrenGrainIds.ToString())); | ||
|
|
||
| base.RaiseEvent(new AddChildManyStateLogEvent | ||
| { | ||
| ChildrenIds = childrenGrainIds | ||
| }); | ||
| await ConfirmEvents(); | ||
| } | ||
|
|
||
| public async Task RemoveChildAsync(GrainId childId) | ||
| { | ||
| _logger.LogInformation("[{grainId}] Removing child GrainId: {GrainId}", this.GetGrainId().ToString(), | ||
| childId); | ||
|
|
||
| RaiseEvent(new RemoveChildStateLogEvent { ChildId = childId }); | ||
| await ConfirmEvents(); | ||
| } | ||
|
|
||
| public Task<List<GrainId>> GetChildrenAsync() | ||
| { | ||
| return Task.FromResult(State.Children); | ||
| } | ||
|
|
||
| public Task<int> GetChildrenCountAsync() | ||
| { | ||
| return Task.FromResult(State.ChildrenCount); | ||
| } | ||
|
|
||
| protected override void TransitionState(EventPubChildrenGroupState state, | ||
| StateLogEventBase<EventPubChildrenGroupStateLogEvent> @event) | ||
| { | ||
| switch (@event) | ||
| { | ||
| case AddChildStateLogEvent addChildEvent: | ||
| state.Children.Add(addChildEvent.ChildId); | ||
| state.ChildrenCount++; | ||
| break; | ||
| case AddChildManyStateLogEvent addChildManyEvent: | ||
| state.Children.AddRange(addChildManyEvent.ChildrenIds); | ||
| state.ChildrenCount += addChildManyEvent.ChildrenIds.Count; | ||
| break; | ||
| case RemoveChildStateLogEvent removeChildEvent: | ||
| state.Children.Remove(removeChildEvent.ChildId); | ||
| state.ChildrenCount--; | ||
| break; | ||
| } | ||
|
|
||
| base.TransitionState(state, @event); | ||
| } | ||
|
|
||
| [GenerateSerializer] | ||
| public class AddChildStateLogEvent : StateLogEventBase<EventPubChildrenGroupStateLogEvent> | ||
| { | ||
| [Id(0)] public required GrainId ChildId { get; set; } | ||
| } | ||
|
|
||
| [GenerateSerializer] | ||
| public class AddChildManyStateLogEvent : StateLogEventBase<EventPubChildrenGroupStateLogEvent> | ||
| { | ||
| [Id(0)] public required List<GrainId> ChildrenIds { get; set; } | ||
| } | ||
|
|
||
| [GenerateSerializer] | ||
| public class RemoveChildStateLogEvent : StateLogEventBase<EventPubChildrenGroupStateLogEvent> | ||
| { | ||
| [Id(0)] public required GrainId ChildId { get; set; } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this GAgentNamespaceSeparator serving any purpose?