Skip to content

Commit

Permalink
Deffer internal stream initialization (OrleansContrib#39)
Browse files Browse the repository at this point in the history
* Deffer internal stream initialization

This allow this package to be used in .Net Generic Host

* Fix build
  • Loading branch information
galvesribeiro authored Jun 23, 2018
1 parent 149b898 commit 6199d2e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 21 deletions.
11 changes: 9 additions & 2 deletions .vsts-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
queue: 'Hosted Linux Preview'

variables:
- Major: '1'
- Minor: '0'
- Patch: '0'

steps:

- task: DotNetCoreCLI@2
Expand All @@ -24,7 +29,9 @@ steps:
command: pack
packagesToPack: '**/*.csproj'
configuration: '$(BuildConfiguration)'
versioningScheme: byEnvVar
versionEnvVar: Version
versioningScheme: byPrereleaseNumber
majorVersion: '$(Major)'
minorVersion: '$(Minor)'
patchVersion: '$(Patch)-preview-$(rev:.r)'

- task: PublishBuildArtifacts@1
17 changes: 13 additions & 4 deletions .vsts-release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
queue: 'Hosted Linux Preview'

variables:
- Major: '1'
- Minor: '0'
- Patch: '0'

steps:

- task: DotNetCoreCLI@2
Expand All @@ -24,15 +29,19 @@ steps:
command: pack
packagesToPack: '**/*.csproj'
configuration: '$(BuildConfiguration)'
versioningScheme: byEnvVar
versionEnvVar: Version
versioningScheme: byPrereleaseNumber
majorVersion: '$(Major)'
minorVersion: '$(Minor)'
patchVersion: '$(Patch)'

- task: NuGetCommand@2
inputs:
command: push
publishFeedCredentials: 'OSS'
nuGetFeedType: external
versioningScheme: byEnvVar
versionEnvVar: Version'
versioningScheme: byPrereleaseNumber
majorVersion: '$(Major)'
minorVersion: '$(Minor)'
patchVersion: '$(Patch)'

- task: PublishBuildArtifacts@1
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<OrleansProvidersVersion>2.0.0</OrleansProvidersVersion>
<OrleansCodeGeneratorVersion>2.0.3</OrleansCodeGeneratorVersion>
<OrleansRuntimeAbstractionsVersion>2.0.0</OrleansRuntimeAbstractionsVersion>
<OrleansRuntimeVersion>2.0.3</OrleansRuntimeVersion>
<SignalRVersion>1.0.1</SignalRVersion>
</PropertyGroup>
</Project>
13 changes: 9 additions & 4 deletions src/SignalR.Orleans/OrleansHubLifetimeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ public OrleansHubLifetimeManager(
_serverId = Guid.NewGuid();
this._logger = logger;
this._clusterClient = clusterClient;

_logger.LogInformation("Initializing: Orleans HubLifetimeManager {hubName} (serverId: {serverId})...", _hubName, _serverId);
this.SetupStreams().Wait();
_logger.LogInformation("Initialized complete: Orleans HubLifetimeManager {hubName} (serverId: {serverId})", _hubName, _serverId);
}

private async Task SetupStreams()
{
_logger.LogInformation("Initializing: Orleans HubLifetimeManager {hubName} (serverId: {serverId})...", _hubName, _serverId);

this._streamProvider = this._clusterClient.GetStreamProvider(Constants.STREAM_PROVIDER);
this._serverStream = this._streamProvider.GetStream<ClientMessage>(_serverId, Constants.SERVERS_STREAM);
this._allStream = this._streamProvider.GetStream<AllMessage>(Constants.ALL_STREAM_ID, Utils.BuildStreamHubName(this._hubName));
Expand All @@ -50,6 +48,8 @@ private async Task SetupStreams()
};

await Task.WhenAll(subscribeTasks);

_logger.LogInformation("Initialized complete: Orleans HubLifetimeManager {hubName} (serverId: {serverId})", _hubName, _serverId);
}

private Task ProcessAllMessage(AllMessage message)
Expand Down Expand Up @@ -80,6 +80,11 @@ public override async Task OnConnectedAsync(HubConnectionContext connection)
{
try
{
if (this._streamProvider == null)
{
await SetupStreams();
}

this._connections.Add(connection);

if (connection.User.Identity.IsAuthenticated)
Expand Down
14 changes: 4 additions & 10 deletions test/SignalR.Orleans.Tests/OrleansFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Orleans;
using Orleans.Configuration;
using Orleans.Hosting;
using Orleans.Runtime;

namespace SignalR.Orleans.Tests
{
Expand All @@ -15,22 +14,17 @@ public class OrleansFixture : IDisposable

public OrleansFixture()
{
var siloPort = 11111;
int gatewayPort = 30000;
var siloAddress = IPAddress.Loopback;

var silo = new SiloHostBuilder()
.Configure<ClusterOptions>(options => options.ClusterId = "test-cluster")
.UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(siloAddress, siloPort))
.ConfigureEndpoints(siloAddress, siloPort, gatewayPort)
.UseLocalhostClustering()
.Configure<EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback)
.UseSignalR()
.Build();
silo.StartAsync().Wait();
this.Silo = silo;

var client = new ClientBuilder()
.Configure<ClusterOptions>(options => options.ClusterId = "test-cluster")
.UseStaticClustering(options => options.Gateways.Add(new IPEndPoint(siloAddress, gatewayPort).ToGatewayUri()))
.UseLocalhostClustering()
.Configure<EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback)
.UseSignalR()
.Build();

Expand Down
2 changes: 1 addition & 1 deletion test/SignalR.Orleans.Tests/SignalR.Orleans.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.Orleans.Core" Version="$(OrleansCoreVersion)" />
<PackageReference Include="Microsoft.Orleans.OrleansProviders" Version="$(OrleansProvidersVersion)" />
<PackageReference Include="Microsoft.Orleans.OrleansCodeGenerator.Build" Version="$(OrleansCodeGeneratorVersion)" />
<PackageReference Include="Microsoft.Orleans.OrleansRuntime" Version="$(OrleansRuntimeAbstractionsVersion)" />
<PackageReference Include="Microsoft.Orleans.OrleansRuntime" Version="$(OrleansRuntimeVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 6199d2e

Please sign in to comment.