-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Settings.cs
419 lines (352 loc) · 17.6 KB
/
Settings.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
//-----------------------------------------------------------------------
// <copyright file="Settings.cs" company="Akka.NET Project">
// Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com>
// Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Threading;
using Akka.Actor.Setup;
using Akka.Configuration;
using Akka.Dispatch;
using Akka.Event;
using Akka.Routing;
using ConfigurationFactory = Akka.Configuration.ConfigurationFactory;
namespace Akka.Actor
{
/// <summary>
/// This class represents the overall <see cref="ActorSystem"/> settings which also provides a convenient
/// access to the <see cref="Configuration.Config"/> object. For more detailed information about the
/// different possible configuration options, look in the Akka.NET Documentation under Configuration
/// (http://getakka.net/docs/concepts/configuration).
/// </summary>
public class Settings
{
private readonly Config _userConfig;
//internal static readonly Config AkkaDllConfig = ConfigurationFactory.FromResource<Settings>("Akka.Configuration.Pigeon.conf");
private Config _fallbackConfig;
private void RebuildConfig()
{
Config = _userConfig.SafeWithFallback(_fallbackConfig);
//if we get a new config definition loaded after all ActorRefProviders have been started, such as Akka.Persistence...
System?.Dispatchers?.ReloadPrerequisites(new DefaultDispatcherPrerequisites(System.EventStream, System.Scheduler, this, System.Mailboxes));
if (System is Internal.ISupportSerializationConfigReload rs)
rs.ReloadSerialization();
}
/// <summary>
/// Injects a system config at the top of the fallback chain
/// </summary>
/// <param name="config">TBD</param>
public void InjectTopLevelFallback(Config config)
{
if (Config.Contains(config))
return;
_fallbackConfig = config.SafeWithFallback(_fallbackConfig);
RebuildConfig();
}
/// <summary>
/// Initializes a new instance of the <see cref="Settings" /> class.
/// </summary>
/// <param name="system">The system.</param>
/// <param name="config">The configuration.</param>
/// <exception cref="ConfigurationException">
/// This exception is thrown if the 'akka.actor.provider' configuration item is not a valid type name or a valid actor ref provider.
/// </exception>
public Settings(ActorSystem system, Config config) : this(system, config, ActorSystemSetup.Empty)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Settings" /> class.
/// </summary>
/// <param name="system">The system.</param>
/// <param name="config">The configuration.</param>
/// <param name="setup">The setup class used to help bootstrap the <see cref="ActorSystem"/></param>
/// <exception cref="ConfigurationException">
/// This exception is thrown if the 'akka.actor.provider' configuration item is not a valid type name or a valid actor ref provider.
/// </exception>
public Settings(ActorSystem system, Config config, ActorSystemSetup setup)
{
Setup = setup;
_userConfig = config;
_fallbackConfig = ConfigurationFactory.Default();
RebuildConfig();
System = system;
var providerSelectionSetup = Setup.Get<BootstrapSetup>()
.FlatSelect(_ => _.ActorRefProvider)
.Select(_ => _.Fqn)
.GetOrElse(Config.GetString("akka.actor.provider", null));
ProviderSelectionType = ProviderSelection.GetProvider(providerSelectionSetup);
ConfigVersion = Config.GetString("akka.version", null);
ProviderClass = ProviderSelectionType.Fqn;
HasCluster = ProviderSelectionType.HasCluster;
var providerType = Type.GetType(ProviderClass);
if (providerType == null)
throw new ConfigurationException($"'akka.actor.provider' is not a valid type name : '{ProviderClass}'");
if (!typeof(IActorRefProvider).IsAssignableFrom(providerType))
throw new ConfigurationException($"'akka.actor.provider' is not a valid actor ref provider: '{ProviderClass}'");
SupervisorStrategyClass = Config.GetString("akka.actor.guardian-supervisor-strategy", null);
AskTimeout = Config.GetTimeSpan("akka.actor.ask-timeout", null, allowInfinite: true);
CreationTimeout = Config.GetTimeSpan("akka.actor.creation-timeout", null);
UnstartedPushTimeout = Config.GetTimeSpan("akka.actor.unstarted-push-timeout", null);
SerializeAllMessages = Config.GetBoolean("akka.actor.serialize-messages", false);
SerializeAllCreators = Config.GetBoolean("akka.actor.serialize-creators", false);
EmitActorTelemetry = Config.GetBoolean("akka.actor.telemetry.enabled", false);
LogLevel = Config.GetString("akka.loglevel", null);
StdoutLogLevel = Config.GetString("akka.stdout-loglevel", null);
var stdoutClassName = Config.GetString("akka.stdout-logger-class", null);
if (string.IsNullOrWhiteSpace(stdoutClassName))
{
StdoutLogger = new StandardOutLogger();
}
else
{
var stdoutLoggerType = Type.GetType(stdoutClassName);
if (stdoutLoggerType == null)
throw new ArgumentException($"Could not load type of {stdoutClassName} for standard out logger.");
if(!typeof(MinimalLogger).IsAssignableFrom(stdoutLoggerType))
throw new ArgumentException("Standard out logger type must inherit from the MinimalLogger abstract class.");
try
{
StdoutLogger = (MinimalLogger)Activator.CreateInstance(stdoutLoggerType);
}
catch (MissingMethodException)
{
throw new MissingMethodException(
"Standard out logger type must inherit from the MinimalLogger abstract class and have an empty constructor.");
}
}
Loggers = Config.GetStringList("akka.loggers", new string[] { });
LoggersDispatcher = Config.GetString("akka.loggers-dispatcher", null);
LoggerStartTimeout = Config.GetTimeSpan("akka.logger-startup-timeout", null);
LoggerAsyncStart = Config.GetBoolean("akka.logger-async-start", false);
//handled
LogConfigOnStart = Config.GetBoolean("akka.log-config-on-start", false);
LogSerializerOverrideOnStart = Config.GetBoolean("akka.log-serializer-override-on-start", true);
LogDeadLetters = 0;
switch (Config.GetString("akka.log-dead-letters", null))
{
case "on":
case "true":
case "yes":
LogDeadLetters = int.MaxValue;
break;
case "off":
case "false":
case "no":
LogDeadLetters = 0;
break;
default:
LogDeadLetters = Config.GetInt("akka.log-dead-letters", 0);
break;
}
LogDeadLettersDuringShutdown = Config.GetBoolean("akka.log-dead-letters-during-shutdown", false);
const string key = "akka.log-dead-letters-suspend-duration";
LogDeadLettersSuspendDuration = Config.GetString(key, null) == "infinite" ? Timeout.InfiniteTimeSpan : Config.GetTimeSpan(key);
AddLoggingReceive = Config.GetBoolean("akka.actor.debug.receive", false);
DebugAutoReceive = Config.GetBoolean("akka.actor.debug.autoreceive", false);
DebugLifecycle = Config.GetBoolean("akka.actor.debug.lifecycle", false);
FsmDebugEvent = Config.GetBoolean("akka.actor.debug.fsm", false);
DebugEventStream = Config.GetBoolean("akka.actor.debug.event-stream", false);
DebugUnhandledMessage = Config.GetBoolean("akka.actor.debug.unhandled", false);
DebugRouterMisconfiguration = Config.GetBoolean("akka.actor.debug.router-misconfiguration", false);
Home = Config.GetString("akka.home", "");
DefaultVirtualNodesFactor = Config.GetInt("akka.actor.deployment.default.virtual-nodes-factor", 0);
SchedulerClass = Config.GetString("akka.scheduler.implementation", null);
SchedulerShutdownTimeout = Config.GetTimeSpan("akka.scheduler.shutdown-timeout", null);
CoordinatedShutdownTerminateActorSystem = Config.GetBoolean("akka.coordinated-shutdown.terminate-actor-system");
CoordinatedShutdownRunByActorSystemTerminate = Config.GetBoolean("akka.coordinated-shutdown.run-by-actor-system-terminate");
if (CoordinatedShutdownRunByActorSystemTerminate && !CoordinatedShutdownTerminateActorSystem)
throw new ConfigurationException(
"akka.coordinated-shutdown.run-by-actor-system-terminate=on and " +
"akka.coordinated-shutdown.terminate-actor-system=off is not a supported configuration combination.");
}
/// <summary>
/// Gets the system.
/// </summary>
/// <value>The system.</value>
public ActorSystem System { get; private set; }
/// <summary>
/// Gets the configuration.
/// </summary>
/// <value>The configuration.</value>
public Config Config { get; private set; }
/// <summary>
/// The setup used to help bootstrap this <see cref="ActorSystem"/>.
/// </summary>
public ActorSystemSetup Setup { get; }
/// <summary>
/// Used to indicate whether or not clustering is enabled for this <see cref="ActorSystem"/>.
/// </summary>
public bool HasCluster { get; }
/// <summary>
/// INTENRAL API
/// </summary>
public ProviderSelection ProviderSelectionType { get; }
/// <summary>
/// Gets the configuration version.
/// </summary>
/// <value>The configuration version.</value>
public string ConfigVersion { get; private set; }
/// <summary>
/// Gets the provider class.
/// </summary>
/// <value>The provider class.</value>
public string ProviderClass { get; private set; }
/// <summary>
/// Gets the supervisor strategy class.
/// </summary>
/// <value>The supervisor strategy class.</value>
public string SupervisorStrategyClass { get; private set; }
/// <summary>
/// Gets a value indicating whether [serialize all messages].
/// </summary>
/// <value><c>true</c> if [serialize all messages]; otherwise, <c>false</c>.</value>
public bool SerializeAllMessages { get; private set; }
/// <summary>
/// Gets a value indicating whether [serialize all creators].
/// </summary>
/// <value><c>true</c> if [serialize all creators]; otherwise, <c>false</c>.</value>
public bool SerializeAllCreators { get; private set; }
/// <summary>
/// When set to <c>true</c>, all actors will emit <see cref="IActorTelemetryEvent"/>s when they are created, stopped, or restarted.
/// </summary>
/// <remarks>
/// Defaults to <c>false</c>.
/// </remarks>
/// <code>
/// akka.actor.telemetry.enabled = on
/// </code>
public bool EmitActorTelemetry { get; }
/// <summary>
/// Gets the default timeout for <see cref="Futures.Ask(ICanTell, object, TimeSpan?)">Futures.Ask</see> calls.
/// </summary>
/// <value>The ask timeout.</value>
public TimeSpan AskTimeout { get; private set; }
/// <summary>
/// Gets the creation timeout.
/// </summary>
/// <value>The creation timeout.</value>
public TimeSpan CreationTimeout { get; private set; }
/// <summary>
/// Gets the unstarted push timeout.
/// </summary>
/// <value>The unstarted push timeout.</value>
public TimeSpan UnstartedPushTimeout { get; private set; }
/// <summary>
/// Gets the log level.
/// </summary>
/// <value>The log level.</value>
public string LogLevel { get; private set; }
/// <summary>
/// Gets the stdout log level.
/// </summary>
/// <value>The stdout log level.</value>
public string StdoutLogLevel { get; private set; }
/// <summary>
/// Returns a singleton instance of the standard out logger.
/// </summary>
public MinimalLogger StdoutLogger { get; }
/// <summary>
/// Gets the loggers.
/// </summary>
/// <value>The loggers.</value>
public IList<string> Loggers { get; private set; }
/// <summary>
/// Gets the default loggers dispatcher.
/// </summary>
/// <value>The loggers dispatcher.</value>
public string LoggersDispatcher { get; private set; }
/// <summary>
/// Gets the logger start timeout.
/// </summary>
/// <value>The logger start timeout.</value>
public TimeSpan LoggerStartTimeout { get; private set; }
/// <summary>
/// Gets the logger start timeout.
/// </summary>
/// <value>The logger start timeout.</value>
public bool LoggerAsyncStart { get; private set; }
/// <summary>
/// Gets a value indicating whether [log configuration on start].
/// </summary>
/// <value><c>true</c> if [log configuration on start]; otherwise, <c>false</c>.</value>
public bool LogConfigOnStart { get; private set; }
/// <summary>
/// Gets a value indicating whether [log serializer override on start].
/// </summary>
/// <value><c>true</c> if [log serializer override on start]; otherwise, <c>false</c>.</value>
public bool LogSerializerOverrideOnStart { get; private set; }
/// <summary>
/// Gets the log dead letters.
/// </summary>
/// <value>The log dead letters.</value>
public int LogDeadLetters { get; private set; }
/// <summary>
/// Gets a value indicating whether [log dead letters during shutdown].
/// </summary>
/// <value><c>true</c> if [log dead letters during shutdown]; otherwise, <c>false</c>.</value>
public bool LogDeadLettersDuringShutdown { get; private set; }
/// <summary>
/// TBD
/// </summary>
public TimeSpan LogDeadLettersSuspendDuration { get; }
/// <summary>
/// Gets a value indicating whether [add logging receive].
/// </summary>
/// <value><c>true</c> if [add logging receive]; otherwise, <c>false</c>.</value>
public bool AddLoggingReceive { get; private set; }
/// <summary>
/// Gets a value indicating whether [debug automatic receive].
/// </summary>
/// <value><c>true</c> if [debug automatic receive]; otherwise, <c>false</c>.</value>
public bool DebugAutoReceive { get; private set; }
/// <summary>
/// Gets a value indicating whether [debug event stream].
/// </summary>
/// <value><c>true</c> if [debug event stream]; otherwise, <c>false</c>.</value>
public bool DebugEventStream { get; private set; }
/// <summary>
/// Gets a value indicating whether [debug unhandled message].
/// </summary>
/// <value><c>true</c> if [debug unhandled message]; otherwise, <c>false</c>.</value>
public bool DebugUnhandledMessage { get; private set; }
/// <summary>
/// Gets a value indicating whether [debug router misconfiguration].
/// </summary>
/// <value><c>true</c> if [debug router misconfiguration]; otherwise, <c>false</c>.</value>
public bool DebugRouterMisconfiguration { get; private set; }
/// <summary>
/// Gets the home.
/// </summary>
/// <value>The home.</value>
public string Home { get; private set; }
/// <summary>
/// Gets a value indicating whether [debug lifecycle].
/// </summary>
/// <value><c>true</c> if [debug lifecycle]; otherwise, <c>false</c>.</value>
public bool DebugLifecycle { get; private set; }
/// <summary>
/// TBD
/// </summary>
public bool FsmDebugEvent { get; private set; }
/// <summary>
/// The number of default virtual nodes to use with <see cref="ConsistentHashingRoutingLogic"/>.
/// </summary>
public int DefaultVirtualNodesFactor { get; private set; }
/// <summary>
/// Gets the scheduler implementation used by this system.
/// </summary>
public string SchedulerClass { get; private set; }
/// <summary>
/// TBD
/// </summary>
public TimeSpan SchedulerShutdownTimeout { get; private set; }
public bool CoordinatedShutdownTerminateActorSystem { get; private set; }
public bool CoordinatedShutdownRunByActorSystemTerminate { get; private set; }
public override string ToString()
{
return Config.Root.ToString();
}
}
}