public void Start() { _subscriptions = new SubscriptionCollection(_messageBus); int heartbeatTickMultiple = (_configuration.HeartbeatIntervalMinutes * 60) / Timer.MessageTimerModule.TimerIntervalSeconds; _subscriptions.TimerSubscribe(heartbeatTickMultiple, b => b .Invoke(e => _heartbeatService.SendScheduledHeartbeat())); int monitorTickMultiple = (_configuration.StitchMonitorIntervalMinutes * 60) / Timer.MessageTimerModule.TimerIntervalSeconds; _subscriptions.TimerSubscribe(monitorTickMultiple, b => b.Invoke(e => MonitorStitchStatus())); _subscriptions.Subscribe <StitchInstanceEvent>(b => b .WithChannelName(StitchInstanceEvent.ChannelSynced) .Invoke(_heartbeatService.StitchSyncReceived)); _subscriptions.Listen <StitchHealthRequest, StitchHealthResponse>(l => l .OnDefaultChannel() .Invoke(_heartbeatService.GetStitchHealthReport)); }
public void Start() { _data.Initialize(); _subscriptions = new SubscriptionCollection(_messageBus); _cacheThreadId = _messageBus.ThreadPool.StartDedicatedWorker(); // On startup, publish the node status and get info from the backplane _subscriptions.Subscribe <CoreEvent>(b => b .WithChannelName(CoreEvent.ChannelInitialized) .Invoke(m => GenerateAndPublishNodeStatus())); _subscriptions.Subscribe <BackplaneEvent>(b => b .WithChannelName(BackplaneEvent.ChannelNetworkIdChanged) .Invoke(m => _service.SetNetworkNodeId(m.Data))); _subscriptions.Subscribe <BackplaneEvent>(b => b .WithChannelName(BackplaneEvent.ChannelSetZones) .Invoke(m => _service.SetClusterZones((m.Data ?? string.Empty).Split(',')))); // Publish the status of the node every 60 seconds int timerTickMultiple = (_configuration.StatusBroadcastIntervalMinutes * 60) / Timer.MessageTimerModule.TimerIntervalSeconds; _subscriptions.TimerSubscribe(timerTickMultiple, b => b .Invoke(t => GenerateAndPublishNodeStatus()) .OnWorkerThread()); // TODO: Publish NodeStatus to cluster when Modules or StitchInstances change _subscriptions.Listen <StitchSummaryRequest, List <StitchSummary> >(b => b .OnDefaultChannel() .Invoke(_service.GetStitchSummaries)); _subscriptions.Subscribe <ClusterMemberEvent>(b => b .WithChannelName(ClusterMemberEvent.EnteringEvent) .Invoke(SendNodeStatusToNewClusterNode)); // Save node status from other nodes _subscriptions.Subscribe <ObjectReceivedEvent <NodeStatus> >(b => b .WithChannelName(ReceivedEvent.ChannelReceived) .Invoke(m => _service.SaveNodeStatus(m.Object))); // Subscribe to events for caching stitch status _subscriptions.Subscribe <ObjectReceivedEvent <NodeStatus> >(b => b .WithChannelName(ReceivedEvent.ChannelReceived) .Invoke(m => _data.StitchCache.AddNodeStatus(m, m.Object)) .OnThread(_cacheThreadId)); _subscriptions.Subscribe <StitchInstanceEvent>(b => b .WithChannelName(StitchInstanceEvent.ChannelCreated) .Invoke(_service.HandleLocalStitchCreated) .OnThread(_cacheThreadId)); _subscriptions.Subscribe <ObjectReceivedEvent <StitchInstanceEvent> >(b => b .WithChannelName(ReceivedEvent.ReceivedEventName(StitchInstanceEvent.ChannelCreated)) .Invoke(m => _service.HandleRemoteStitchCreated(m, m.Object)) .OnThread(_cacheThreadId)); _subscriptions.Subscribe <StitchInstanceEvent>(b => b .WithChannelName(StitchInstanceEvent.ChannelDeleted) .Invoke(_service.HandleLocalStitchDeleted) .OnThread(_cacheThreadId)); _subscriptions.Subscribe <ObjectReceivedEvent <StitchInstanceEvent> >(b => b .WithChannelName(ReceivedEvent.ReceivedEventName(StitchInstanceEvent.ChannelDeleted)) .Invoke(m => _service.HandleRemoteStitchDeleted(m, m.Object)) .OnThread(_cacheThreadId)); // TODO: On Stitch Started/Stopped we should publish notification to the cluster so other Master nodes can update their // caches. // Upload package files and distribute to all nodes _subscriptions.Listen <PackageFileUploadRequest, PackageFileUploadResponse>(l => l .OnDefaultChannel() .Invoke(UploadPackageFile)); // Create new stitch instances _subscriptions.Listen <CreateInstanceRequest, CreateInstanceResponse>(l => l .OnDefaultChannel() .Invoke(_service.CreateNewInstances)); _subscriptions.Subscribe <ObjectReceivedEvent <CreateInstanceRequest> >(b => b .WithChannelName(ReceivedEvent.ChannelReceived) .Invoke(m => _service.CreateNewInstanceFromRemote(m, m.Object))); // Handle incoming commands _subscriptions.Listen <CommandRequest, CommandResponse>(b => b .OnDefaultChannel() .Invoke(_service.DispatchCommandRequest)); _subscriptions.Subscribe <ObjectReceivedEvent <CommandRequest> >(b => b .WithChannelName(ReceivedEvent.ChannelReceived) .Invoke(ore => _service.ReceiveCommandFromRemote(ore, ore.Object))); // Handle incoming command receipt messages _subscriptions.Subscribe <ObjectReceivedEvent <CommandReceipt> >(b => b .WithChannelName(ReceivedEvent.ChannelReceived) .Invoke(m => _service.ReceiveReceiptFromRemote(m, m.Object))); // Route StitchDataMessage to the correct node _subscriptions.Subscribe <StitchDataMessage>(b => b .OnDefaultChannel() .Invoke(_service.EnrichStitchDataMessageWithAddress)); }