VLink  2.0.0
A high-performance communication middleware
abstract_factory.h 文件参考

Topic-scoped registration store that fans transport callbacks across NodeImpl peers. 更多...

#include <algorithm>
#include <atomic>
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include "../base/functional.h"
#include "../base/logger.h"
#include "./node_impl.h"
abstract_factory.h 的引用(Include)关系图:

浏览源代码.

class  vlink::AbstractObject< FilterT >
 Topic-scoped fan-out store of NodeImpl peers and their callbacks. 更多...
 
class  vlink::AbstractFactory< FilterT >
 Lazily allocates and caches AbstractObject instances keyed by FilterT. 更多...
 

命名空间

 

详细描述

Topic-scoped registration store that fans transport callbacks across NodeImpl peers.

This is an internal implementation header used by the public VLink node templates (Publisher, Subscriber, Client, Server, Setter, Getter); it should not be included directly by application code. The header introduces two co-operating class templates that let several NodeImpl instances bound to the same logical topic share one registration record:

  • AbstractObject – a per-topic record that owns the set of registered NodeImpl pointers together with six callback dictionaries (server connect, subscriber connect, request/response, serialised message, intra-process message and transport status).
  • AbstractFactory – a thread-safe map keyed on FilterT (commonly the topic URL string) that lazily creates an AbstractObject for each key and reuses it via a cached std::weak_ptr until the last owner releases it.
Registration flow
+----------------------+
| AbstractFactory<K> |
| map<K, weak_ptr<O>> |
+----------+-----------+
| get_object<O>(key)
v
+----------------------+
| AbstractObject<K> |
| ImplList |
| ConnectCallbackMap |
| MsgCallbackMap ... |
+----------+-----------+
^ | ^
add_impl(impl) | | | register_msg_callback(impl, cb)
remove_impl(impl)| | |
| v
+------+--+ +-+--------+ +----------+
| NodeImpl| | NodeImpl | | NodeImpl |
+---------+ +----------+ +----------+
Registry keys
Map field Callback signature
server_connect_callback_map_ void(bool) – server side peer presence change
sub_connect_callback_map_ void(bool) – subscriber side presence change
req_resp_callback_map_ void(uint64_t, const Bytes&, Bytes*)
msg_callback_map_ void(const Bytes&)
intra_msg_callback_map_ void(const IntraData&)
status_callback_map_ void(const Status::BasePtr&)
Example
struct TopicObject final : vlink::AbstractObject<std::string> {
};
auto object = factory.get_object<TopicObject>("dds://my_topic");
object->add_impl(impl);
object->register_msg_callback(impl, [](const vlink::Bytes& bytes) {
// forward each delivery to the owning node
});
object->traverse_msg_callback([](vlink::NodeImpl*, const vlink::NodeImpl::MsgCallback& cb) {
cb(payload);
});
注解
Every public AbstractObject method acquires the internal std::recursive_mutex; callbacks invoked through traverse_*() execute under that lock and may re-enter the same AbstractObject safely.
模板参数
FilterTKey type used to identify topics inside the factory map.