diff --git a/plugins/example-plugin/src/lib.rs b/plugins/example-plugin/src/lib.rs index 5e82170376..18dbedb2aa 100644 --- a/plugins/example-plugin/src/lib.rs +++ b/plugins/example-plugin/src/lib.rs @@ -47,7 +47,7 @@ impl Plugin for ExamplePlugin { // The first operation called by zenohd on the plugin fn start(name: &str, runtime: &Self::StartArgs) -> ZResult { - let config = runtime.config.lock(); + let config = runtime.config().lock(); let self_cfg = config.plugin(name).unwrap().as_object().unwrap(); // get the plugin's config details from self_cfg Map (here the "storage-selector" property) let selector: KeyExpr = match self_cfg.get("storage-selector") { diff --git a/plugins/zenoh-plugin-rest/src/lib.rs b/plugins/zenoh-plugin-rest/src/lib.rs index 6cea5f8e0c..6c908bf92c 100644 --- a/plugins/zenoh-plugin-rest/src/lib.rs +++ b/plugins/zenoh-plugin-rest/src/lib.rs @@ -225,7 +225,7 @@ impl Plugin for RestPlugin { let _ = env_logger::try_init(); log::debug!("REST plugin {}", LONG_VERSION.as_str()); - let runtime_conf = runtime.config.lock(); + let runtime_conf = runtime.config().lock(); let plugin_conf = runtime_conf .plugin(name) .ok_or_else(|| zerror!("Plugin `{}`: missing config", name))?; @@ -476,7 +476,7 @@ pub async fn run(runtime: Runtime, conf: Config) -> ZResult<()> { // But cannot be done twice in case of static link. let _ = env_logger::try_init(); - let zid = runtime.zid.to_string(); + let zid = runtime.zid().to_string(); let session = zenoh::init(runtime).res().await.unwrap(); let mut app = Server::with_state((Arc::new(session), zid)); diff --git a/plugins/zenoh-plugin-storage-manager/src/lib.rs b/plugins/zenoh-plugin-storage-manager/src/lib.rs index e9d9f6594b..0c4d4778c2 100644 --- a/plugins/zenoh-plugin-storage-manager/src/lib.rs +++ b/plugins/zenoh-plugin-storage-manager/src/lib.rs @@ -65,7 +65,7 @@ impl Plugin for StoragesPlugin { std::mem::drop(env_logger::try_init()); log::debug!("StorageManager plugin {}", LONG_VERSION.as_str()); let config = - { PluginConfig::try_from((name, runtime.config.lock().plugin(name).unwrap())) }?; + { PluginConfig::try_from((name, runtime.config().lock().plugin(name).unwrap())) }?; Ok(Box::new(StorageRuntime::from(StorageRuntimeInner::new( runtime.clone(), config, @@ -85,7 +85,8 @@ impl StorageRuntimeInner { fn status_key(&self) -> String { format!( "@/router/{}/status/plugins/{}", - &self.runtime.zid, &self.name + &self.runtime.zid(), + &self.name ) } fn new(runtime: Runtime, config: PluginConfig) -> ZResult { diff --git a/zenoh/src/info.rs b/zenoh/src/info.rs index b8b3d0bd88..5ab1cf4c3e 100644 --- a/zenoh/src/info.rs +++ b/zenoh/src/info.rs @@ -41,7 +41,7 @@ impl<'a> Resolvable for ZidBuilder<'a> { impl<'a> SyncResolve for ZidBuilder<'a> { fn res_sync(self) -> Self::To { - self.session.runtime.zid + self.session.runtime.zid() } } diff --git a/zenoh/src/liveliness.rs b/zenoh/src/liveliness.rs index be39e3b7f6..6604d069e6 100644 --- a/zenoh/src/liveliness.rs +++ b/zenoh/src/liveliness.rs @@ -185,11 +185,14 @@ impl<'a> Liveliness<'a> { >>::Error: Into, { let key_expr = key_expr.try_into().map_err(Into::into); - let conf = self.session.runtime.config.lock(); + let timeout = { + let conf = self.session.runtime.config().lock(); + Duration::from_millis(unwrap_or_default!(conf.queries_default_timeout())) + }; LivelinessGetBuilder { session: &self.session, key_expr, - timeout: Duration::from_millis(unwrap_or_default!(conf.queries_default_timeout())), + timeout, handler: DefaultHandler, } } diff --git a/zenoh/src/net/routing/network.rs b/zenoh/src/net/routing/network.rs index 3af1e0a87c..34ef6e90f3 100644 --- a/zenoh/src/net/routing/network.rs +++ b/zenoh/src/net/routing/network.rs @@ -134,7 +134,7 @@ impl Network { log::debug!("{} Add node (self) {}", name, zid); let idx = graph.add_node(Node { zid, - whatami: Some(runtime.whatami), + whatami: Some(runtime.whatami()), locators: None, sn: 1, links: vec![], diff --git a/zenoh/src/net/routing/resource.rs b/zenoh/src/net/routing/resource.rs index e26a9217f3..2b60a301ea 100644 --- a/zenoh/src/net/routing/resource.rs +++ b/zenoh/src/net/routing/resource.rs @@ -363,6 +363,7 @@ impl Resource { } } + #[allow(dead_code)] pub fn print_tree(from: &Arc) -> String { let mut result = from.expr(); result.push('\n'); diff --git a/zenoh/src/net/routing/router.rs b/zenoh/src/net/routing/router.rs index dbf687ba79..5a2369f08c 100644 --- a/zenoh/src/net/routing/router.rs +++ b/zenoh/src/net/routing/router.rs @@ -140,6 +140,7 @@ impl Tables { &self.root_res } + #[allow(dead_code)] pub fn print(&self) -> String { Resource::print_tree(&self.root_res) } diff --git a/zenoh/src/net/runtime/mod.rs b/zenoh/src/net/runtime/mod.rs index 92d369e998..c776e229d4 100644 --- a/zenoh/src/net/runtime/mod.rs +++ b/zenoh/src/net/runtime/mod.rs @@ -47,16 +47,16 @@ use zenoh_transport::{ }; pub struct RuntimeState { - pub zid: ZenohId, - pub whatami: WhatAmI, - pub metadata: serde_json::Value, - pub router: Arc, - pub config: Notifier, - pub manager: TransportManager, - pub transport_handlers: std::sync::RwLock>>, - pub(crate) locators: std::sync::RwLock>, - pub hlc: Option>, - pub(crate) stop_source: std::sync::RwLock>, + zid: ZenohId, + whatami: WhatAmI, + metadata: serde_json::Value, + router: Arc, + config: Notifier, + manager: TransportManager, + transport_handlers: std::sync::RwLock>>, + locators: std::sync::RwLock>, + hlc: Option>, + stop_source: std::sync::RwLock>, } #[derive(Clone)] @@ -213,6 +213,26 @@ impl Runtime { .as_ref() .map(|source| async_std::task::spawn(future.timeout_at(source.token()))) } + + pub(crate) fn router(&self) -> Arc { + self.router.clone() + } + + pub fn config(&self) -> &Notifier { + &self.config + } + + pub fn hlc(&self) -> Option<&HLC> { + self.hlc.as_ref().map(Arc::as_ref) + } + + pub fn zid(&self) -> ZenohId { + self.zid + } + + pub fn whatami(&self) -> WhatAmI { + self.whatami + } } struct RuntimeTransportEventHandler { diff --git a/zenoh/src/session.rs b/zenoh/src/session.rs index 744f21965f..d83981ed53 100644 --- a/zenoh/src/session.rs +++ b/zenoh/src/session.rs @@ -333,7 +333,7 @@ impl Session { aggregated_publishers: Vec, ) -> impl Resolve { ResolveClosure::new(move || { - let router = runtime.router.clone(); + let router = runtime.router(); let state = Arc::new(RwLock::new(SessionState::new( aggregated_subscribers, aggregated_publishers, @@ -426,7 +426,7 @@ impl Session { } pub fn hlc(&self) -> Option<&HLC> { - self.runtime.hlc.as_ref().map(Arc::as_ref) + self.runtime.hlc() } /// Close the zenoh [`Session`](Session). @@ -491,7 +491,7 @@ impl Session { /// # }) /// ``` pub fn config(&self) -> &Notifier { - &self.runtime.config + &self.runtime.config() } /// Get informations about the zenoh [`Session`](Session). @@ -780,7 +780,10 @@ impl Session { >>::Error: Into, { let selector = selector.try_into().map_err(Into::into); - let conf = self.runtime.config.lock(); + let timeout = { + let conf = self.runtime.config().lock(); + Duration::from_millis(unwrap_or_default!(conf.queries_default_timeout())) + }; GetBuilder { session: self, selector, @@ -788,7 +791,7 @@ impl Session { target: QueryTarget::default(), consolidation: QueryConsolidation::default(), destination: Locality::default(), - timeout: Duration::from_millis(unwrap_or_default!(conf.queries_default_timeout())), + timeout, value: None, handler: DefaultHandler, } @@ -1590,7 +1593,7 @@ impl Session { }; task::spawn({ let state = self.state.clone(); - let zid = self.runtime.zid; + let zid = self.runtime.zid(); async move { task::sleep(timeout).await; let mut state = zwrite!(state); @@ -1731,7 +1734,7 @@ impl Session { let parameters = parameters.to_owned(); - let zid = self.runtime.zid; // @TODO build/use prebuilt specific zid + let zid = self.runtime.zid(); // @TODO build/use prebuilt specific zid let query = Query { inner: Arc::new(QueryInner { diff --git a/zenohd/src/main.rs b/zenohd/src/main.rs index 2b23604c83..5c9396e3d8 100644 --- a/zenohd/src/main.rs +++ b/zenohd/src/main.rs @@ -137,7 +137,7 @@ clap::Arg::new("adminspace-permissions").long("adminspace-permissions").value_na log::info!("Finished loading plugins"); { - let mut config_guard = runtime.config.lock(); + let mut config_guard = runtime.config().lock(); for (name, (_, plugin)) in plugins.running_plugins() { let hook = plugin.config_checker(); config_guard.add_plugin_validator(name, hook)