Refactor BaseDataCollector to integrate CallbackDispatcher for improved callback management

- Extracted callback management logic into a new `CallbackDispatcher` class, promoting separation of concerns and enhancing modularity.
- Updated `BaseDataCollector` to utilize the `CallbackDispatcher` for adding, removing, and notifying data callbacks, improving code clarity and maintainability.
- Refactored related methods to ensure consistent error handling and logging practices.
- Added unit tests for the `CallbackDispatcher` to validate its functionality and ensure robust error handling.

These changes streamline the callback management architecture, aligning with project standards for maintainability and performance.
This commit is contained in:
Vasily.onl
2025-06-09 17:47:26 +08:00
parent 41f0e8e6b6
commit 3db8fb1c41
4 changed files with 214 additions and 30 deletions

View File

@@ -36,13 +36,13 @@
- [x] 2.5 Add necessary imports to both `data/base_collector.py` and `data/collector/collector_connection_manager.py`.
- [x] 2.6 Create `tests/data/collector/test_collector_connection_manager.py` and add initial tests for the new class.
- [ ] 3.0 Extract `CallbackDispatcher` Class
- [ ] 3.1 Create `data/collector/collector_callback_dispatcher.py`.
- [ ] 3.2 Move `_data_callbacks` attribute to `CallbackDispatcher`.
- [ ] 3.3 Move `add_data_callback`, `remove_data_callback`, `_notify_callbacks` methods to `CallbackDispatcher`.
- [ ] 3.4 Implement a constructor for `CallbackDispatcher` to receive logger.
- [ ] 3.5 Add necessary imports to both `data/base_collector.py` and `data/collector/collector_callback_dispatcher.py`.
- [ ] 3.6 Create `tests/data/collector/test_collector_callback_dispatcher.py` and add initial tests for the new class.
- [x] 3.0 Extract `CallbackDispatcher` Class
- [x] 3.1 Create `data/collector/collector_callback_dispatcher.py`.
- [x] 3.2 Move `_data_callbacks` attribute to `CallbackDispatcher`.
- [x] 3.3 Move `add_data_callback`, `remove_data_callback`, `_notify_callbacks` methods to `CallbackDispatcher`.
- [x] 3.4 Implement a constructor for `CallbackDispatcher` to receive logger.
- [x] 3.5 Add necessary imports to both `data/base_collector.py` and `data/collector/collector_callback_dispatcher.py`.
- [x] 3.6 Create `tests/data/collector/test_collector_callback_dispatcher.py` and add initial tests for the new class.
- [ ] 4.0 Refactor `BaseDataCollector` to use new components
- [ ] 4.1 Update `BaseDataCollector.__init__` to instantiate and use `CollectorStateAndTelemetry`, `ConnectionManager`, and `CallbackDispatcher` instances.