CatapultServer
v0.5.0.1 (Elephant)
|
Go to the documentation of this file.
25 namespace catapult {
namespace observers {
29 return NotifyMode::Commit == context.
Mode && 0 == context.
Height.
unwrap() % pruneInterval;
33 template<
typename TAction>
35 return NotifyMode::Commit == notifyMode ? TAction::Link ==
action : TAction::Unlink ==
action;
40 template<
typename TCache>
42 const std::string& name,
46 return std::make_unique<ObserverType>(name +
"PruningObserver", [interval, gracePeriod](
const auto&,
auto& context) {
50 if (context.Height.unwrap() <= gracePeriod.
unwrap())
53 auto pruneHeight =
Height(context.Height.unwrap() - gracePeriod.
unwrap());
54 auto& cache = context.Cache.template sub<TCache>();
55 cache.prune(pruneHeight);
60 template<
typename TCache>
63 return std::make_unique<ObserverType>(name +
"PruningObserver", [interval](
const auto& notification,
const auto& context) {
67 auto& cache = context.Cache.template sub<TCache>();
68 cache.prune(notification.Timestamp);
74 template<
typename TCache>
76 const std::string& name,
79 return std::make_unique<ObserverType>(name +
"TouchObserver", [receiptType](
const auto&,
auto& context) {
80 auto& cache = context.Cache.template sub<TCache>();
81 auto expiryIds = cache.touch(context.Height);
83 if (NotifyMode::Rollback == context.Mode)
87 std::set<
typename decltype(expiryIds)::value_type> orderedExpiryIds(expiryIds.cbegin(), expiryIds.cend());
88 for (
auto id : orderedExpiryIds)
Context passed to all the observers.
Definition: ObserverContext.h:78
utils::BaseValue< uint64_t, Height_tag > Height
Definition: src/catapult/types.h:85
NotifyMode
Enumeration of possible notification modes.
Definition: ObserverContext.h:41
A notification observer implementation that wraps a function.
Definition: FunctionalNotificationObserver.h:29
constexpr ValueType unwrap() const
Unwraps this value and returns the underlying raw value.
Definition: BaseValue.h:53
NotificationObserverPointerT< model::BlockNotification > CreateCacheBlockPruningObserver(const std::string &name, size_t interval, BlockDuration gracePeriod)
Definition: ObserverUtils.h:41
NotificationObserverPointerT< model::BlockNotification > CreateCacheBlockTouchObserver(const std::string &name, model::ReceiptType receiptType)
Definition: ObserverUtils.h:75
ReceiptType
Enumeration of receipt types.
Definition: ReceiptType.h:58
NotificationObserverPointerT< model::BlockNotification > CreateCacheTimePruningObserver(const std::string &name, size_t interval)
Creates a time-based cache pruning observer with name that runs every interval blocks.
Definition: ObserverUtils.h:61
std::function< void()> action
An action function.
Definition: functions.h:27
const NotifyMode Mode
Notification mode.
Definition: ObserverContext.h:95
std::unique_ptr< const NotificationObserverT< TNotification > > NotificationObserverPointerT
A notification observer (unique) pointer.
Definition: ObserverTypes.h:34
Binary layout for an artifact expiry receipt.
Definition: Receipt.h:118
Definition: AddressExtractionExtension.cpp:28
const catapult::Height Height
Current height.
Definition: ObserverContext.h:92
constexpr bool ShouldPrune(const ObserverContext &context, size_t pruneInterval)
Returns true if context and pruneInterval indicate that pruning should be done.
Definition: ObserverUtils.h:28
constexpr bool ShouldLink(TAction action, NotifyMode notifyMode)
Returns true if action and notifyMode indicate that a link should be made.
Definition: ObserverUtils.h:34