Skip to content

Commit

Permalink
Cs9 (#560)
Browse files Browse the repository at this point in the history
* update to C#9

* update to C#9

* record props

* record router configs

* Router messages as records

* Immutable lists in props

* Immutable lists in props

* Immutable lists in props

* RootContext is record

* MessageEnvelope.cs is record

* RemoteDeliver is record

* RemoteDeliver is record

* buildsteps

* buildsteps

* buildsteps
  • Loading branch information
rogeralsing authored Nov 1, 2020
1 parent cb2652c commit 9e8addf
Show file tree
Hide file tree
Showing 68 changed files with 388 additions and 609 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.102'
dotnet-version: '5.0.100-rc.2.20479.15'
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'

- name: Build
run: dotnet build -c Release
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.102'
dotnet-version: '5.0.100-rc.2.20479.15'
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'

- name: Run tests netcoreapp3.1
run: |
Expand Down
5 changes: 5 additions & 0 deletions ProtoActor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".meta", ".meta", "{222D5932
ProjectSection(SolutionItems) = preProject
README.md = README.md
Terminology.md = Terminology.md
.gitignore = .gitignore
.github\workflows\pull-request.yml = .github\workflows\pull-request.yml
.github\workflows\build-master.yml = .github\workflows\build-master.yml
.github\PULL_REQUEST_TEMPLATE.md = .github\PULL_REQUEST_TEMPLATE.md
.github\ISSUE_TEMPLATE.md = .github\ISSUE_TEMPLATE.md
EndProjectSection
EndProject
Global
Expand Down
5 changes: 4 additions & 1 deletion ProtoActor.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Asynkron/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=backoff/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=hashable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=pids/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=reff/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=routee/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=routees/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Spawner/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Spawner/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Watchee/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion benchmarks/RemoteBenchmark/Messages/Messages.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.11.4" />
Expand Down
1 change: 1 addition & 0 deletions benchmarks/RemoteBenchmark/Node1/Node1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<ServerGarbageCollection>true</ServerGarbageCollection>
<ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
<LangVersion>9</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Proto.Actor\Proto.Actor.csproj" />
Expand Down
1 change: 1 addition & 0 deletions benchmarks/RemoteBenchmark/Node2/Node2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<ServerGarbageCollection>true</ServerGarbageCollection>
<ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
<LangVersion>9</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Proto.Actor\Proto.Actor.csproj" />
Expand Down
1 change: 1 addition & 0 deletions examples/Chat/Client/Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>9</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Proto.Remote\Proto.Remote.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion examples/Chat/Messages/Chat.Messages.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Grpc.Tools" Version="2.23.0" PrivateAssets="All" />
Expand Down
1 change: 1 addition & 0 deletions examples/Chat/Server/Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>9</LangVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Proto.Remote\Proto.Remote.csproj" />
Expand Down
22 changes: 8 additions & 14 deletions src/Proto.Actor/Configuration/ActorSystemConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,17 @@
namespace Proto
{
[PublicAPI]
public class ActorSystemConfig
public record ActorSystemConfig
{
public static ActorSystemConfig Setup() => new ActorSystemConfig();

public TimeSpan DeadLetterThrottleInterval { get; set; }
public int DeadLetterThrottleCount { get; set; }
public TimeSpan DeadLetterThrottleInterval { get; init; }
public int DeadLetterThrottleCount { get; init; }

public ActorSystemConfig WithDeadLetterThrottleInterval(TimeSpan deadLetterThrottleInterval)
{
DeadLetterThrottleInterval = deadLetterThrottleInterval;
return this;
}

public ActorSystemConfig WithDeadLetterThrottleCount(int deadLetterThrottleCount)
{
DeadLetterThrottleCount = deadLetterThrottleCount;
return this;
}
public ActorSystemConfig WithDeadLetterThrottleInterval(TimeSpan deadLetterThrottleInterval) =>
this with { DeadLetterThrottleInterval = deadLetterThrottleInterval};

public ActorSystemConfig WithDeadLetterThrottleCount(int deadLetterThrottleCount) =>
this with {DeadLetterThrottleCount = deadLetterThrottleCount};
}
}
34 changes: 11 additions & 23 deletions src/Proto.Actor/Context/RootContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface IRootContext : ISpawnerContext, ISenderContext, IStopperContext
}

[PublicAPI]
public class RootContext : IRootContext
public record RootContext : IRootContext
{
public RootContext(ActorSystem system)
{
Expand All @@ -36,9 +36,9 @@ public RootContext(ActorSystem system, MessageHeader? messageHeader, params Func
Headers = messageHeader ?? MessageHeader.Empty;
}

private Sender? SenderMiddleware { get; set; }
private Sender? SenderMiddleware { get; init; }
public ActorSystem System { get; }
public MessageHeader Headers { get; private set; }
public MessageHeader Headers { get; init; }

public PID? Parent => null;
public PID? Self => null;
Expand Down Expand Up @@ -119,27 +119,15 @@ public Task PoisonAsync(PID pid)
return future.Task;
}

public RootContext WithHeaders(MessageHeader headers) => Copy(c => c.Headers = headers);
public RootContext WithHeaders(MessageHeader headers) =>
this with {Headers = headers};

public RootContext WithSenderMiddleware(params Func<Sender, Sender>[] middleware)
=> Copy(
c =>
{
SenderMiddleware = middleware.Reverse()
.Aggregate((Sender) DefaultSender, (inner, outer) => outer(inner));
}
);

private RootContext Copy(Action<RootContext> mutator)
{
var copy = new RootContext(System)
{
SenderMiddleware = SenderMiddleware,
Headers = Headers
};
mutator(copy);
return copy;
}
public RootContext WithSenderMiddleware(params Func<Sender, Sender>[] middleware) =>
this with {
SenderMiddleware = middleware.Reverse()
.Aggregate((Sender) DefaultSender, (inner, outer) => outer(inner))
};


private Task DefaultSender(ISenderContext context, PID target, MessageEnvelope message)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Threading.Tasks;
using Proto.Mailbox;

// ReSharper disable once CheckNamespace
namespace Proto
{
Expand All @@ -7,4 +9,10 @@ namespace Proto
public delegate Task Receiver(IReceiverContext context, MessageEnvelope envelope);

public delegate Task Sender(ISenderContext context, PID target, MessageEnvelope envelope);

public delegate PID Spawner(ActorSystem system, string id, Props props, PID? parent);

public delegate IActor Producer();

public delegate IMailbox MailboxProducer();
}
2 changes: 1 addition & 1 deletion src/Proto.Actor/Mailbox/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Proto.Mailbox
{
public abstract class SystemMessage
public interface SystemMessage
{
}

Expand Down
21 changes: 12 additions & 9 deletions src/Proto.Actor/Messages/MessageEnvelope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Proto
{
[PublicAPI]
public class MessageEnvelope
public record MessageEnvelope
{
public MessageEnvelope(object message, PID? sender, MessageHeader? header = null)
{
Expand All @@ -20,29 +20,32 @@ public MessageEnvelope(object message, PID? sender, MessageHeader? header = null
Header = header ?? MessageHeader.Empty;
}

public PID? Sender { get; }
public object Message { get; }
public MessageHeader Header { get; }
public PID? Sender { get; init; }
public object Message { get; init; }
public MessageHeader Header { get; init; }

public static MessageEnvelope Wrap(object message) =>
message is MessageEnvelope env ? env : new MessageEnvelope(message, null);

public MessageEnvelope WithSender(PID sender) => new MessageEnvelope(Message, sender, Header);
public MessageEnvelope WithSender(PID sender) =>
this with { Sender = sender};

public MessageEnvelope WithMessage(object message) => new MessageEnvelope(message, Sender, Header);
public MessageEnvelope WithMessage(object message) =>
this with {Message = message};

public MessageEnvelope WithHeader(MessageHeader header) => new MessageEnvelope(Message, Sender, header);
public MessageEnvelope WithHeader(MessageHeader header) =>
this with { Header = header};

public MessageEnvelope WithHeader(string key, string value)
{
var header = Header.With(key, value);
return new MessageEnvelope(Message, Sender, header);
return this with {Header = header};
}

public MessageEnvelope WithHeaders(IEnumerable<KeyValuePair<string, string>> items)
{
var header = Header.With(items);
return new MessageEnvelope(Message, Sender, header);
return this with {Header = header};
}

public static (object message, PID? sender, MessageHeader headers) Unwrap(object message)
Expand Down
47 changes: 18 additions & 29 deletions src/Proto.Actor/Messages/MessageHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,41 @@
namespace Proto
{
[PublicAPI]
public class MessageHeader : IReadOnlyDictionary<string, string>
public record MessageHeader : IReadOnlyDictionary<string, string>
{
public static readonly MessageHeader Empty = new MessageHeader();

private readonly ImmutableDictionary<string, string> _inner;

public MessageHeader()
{
_inner = ImmutableDictionary<string, string>.Empty;
}
public static readonly MessageHeader Empty = new MessageHeader(ImmutableDictionary<string, string>.Empty);

private ImmutableDictionary<string, string> Inner { get; init; }

public MessageHeader(IDictionary<string, string> headers)
{
_inner = headers.ToImmutableDictionary();
Inner = headers.ToImmutableDictionary();
}

public IEnumerator<KeyValuePair<string, string>> GetEnumerator() => _inner.GetEnumerator();
public IEnumerator<KeyValuePair<string, string>> GetEnumerator() => Inner.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => _inner.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => Inner.GetEnumerator();

public int Count => _inner.Count;
public int Count => Inner.Count;

public bool ContainsKey(string key) => _inner.ContainsKey(key);
public bool ContainsKey(string key) => Inner.ContainsKey(key);

public bool TryGetValue(string key, out string value) => _inner.TryGetValue(key, out value);
public bool TryGetValue(string key, out string value) => Inner.TryGetValue(key, out value);

public string this[string key] => _inner[key];
public string this[string key] => Inner[key];

public IEnumerable<string> Keys => _inner.Keys;
public IEnumerable<string> Values => _inner.Values;
public IEnumerable<string> Keys => Inner.Keys;
public IEnumerable<string> Values => Inner.Values;

public IDictionary<string, string> ToDictionary() => _inner;
public IDictionary<string, string> ToDictionary() => Inner;

public string? GetOrDefault(string key, string? @default = null) =>
TryGetValue(key, out var value) ? value : @default;

public MessageHeader With(string key, string value)
{
var copy = _inner.SetItem(key, value);
return new MessageHeader(copy);
}
public MessageHeader With(string key, string value) =>
this with { Inner = Inner.SetItem(key, value)};

public MessageHeader With(IEnumerable<KeyValuePair<string, string>> items)
{
var copy = _inner.SetItems(items);
return new MessageHeader(copy);
}
public MessageHeader With(IEnumerable<KeyValuePair<string, string>> items) =>
this with { Inner = Inner.SetItems(items)};
}
}
Loading

0 comments on commit 9e8addf

Please sign in to comment.