|
PACS System 0.1.0
PACS DICOM system library
|
#include <hsm_migration_service.h>

Public Member Functions | |
| hsm_migration_service (hsm_storage &storage, const migration_service_config &config={}) | |
| Construct migration service. | |
| hsm_migration_service (hsm_storage &storage, std::shared_ptr< kcenon::thread::thread_pool > thread_pool, const migration_service_config &config={}) | |
| Construct migration service with thread pool. | |
| ~hsm_migration_service () | |
| Destructor - ensures graceful shutdown. | |
| hsm_migration_service (const hsm_migration_service &)=delete | |
| Non-copyable. | |
| hsm_migration_service & | operator= (const hsm_migration_service &)=delete |
| hsm_migration_service (hsm_migration_service &&)=delete | |
| Non-movable. | |
| hsm_migration_service & | operator= (hsm_migration_service &&)=delete |
| void | start () |
| Start the background migration service. | |
| void | stop (bool wait_for_completion=true) |
| Stop the background migration service. | |
| auto | is_running () const noexcept -> bool |
| Check if the service is running. | |
| auto | run_migration_cycle () -> migration_result |
| Manually trigger a migration cycle. | |
| void | trigger_cycle () |
| Trigger next cycle immediately. | |
| auto | get_last_result () const -> std::optional< migration_result > |
| Get the result of the last migration cycle. | |
| auto | get_cumulative_stats () const -> migration_result |
| Get total statistics since service started. | |
| auto | time_until_next_cycle () const -> std::optional< std::chrono::seconds > |
| Get the time until the next scheduled migration. | |
| auto | cycles_completed () const noexcept -> std::size_t |
| Get the number of cycles completed. | |
| void | set_migration_interval (std::chrono::seconds interval) |
| Update the migration interval. | |
| auto | get_migration_interval () const noexcept -> std::chrono::seconds |
| Get the current migration interval. | |
| void | set_progress_callback (migration_service_config::progress_callback callback) |
| Set the progress callback. | |
| void | set_error_callback (migration_service_config::error_callback callback) |
| Set the error callback. | |
Private Member Functions | |
| void | run_loop () |
| Background thread main loop. | |
| auto | execute_cycle () -> migration_result |
| Execute a single migration cycle. | |
| void | update_stats (const migration_result &result) |
| Update cumulative statistics. | |
Private Attributes | |
| hsm_storage & | storage_ |
| Reference to managed HSM storage. | |
| std::shared_ptr< kcenon::thread::thread_pool > | thread_pool_ |
| Thread pool for parallel migrations (optional) | |
| migration_service_config | config_ |
| Service configuration. | |
| std::thread | worker_thread_ |
| Background worker thread. | |
| std::mutex | mutex_ |
| Mutex for thread synchronization. | |
| std::condition_variable | cv_ |
| Condition variable for sleep/wake. | |
| std::atomic< bool > | stop_requested_ {false} |
| Flag to signal shutdown. | |
| std::atomic< bool > | running_ {false} |
| Flag indicating service is running. | |
| std::atomic< bool > | cycle_in_progress_ {false} |
| Flag indicating a cycle is in progress. | |
| std::optional< migration_result > | last_result_ |
| Last migration result. | |
| migration_result | cumulative_stats_ |
| Cumulative statistics. | |
| std::atomic< std::size_t > | cycles_count_ {0} |
| Number of completed cycles. | |
| std::chrono::steady_clock::time_point | next_cycle_time_ |
| Time of next scheduled cycle. | |
Definition at line 99 of file hsm_migration_service.h.
|
explicit |
Construct migration service.
| storage | Reference to the HSM storage to manage |
| config | Service configuration |
Definition at line 20 of file hsm_migration_service.cpp.
References kcenon::pacs::storage::migration_service_config::auto_start, and config_.
| kcenon::pacs::storage::hsm_migration_service::hsm_migration_service | ( | hsm_storage & | storage, |
| std::shared_ptr< kcenon::thread::thread_pool > | thread_pool, | ||
| const migration_service_config & | config = {} ) |
Construct migration service with thread pool.
| storage | Reference to the HSM storage to manage |
| thread_pool | Thread pool for parallel migrations |
| config | Service configuration |
Definition at line 28 of file hsm_migration_service.cpp.
References kcenon::pacs::storage::migration_service_config::auto_start, and config_.
| kcenon::pacs::storage::hsm_migration_service::~hsm_migration_service | ( | ) |
Destructor - ensures graceful shutdown.
Definition at line 40 of file hsm_migration_service.cpp.
References stop().

|
delete |
Non-copyable.
|
delete |
Non-movable.
|
nodiscardnoexcept |
Get the number of cycles completed.
Definition at line 150 of file hsm_migration_service.cpp.
References cycles_count_.
|
nodiscardprivate |
Execute a single migration cycle.
Definition at line 227 of file hsm_migration_service.cpp.
References uid.
Referenced by run_loop().

|
nodiscard |
Get total statistics since service started.
Definition at line 128 of file hsm_migration_service.cpp.
References cumulative_stats_, and mutex_.
|
nodiscard |
Get the result of the last migration cycle.
Definition at line 122 of file hsm_migration_service.cpp.
References last_result_, and mutex_.
|
nodiscardnoexcept |
Get the current migration interval.
Definition at line 164 of file hsm_migration_service.cpp.
References config_, and kcenon::pacs::storage::migration_service_config::migration_interval.
|
nodiscardnoexcept |
Check if the service is running.
Definition at line 92 of file hsm_migration_service.cpp.
References running_.
|
delete |
|
delete |
|
private |
Background thread main loop.
Definition at line 185 of file hsm_migration_service.cpp.
References config_, cv_, cycles_count_, execute_cycle(), last_result_, kcenon::pacs::storage::migration_service_config::migration_interval, mutex_, next_cycle_time_, kcenon::pacs::storage::migration_service_config::on_cycle_complete, stop_requested_, and update_stats().
Referenced by start().


|
nodiscard |
Manually trigger a migration cycle.
Runs a migration cycle immediately, regardless of the scheduled interval. Can be called whether the service is running or not.
Definition at line 100 of file hsm_migration_service.cpp.
| void kcenon::pacs::storage::hsm_migration_service::set_error_callback | ( | migration_service_config::error_callback | callback | ) |
Set the error callback.
| callback | Function called when a migration fails |
Definition at line 175 of file hsm_migration_service.cpp.
References config_, mutex_, and kcenon::pacs::storage::migration_service_config::on_migration_error.
| void kcenon::pacs::storage::hsm_migration_service::set_migration_interval | ( | std::chrono::seconds | interval | ) |
Update the migration interval.
| interval | New interval between migration cycles |
Definition at line 158 of file hsm_migration_service.cpp.
References config_, kcenon::pacs::storage::migration_service_config::migration_interval, and mutex_.
| void kcenon::pacs::storage::hsm_migration_service::set_progress_callback | ( | migration_service_config::progress_callback | callback | ) |
Set the progress callback.
| callback | Function called after each migration cycle |
Definition at line 169 of file hsm_migration_service.cpp.
References config_, mutex_, and kcenon::pacs::storage::migration_service_config::on_cycle_complete.
| void kcenon::pacs::storage::hsm_migration_service::start | ( | ) |
Start the background migration service.
Starts the background thread that runs periodic migration cycles. If already started, this is a no-op.
Definition at line 48 of file hsm_migration_service.cpp.
References config_, kcenon::pacs::storage::migration_service_config::migration_interval, mutex_, next_cycle_time_, run_loop(), running_, stop_requested_, and worker_thread_.

| void kcenon::pacs::storage::hsm_migration_service::stop | ( | bool | wait_for_completion = true | ) |
Stop the background migration service.
Gracefully stops the service, waiting for any in-progress migrations to complete. If not started, this is a no-op.
| wait_for_completion | If true, waits for current cycle to complete |
Definition at line 66 of file hsm_migration_service.cpp.
References cv_, mutex_, running_, stop_requested_, and worker_thread_.
Referenced by ~hsm_migration_service().

|
nodiscard |
Get the time until the next scheduled migration.
Definition at line 133 of file hsm_migration_service.cpp.
References mutex_, next_cycle_time_, and running_.
| void kcenon::pacs::storage::hsm_migration_service::trigger_cycle | ( | ) |
Trigger next cycle immediately.
Wakes up the background thread to run a migration cycle immediately, without waiting for the scheduled interval. Only works if service is running.
Definition at line 104 of file hsm_migration_service.cpp.
References cv_, mutex_, next_cycle_time_, and running_.
|
private |
Update cumulative statistics.
| result | Result from latest cycle |
Definition at line 244 of file hsm_migration_service.cpp.
References kcenon::pacs::storage::migration_result::bytes_migrated, cumulative_stats_, kcenon::pacs::storage::migration_result::duration, kcenon::pacs::storage::migration_result::failed_uids, kcenon::pacs::storage::migration_result::instances_migrated, kcenon::pacs::storage::migration_result::instances_skipped, mutex_, and uid.
Referenced by run_loop().

|
private |
Service configuration.
Definition at line 293 of file hsm_migration_service.h.
Referenced by get_migration_interval(), hsm_migration_service(), hsm_migration_service(), run_loop(), set_error_callback(), set_migration_interval(), set_progress_callback(), and start().
|
private |
Cumulative statistics.
Definition at line 317 of file hsm_migration_service.h.
Referenced by get_cumulative_stats(), and update_stats().
|
private |
Condition variable for sleep/wake.
Definition at line 302 of file hsm_migration_service.h.
Referenced by run_loop(), stop(), and trigger_cycle().
|
private |
Flag indicating a cycle is in progress.
Definition at line 311 of file hsm_migration_service.h.
|
private |
Number of completed cycles.
Definition at line 320 of file hsm_migration_service.h.
Referenced by cycles_completed(), and run_loop().
|
private |
Last migration result.
Definition at line 314 of file hsm_migration_service.h.
Referenced by get_last_result(), and run_loop().
|
mutableprivate |
Mutex for thread synchronization.
Definition at line 299 of file hsm_migration_service.h.
Referenced by get_cumulative_stats(), get_last_result(), run_loop(), set_error_callback(), set_migration_interval(), set_progress_callback(), start(), stop(), time_until_next_cycle(), trigger_cycle(), and update_stats().
|
private |
Time of next scheduled cycle.
Definition at line 323 of file hsm_migration_service.h.
Referenced by run_loop(), start(), time_until_next_cycle(), and trigger_cycle().
|
private |
Flag indicating service is running.
Definition at line 308 of file hsm_migration_service.h.
Referenced by is_running(), start(), stop(), time_until_next_cycle(), and trigger_cycle().
|
private |
Flag to signal shutdown.
Definition at line 305 of file hsm_migration_service.h.
Referenced by run_loop(), start(), and stop().
|
private |
Reference to managed HSM storage.
Definition at line 287 of file hsm_migration_service.h.
|
private |
Thread pool for parallel migrations (optional)
Definition at line 290 of file hsm_migration_service.h.
|
private |
Background worker thread.
Definition at line 296 of file hsm_migration_service.h.