Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Commit

Permalink
next port finder made static
Browse files Browse the repository at this point in the history
  • Loading branch information
dasiths committed Dec 2, 2020
1 parent abb10b1 commit ac1e237
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
14 changes: 6 additions & 8 deletions src/Microsoft.Tye.Core/NextPortFinder.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
using System.Net;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Net;
using System.Net.Sockets;

namespace Microsoft.Tye
{
public sealed class NextPortFinder
{
public static NextPortFinder Instance { get; } = new NextPortFinder();

private NextPortFinder()
{
}

public int GetNextPort()
public static int GetNextPort()
{
// Let the OS assign the next available port. Unless we cycle through all ports
// on a test run, the OS will always increment the port number when making these calls.
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Tye.Extensions/Dapr/DaprExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override Task ProcessAsync(ExtensionContext context, ExtensionConfigurati
// default placement port number
var daprPlacementImage = "daprio/dapr";
var daprPlacementContainerPort = 50005;
var daprPlacementPort = NextPortFinder.Instance.GetNextPort();
var daprPlacementPort = NextPortFinder.GetNextPort();
var isCustomPlacementPortDefined = false;

// see if a placement port number has been defined
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Tye.Hosting/PortAssigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Task StartAsync(Application application)
// Auto assign a port
if (binding.Port == null)
{
binding.Port = NextPortFinder.Instance.GetNextPort();
binding.Port = NextPortFinder.GetNextPort();
}

if (service.Description.Readiness == null && service.Description.Replicas == 1)
Expand All @@ -48,7 +48,7 @@ public Task StartAsync(Application application)
for (var i = 0; i < service.Description.Replicas; i++)
{
// Reserve a port for each replica
var port = NextPortFinder.Instance.GetNextPort();
var port = NextPortFinder.GetNextPort();
binding.ReplicaPorts.Add(port);
}

Expand Down

0 comments on commit ac1e237

Please sign in to comment.