Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
LedgerCacheLoadingState.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2026, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "data/LedgerCacheInterface.hpp"
23
24#include <atomic>
25#include <functional>
26#include <memory>
27
28namespace data {
29
38public:
39 virtual ~LedgerCacheLoadingStateInterface() = default;
40
44 virtual void
46
51 [[nodiscard]] virtual bool
52 isLoadingAllowed() const = 0;
53
58 virtual void
60
65 [[nodiscard]] virtual bool
66 isCurrentlyLoading() const = 0;
67
74 [[nodiscard]] virtual std::unique_ptr<LedgerCacheLoadingStateInterface>
75 clone() const = 0;
76};
77
85 std::reference_wrapper<LedgerCacheInterface const> cache_;
86 std::shared_ptr<std::atomic_bool> isLoadingAllowed_ = std::make_shared<std::atomic_bool>(false);
87
88public:
93 explicit LedgerCacheLoadingState(LedgerCacheInterface const& cache);
94
96 void
97 allowLoading() override;
98
100 [[nodiscard]] bool
101 isLoadingAllowed() const override;
102
104 void
105 waitForLoadingAllowed() const override;
106
108 [[nodiscard]] bool
109 isCurrentlyLoading() const override;
110
112 [[nodiscard]] std::unique_ptr<LedgerCacheLoadingStateInterface>
113 clone() const override;
114};
115
116} // namespace data
Cache for an entire ledger.
Definition LedgerCacheInterface.hpp:40
Interface for coordinating cache loading permissions across a cluster.
Definition LedgerCacheLoadingState.hpp:37
virtual void waitForLoadingAllowed() const =0
Block until loading is permitted.
virtual std::unique_ptr< LedgerCacheLoadingStateInterface > clone() const =0
Create a clone that shares the same loading-allowed flag.
virtual bool isCurrentlyLoading() const =0
Check whether the cache is currently being loaded from the backend.
virtual bool isLoadingAllowed() const =0
Check whether loading has been permitted.
virtual void allowLoading()=0
Allow this node to begin loading the cache from the backend.
bool isCurrentlyLoading() const override
Check whether the cache is currently being loaded from the backend.
Definition LedgerCacheLoadingState.cpp:52
std::unique_ptr< LedgerCacheLoadingStateInterface > clone() const override
Create a clone that shares the same loading-allowed flag.
Definition LedgerCacheLoadingState.cpp:58
LedgerCacheLoadingState(LedgerCacheInterface const &cache)
Construct a new LedgerCacheLoadingState.
Definition LedgerCacheLoadingState.cpp:28
void allowLoading() override
Allow this node to begin loading the cache from the backend.
Definition LedgerCacheLoadingState.cpp:33
bool isLoadingAllowed() const override
Check whether loading has been permitted.
Definition LedgerCacheLoadingState.cpp:40
void waitForLoadingAllowed() const override
Block until loading is permitted.
Definition LedgerCacheLoadingState.cpp:46
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:75