-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathAkkaRemoteHostingExtensions.cs
85 lines (79 loc) · 3.59 KB
/
AkkaRemoteHostingExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// -----------------------------------------------------------------------
// <copyright file="AkkaRemoteHostingExtensions.cs" company="Akka.NET Project">
// Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
// -----------------------------------------------------------------------
using System;
using System.Text;
using Akka.Actor;
using Akka.Hosting;
namespace Akka.Remote.Hosting
{
public static class AkkaRemoteHostingExtensions
{
/// <summary>
/// Adds Akka.Remote support to this <see cref="ActorSystem"/>.
/// </summary>
/// <param name="builder">A configuration delegate.</param>
/// <param name="hostname">Optional. The hostname to bind Akka.Remote upon. <b>Default</b>: "0.0.0.0"</param>
/// <param name="port">Optional. The port to bind Akka.Remote upon. <b>Default</b>: 2552</param>
/// <param name="publicHostname">Optional. If using hostname aliasing, this is the host we will advertise.</param>
/// <param name="publicPort">Optional. If using port aliasing, this is the port we will advertise.</param>
/// <returns>The same <see cref="AkkaConfigurationBuilder"/> instance originally passed in.</returns>
public static AkkaConfigurationBuilder WithRemoting(
this AkkaConfigurationBuilder builder,
string? hostname = null,
int? port = null,
string? publicHostname = null,
int? publicPort = null)
=> builder.WithRemoting(new RemoteOptions
{
HostName = hostname,
Port = port,
PublicHostName = publicHostname,
PublicPort = publicPort
});
/// <summary>
/// Adds Akka.Remote support to this <see cref="ActorSystem"/>.
/// </summary>
/// <param name="builder">A configuration delegate.</param>
/// <param name="configure">
/// An <see cref="Action{T}"/> delegate used to configure an <see cref="RemoteOptions"/>
/// instance to configure Akka.Remote
/// </param>
/// <returns>The same <see cref="AkkaConfigurationBuilder"/> instance originally passed in.</returns>
public static AkkaConfigurationBuilder WithRemoting(
this AkkaConfigurationBuilder builder,
Action<RemoteOptions> configure)
{
var options = new RemoteOptions();
configure(options);
return builder.WithRemoting(options);
}
/// <summary>
/// Adds Akka.Remote support to this <see cref="ActorSystem"/>.
/// </summary>
/// <param name="builder">A configuration delegate.</param>
/// <param name="options">
/// A <see cref="RemoteOptions"/> instance to configure Akka.Remote
/// </param>
/// <returns>The same <see cref="AkkaConfigurationBuilder"/> instance originally passed in.</returns>
public static AkkaConfigurationBuilder WithRemoting(
this AkkaConfigurationBuilder builder,
RemoteOptions options)
{
options.Build(builder);
if (builder.ActorRefProvider.HasValue)
{
switch (builder.ActorRefProvider.Value)
{
case ProviderSelection.Cluster _:
case ProviderSelection.Remote _:
case ProviderSelection.Custom _:
return builder; // no-op
}
}
return builder.WithActorRefProvider(ProviderSelection.Remote.Instance);
}
}
}