This repository was archived by the owner on Apr 20, 2018. It is now read-only.
forked from microsoft/Tx
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathProgram.cs
More file actions
69 lines (56 loc) · 2.02 KB
/
Program.cs
File metadata and controls
69 lines (56 loc) · 2.02 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
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
namespace BombActor
{
class Program
{
static Random _random;
static void Main(string[] args)
{
ProtocolNode.Open(OnReceived, OnTimer);
_random = new Random(ProtocolNode.ProcessId);
Console.WriteLine("Press Enter on any of the consoles to continue");
Console.ReadLine();
ProtocolNode.StartAll();
Console.WriteLine("Press Enter to terminate all");
Console.WriteLine();
Console.ReadLine();
ProtocolNode.StopAll();
}
static void OnReceived(Guid messageId, int from)
{
string host = ProtocolNode.Endpoints[from].Host.ToLowerInvariant();
Trace.WriteLine(String.Format("{0} {1} received message {2} from {3} at {4}",
ProtocolNode.ProcessId,
ProtocolNode.LocalCounter,
messageId,
from,
host));
}
static void OnTimer(object state)
{
int r = _random.Next(10);
if (r == 0)
{
int to = _random.Next(ProtocolNode.Endpoints.Length);
Guid messageId = Guid.NewGuid();
string host = ProtocolNode.Endpoints[to].Host.ToLowerInvariant();
Trace.WriteLine(String.Format("{0} {1} sending message {2} to {3} at {4}",
ProtocolNode.ProcessId,
ProtocolNode.LocalCounter,
messageId,
to,
host));
ProtocolNode.Send(messageId, to);
}
else
{
Trace.WriteLine(String.Format("{0} {1} clock increment",
ProtocolNode.ProcessId,
ProtocolNode.LocalCounter));
return;
}
}
}
}