iceberg-cpp
Loading...
Searching...
No Matches
iceberg
catalog
rest
auth
token_refresh_scheduler.h
Go to the documentation of this file.
1
/*
2
* Licensed to the Apache Software Foundation (ASF) under one
3
* or more contributor license agreements. See the NOTICE file
4
* distributed with this work for additional information
5
* regarding copyright ownership. The ASF licenses this file
6
* to you under the Apache License, Version 2.0 (the
7
* "License"); you may not use this file except in compliance
8
* with the License. You may obtain a copy of the License at
9
*
10
* http://www.apache.org/licenses/LICENSE-2.0
11
*
12
* Unless required by applicable law or agreed to in writing,
13
* software distributed under the License is distributed on an
14
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
* KIND, either express or implied. See the License for the
16
* specific language governing permissions and limitations
17
* under the License.
18
*/
19
20
#pragma once
21
22
#include <chrono>
23
#include <condition_variable>
24
#include <cstdint>
25
#include <functional>
26
#include <mutex>
27
#include <thread>
28
#include <vector>
29
30
#include "iceberg/catalog/rest/iceberg_rest_export.h"
31
34
35
namespace
iceberg::rest::auth {
36
47
class
ICEBERG_REST_EXPORT
TokenRefreshScheduler
{
48
public
:
54
static
TokenRefreshScheduler
& Instance();
55
61
uint64_t Schedule(std::chrono::milliseconds delay, std::function<
void
()> callback);
62
68
void
Cancel(uint64_t handle);
69
78
void
Shutdown();
79
80
~TokenRefreshScheduler
();
81
82
// Non-copyable, non-movable
83
TokenRefreshScheduler
(
const
TokenRefreshScheduler
&) =
delete
;
84
TokenRefreshScheduler
& operator=(
const
TokenRefreshScheduler
&) =
delete
;
85
TokenRefreshScheduler
(
TokenRefreshScheduler
&&) =
delete
;
86
TokenRefreshScheduler
& operator=(
TokenRefreshScheduler
&&) =
delete
;
87
92
TokenRefreshScheduler
();
93
94
private
:
96
void
Run();
97
98
struct
Task {
99
uint64_t id;
100
std::chrono::steady_clock::time_point fire_at;
101
std::function<void()> callback;
102
};
103
104
std::mutex mutex_;
105
std::condition_variable cv_;
106
std::vector<Task> tasks_;
107
uint64_t next_id_ = 1;
// 0 is reserved as "invalid handle"
108
bool
shutdown_ =
false
;
109
std::thread worker_;
110
};
111
112
}
// namespace iceberg::rest::auth
iceberg::rest::auth::TokenRefreshScheduler
A process-global scheduler for delayed token refresh tasks.
Definition
token_refresh_scheduler.h:47
Generated by
1.9.8