iceberg-cpp
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
iceberg::rest::auth::TokenRefreshScheduler Class Reference

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
 
TokenRefreshScheduleroperator= (const TokenRefreshScheduler &)=delete
 
 TokenRefreshScheduler (TokenRefreshScheduler &&)=delete
 
TokenRefreshScheduleroperator= (TokenRefreshScheduler &&)=delete
 
 TokenRefreshScheduler ()
 Construct a scheduler (prefer Instance() for production use).
 

Static Public Member Functions

static TokenRefreshSchedulerInstance ()
 Get the global singleton instance.
 

Detailed Description

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).

Constructor & Destructor Documentation

◆ TokenRefreshScheduler()

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.

Member Function Documentation

◆ Cancel()

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.

Parameters
handleThe handle returned by Schedule().

◆ Instance()

TokenRefreshScheduler & iceberg::rest::auth::TokenRefreshScheduler::Instance ( )
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.

◆ Schedule()

uint64_t iceberg::rest::auth::TokenRefreshScheduler::Schedule ( std::chrono::milliseconds  delay,
std::function< void()>  callback 
)

Schedule a callback to run after a delay.

Parameters
delayTime to wait before executing the callback.
callbackFunction to execute when the delay expires.
Returns
A unique handle that can be used to cancel the task.

◆ Shutdown()

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.


The documentation for this class was generated from the following files: