pub struct RuntimeBuilder { /* private fields */ }
Expand description
Builder structure to help create a Runtime.
Most of the internals of the Runtime can left to their default values. Leveraging a builder pattern thus simplifies the creation of a Runtime.
Implementations§
Source§impl RuntimeBuilder
impl RuntimeBuilder
Sourcepub fn runtime_id(self, runtime_id: impl Into<RuntimeId>) -> Result<Self>
pub fn runtime_id(self, runtime_id: impl Into<RuntimeId>) -> Result<Self>
Forces the identifier of the Runtime to be build.
If no Session is provided, this identifier will be forced on the Session.
§Errors
This method will fail if the Zenoh feature is enabled (it is by default) and a Session was already provided. Zenoh-Flow will re-use the unique identifier of the Zenoh session for the Runtime.
⚠️ If the runtime identifier is set first and a Session is provided after, the runtime identifier will be overwritten by the identifier of the Zenoh session.
§Example
use zenoh_flow_runtime::Runtime;
use zenoh_flow_commons::RuntimeId;
let builder = Runtime::builder("demo")
.runtime_id(RuntimeId::rand());
Sourcepub fn session(self, session: Arc<Session>) -> Self
pub fn session(self, session: Arc<Session>) -> Self
Forces the Session the Runtime should use to communicate over Zenoh.
§Runtime identifier
If a Session is provided, the Zenoh-Flow runtime will re-use the identifier of the Session as its identifier.
§Example
use zenoh_flow_runtime::Runtime;
use zenoh_flow_runtime::{zenoh, zenoh::AsyncResolve};
let zenoh_session = zenoh::open(zenoh::peer())
.res_async()
.await
.expect("Failed to open Session")
.into_arc();
let builder = Runtime::builder("demo")
.session(zenoh_session);
Sourcepub fn hlc(self, hlc: HLC) -> Self
pub fn hlc(self, hlc: HLC) -> Self
Forces the hybrid logical clock the Runtime should use.
§Example
use zenoh_flow_runtime::Runtime;
use uhlc::HLC;
let builder = Runtime::builder("demo")
.hlc(HLC::default());
Sourcepub fn add_extensions(self, extensions: Extensions) -> Result<Self>
pub fn add_extensions(self, extensions: Extensions) -> Result<Self>
Attempts to add the provided Extensions to the list of extensions supported by this Runtime.
If previous extensions were already declared for the same file extension, the newly added extensions will override the previous values.
§Errors
This method will fail if any of the extension is not valid. See here for a complete list of error cases.
Note that the extensions are added after checking them all.
§Example
use zenoh_flow_runtime::{Extensions, Runtime};
use zenoh_flow_commons::{try_parse_from_file, Vars};
let (extensions, _) = try_parse_from_file::<Extensions>(
"/home/zenoh-flow/extensions.ext",
Vars::default()
)
.expect("Failed to parse Extensions");
let builder = Runtime::builder("demo")
.add_extensions(extensions)
.expect("Failed to add set of extensions");
Sourcepub fn add_extension(
self,
file_extension: impl Into<String>,
source: impl Into<PathBuf>,
operator: impl Into<PathBuf>,
sink: impl Into<PathBuf>,
) -> Result<Self>
pub fn add_extension( self, file_extension: impl Into<String>, source: impl Into<PathBuf>, operator: impl Into<PathBuf>, sink: impl Into<PathBuf>, ) -> Result<Self>
Attempts to add a single Extension to the list of extensions supported by this Runtime.
If a previous extension was already declared for the same file extension, the newly added extension will override the previous value.
§Errors
This method will return an error if any of the library:
- does not expose the correct symbol (see these macros: 1, 2, 3),
- was not compiled with the same Rust version,
- was not using the same version of Zenoh-Flow as this runtime.
§Example
use zenoh_flow_runtime::Runtime;
let builder = Runtime::builder("demo")
.add_extension(
"py",
"/home/zenoh-flow/libpy_source.so",
"/home/zenoh-flow/libpy_operator.so",
"/home/zenoh-flow/libpy_sink.so",
)
.expect("Failed to add 'py' extension");
Sourcepub async fn build(self) -> Result<Runtime>
pub async fn build(self) -> Result<Runtime>
Attempts to build the Runtime.
§Errors
This method can fail if the zenoh
feature is enabled (it is by default), no Session was provided to the
builder and the creation of a Session failed.
§Example
use zenoh_flow_runtime::Runtime;
let runtime = Runtime::builder("demo")
.build()
.await
.expect("Failed to build Zenoh-Flow runtime");