Skip to content

Commit

Permalink
Merge pull request #10 from LiamMorrow/orleans-serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamMorrow authored May 25, 2020
2 parents f03ed43 + f99309e commit 61bbe17
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 75 deletions.
11 changes: 11 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project>
<PropertyGroup>
<Version>1.3.0-prerelease</Version>
<Authors>Liam Morrow</Authors>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IncludeSource>true</IncludeSource>
<RepositoryUrl>https://github.com/LiamMorrow/OrgnalR</RepositoryUrl>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public DelegateClientMessageObserver(string connectionId, Func<AddressedMessage,
this.onSubscriptionEnded = onSubscriptionEnded ?? throw new ArgumentNullException(nameof(onSubscriptionEnded));
}

public void ReceiveMessage(HubInvocationMessage message, MessageHandle handle)
public void ReceiveMessage(MethodMessage message, MessageHandle handle)
{
messageCallback(new AddressedMessage(connectionId, message), handle).Ignore();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@
</PropertyGroup>
<PropertyGroup>
<PackageId>OrgnalR.Backplane.GrainAdaptors</PackageId>
<Version>1.2.1</Version>
<Authors>Liam Morrow</Authors>
<Title>
OrgnalR Backplane Grain Adaptors
</Title>
<Description>
A core package of OrgnalR. You likely want one of either `OrgnalR.SignalR`, or `OrgnalR.OrleansSilo`
</Description>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IncludeSource>true</IncludeSource>
<RepositoryUrl>https://github.com/LiamMorrow/OrgnalR</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\OrgnalR.Backplane.GrainInterfaces\OrgnalR.Backplane.GrainInterfaces.csproj" />
Expand Down
6 changes: 3 additions & 3 deletions src/OrgnalR.Backplane.GrainImplementations/ClientGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public class ClientGrain : Grain, IClientGrain
OnFailBeforeDefunct = x => x.SubscriptionEnded()
};

private IRewindableMessageGrain<HubInvocationMessage> rewoundMessagesGrain = null!;
private IRewindableMessageGrain<MethodMessage> rewoundMessagesGrain = null!;

public override Task OnActivateAsync()
{
rewoundMessagesGrain = GrainFactory.GetGrain<IRewindableMessageGrain<HubInvocationMessage>>(this.GetPrimaryKeyString());
rewoundMessagesGrain = GrainFactory.GetGrain<IRewindableMessageGrain<MethodMessage>>(this.GetPrimaryKeyString());
return base.OnActivateAsync();
}

Expand All @@ -33,7 +33,7 @@ public override Task OnDeactivateAsync()
return base.OnDeactivateAsync();
}

public async Task AcceptMessageAsync(HubInvocationMessage message, GrainCancellationToken cancellationToken)
public async Task AcceptMessageAsync(MethodMessage message, GrainCancellationToken cancellationToken)
{
var handle = await rewoundMessagesGrain.PushMessageAsync(message);
observers.Notify(x => x.ReceiveMessage(message, handle));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@
</PropertyGroup>
<PropertyGroup>
<PackageId>OrgnalR.Backplane.GrainImplementations</PackageId>
<Version>1.2.1</Version>
<Authors>Liam Morrow</Authors>
<Title>
OrgnalR Backplane Grain Implementations
</Title>
<Description>
A core package of OrgnalR. You likely want one of either `OrgnalR.SignalR`, or `OrgnalR.OrleansSilo`
</Description>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IncludeSource>true</IncludeSource>
<RepositoryUrl>https://github.com/LiamMorrow/OrgnalR</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\OrgnalR.Backplane.GrainInterfaces\OrgnalR.Backplane.GrainInterfaces.csproj" />
Expand Down
4 changes: 2 additions & 2 deletions src/OrgnalR.Backplane.GrainInterfaces/IClientGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace OrgnalR.Backplane.GrainInterfaces
{
public interface IClientGrain : IGrainWithStringKey
{
Task AcceptMessageAsync(HubInvocationMessage message, GrainCancellationToken cancellationToken);
Task AcceptMessageAsync(MethodMessage message, GrainCancellationToken cancellationToken);
/// <summary>
/// Subscribes to messages for this client, optionally replaying all messages since a last seen message
/// </summary>
Expand All @@ -19,7 +19,7 @@ public interface IClientGrain : IGrainWithStringKey

public interface IClientMessageObserver : IGrainObserver
{
void ReceiveMessage(HubInvocationMessage message, MessageHandle handle);
void ReceiveMessage(MethodMessage message, MessageHandle handle);
void SubscriptionEnded();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@
</PropertyGroup>
<PropertyGroup>
<PackageId>OrgnalR.GrainInterfaces</PackageId>
<Version>1.2.1</Version>
<Authors>Liam Morrow</Authors>
<Title>
OrgnalR Grain Interfaces package
</Title>
<Description>
A core package of OrgnalR. You likely want one of either `OrgnalR.SignalR`, or `OrgnalR.OrleansSilo`
</Description>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IncludeSource>true</IncludeSource>
<RepositoryUrl>https://github.com/LiamMorrow/OrgnalR</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\OrgnalR.Core\OrgnalR.Core.csproj" />
Expand Down
6 changes: 0 additions & 6 deletions src/OrgnalR.Backplane/OrgnalR.Backplane.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@
</PropertyGroup>
<PropertyGroup>
<PackageId>OrgnalR.Backplane</PackageId>
<Version>1.2.1</Version>
<Authors>Liam Morrow</Authors>
<Title>
OrgnalR Backplane package
</Title>
<Description>
A core package of OrgnalR. You likely want one of either `OrgnalR.SignalR`, or `OrgnalR.OrleansSilo`
</Description>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IncludeSource>true</IncludeSource>
<RepositoryUrl>https://github.com/LiamMorrow/OrgnalR</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\OrgnalR.Core\OrgnalR.Core.csproj" />
Expand Down
16 changes: 8 additions & 8 deletions src/OrgnalR.Backplane/OrgnalRHubLifetimeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ public override Task RemoveFromGroupAsync(string connectionId, string groupName,

public override Task SendAllAsync(string methodName, object[] args, CancellationToken cancellationToken = default)
{
return messageObserver.SendAllMessageAsync(new AnonymousMessage(EmptySet<string>.Instance, new InvocationMessage(methodName, args)), cancellationToken);
return messageObserver.SendAllMessageAsync(new AnonymousMessage(EmptySet<string>.Instance, new MethodMessage(methodName, args)), cancellationToken);
}

public override Task SendAllExceptAsync(string methodName, object[] args, IReadOnlyList<string> excludedConnectionIds, CancellationToken cancellationToken = default)
{
return messageObserver.SendAllMessageAsync(new AnonymousMessage(excludedConnectionIds.ToSet(), new InvocationMessage(methodName, args)), cancellationToken);
return messageObserver.SendAllMessageAsync(new AnonymousMessage(excludedConnectionIds.ToSet(), new MethodMessage(methodName, args)), cancellationToken);
}

public override Task SendConnectionAsync(string connectionId, string methodName, object[] args, CancellationToken cancellationToken = default)
Expand All @@ -132,7 +132,7 @@ public override Task SendConnectionsAsync(IReadOnlyList<string> connectionIds, s
foreach (var connectionId in connectionIds)
{
var local = hubConnectionStore[connectionId];
var msg = new AddressedMessage(connectionId, new InvocationMessage(methodName, args));
var msg = new AddressedMessage(connectionId, new MethodMessage(methodName, args));
if (local != null)
{
toAwait.Add(OnAddressedMessageReceived(msg, default));
Expand All @@ -148,13 +148,13 @@ public override Task SendConnectionsAsync(IReadOnlyList<string> connectionIds, s
public override Task SendGroupAsync(string groupName, string methodName, object[] args, CancellationToken cancellationToken = default)
{
var group = groupActorProvider.GetGroupActor(groupName);
return group.AcceptMessageAsync(new AnonymousMessage(EmptySet<string>.Instance, new InvocationMessage(methodName, args)), cancellationToken);
return group.AcceptMessageAsync(new AnonymousMessage(EmptySet<string>.Instance, new MethodMessage(methodName, args)), cancellationToken);
}

public override Task SendGroupExceptAsync(string groupName, string methodName, object[] args, IReadOnlyList<string> excludedConnectionIds, CancellationToken cancellationToken = default)
{
var group = groupActorProvider.GetGroupActor(groupName);
return group.AcceptMessageAsync(new AnonymousMessage(excludedConnectionIds.ToSet(), new InvocationMessage(methodName, args)), cancellationToken);
return group.AcceptMessageAsync(new AnonymousMessage(excludedConnectionIds.ToSet(), new MethodMessage(methodName, args)), cancellationToken);
}

public override Task SendGroupsAsync(IReadOnlyList<string> groupNames, string methodName, object[] args, CancellationToken cancellationToken = default)
Expand All @@ -167,7 +167,7 @@ public override Task SendGroupsAsync(IReadOnlyList<string> groupNames, string me
public override Task SendUserAsync(string userId, string methodName, object[] args, CancellationToken cancellationToken = default)
{
var user = userActorProvider.GetUserActor(userId);
return user.AcceptMessageAsync(new AnonymousMessage(EmptySet<string>.Instance, new InvocationMessage(methodName, args)), cancellationToken);
return user.AcceptMessageAsync(new AnonymousMessage(EmptySet<string>.Instance, new MethodMessage(methodName, args)), cancellationToken);
}

public override Task SendUsersAsync(IReadOnlyList<string> userIds, string methodName, object[] args, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -204,7 +204,7 @@ private async Task OnAddressedMessageReceived(AddressedMessage arg, MessageHandl
return;
if (connection.ConnectionAborted.IsCancellationRequested)
return;
await connection.WriteAsync(arg.Payload);
await connection.WriteAsync(new InvocationMessage(arg.Payload.MethodName, arg.Payload.Args));

var latestClientMessageHandle = GetClientMessageHandle(connection);
if (handle != default
Expand Down Expand Up @@ -248,7 +248,7 @@ private async Task OnAnonymousMessageReceived(AnonymousMessage msg, MessageHandl
continue;
if (conn.ConnectionAborted.IsCancellationRequested)
continue;
toAwait.Add(conn.WriteAsync(msg.Payload));
toAwait.Add(conn.WriteAsync(new InvocationMessage(msg.Payload.MethodName, msg.Payload.Args)));
}
await Task.WhenAll(toAwait.Where(vt => !vt.IsCompleted).Select(vt => vt.AsTask()));
if (handle != default
Expand Down
11 changes: 5 additions & 6 deletions src/OrgnalR.Core/OrgnalR.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@
</PropertyGroup>
<PropertyGroup>
<PackageId>OrgnalR.Core</PackageId>
<Version>1.2.1</Version>
<Authors>Liam Morrow</Authors>
<Title>
OrgnalR Core package
</Title>
<Description>
A core package of OrgnalR. You likely want one of either `OrgnalR.SignalR`, or `OrgnalR.OrleansSilo`
</Description>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IncludeSource>true</IncludeSource>
<RepositoryUrl>https://github.com/LiamMorrow/OrgnalR</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Orleans.CodeGenerator.MSBuild" Version="3.1.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Orleans.Runtime.Abstractions" Version="3.1.6" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.1.0" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions src/OrgnalR.Core/Provider/AddressedMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ namespace OrgnalR.Core.Provider
public class AddressedMessage
{
public string ConnectionId { get; }
public HubInvocationMessage Payload { get; }
public AddressedMessage(string connectionId, HubInvocationMessage messagePayload)
public MethodMessage Payload { get; }
public AddressedMessage(string connectionId, MethodMessage payload)
{
ConnectionId = connectionId;
Payload = messagePayload;
Payload = payload;
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/OrgnalR.Core/Provider/AnonymousMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ namespace OrgnalR.Core.Provider
public class AnonymousMessage
{
public ISet<string> Excluding { get; }
public HubInvocationMessage Payload { get; }
public AnonymousMessage(ISet<string> excluding, HubInvocationMessage messagePayload)
public MethodMessage Payload { get; }

public AnonymousMessage(ISet<string> excluding, MethodMessage payload)
{
Excluding = excluding;
Payload = messagePayload;
Payload = payload;
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/OrgnalR.Core/Provider/MethodMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace OrgnalR.Core.Provider
{
public class MethodMessage
{
public string MethodName { get; }

public object[] Args { get; }

public MethodMessage(string methodName, object[] args)
{
MethodName = methodName;
Args = args;
}
}
}
6 changes: 0 additions & 6 deletions src/OrgnalR.OrleansSilo/OrgnalR.OrleansSilo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</PropertyGroup>
<PropertyGroup>
<PackageId>OrgnalR.OrleansSilo</PackageId>
<Version>1.2.1</Version>
<Authors>Liam Morrow</Authors>
<Title>
OrgnalR Orleans Silo
Expand All @@ -17,11 +16,6 @@
The Orleans silo library for OrgnalR. This is the package you'd want on the Orleans Silo application.
For the SignalR server, use OrgnalR.SignalR
</Description>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IncludeSource>true</IncludeSource>
<RepositoryUrl>https://github.com/LiamMorrow/OrgnalR</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\OrgnalR.Backplane.GrainImplementations\OrgnalR.Backplane.GrainImplementations.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion src/OrgnalR.SignalR/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public OrgnalRHubLifetimeManagerFactory(IServiceProvider services)
services.GetService<IMessageObservable<T>>(),
services.GetService<IMessageObserver<T>>(),
services.GetRequiredService<ILogger<OrgnalRHubLifetimeManager<T>>>()
).Result;
).GetAwaiter().GetResult();
}
public override Task AddToGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default)
{
Expand Down
6 changes: 0 additions & 6 deletions src/OrgnalR.SignalR/OrgnalR.SignalR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</PropertyGroup>
<PropertyGroup>
<PackageId>OrgnalR.SignalR</PackageId>
<Version>1.2.1</Version>
<Authors>Liam Morrow</Authors>
<Title>
OrgnalR SignalR
Expand All @@ -17,11 +16,6 @@
The SignalR library for OrgnalR. This is the package you'd want on the SignalR server.
For the Orleans Silo, use OrgnalR.OrleansSilo
</Description>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<IncludeSource>true</IncludeSource>
<RepositoryUrl>https://github.com/LiamMorrow/OrgnalR</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.1.0" />
Expand Down
Loading

0 comments on commit 61bbe17

Please sign in to comment.