());
36 | }
37 |
38 | protected internal override void AfterStop()
39 | {
40 | Stage.World.SetDefaultParent(null);
41 | Stage.World.SetPublicRoot(null);
42 | base.AfterStop();
43 | }
44 |
45 | private class PublicRootActorSupervisionStrategy : ISupervisionStrategy
46 | {
47 | public int Intensity => ForeverIntensity;
48 |
49 | public long Period => ForeverPeriod;
50 |
51 | public Scope Scope => Scope.One;
52 | }
53 | }
--------------------------------------------------------------------------------
/src/Vlingo.Xoom.Actors/RandomRouter.cs:
--------------------------------------------------------------------------------
1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved.
2 | //
3 | // This Source Code Form is subject to the terms of the
4 | // Mozilla Public License, v. 2.0. If a copy of the MPL
5 | // was not distributed with this file, You can obtain
6 | // one at https://mozilla.org/MPL/2.0/.
7 |
8 | using System;
9 |
10 | namespace Vlingo.Xoom.Actors;
11 |
12 | ///
13 | /// RandomRouter
14 | ///
15 | public class RandomRouter : Router
16 | {
17 | private readonly Random _random;
18 |
19 | public RandomRouter(RouterSpecification
specification, int seed) : this(specification, new Random(seed))
20 | {
21 | }
22 |
23 | public RandomRouter(RouterSpecification
specification, Random seededRandom) : base(specification)
24 | => _random = seededRandom;
25 |
26 | protected internal override Routing
ComputeRouting() => Routing.With(NextRoutee());
27 |
28 | protected internal virtual Routee
? NextRoutee()
29 | {
30 | var index = _random.Next(routees.Count);
31 | return RouteeAt(index);
32 | }
33 | }
--------------------------------------------------------------------------------
/src/Vlingo.Xoom.Actors/ResumingMailbox.cs:
--------------------------------------------------------------------------------
1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved.
2 | //
3 | // This Source Code Form is subject to the terms of the
4 | // Mozilla Public License, v. 2.0. If a copy of the MPL
5 | // was not distributed with this file, You can obtain
6 | // one at https://mozilla.org/MPL/2.0/.
7 |
8 | using System;
9 | using System.Linq.Expressions;
10 | using System.Threading.Tasks;
11 | using Vlingo.Xoom.Common;
12 |
13 | namespace Vlingo.Xoom.Actors;
14 |
15 | public class ResumingMailbox : IMailbox
16 | {
17 | private readonly IMessage _message;
18 |
19 | public ResumingMailbox(IMessage message) => _message = message;
20 |
21 | public TaskScheduler TaskScheduler { get; } = null!;
22 |
23 | public bool IsClosed => false;
24 |
25 | public bool IsDelivering => true;
26 | public int ConcurrencyCapacity => 0;
27 |
28 | public bool IsSuspendedFor(string name) => throw new InvalidOperationException("Mailbox implementation does not support this operation.");
29 |
30 | public bool IsSuspended => false;
31 |
32 | public int PendingMessages => 1;
33 |
34 | public bool IsPreallocated => false;
35 |
36 | public void Close()
37 | {
38 | }
39 |
40 | public IMessage? Receive() => null;
41 |
42 | public void Resume(string name)
43 | {
44 | }
45 |
46 | public void Run() => _message.Deliver();
47 |
48 | public void Send(IMessage message)
49 | {
50 | }
51 |
52 | public void Send(Actor actor, Action consumer, ICompletes? completes, string representation) =>
53 | throw new InvalidOperationException("Not a preallocated mailbox.");
54 |
55 | public void Send(Actor actor, Type protocol, LambdaExpression consumer, ICompletes? completes, string representation) =>
56 | throw new InvalidOperationException("Not a preallocated mailbox.");
57 |
58 | public void SuspendExceptFor(string name, params Type[] overrides)
59 | {
60 | }
61 | }
--------------------------------------------------------------------------------
/src/Vlingo.Xoom.Actors/RoundRobinRouter.cs:
--------------------------------------------------------------------------------
1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved.
2 | //
3 | // This Source Code Form is subject to the terms of the
4 | // Mozilla Public License, v. 2.0. If a copy of the MPL
5 | // was not distributed with this file, You can obtain
6 | // one at https://mozilla.org/MPL/2.0/.
7 |
8 | namespace Vlingo.Xoom.Actors;
9 |
10 | public class RoundRobinRouter : Router
11 | {
12 | private int _poolIndex;
13 |
14 | public RoundRobinRouter(RouterSpecification
specification) : base(specification) => _poolIndex = 0;
15 |
16 | internal int PoolIndex => _poolIndex;
17 |
18 | protected internal override Routing
ComputeRouting() => Routing.With(NextRoutee());
19 |
20 | protected internal virtual Routee
NextRoutee()
21 | {
22 | var routees = Routees;
23 | _poolIndex = IncrementAndGetPoolIndex() % routees.Count;
24 | return routees[_poolIndex];
25 | }
26 |
27 | private int IncrementAndGetPoolIndex()
28 | {
29 | _poolIndex = (_poolIndex == int.MaxValue) ? 0 : _poolIndex + 1;
30 | return _poolIndex;
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Vlingo.Xoom.Actors/RouterSpecification.cs:
--------------------------------------------------------------------------------
1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved.
2 | //
3 | // This Source Code Form is subject to the terms of the
4 | // Mozilla Public License, v. 2.0. If a copy of the MPL
5 | // was not distributed with this file, You can obtain
6 | // one at https://mozilla.org/MPL/2.0/.
7 |
8 | using System;
9 |
10 | namespace Vlingo.Xoom.Actors;
11 |
12 | ///
13 | /// RouterSpecification specifies the definition and protocol of
14 | /// the to which a will route,
15 | /// as well as other details such as pool size.
16 | ///
17 | public class RouterSpecification
18 | {
19 | private readonly int _initialPoolSize;
20 | private readonly Definition _routerDefinition;
21 | private readonly Type _routerProtocol;
22 |
23 | public RouterSpecification(int poolSize, Definition routerDefinition)
24 | {
25 | if (poolSize < 0)
26 | {
27 | throw new ArgumentException("poolSize must be 1 or greater");
28 | }
29 |
30 | _initialPoolSize = poolSize;
31 | _routerDefinition = routerDefinition;
32 | _routerProtocol = typeof(T);
33 | }
34 |
35 | public virtual int InitialPoolSize => _initialPoolSize;
36 |
37 | public virtual Definition RouterDefinition => _routerDefinition;
38 |
39 | public virtual Type RouterProtocol => _routerProtocol;
40 | }
--------------------------------------------------------------------------------
/src/Vlingo.Xoom.Actors/Routing.cs:
--------------------------------------------------------------------------------
1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved.
2 | //
3 | // This Source Code Form is subject to the terms of the
4 | // Mozilla Public License, v. 2.0. If a copy of the MPL
5 | // was not distributed with this file, You can obtain
6 | // one at https://mozilla.org/MPL/2.0/.
7 |
8 | using System;
9 | using System.Collections.Generic;
10 | using System.Linq;
11 |
12 | namespace Vlingo.Xoom.Actors;
13 |
14 | ///
15 | /// See
16 | ///
17 | public static class Routing
18 | {
19 | public static Routing With(Routee? routee)
20 | => new Routing(new List> {
21 | routee ?? throw new ArgumentNullException(nameof(routee), "Routee may not be null")
22 | });
23 |
24 | public static Routing With(ICollection> routees)
25 | {
26 | if (routees == null || routees.Count == 0)
27 | {
28 | throw new ArgumentNullException(nameof(routees), "routees may not be null or empty");
29 | }
30 |
31 | return new Routing(routees);
32 | }
33 | }
34 |
35 | ///
36 | /// Routing is an ordered sequence of that
37 | /// was computed by way of some routing strategy and whose elements
38 | /// will be the target of a message forwarded by a .
39 | ///
40 | public class Routing
41 | {
42 | private readonly ArraySegment> _routees;
43 |
44 | internal Routing() : this(null)
45 | {
46 | }
47 |
48 | internal Routing(ICollection>? routees)
49 | {
50 | var routeesCollection = routees ?? new List>();
51 | _routees = new ArraySegment>(routeesCollection.ToArray());
52 | }
53 |
54 | public virtual Routee First => _routees.ElementAt(0);
55 |
56 | public virtual IReadOnlyList> Routees => _routees;
57 |
58 | public virtual bool IsEmpty => _routees.Count == 0;
59 |
60 | public override string ToString() => $"Routing[routees={_routees}]";
61 |
62 | public virtual void Validate()
63 | {
64 | if (IsEmpty)
65 | {
66 | throw new InvalidOperationException("routees may not be empty");
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/src/Vlingo.Xoom.Actors/Scheduled__Proxy.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Vlingo.Xoom.Common;
3 |
4 | namespace Vlingo.Xoom.Actors;
5 |
6 | public class Scheduled__Proxy : IScheduled
7 | {
8 | private const string IntervalSignalRepresentation1 = "IntervalSignal(Vlingo.Xoom.Common.IScheduled, T)";
9 |
10 | private readonly Actor _actor;
11 | private readonly IMailbox _mailbox;
12 |
13 | public Scheduled__Proxy(Actor actor, IMailbox mailbox)
14 | {
15 | _actor = actor;
16 | _mailbox = mailbox;
17 | }
18 |
19 | public void IntervalSignal(IScheduled scheduled, T data)
20 | {
21 | if (!_actor.IsStopped)
22 | {
23 | Action> cons1513252312 = __ => __.IntervalSignal(scheduled, data);
24 | if (_mailbox.IsPreallocated)
25 | {
26 | _mailbox.Send(_actor, cons1513252312, null, IntervalSignalRepresentation1);
27 | }
28 | else
29 | {
30 | _mailbox.Send(new LocalMessage>(_actor, cons1513252312,
31 | IntervalSignalRepresentation1));
32 | }
33 | }
34 | else
35 | {
36 | _actor.DeadLetters?.FailedDelivery(new DeadLetter(_actor, IntervalSignalRepresentation1));
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/src/Vlingo.Xoom.Actors/SmallestMailboxRouter.cs:
--------------------------------------------------------------------------------
1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved.
2 | //
3 | // This Source Code Form is subject to the terms of the
4 | // Mozilla Public License, v. 2.0. If a copy of the MPL
5 | // was not distributed with this file, You can obtain
6 | // one at https://mozilla.org/MPL/2.0/.
7 |
8 |
9 | namespace Vlingo.Xoom.Actors;
10 |
11 | ///
12 | /// SmallestMailboxRouter
13 | ///
14 | public class SmallestMailboxRouter : Router
15 | {
16 | public SmallestMailboxRouter(RouterSpecification
specification) : base(specification)
17 | {
18 | }
19 |
20 | ///
21 | /// See
22 | ///
23 | protected internal override Routing
ComputeRouting()
24 | {
25 | Routee
? least = null;
26 | var leastCount = int.MaxValue;
27 |
28 | foreach(var routee in Routees)
29 | {
30 | var count = routee.PendingMessages;
31 | if(count == 0)
32 | {
33 | least = routee;
34 | break;
35 | }
36 |
37 | if(count < leastCount)
38 | {
39 | least = routee;
40 | leastCount = count;
41 | }
42 | }
43 |
44 | return Routing.With(least);
45 | }
46 | }
--------------------------------------------------------------------------------
/src/Vlingo.Xoom.Actors/Startable__Proxy.cs:
--------------------------------------------------------------------------------
1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved.
2 | //
3 | // This Source Code Form is subject to the terms of the
4 | // Mozilla Public License, v. 2.0. If a copy of the MPL
5 | // was not distributed with this file, You can obtain
6 | // one at https://mozilla.org/MPL/2.0/.
7 |
8 | using System;
9 |
10 | namespace Vlingo.Xoom.Actors;
11 |
12 | public class Startable__Proxy : IStartable
13 | {
14 | private readonly Actor actor;
15 | private readonly IMailbox mailbox;
16 |
17 | public Startable__Proxy(Actor actor, IMailbox mailbox)
18 | {
19 | this.actor = actor;
20 | this.mailbox = mailbox;
21 | }
22 |
23 | public void Start()
24 | {
25 | Action consumer = x => x.Start();
26 | if (mailbox.IsPreallocated)
27 | {
28 | mailbox.Send(actor, consumer, null, "Start()");
29 | }
30 | else
31 | {
32 | mailbox.Send(new LocalMessage(actor, consumer, "Start()"));
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/Vlingo.Xoom.Actors/Stoppable__Proxy.cs:
--------------------------------------------------------------------------------
1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved.
2 | //
3 | // This Source Code Form is subject to the terms of the
4 | // Mozilla Public License, v. 2.0. If a copy of the MPL
5 | // was not distributed with this file, You can obtain
6 | // one at https://mozilla.org/MPL/2.0/.
7 |
8 | using System;
9 |
10 | namespace Vlingo.Xoom.Actors;
11 |
12 | public class Stoppable__Proxy : IStoppable
13 | {
14 | private readonly Actor _actor;
15 | private readonly IMailbox _mailbox;
16 |
17 | public Stoppable__Proxy(Actor actor, IMailbox mailbox)
18 | {
19 | _actor = actor;
20 | _mailbox = mailbox;
21 | }
22 |
23 | public bool IsStopped => _actor.IsStopped;
24 |
25 | public void Conclude()
26 | {
27 | if (!_actor.IsStopped)
28 | {
29 | Action consumer = x => x.Conclude();
30 | if (_mailbox.IsPreallocated)
31 | {
32 | _mailbox.Send(_actor, consumer, null, "Conclude()");
33 | }
34 | else
35 | {
36 | _mailbox.Send(new LocalMessage(_actor, consumer, "Conclude()"));
37 | }
38 | }
39 | else
40 | {
41 | _actor.DeadLetters?.FailedDelivery(new DeadLetter(_actor, "Conclude()"));
42 | }
43 | }
44 |
45 | public void Stop()
46 | {
47 | if (!_actor.IsStopped)
48 | {
49 | Action consumer = x => x.Stop();
50 | if (_mailbox.IsPreallocated)
51 | {
52 | _mailbox.Send(_actor, consumer, null, "Stop()");
53 | }
54 | else
55 | {
56 | _mailbox.Send(new LocalMessage(_actor, consumer, "Stop()"));
57 | }
58 | }
59 | else
60 | {
61 | _actor.DeadLetters?.FailedDelivery(new DeadLetter(_actor, "Stop()"));
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/src/Vlingo.Xoom.Actors/StowedLocalMessage.cs:
--------------------------------------------------------------------------------
1 | // Copyright © 2012-2023 VLINGO LABS. All rights reserved.
2 | //
3 | // This Source Code Form is subject to the terms of the
4 | // Mozilla Public License, v. 2.0. If a copy of the MPL
5 | // was not distributed with this file, You can obtain
6 | // one at https://mozilla.org/MPL/2.0/.
7 |
8 | using System;
9 | using Vlingo.Xoom.Common;
10 |
11 | namespace Vlingo.Xoom.Actors;
12 |
13 | public class StowedLocalMessage : LocalMessage
14 | {
15 | public StowedLocalMessage(Actor actor, Action consumer, ICompletes