VLink  2.0.0
A high-performance communication middleware
vlink::AckManager类 参考final

Thread-safe coordinator that pairs RPC requests with their acknowledgements. 更多...

#include <ack_manager.h>

vlink::AckManager 的协作图:

Public 类型

using ProcessCallback = MoveFunction< bool()>
 Send callback supplied to process(); returning false aborts the wait. 更多...
 
using NotifyCallback = MoveFunction< void()>
 Optional fill-in callback invoked from inside notify() under the lock. 更多...
 
using RequestPtr = std::shared_ptr< Request >
 Shared handle representing a single in-flight RPC request. 更多...
 

Public 成员函数

 AckManager () noexcept
 Constructs an empty manager. 更多...
 
 ~AckManager () noexcept
 Destroys the manager and releases any remaining pending records. 更多...
 
RequestPtr create_request () noexcept
 Allocates a new request token with the next monotonic sequence number. 更多...
 
bool process (RequestPtr request, int ms, ProcessCallback &&process_callback) noexcept
 Publishes request via process_callback and blocks until it is acknowledged. 更多...
 
bool notify (RequestPtr request, NotifyCallback &&notify_callback=nullptr) noexcept
 Resolves request and, if supplied, runs notify_callback before waking the caller. 更多...
 
bool remove (RequestPtr request) noexcept
 Cancels request without waking any waiter. 更多...
 
void clear () noexcept
 Interrupts every pending wait and refuses new ones until reset_interrupted(). 更多...
 
void reset_interrupted () noexcept
 Permits new process() calls again after a previous clear(). 更多...
 

详细描述

Thread-safe coordinator that pairs RPC requests with their acknowledgements.

Stores a sorted set of in-flight RequestPtr handles indexed by their sequence number and uses one condition variable per request to wake the blocked caller when notify() arrives. Used internally by every ClientImpl subclass to provide the blocking call() semantics exposed at the public Client API.

成员类型定义说明

◆ NotifyCallback

Optional fill-in callback invoked from inside notify() under the lock.

Lets the transport copy the response into the caller's buffer before the waiting thread is resumed. May be nullptr.

◆ ProcessCallback

Send callback supplied to process(); returning false aborts the wait.

Invoked while the request is already part of the pending set, so any concurrent notify() that arrives before the callback returns is safe.

◆ RequestPtr

using vlink::AckManager::RequestPtr = std::shared_ptr<Request>

Shared handle representing a single in-flight RPC request.

Returned by create_request() and consumed by process(), notify() and remove(). Equality is implied by the monotonic sequence number.

构造及析构函数说明

◆ AckManager()

vlink::AckManager::AckManager ( )
noexcept

Constructs an empty manager.

◆ ~AckManager()

vlink::AckManager::~AckManager ( )
noexcept

Destroys the manager and releases any remaining pending records.

成员函数说明

◆ clear()

void vlink::AckManager::clear ( )
noexcept

Interrupts every pending wait and refuses new ones until reset_interrupted().

Bumps the generation counter, drains the pending set into a local copy and notifies every condition variable so that the affected process() calls return false. Used during node shutdown to avoid blocking destructors.

◆ create_request()

RequestPtr vlink::AckManager::create_request ( )
noexcept

Allocates a new request token with the next monotonic sequence number.

返回
Shared handle ready to be passed to process().

◆ notify()

bool vlink::AckManager::notify ( RequestPtr  request,
NotifyCallback &&  notify_callback = nullptr 
)
noexcept

Resolves request and, if supplied, runs notify_callback before waking the caller.

Erases the entry from the pending set, executes notify_callback while holding the request lock so the caller observes the side effects before resuming, and signals the condition variable.

参数
requestToken to acknowledge.
notify_callbackOptional callable executed before notification.
返回
true if the request was still pending and was resolved; false otherwise.

◆ process()

bool vlink::AckManager::process ( RequestPtr  request,
int  ms,
ProcessCallback &&  process_callback 
)
noexcept

Publishes request via process_callback and blocks until it is acknowledged.

The method performs four steps:

  1. Registers request in the pending set; returns false straight away if clear() has been called and not yet reset.
  2. Invokes process_callback to dispatch the request. When the callback returns false the entry is removed and process() also returns false.
  3. Sleeps on a per-request condition variable until notify() / remove() fires or ms expires. A negative ms blocks forever.
  4. Returns true on a successful notify(); false on timeout, abort or clear() interruption.
参数
requestToken obtained from create_request().
msWait budget in milliseconds; negative for unlimited.
process_callbackSend callback; returning false aborts the wait.
返回
true on acknowledgement, false otherwise.

◆ remove()

bool vlink::AckManager::remove ( RequestPtr  request)
noexcept

Cancels request without waking any waiter.

参数
requestToken to drop from the pending set.
返回
true if the entry existed and was removed; false otherwise.

◆ reset_interrupted()

void vlink::AckManager::reset_interrupted ( )
noexcept

Permits new process() calls again after a previous clear().

Does not unblock requests interrupted by the earlier clear(); the generation tag they were created in remains cancelled.


该类的文档由以下文件生成: