public void When_secondary_takes_over_it_will_let_workers_know_that_it_took_over() { using (var secondary = container.Resolve <MsmqSecondaryLoadBalancer>()) { secondary.TimeoutForHeartBeatFromPrimary = TimeSpan.FromMilliseconds(10); secondary.KnownWorkers.Add(TestQueueUri.Uri); secondary.KnownEndpoints.Add(TestQueueUri.Uri);//any worker is also endpoint var wait = new ManualResetEvent(false); secondary.TookOverAsActiveLoadBalancer += () => wait.Set(); secondary.Start(); Assert.True(wait.WaitOne()); int tries = 5; var serializer = container.Resolve <IMessageSerializer>(); Reroute reroute = null; while (reroute == null) { var message = queue.Receive(TimeSpan.FromSeconds(30)); reroute = serializer.Deserialize(message.BodyStream) .OfType <Reroute>().FirstOrDefault(); Assert.True(tries > 0); tries -= 1; } Assert.Equal(secondary.PrimaryLoadBalancer, reroute.OriginalEndPoint); Assert.Equal(secondary.Endpoint.Uri, reroute.NewEndPoint); } }
protected override void AfterStart(OpenedQueue queue) { if (_readyForWorkListener != null) { _readyForWorkListener.ReadyToWorkMessageArrived += readyForWorkMessage => HandleReadyForWork(queue, readyForWorkMessage); _readyForWorkListener.Start(); } if (secondaryLoadBalancer != null) { foreach (var queueUri in KnownEndpoints.GetValues()) { logger.InfoFormat("Notifying {0} that primary load balancer {1} is taking over from secondary", queueUri, Endpoint.Uri ); SendToQueue(queueUri, new Reroute { NewEndPoint = Endpoint.Uri, OriginalEndPoint = Endpoint.Uri }); } SendHeartBeatToSecondaryServer(null); heartBeatTimer.Change(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)); Reroute reroute; if (_readyForWorkListener != null) { reroute = new Reroute { NewEndPoint = _readyForWorkListener.Endpoint.Uri, OriginalEndPoint = _readyForWorkListener.Endpoint.Uri } } ; else { reroute = new Reroute { NewEndPoint = Endpoint.Uri, OriginalEndPoint = Endpoint.Uri } }; SendToAllWorkers( GenerateMsmqMessageFromMessageBatch(reroute), "Rerouting {1} back to {0}" ); } if (ShouldNotifyWorkersLoaderIsReadyToAcceptWorkOnStartup) { NotifyWorkersThatLoaderIsReadyToAcceptWork(); } }
public Program() { Reroute console = new Reroute(this); try { console.Compile("Good Class"); GoodClass gc = new GoodClass(this); console.Compile("Bad Class"); BadClass bc = new BadClass(this); console.Report(); } catch (Exception e) { console.Cancel(e.Message); } }
private static void LoadSprites(string filePath) { string[] directories = Directory.GetDirectories(filePath); foreach (string directory in directories) { LoadSprites(directory); } string[] files = Directory.GetFiles(filePath); string spriteCategory = new DirectoryInfo(filePath).Name; Reroute reroute = new Reroute(filePath); if (reroute.Exists) { reroutes.Add(spriteCategory, reroute); } foreach (string file in files) { LoadImage(spriteCategory, file); } }
public Worker(Program parent, string cockpit = "", string container = "", float yaw_speed = 0.5f) { Reroute console = new Reroute((gParent = parent)); try { console.Compile("Battery"); gBattery = new Battery(gParent); console.Compile("Payload"); gPayload = new Payload(gParent, container); console.Compile("Stabilizer"); gStabilizer = new Stabilizer(gParent, yaw_speed); console.Compile("Worker"); // Get a cockpit: if (cockpit == string.Empty) { List <IMyCockpit> cockpitblocks = new List <IMyCockpit>(); gParent.GridTerminalSystem.GetBlocksOfType(cockpitblocks, x => x.IsSameConstructAs(gParent.Me)); if (cockpitblocks.Count == 0) { throw new Exception("No cockpit found."); } else { gCockpit = cockpitblocks[0]; } } else { gCockpit = gParent.GridTerminalSystem.GetBlockWithName(cockpit) as IMyCockpit; } if (gCockpit == null || !gCockpit.IsSameConstructAs(gParent.Me)) { throw new Exception($"No cockpit found with argument: '{cockpit}'"); } // Set up text surfaces: lSurface = null; switch (gCockpit.BlockDefinition.SubtypeName) { case "SmallBlockCockpit": case "LargeBlockCockpitSeat": lSurface = new List <IMyTextSurface> { gCockpit.GetSurface(0), gCockpit.GetSurface(1), gCockpit.GetSurface(2) }; break; case "SmallBlockCockpitIndustrial": lSurface = new List <IMyTextSurface> { gCockpit.GetSurface(1), gCockpit.GetSurface(0), gCockpit.GetSurface(2) }; break; case "LargeBlockCockpitIndustrial": lSurface = new List <IMyTextSurface> { gCockpit.GetSurface(2), gCockpit.GetSurface(1), gCockpit.GetSurface(3) }; break; default: throw new Exception($"Cockpit '{gCockpit.CustomName}' is not a suitable cockpit."); } gParent.Echo($"Using cockpit: '{gCockpit.CustomName}'"); foreach (IMyTextSurface s in lSurface) { s.Font = "Debug"; s.FontSize = 3.0f; s.TextPadding = 20.0f; s.ContentType = ContentType.TEXT_AND_IMAGE; s.Alignment = TextAlignment.CENTER; } if (gCockpit.BlockDefinition.SubtypeName == "SmallBlockCockpit") { lSurface[0].FontSize = 4.0f; } // Done: SetCargoScreen(); SetStabilizerScreen(false); SetBatteryScreen(); console.Report(); gParent.Runtime.UpdateFrequency = UpdateFrequency.Update100; } catch (Exception e) { console.Cancel(e.Message); } }