Skip to content

Commit 8a4321a

Browse files
committed
[eclipse-iceoryx#674] Rename Monitor to Service
1 parent 273805f commit 8a4321a

File tree

10 files changed

+196
-221
lines changed

10 files changed

+196
-221
lines changed

iceoryx2-cli/iox2-service/src/cli.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct DetailsOptions {
5858
}
5959

6060
#[derive(Parser)]
61-
pub struct MonitorOptions {
61+
pub struct DiscoveryOptions {
6262
#[clap(
6363
short,
6464
long,
@@ -93,8 +93,8 @@ pub enum Action {
9393
)]
9494
Details(DetailsOptions),
9595
#[clap(
96-
about = "Start a service monitor",
97-
help_template = help_template("iox2 service monitor", false)
96+
about = "Runs the service discovery service within a process",
97+
help_template = help_template("iox2 service discovery", false)
9898
)]
99-
Monitor(MonitorOptions),
99+
Discovery(DiscoveryOptions),
100100
}

iceoryx2-cli/iox2-service/src/commands.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use iceoryx2_cli::filter::Filter;
1818
use iceoryx2_cli::output::ServiceDescription;
1919
use iceoryx2_cli::output::ServiceDescriptor;
2020
use iceoryx2_cli::Format;
21-
use iceoryx2_services_discovery::service::Monitor;
22-
use iceoryx2_services_discovery::service::MonitorConfig;
21+
use iceoryx2_services_discovery::service_discovery::DiscoveryConfig;
22+
use iceoryx2_services_discovery::service_discovery::Service as DiscoveryService;
2323

2424
use crate::cli::OutputFilter;
2525

@@ -96,16 +96,16 @@ impl ChangeDetails {
9696
}
9797

9898
#[derive(serde::Serialize)]
99-
struct SerializableMonitorConfig {
99+
struct SerializableDiscoveryConfig {
100100
publish_events: bool,
101101
max_subscribers: usize,
102102
send_notifications: bool,
103103
max_listeners: usize,
104104
include_internal: bool,
105105
}
106106

107-
impl SerializableMonitorConfig {
108-
fn from_config(config: &MonitorConfig) -> Self {
107+
impl SerializableDiscoveryConfig {
108+
fn from_config(config: &DiscoveryConfig) -> Self {
109109
Self {
110110
publish_events: config.publish_events,
111111
max_subscribers: config.max_subscribers,
@@ -124,32 +124,34 @@ impl SerializableMonitorConfig {
124124
/// * `rate` - The update rate in milliseconds between monitor refreshes
125125
/// * `publish_events` - Whether to publish events about service changes
126126
/// * `send_notifications` - Whether to send notifications about service changes
127-
pub fn monitor(
127+
pub fn discovery(
128128
rate: u64,
129129
publish_events: bool,
130130
max_subscribers: usize,
131131
send_notifications: bool,
132132
max_listeners: usize,
133133
format: Format,
134134
) -> Result<()> {
135-
let monitor_config = MonitorConfig {
135+
let monitor_config = DiscoveryConfig {
136136
publish_events,
137137
max_subscribers,
138138
send_notifications,
139139
max_listeners,
140140
include_internal: false,
141141
};
142142

143-
let mut monitor = Monitor::<ipc::Service>::create(&monitor_config, &Config::global_config())
144-
.map_err(|e| anyhow::anyhow!("failed to create service monitor: {:?}", e))?;
143+
let mut service =
144+
DiscoveryService::<ipc::Service>::create(&monitor_config, &Config::global_config())
145+
.map_err(|e| anyhow::anyhow!("failed to create service monitor: {:?}", e))?;
145146

147+
println!("=== Service Discovery Service Started ===");
146148
println!(
147149
"{}",
148-
format.as_string(&SerializableMonitorConfig::from_config(&monitor_config))?
150+
format.as_string(&SerializableDiscoveryConfig::from_config(&monitor_config))?
149151
);
150152

151153
while !SignalHandler::termination_requested() {
152-
match monitor.spin() {
154+
match service.spin() {
153155
Ok((added, removed)) => {
154156
for service in added {
155157
println!(

iceoryx2-cli/iox2-service/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ fn main() -> Result<()> {
6565
error!("Failed to retrieve service details: {}", e);
6666
}
6767
}
68-
Action::Monitor(options) => {
68+
Action::Discovery(options) => {
6969
let should_publish = options.disable_publish == false;
7070
let should_notify = options.disable_notify == false;
71-
if let Err(_e) = commands::monitor(
71+
if let Err(_e) = commands::discovery(
7272
options.rate,
7373
should_publish,
7474
options.max_subscribers,

iceoryx2-services/discovery/src/lib.rs

+8-100
Original file line numberDiff line numberDiff line change
@@ -10,106 +10,14 @@
1010
//
1111
// SPDX-License-Identifier: Apache-2.0 OR MIT
1212

13-
#![warn(missing_docs)]
14-
15-
//! # iceoryx2-services-discovery
16-
//!
17-
//! A service for discovery and monitoring of other iceoryx2 services.
18-
//!
19-
//! This crate provides utilities for discovering, tracking, and monitoring services
20-
//! in an iceoryx2 system. It enables applications to detect when services become
21-
//! available or unavailable, and to react to these changes.
22-
//!
23-
//! ## Features
24-
//!
25-
//! - **Service Tracking**: Track the availability of services in the system
26-
//! - **Service Monitoring**: Monitor services and receive notifications when they appear or disappear
27-
//!
28-
//! ## Usage Examples
29-
//!
30-
//! ### Tracking Services
31-
//!
32-
//! ```rust
33-
//! use iceoryx2::config::Config;
34-
//! use iceoryx2_discovery::service::Tracker;
35-
//! use iceoryx2::service::YourServiceType;
36-
//!
37-
//! // Create a new tracker for your service type
38-
//! let mut tracker = Tracker::<YourServiceType>::new();
39-
//!
40-
//! // Sync with the system to discover services
41-
//! let (added_services, removed_services) = tracker.sync(&Config::global_config());
42-
//!
43-
//! // Process newly discovered services
44-
//! for service_id in added_services {
45-
//! if let Some(service_details) = tracker.get(&service_id) {
46-
//! println!("Discovered service: {:?}", service_details.static_details.name());
47-
//! }
48-
//! }
49-
//! ```
50-
//!
51-
//! ### Monitoring Services
13+
//! # Discovery Services
5214
//!
53-
//! ```rust
54-
//! use iceoryx2_discovery::service::Monitor;
55-
//! use iceoryx2::service::YourServiceType;
15+
//! The `iceoryx2-services-discovery` crate provides discovery services for the components
16+
//! of an iceoryx2 system. These services enable other applications built on iceoryx2 to
17+
//! get informed of the presense of these components.
5618
//!
57-
//! // Create a new service monitor
58-
//! let mut monitor = Monitor::<YourServiceType>::new();
59-
//!
60-
//! // Periodically call spin() to detect and publish service changes
61-
//! loop {
62-
//! monitor.spin();
63-
//! std::thread::sleep(std::time::Duration::from_secs(1));
64-
//! }
65-
//! ```
66-
//!
67-
//! ### Subscribing to Service Discovery Events
68-
//!
69-
//! ```rust
70-
//! use iceoryx2::config::Config;
71-
//! use iceoryx2::node::{Node, NodeBuilder};
72-
//! use iceoryx2::port::subscriber::Subscriber;
73-
//! use iceoryx2::prelude::ServiceName;
74-
//! use iceoryx2_discovery::service::DiscoveryEvent;
75-
//! use iceoryx2::service::YourServiceType;
76-
//!
77-
//! // Create a node
78-
//! let node = NodeBuilder::new()
79-
//! .config(Config::global_config())
80-
//! .create::<YourServiceType>()
81-
//! .expect("Failed to create node");
82-
//!
83-
//! // Create a subscriber for discovery events
84-
//! let service_name = ServiceName::new("iox2://monitor/services")
85-
//! .expect("Failed to create service name");
86-
//!
87-
//! let publish_subscribe = node
88-
//! .service_builder(&service_name)
89-
//! .publish_subscribe::<DiscoveryEvent>()
90-
//! .create()
91-
//! .expect("Failed to create publish-subscribe service");
92-
//!
93-
//! let subscriber = publish_subscribe
94-
//! .subscriber_builder()
95-
//! .create()
96-
//! .expect("Failed to create subscriber");
97-
//!
98-
//! // Process discovery events
99-
//! while let Some(event) = subscriber.receive() {
100-
//! match event.payload() {
101-
//! DiscoveryEvent::Added(config) => println!("Service added: {:?}", config.name()),
102-
//! DiscoveryEvent::Removed(config) => println!("Service removed: {:?}", config.name()),
103-
//! }
104-
//! }
105-
//! ```
106-
//!
107-
//! ## Integration with iceoryx2
108-
//!
109-
//! This crate is designed to work seamlessly with the core iceoryx2 library and provides
110-
//! a higher-level API for service discovery. It builds upon the service management
111-
//! capabilities of iceoryx2 to provide a more convenient interface for tracking and
112-
//! monitoring services.
11319
114-
/// Utilities for service discovery and monitoring
115-
pub mod service;
20+
#![warn(missing_docs)]
21+
22+
/// Discovery and tracking of services in an iceoryx2 system
23+
pub mod service_discovery;

iceoryx2-services/discovery/src/service/mod.rs

-20
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) 2025 Contributors to the Eclipse Foundation
2+
//
3+
// See the NOTICE file(s) distributed with this work for additional
4+
// information regarding copyright ownership.
5+
//
6+
// This program and the accompanying materials are made available under the
7+
// terms of the Apache Software License 2.0 which is available at
8+
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
9+
// which is available at https://opensource.org/licenses/MIT.
10+
//
11+
// SPDX-License-Identifier: Apache-2.0 OR MIT
12+
13+
//! # Service Discovery
14+
//!
15+
//! This module provides functionality for discovering and tracking services in an iceoryx2 system.
16+
//!
17+
//! The service discovery system consists of two main components:
18+
//!
19+
//! 1. **Service**: A service that tracks and publishes information about other services in the system.
20+
//! It detects when services are added or removed and notifies interested parties about these changes.
21+
//!
22+
//! 2. **Tracker**: A component that keeps track of services in the system. It maintains a list of
23+
//! currently available services and can detect changes in the service landscape.
24+
//!
25+
//! ## Usage
26+
//!
27+
//! To use the service discovery system, you typically create a `Service` instance with appropriate
28+
//! configuration, and then periodically call its `spin` method to process service changes and emit
29+
//! events/notifications.
30+
//!
31+
//! ```rust,no_run
32+
//! use iceoryx2_services_discovery::service_discovery::{Service, DiscoveryConfig};
33+
//! use iceoryx2::prelude::*;
34+
//!
35+
//! // Create a service discovery service
36+
//! let config = DiscoveryConfig::default();
37+
//! let mut service = Service::<ipc::Service>::create(&config, &Config::global_config()).expect("Failed to create service");
38+
//!
39+
//! // Periodically process service changes
40+
//! loop {
41+
//! match service.spin() {
42+
//! Ok((added, removed)) => {
43+
//! println!("Added {} services, removed {} services", added.len(), removed.len());
44+
//! }
45+
//! Err(e) => {
46+
//! eprintln!("Error spinning service: {:?}", e);
47+
//! break;
48+
//! }
49+
//! }
50+
//! // Sleep or do other work...
51+
//! }
52+
53+
/// A service discovery service that tracks and publishes information about services in the system.
54+
mod service;
55+
56+
/// A tracker for services that maintains a list of currently available services.
57+
mod tracker;
58+
59+
pub use service::*;
60+
pub use tracker::*;

0 commit comments

Comments
 (0)