pub struct Process { /* private fields */ }
Expand description

Process helper for RPC and PubSub communication.

The station library’s RPC and PubSub clients/servers require a bit of manual tuning. However, the Process helper and configuration system simplifies this. Unless specified in a config, networking for RPCs and PubSub channels are automatically generated Unix sockets based on the process name and the RPC/PubSub channel name. This allows for easy communication between processes on the same machine and being specific about configuring endpoints for processes on two different machines.

Implementations

Create a new Process from a config file.

Args:

  • name: The name to associate the process with. Best practice is that process names should be unique, as per the convention for automatically defining Unix socket paths.
  • config_path: Path to the YAML process/station configuration. This must exist even if no RPC or PubSub channels are defined in it. The directory containing this path must be writable by the user ID creating the Process instance. Any RPC method listed in the config at this path must be named as <process_name>.<rpc_name> in order for Process to find TCP configurations when calling RPCs implemented as TCP sockets.

Create a new Process with a config and run directory.

Args:

  • name: The name to associate the process with. Best practice is that process names should be unique, as per the convention for automatically defining Unix socket paths.
  • run_directory: Path to where Unix sockets will be created for this process.
  • config: A process/station configuration defining TCP interfaces.

Create a new Process from without a run directory.

Because the config has been pre-loaded and no run directory has been specified, the Process instance returned by this will not support RPC/PubSub with Unix sockets.

Args:

  • name: The name to associate the process with. Best practice is that process names should be unique, as per the convention for automatically defining Unix socket paths.
  • config: A process/station configuration defining TCP interfaces.

Call an RPC.

This function allows one to make a request to an RPC and get either the result of the call or an error returned. If the RPC endpoint is not listed in the config, it is assumed to be a Unix socket. If the endpoint does not exist, the RPC call will time out. The types for request T and response U must match waht the RPC server at the endpoint expects or an error may occur.

Args:

  • process_name: The name of the Process instance running the RPC server.
  • rpc_name: The name of the RPC running inside the target Process.
  • request: The data to pass into the RPC request.
  • timeout: The expected maximum duration of the RPC call.

Returns either the result of the RPC call on success or an RpcError on failure.

Create an RPC server.

If the RPC server is defined in the config the Process was initialized with, and the IP address in the config is localhost, then the RPC server is a TCP endpoint. If the address for the RPC server is not a localhost address, an error is returned. IF the RPC server is not listed in the config, then the endpoint is a Unix socket based on the RPC name, Process name, and config path.

Args:

  • name: The name to assign the RPC so clients can call it.
  • callback: The function that is called when the RPC server receives data.

Publish a message to a topic.

The topic must be defined in the Process config. Additionally, if publishing to a Unix socket, the run directory for the proces must exist.

Args:

  • topic: The PubSub topic to publish to.
  • message: The data to publish.

Subscribe to a topic.

The topic must be defined in the Process config and there must be an endpoint listed for the Process name. If the endpoint is a UDP endpoint, it must be a local address. Additionally, if the topic has already been subscribed to, an error will be returned.

Args:

  • topic: The PubSub topic to subscribe to.
  • callback: The function that is called when the PubSub subscriber receives data.

Return the name of the Process instance.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.