Class EntityMerger

Class Documentation

class EntityMerger

Merges entities from a remote peer gateway with local entities.

Type-aware merge logic:

  • Area: merge by ID (combine tags/description, no duplication)

  • Function: merge by ID (combine hosts lists)

  • Component: merge by ID (combine tags/description, no duplication)

  • App: prefix remote ID with “peername__” on collision

After merging, a routing table maps remote entity IDs (possibly prefixed) to the peer name, enabling request forwarding. Merged entities (Area, Function, Component with same ID) do NOT appear in the routing table.

Public Functions

explicit EntityMerger(const std::string &peer_name)
std::vector<Area> merge_areas(const std::vector<Area> &local, const std::vector<Area> &remote)

Merge local and remote Areas by ID.

Same area ID from both local and remote yields one Area entity. Remote-only areas are added with source tagged as “peer:<name>”.

std::vector<Function> merge_functions(const std::vector<Function> &local, const std::vector<Function> &remote)

Merge local and remote Functions by ID, combining hosts lists.

Same function ID from both local and remote yields one Function with the union of hosts from both sides.

std::vector<Component> merge_components(const std::vector<Component> &local, const std::vector<Component> &remote)

Merge local and remote Components by ID.

Same component ID from both local and remote yields one Component entity with merged tags and description. Remote-only components are added with source tagged as “peer:<name>”.

std::vector<App> merge_apps(const std::vector<App> &local, const std::vector<App> &remote)

Merge local and remote Apps with prefix on collision.

If a remote App has the same ID as a local one, the remote entity gets its ID prefixed with “peername__”.

const std::unordered_map<std::string, std::string> &get_routing_table() const

Get the routing table: entity_id -> peer_name for remote entities.

Prefixed entities map their prefixed ID. Merged entities (Area/Function) do not appear in the routing table. Non-colliding remote Components/Apps still appear because they need request forwarding.

Public Static Attributes

static constexpr const char *SEPARATOR = "__"

Separator used for prefixing remote entity IDs on collision.