forked from PeterWaher/IoTGateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageStatus.cs
More file actions
67 lines (59 loc) · 1.6 KB
/
MessageStatus.cs
File metadata and controls
67 lines (59 loc) · 1.6 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
using System;
using System.Collections.Generic;
using System.Net;
namespace Waher.Networking.Cluster
{
/// <summary>
/// Keeps track of an outgoing message.
/// </summary>
internal class MessageStatus
{
public Guid Id;
public Dictionary<IPEndPoint, bool?> Acknowledged = new Dictionary<IPEndPoint, bool?>();
public IClusterMessage Message;
public byte[] MessageBinary;
public DateTime Timeout;
public DateTime TimeLimit;
public ClusterMessageAckEventHandler Callback;
public object State;
/// <summary>
/// If all responses have been returned.
/// </summary>
/// <param name="Statuses">Valid statuses.</param>
/// <returns>If all responses have been returned.</returns>
public bool IsComplete(EndpointStatus[] Statuses)
{
lock (this.Acknowledged)
{
foreach (EndpointStatus Status in Statuses)
{
if (!Acknowledged.ContainsKey(Status.Endpoint))
return false;
}
}
return true;
}
/// <summary>
/// Compiles available responses.
/// </summary>
/// <returns>Set of responses</returns>
public EndpointAcknowledgement[] GetResponses(EndpointStatus[] Statuses)
{
EndpointAcknowledgement[] Result;
int i, c;
lock (this.Acknowledged)
{
foreach (EndpointStatus Status in Statuses)
{
if (!Acknowledged.ContainsKey(Status.Endpoint))
Acknowledged[Status.Endpoint] = null;
}
Result = new EndpointAcknowledgement[c = this.Acknowledged.Count];
i = 0;
foreach (KeyValuePair<IPEndPoint, bool?> P in this.Acknowledged)
Result[i++] = new EndpointAcknowledgement(P.Key, P.Value);
}
return Result;
}
}
}