-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy pathPID.cs
More file actions
70 lines (55 loc) · 1.89 KB
/
Copy pathPID.cs
File metadata and controls
70 lines (55 loc) · 1.89 KB
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
// -----------------------------------------------------------------------
// <copyright file="PID.cs" company="Asynkron AB">
// Copyright (C) 2015-2022 Asynkron AB All rights reserved
// </copyright>
// -----------------------------------------------------------------------
using Google.Protobuf;
using Proto.Mailbox;
namespace Proto;
// ReSharper disable once InconsistentNaming
public partial class PID : ICustomDiagnosticMessage
{
private Process? _process;
public PID(string address, string id)
{
Address = address;
Id = id;
}
internal PID(string address, string id, Process process) : this(address, id) => _process = process;
public string ToDiagnosticString() => $"{Address}/{Id}";
public static PID FromAddress(string address, string id) => new(address, id);
internal Process? Ref(ActorSystem system)
{
if (_process is not null)
{
if (_process is ActorProcess {IsDead: true}) _process = null;
return _process;
}
var reff = system.ProcessRegistry.Get(this);
if (reff is not DeadLetterProcess) _process = reff;
return _process;
}
internal Process? CurrentRef => _process;
internal void SendUserMessage(ActorSystem system, object message)
{
var reff = Ref(system) ?? system.ProcessRegistry.Get(this);
reff.SendUserMessage(this, message);
}
public void SendSystemMessage(ActorSystem system, SystemMessage sys)
{
var reff = Ref(system) ?? system.ProcessRegistry.Get(this);
reff.SendSystemMessage(this, sys);
}
public void Stop(ActorSystem system)
{
var reff = _process ?? system.ProcessRegistry.Get(this);
reff.Stop(this);
}
public PID WithRequestId(uint requestId) => new()
{
Id = Id,
Address = Address,
_process = _process,
RequestId = requestId
};
}