|
iceberg-cpp
|
A process-global scheduler for delayed token refresh tasks. More...
#include <token_refresh_scheduler.h>
Public Member Functions | |
| uint64_t | Schedule (std::chrono::milliseconds delay, std::function< void()> callback) |
| Schedule a callback to run after a delay. | |
| void | Cancel (uint64_t handle) |
| Cancel a previously scheduled task. | |
| void | Shutdown () |
| Shutdown the scheduler, cancelling all pending tasks. | |
| TokenRefreshScheduler (const TokenRefreshScheduler &)=delete | |
| TokenRefreshScheduler & | operator= (const TokenRefreshScheduler &)=delete |
| TokenRefreshScheduler (TokenRefreshScheduler &&)=delete | |
| TokenRefreshScheduler & | operator= (TokenRefreshScheduler &&)=delete |
| TokenRefreshScheduler () | |
| Construct a scheduler (prefer Instance() for production use). | |
Static Public Member Functions | |
| static TokenRefreshScheduler & | Instance () |
| Get the global singleton instance. | |
A process-global scheduler for delayed token refresh tasks.
Uses a single background thread that sleeps until the next task is due. All OAuth2AuthSession instances share this scheduler. Tasks are lightweight (a single HTTP POST to refresh a token), so one thread is sufficient.
Thread safety: All public methods are thread-safe.
TODO(lishuxu): Migrate to the shared thread pool abstraction once available (see https://github.com/apache/iceberg-cpp/pull/646#discussion_r3304315308).
| iceberg::rest::auth::TokenRefreshScheduler::TokenRefreshScheduler | ( | ) |
Construct a scheduler (prefer Instance() for production use).
This constructor is public to allow testing with isolated instances. In production code, use Instance() to get the global singleton.
| void iceberg::rest::auth::TokenRefreshScheduler::Cancel | ( | uint64_t | handle | ) |
Cancel a previously scheduled task.
If the task has already fired or does not exist, this is a no-op.
| handle | The handle returned by Schedule(). |
|
static |
Get the global singleton instance.
Lazily created on first access and intentionally leaked: the worker thread is reclaimed by the OS at process exit. Tests needing deterministic shutdown should use a local instance.
| uint64_t iceberg::rest::auth::TokenRefreshScheduler::Schedule | ( | std::chrono::milliseconds | delay, |
| std::function< void()> | callback | ||
| ) |
Schedule a callback to run after a delay.
| delay | Time to wait before executing the callback. |
| callback | Function to execute when the delay expires. |
| void iceberg::rest::auth::TokenRefreshScheduler::Shutdown | ( | ) |
Shutdown the scheduler, cancelling all pending tasks.
After shutdown, Schedule() calls are no-ops (return 0). This is called automatically on destruction.
WARNING: Do not call this on the global Instance() unless you intend to permanently stop all token refresh for the entire process. This is mainly useful for testing with locally-constructed scheduler instances.