/// <summary> /// Thread that is responsible for late initialization of network servers. /// This is needed because in order for the proximity server to run, it must know its location. /// The location is received from LOC server, but there is no guarantee LOC server is running /// when the proximity server starts. /// </summary> private async void DelayedStartupThread() { LogDiagnosticContext.Start(); log.Info("()"); delayedStartupThreadFinished.Reset(); try { Console.WriteLine("Waiting for location initialization ..."); LocationBasedNetwork loc = (LocationBasedNetwork)Base.ComponentDictionary[LocationBasedNetwork.ComponentName]; bool locInit = false; try { locInit = await loc.LocLocationInitializedEvent.Task; } catch { // Catch cancellation exception. log.Trace("Shutdown detected."); } if (locInit) { log.Debug("LOC location is initialized, we can continue with Network server component initialization."); if (base.Init()) { RegisterCronJobs(); DelayedStartupCompletedEvent.TrySetResult(true); } else { log.Error("Delayed initialization failed, initiating shutdown."); Base.ComponentManager.GlobalShutdown.SignalShutdown(); } Console.WriteLine("Location initialization completed."); } } catch (Exception e) { log.Error("Exception occurred (and rethrowing): {0}", e.ToString()); await Task.Delay(5000); throw e; } delayedStartupThreadFinished.Set(); log.Info("(-)"); LogDiagnosticContext.Stop(); }
/// <summary> /// Creates a new instance connected to the parent role server. /// </summary> public LocMessageProcessor() { log = new Logger("ProximityServer.Network.LocMessageProcessor"); serverComponent = (LocationBasedNetwork)Base.ComponentDictionary[LocationBasedNetwork.ComponentName]; }