-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for struct based routers
- Loading branch information
1 parent
c3c8237
commit 8d9da3b
Showing
12 changed files
with
638 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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,60 @@ | ||
|
||
using Nixie.Routers; | ||
|
||
namespace Nixie.Tests.Actors; | ||
|
||
public readonly struct RouterMessageStruct : IConsistentHashable | ||
{ | ||
public RouterMessageType Type { get; } | ||
|
||
public string Data { get; } | ||
|
||
public RouterMessageStruct(RouterMessageType type, string data) | ||
{ | ||
Type = type; | ||
Data = data; | ||
} | ||
|
||
public int GetHash() | ||
{ | ||
return Data switch | ||
{ | ||
"aaa" => 0, | ||
"bbb" => 1, | ||
"ccc" => 2, | ||
"ddd" => 3, | ||
"eee" => 4, | ||
_ => 0 | ||
}; | ||
} | ||
} | ||
|
||
public sealed class RouteeActorStruct : IActorStruct<RouterMessageStruct> | ||
{ | ||
private int receivedMessages; | ||
|
||
private readonly IActorContextStruct<RouteeActorStruct, RouterMessageStruct> context; | ||
|
||
public RouteeActorStruct(IActorContextStruct<RouteeActorStruct, RouterMessageStruct> context) | ||
{ | ||
this.context = context; | ||
} | ||
|
||
public int GetMessages() | ||
{ | ||
return receivedMessages; | ||
} | ||
|
||
private void IncrMessage() | ||
{ | ||
receivedMessages++; | ||
} | ||
|
||
public async Task Receive(RouterMessageStruct message) | ||
{ | ||
await Task.Yield(); | ||
|
||
if (message.Type == RouterMessageType.Route) | ||
IncrMessage(); | ||
} | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.