/// <summary> /// See interface docs. /// </summary> /// <param name="parameters"></param> public void Startup(PluginStartupParameters parameters) { lock (_SyncLock) { var optionsStorage = new OptionsStorage(); _Options = optionsStorage.Load(this); _Database = Factory.Singleton.Resolve <IAutoConfigBaseStationDatabase>().Singleton.Database; _Database.FileNameChanging += BaseStationDatabase_FileNameChanging; _Database.FileNameChanged += BaseStationDatabase_FileNameChanged; _StandingDataManager = Factory.Singleton.Resolve <IStandingDataManager>().Singleton; _StandingDataManager.LoadCompleted += StandingDataManager_LoadCompleted; StartSession(); // If we process messages on the same thread as IAutoConfigListener raises the message received event on then we // will be running on the same thread as the aircraft list. Our processing can take some time, particularly if many // database writes have to happen simultaneously on startup, so to avoid blocking the update of the aircraft list // we create a background thread and process the messages on that. _BackgroundThreadMessageQueue = new BackgroundThreadQueue <BaseStationMessageEventArgs>("BaseStationDatabaseWriterMessageQueue"); _BackgroundThreadMessageQueue.StartBackgroundThread(MessageQueue_MessageReceived, MessageQueue_ExceptionCaught); var listener = Factory.Singleton.Resolve <IAutoConfigListener>().Singleton.Listener; listener.Port30003MessageReceived += MessageListener_MessageReceived; listener.SourceChanged += MessageListener_SourceChanged; Factory.Singleton.Resolve <IHeartbeatService>().Singleton.SlowTick += Heartbeat_SlowTick; } }
private static void SendToWriters(LogEntry entry) { lock (LockObject) { var written = false; if (BackgroundThreadQueue.WriterCount > 0) { BackgroundThreadQueue.AddMessage(entry); written = true; } if (DirectWriters.Count > 0) { foreach (var directWriter in DirectWriters) { directWriter.Write(entry); } written = true; } if (!written) { entry.Message = $"No Writers : {entry.Message}"; WriteSystem(entry); } } }
private static void appDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { var exc = e.ExceptionObject as Exception; if (exc == null) { string exceptionObjectType = "NULL", exceptionObjectToString = "NULL"; if (e.ExceptionObject != null) //ExceptionObject was set but not an exception type { exceptionObjectType = e.ExceptionObject.GetType().FullName; exceptionObjectToString = e.ExceptionObject.ToString(); } var message = $"Unhandled Exception in AppDomain. [IsTerminating: {e.IsTerminating}, ExceptionObjectType: {exceptionObjectType}, ExceptionObject: {exceptionObjectToString}]"; WriteError(message, typeof(Log).FullName, MethodBase.GetCurrentMethod().Name); WriteSystem(message); } else { var message = $"Unhandled Exception in AppDomain. [IsTerminating: {e.IsTerminating}]"; WriteError(message, typeof(Log).FullName, MethodBase.GetCurrentMethod().Name, exc); WriteSystem(new LogEntry(Thread.CurrentThread.ManagedThreadId, DateTime.Now, typeof(Log).FullName, MethodBase.GetCurrentMethod().Name, LogEntryType.Error, exc, message)); } BackgroundThreadQueue.Exit(TimeSpan.FromSeconds(5)); }
public void Enqueue(Type type, object data) { BackgroundThreadQueue.Enqueue(new Meta(data, this) { Type = type }); }
/// <summary> /// Disposes of or finalises the object. /// </summary> /// <param name="disposing"></param> private void Dispose(bool disposing) { if (disposing) { lock (_SyncLock) _Disposed = true; foreach (var client in _ConnectedClients.ToArray()) { try { DisconnectClient(client); } catch { } } _ConnectedClients.Clear(); if (_SendQueue != null) { _SendQueue.Dispose(); _SendQueue = null; } if (_Listener != null) { try { _Listener.Stop(); _Listener = null; } catch { } } } }
/// <summary> /// See base docs. /// </summary> protected override void DoInitialise() { _AutoConfigDatabase = Factory.Singleton.Resolve <IAutoConfigBaseStationDatabase>().Singleton; _AutoConfigDatabase.Database.AircraftUpdated += BaseStationDatabase_AircraftUpdated; _AutoConfigDatabase.Database.FileNameChanged += BaseStationDatabase_FileNameChanged; _AircraftOnlineLookupManager = Factory.Singleton.Resolve <IAircraftOnlineLookupManager>().Singleton; _AircraftOnlineLookupManager.AircraftFetched += AircraftOnlineLookupManager_AircraftFetched; _PictureManager = Factory.Singleton.Resolve <IAircraftPictureManager>().Singleton; var autoConfigurationPictureFolderCache = Factory.Singleton.Resolve <IAutoConfigPictureFolderCache>().Singleton; _PictureFolderCache = autoConfigurationPictureFolderCache.DirectoryCache; autoConfigurationPictureFolderCache.CacheConfigurationChanged += AutoConfigPictureFolderCache_CacheConfigurationChanged; _StandingDataManager = Factory.Singleton.Resolve <IStandingDataManager>().Singleton; _StandingDataManager.LoadCompleted += StandingDataManager_LoadCompleted; if (_PictureLookupThread == null) { _PictureLookupThread = new BackgroundThreadQueue <LookupPictureDetail>("PictureLookup", BackgroundThreadQueueMechanism.ThreadPool); _PictureLookupThread.MaximumParallelThreads = 10; _PictureLookupThread.StartBackgroundThread(PictureLookupThread_ProcessLookup, PictureLookupThread_ProcessException); } base.DoInitialise(); }
public DatabaseRepository(ITypeTableNameProvider tableNameProvider = null, Func <SchemaDefinition, TypeSchema, string> schemaTempPathProvider = null) : base(tableNameProvider, schemaTempPathProvider) { BlockOnChildWrites = true; BackgroundThreadQueue = new BackgroundThreadQueue <SqlStringBuilder> { Process = Execute }; }
public ObjectReaderWriter(string rootDirectory) : base() { RootDirectory = rootDirectory; BackgroundThreadQueue = new BackgroundThreadQueue <Meta> { Process = Write }; }
private static void DisposeAllWriters() { foreach (var writer in DirectWriters) { writer.Dispose(); } DirectWriters.Clear(); BackgroundThreadQueue.Exit(TimeSpan.FromSeconds(1)); }
private static void RemoveWriter(ILogWriter writer) { if (writer.UseBackgroundThreadQueue) { BackgroundThreadQueue.Remove(writer); } else { DirectWriters.Remove(writer); } // adding a message as soon as the logger is removed so that the logger has a timestamp in its log for when it was removed WriteTrace($"LogWriter '{writer.GetType().Name}'({(writer.UseBackgroundThreadQueue ? "queued" : "not queued")}) removed", typeof(Log).FullName, MethodBase.GetCurrentMethod().Name); }
/// <summary> /// Creates a new object. /// </summary> public Listener() { _Statistics = Factory.Singleton.Resolve <IStatistics>().Singleton; _Port30003MessageTranslator = Factory.Singleton.Resolve <IBaseStationMessageTranslator>(); _ModeSMessageTranslator = Factory.Singleton.Resolve <IModeSTranslator>(); _AdsbMessageTranslator = Factory.Singleton.Resolve <IAdsbTranslator>(); _ModeSParity = Factory.Singleton.Resolve <IModeSParity>(); var messageQueueName = String.Format("MessageProcessingAndDispatchQueue_{0}", ++_ListenerCounter); _MessageProcessingAndDispatchQueue = new BackgroundThreadQueue <MessageDispatch>(messageQueueName); _MessageProcessingAndDispatchQueue.StartBackgroundThread(ProcessAndDispatchMessageQueueItem, HandleMessageDispatchException); }
private static void EnsureQueue() { _messageQueue = _queueLock.DoubleCheckLock(ref _messageQueue, () => { return(new BackgroundThreadQueue <ConsoleMessage>((msg) => { lock (_colorLock) { Console.ForegroundColor = msg.Colors.ForegroundColor; Console.BackgroundColor = msg.Colors.BackgroundColor; Console.Write(msg.Text); Console.ResetColor(); } })); }); }
#pragma warning restore 0067 #endregion #endregion #region Constructor, finaliser /// <summary> /// Creates a new object. /// </summary> public MergedFeedListener() { _Clock = Factory.Resolve <IClock>(); Listeners = new ReadOnlyCollection <IMergedFeedComponentListener>(_Listeners); IcaoTimeout = 5000; ConnectionStatus = ConnectionStatus.Connected; var messageQueueName = String.Format("MergedFeedListenerMessages_{0}", ++_ListenerCounter); _MessageProcessingQueue = new BackgroundThreadQueue <MessageReceived>(messageQueueName, 200000); _MessageProcessingQueue.StartBackgroundThread(ProcessReceivedMessage, HandleMessageProcessingException); var heartbeatService = Factory.ResolveSingleton <IHeartbeatService>(); heartbeatService.SlowTick += HeartbeatService_SlowTick; _HookedSlowTick = true; }
public DynamicTypeManager(DynamicTypeDataRepository descriptorRepository, DataSettings settings) { DataSettings = settings; JsonDirectory = settings.GetRootDataDirectory(nameof(DynamicTypeManager)); if (!JsonDirectory.Exists) { JsonDirectory.Create(); } descriptorRepository.EnsureDaoAssemblyAndSchema(); DynamicTypeDataRepository = descriptorRepository; JsonFileProcessor = new BackgroundThreadQueue <DataFile>() { Process = (df) => { ProcessJsonFile(df.TypeName, df.FileInfo); } }; }
/// <summary> /// Creates a new object. /// </summary> /// <param name="connector"></param> /// <param name="initialStatus"></param> public Connection(Connector connector, ConnectionStatus initialStatus) { if (connector == null) { throw new ArgumentNullException("connector"); } _Connector = connector; Created = DateTime.UtcNow; string operationQueueName; lock (_SyncLock) { operationQueueName = String.Format("ConnectionOpQueue-{0}-{1}", _Connector.Name ?? "unnamed", ++_ConnectionCount); } _OperationQueue = new BackgroundThreadQueue <ReadWriteOperation>(operationQueueName, BackgroundThreadQueueMechanism.QueueWithNoBlock, 200000); _OperationQueue.StartBackgroundThread(OperationQueue_ProcessOperation, OperationQueue_ProcessException); ConnectionStatus = initialStatus; }
/// <summary> /// See interface docs. /// </summary> /// <param name="parameters"></param> public void Startup(PluginStartupParameters parameters) { Singleton = this; lock (_SyncLock) { var optionsStorage = new OptionsStorage(); _Options = optionsStorage.Load(); _Database = Factory.Singleton.Resolve <IAutoConfigBaseStationDatabase>().Singleton.Database; _Database.FileNameChanging += BaseStationDatabase_FileNameChanging; _Database.FileNameChanged += BaseStationDatabase_FileNameChanged; _StandingDataManager = Factory.Singleton.Resolve <IStandingDataManager>().Singleton; _StandingDataManager.LoadCompleted += StandingDataManager_LoadCompleted; var feedManager = Factory.Singleton.Resolve <IFeedManager>().Singleton; feedManager.FeedsChanged += FeedManager_FeedsChanged; _OnlineLookupCache = Provider.CreateOnlineLookupCache(); _OnlineLookupCache.Database = _Database; _OnlineLookupCache.RefreshOutOfDateAircraft = _Options.RefreshOutOfDateAircraft; _OnlineLookupCache.EnabledChanged += OnlineLookupCache_EnabledChanged; StartSession(); var onlineLookupManager = Factory.Singleton.Resolve <IAircraftOnlineLookupManager>().Singleton; onlineLookupManager.RegisterCache(_OnlineLookupCache, 100, letManagerControlLifetime: false); // If we process messages on the same thread as the listener raises the message received event on then we // will be running on the same thread as the aircraft list. Our processing can take some time, particularly if many // database writes have to happen simultaneously on startup, so to avoid blocking the update of the aircraft list // we create a background thread and process the messages on that. _BackgroundThreadMessageQueue = new BackgroundThreadQueue <BaseStationMessageEventArgs>("BaseStationDatabaseWriterMessageQueue", 200000); _BackgroundThreadMessageQueue.StartBackgroundThread(MessageQueue_MessageReceived, MessageQueue_ExceptionCaught); HookFeed(); _HeartbeatService = Factory.Singleton.Resolve <IHeartbeatService>(); _HeartbeatService.SlowTick += Heartbeat_SlowTick; _HeartbeatService.Start(); } }
/// <summary> /// Creates a new object. /// </summary> public Listener() { _Clock = Factory.Singleton.Resolve <IClock>(); Statistics = Factory.Singleton.Resolve <IStatistics>(); Statistics.Initialise(); _Port30003MessageTranslator = Factory.Singleton.Resolve <IBaseStationMessageTranslator>(); _ModeSMessageTranslator = Factory.Singleton.Resolve <IModeSTranslator>(); _AdsbMessageTranslator = Factory.Singleton.Resolve <IAdsbTranslator>(); _ModeSParity = Factory.Singleton.Resolve <IModeSParity>(); _Compressor = Factory.Singleton.Resolve <IBaseStationMessageCompressor>(); _AircraftListJsonMessageConverter = Factory.Singleton.Resolve <IAircraftListJsonMessageConverter>(); _ModeSMessageTranslator.Statistics = Statistics; _AdsbMessageTranslator.Statistics = Statistics; var messageQueueName = String.Format("MessageProcessingAndDispatchQueue_{0}", ++_ListenerCounter); _MessageProcessingAndDispatchQueue = new BackgroundThreadQueue <MessageDispatch>(messageQueueName, 200000); _MessageProcessingAndDispatchQueue.StartBackgroundThread(ProcessAndDispatchMessageQueueItem, HandleMessageDispatchException); }
/// <summary> /// Flush Queue and shutdowns all Logging. /// Waits for the given timeout before forcing the shutdown. /// </summary> public static bool Exit(TimeSpan?timeout = null) { if (timeout == null) { timeout = new TimeSpan(0, 0, 10); } lock (LockObject) { SendToWriters(new LogEntry(Thread.CurrentThread.ManagedThreadId, DateTime.Now, typeof(BackgroundThreadQueue).FullName, MethodBase.GetCurrentMethod().Name, LogEntryType.Trace, null, "BackgroundThreadQueue Exit Requested")); var result = true; result = BackgroundThreadQueue.Exit(timeout.Value); AppDomain.CurrentDomain.UnhandledException -= appDomain_UnhandledException; DisposeAllWriters(); return(result); } }
private void DoAbandon(bool raiseExceptionEvent) { var inAbandon = false; BackgroundThreadQueue <ReadWriteOperation> operationQueue = null; lock (_SyncLock) { inAbandon = _InAbandon; if (!inAbandon) { _InAbandon = true; operationQueue = _OperationQueue; _OperationQueue = null; } } if (!inAbandon) { try { try { AbandonConnection(); } catch (Exception ex) { if (_Connector != null && raiseExceptionEvent) { _Connector.RaiseConnectionException(this, ex); } } if (operationQueue != null) { // This will throw a ThreadAborted exception - any code outside of a catch or finally // after this point will not run. operationQueue.Dispose(); } } finally { _InAbandon = false; } } }
/// <summary> /// Creates a new object. /// </summary> public Listener() { _Statistics = Factory.Singleton.Resolve<IStatistics>().Singleton; _Port30003MessageTranslator = Factory.Singleton.Resolve<IBaseStationMessageTranslator>(); _ModeSMessageTranslator = Factory.Singleton.Resolve<IModeSTranslator>(); _AdsbMessageTranslator = Factory.Singleton.Resolve<IAdsbTranslator>(); _ModeSParity = Factory.Singleton.Resolve<IModeSParity>(); var messageQueueName = String.Format("MessageProcessingAndDispatchQueue_{0}", ++_ListenerCounter); _MessageProcessingAndDispatchQueue = new BackgroundThreadQueue<MessageDispatch>(messageQueueName); _MessageProcessingAndDispatchQueue.StartBackgroundThread(ProcessAndDispatchMessageQueueItem, HandleMessageDispatchException); }
/// <summary> /// Disposes of or finalises the object. /// </summary> /// <param name="disposing"></param> private void Dispose(bool disposing) { if(disposing) { lock(_SyncLock) _Disposed = true; foreach(var client in _ConnectedClients.ToArray()) { try { DisconnectClient(client); } catch { } } _ConnectedClients.Clear(); if(_SendQueue != null) { _SendQueue.Dispose(); _SendQueue = null; } if(_Listener != null) { try { _Listener.Stop(); _Listener = null; } catch { } } } }
/// <summary> /// Creates a new object. /// </summary> public BroadcastProvider() { _SendQueue = new BackgroundThreadQueue<byte[]>(String.Format("BroadcastProvider{0}", ++_InstanceCounter)); _SendQueue.StartBackgroundThread(SendQueueHandler, SendQueueExceptionHandler); }
private static void AddQueueWriter(ILogWriter writer) { BackgroundThreadQueue.Add(writer); }
/// <summary> /// See interface docs. /// </summary> /// <param name="parameters"></param> public void Startup(PluginStartupParameters parameters) { lock(_SyncLock) { var optionsStorage = new OptionsStorage(); _Options = optionsStorage.Load(this); _Database = Factory.Singleton.Resolve<IAutoConfigBaseStationDatabase>().Singleton.Database; _Database.FileNameChanging += BaseStationDatabase_FileNameChanging; _Database.FileNameChanged += BaseStationDatabase_FileNameChanged; _StandingDataManager = Factory.Singleton.Resolve<IStandingDataManager>().Singleton; _StandingDataManager.LoadCompleted += StandingDataManager_LoadCompleted; StartSession(); // If we process messages on the same thread as IAutoConfigListener raises the message received event on then we // will be running on the same thread as the aircraft list. Our processing can take some time, particularly if many // database writes have to happen simultaneously on startup, so to avoid blocking the update of the aircraft list // we create a background thread and process the messages on that. _BackgroundThreadMessageQueue = new BackgroundThreadQueue<BaseStationMessageEventArgs>("BaseStationDatabaseWriterMessageQueue"); _BackgroundThreadMessageQueue.StartBackgroundThread(MessageQueue_MessageReceived, MessageQueue_ExceptionCaught); var listener = Factory.Singleton.Resolve<IAutoConfigListener>().Singleton.Listener; listener.Port30003MessageReceived += MessageListener_MessageReceived; listener.SourceChanged += MessageListener_SourceChanged; Factory.Singleton.Resolve<IHeartbeatService>().Singleton.SlowTick += Heartbeat_SlowTick; } }
/// <summary> /// Creates a new object. /// </summary> public BroadcastProvider() { _SendQueue = new BackgroundThreadQueue <byte[]>(String.Format("BroadcastProvider{0}", ++_InstanceCounter)); _SendQueue.StartBackgroundThread(SendQueueHandler, SendQueueExceptionHandler); }