dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::Graph::TransportFactory Class Reference

Registry and factory for creating Source and Destination transports. More...

#include <dfx-graph/TransportFactory.hpp>

Public Types

using SourceBuilder = std::move_only_function<Core::SourceTransportPtr (Core::Endpoint, nlohmann::json)>
 Function signature for creating a source transport.
using DestinationBuilder = std::move_only_function<Core::DestinationTransportPtr (Core::Endpoint, nlohmann::json)>
 Function signature for creating a destination transport.

Public Member Functions

 TransportFactory ()
 Default constructor.
void registerBuilder (std::string scheme, SourceBuilder sourceBuilder, DestinationBuilder destinationBuilder)
 Register new builders for a specific scheme into the factory.
Core::SourceTransportPtr createSource (std::string_view uri, nlohmann::json config, Controller &controller)
 Creates a SourceTransport based on a URI string.
Core::SourceTransportPtr createSource (Core::Endpoint::Descriptor descriptor, nlohmann::json config, Controller &controller)
 Creates a SourceTransport based on a Core::Endpoint::Descriptor.
Core::DestinationTransportPtr createDestination (std::string_view uri, nlohmann::json config, Controller &controller)
 Creates a DestinationTransport based on a URI string.
Core::DestinationTransportPtr createDestination (Core::Endpoint::Descriptor descriptor, nlohmann::json config, Controller &controller)
 Creates a DestinationTransport based on a Core::Endpoint::Descriptor.

Static Public Member Functions

static Core::Endpoint::Descriptor descriptorFromString (std::string_view str)
 Parses a URI-like string into an endpoint descriptor.
static Core::Endpoint endpointFromDescriptor (Core::Endpoint::Descriptor desc, Core::Port *port=nullptr)
 Converts a descriptor into a concrete Endpoint.

Detailed Description

Registry and factory for creating Source and Destination transports.

The TransportFactory is responsible for translating URI-like endpoint strings (e.g., "mq:///dfx-queue/node.port" or "local_node.port") into concrete dfx::Core::Transport instances.

URI Interpretation
The factory parses strings using descriptorFromString into four segments:
  • Scheme: The protocol (e.g., "mq", "tcp", "shm"). If missing, "local" is assumed.
  • Address: Optional metadata for remote transports (e.g., the MQ path).
  • Node: The target node.
  • Port: The target port.
See also
dfx::Core::Transport, dfx::Core::Endpoint

Member Typedef Documentation

◆ DestinationBuilder

using dfx::Graph::TransportFactory::DestinationBuilder = std::move_only_function<Core::DestinationTransportPtr (Core::Endpoint, nlohmann::json)>

Function signature for creating a destination transport.

Parameters
endpointThe resolved endpoint descriptor.
configThe JSON configuration block for this specific transport.

◆ SourceBuilder

using dfx::Graph::TransportFactory::SourceBuilder = std::move_only_function<Core::SourceTransportPtr (Core::Endpoint, nlohmann::json)>

Function signature for creating a source transport.

Parameters
endpointThe resolved endpoint descriptor.
configThe JSON configuration block for this specific transport.

Constructor & Destructor Documentation

◆ TransportFactory()

dfx::Graph::TransportFactory::TransportFactory ( )

Default constructor.

Registers built-in transports (Local, MQ, etc.) into the internal builders map.

Member Function Documentation

◆ createDestination() [1/2]

Core::DestinationTransportPtr dfx::Graph::TransportFactory::createDestination ( Core::Endpoint::Descriptor descriptor,
nlohmann::json config,
Controller & controller )

Creates a DestinationTransport based on a Core::Endpoint::Descriptor.

Parameters
descriptorThe descriptor of this transport.
configThe additional transport configuration JSON.
controllerThe controller used to resolve local port references.
Returns
A unique pointer to the constructed DestinationTransport.
Exceptions
dfx::Utils::Exceptionif the scheme is unknown.

◆ createDestination() [2/2]

Core::DestinationTransportPtr dfx::Graph::TransportFactory::createDestination ( std::string_view uri,
nlohmann::json config,
Controller & controller )

Creates a DestinationTransport based on a URI string.

Performs the same resolution logic as createSource but utilizes the DestinationBuilder registry.

Parameters
uriThe URI string (e.g., "node.in").
configThe additional transport configuration JSON.
controllerThe controller used to resolve local port references.
Returns
A unique pointer to the constructed DestinationTransport.
Exceptions
dfx::Utils::Exceptionif the scheme is unknown or the URI is malformed.

◆ createSource() [1/2]

Core::SourceTransportPtr dfx::Graph::TransportFactory::createSource ( Core::Endpoint::Descriptor descriptor,
nlohmann::json config,
Controller & controller )

Creates a SourceTransport based on a Core::Endpoint::Descriptor.

Parameters
descriptorThe descriptor of this transport.
configThe additional transport configuration JSON.
controllerThe controller used to resolve local port references.
Returns
A unique pointer to the constructed SourceTransport.
Exceptions
dfx::Utils::Exceptionif the scheme is unknown.

◆ createSource() [2/2]

Core::SourceTransportPtr dfx::Graph::TransportFactory::createSource ( std::string_view uri,
nlohmann::json config,
Controller & controller )

Creates a SourceTransport based on a URI string.

This method:

  1. Parses the uri to find the scheme.
  2. Resolves the Core::Endpoint (mapping local strings to Core::Port pointers via the controller).
  3. Selects the appropriate SourceBuilder.
  4. Instantiates and returns the transport.
Parameters
uriThe URI string (e.g., "mq:///path/node.port").
configThe additional transport configuration JSON.
controllerThe controller used to resolve local port references.
Returns
A unique pointer to the constructed SourceTransport.
Exceptions
dfx::Utils::Exceptionif the scheme is unknown or the URI is malformed.

◆ descriptorFromString()

Core::Endpoint::Descriptor dfx::Graph::TransportFactory::descriptorFromString ( std::string_view str)
static

Parses a URI-like string into an endpoint descriptor.

Examples:

  • "node.port" -> scheme: "local", node: "node", port: "port"
  • "mq:///queue/node.port" -> scheme: "mq", address: "/queue", node: "node", port: "port"
Parameters
strThe string to parse (e.g., "node_name.port_name", "mq:///dfx-message-queue/node_name.port_name").
Returns
A descriptor containing the scheme, node, and port segments.

◆ endpointFromDescriptor()

Core::Endpoint dfx::Graph::TransportFactory::endpointFromDescriptor ( Core::Endpoint::Descriptor desc,
Core::Port * port = nullptr )
static

Converts a descriptor into a concrete Endpoint.

Parameters
descThe descriptor produced by descriptorFromString.
portOptional pointer to the resolved port object (Required if desc is local).
Returns
A Core::Endpoint ready for channel construction.

◆ registerBuilder()

void dfx::Graph::TransportFactory::registerBuilder ( std::string scheme,
SourceBuilder sourceBuilder,
DestinationBuilder destinationBuilder )

Register new builders for a specific scheme into the factory.

The scheme must not already be registered in the factory or an exception will be throw.

Parameters
schemeThe scheme associated with the new builder.
sourceBuilderThe builder of the Core::SourceTransport.
destinationBuilderThe builder of the Core::DestinationTransport.

The documentation for this class was generated from the following file: