⬆️ (Cargo.toml): bump version to 0.1.2 for new release
♻️ (connection_details.rs): refactor `new` method to return Result for better error handling ✨ (connection_details.rs): set default adapter set to "DEFAULT" if none provided ✨ (ls_client.rs): update `new` method to handle Result from ConnectionDetails::new 🐛 (main.rs): fix subscription item list to include correct items ♻️ (main.rs): replace magic number with constant for max connection attempts
This commit is contained in:
parent
0a1fa8873a
commit
1d74478512
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lightstreamer-client"
|
name = "lightstreamer-client"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Daniel López Azaña <daniloaz@gmail.com>"]
|
authors = ["Daniel López Azaña <daniloaz@gmail.com>"]
|
||||||
description = "A Rust client for Lightstreamer, designed to facilitate real-time communication with Lightstreamer servers."
|
description = "A Rust client for Lightstreamer, designed to facilitate real-time communication with Lightstreamer servers."
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::client_listener::ClientListener;
|
use crate::client_listener::ClientListener;
|
||||||
use crate::error::IllegalArgumentException;
|
use crate::error::IllegalArgumentException;
|
||||||
|
|
||||||
|
use std::error::Error;
|
||||||
use std::fmt::{self, Debug, Formatter};
|
use std::fmt::{self, Debug, Formatter};
|
||||||
|
|
||||||
/// Used by `LightstreamerClient` to provide a basic connection properties data object.
|
/// Used by `LightstreamerClient` to provide a basic connection properties data object.
|
||||||
@ -170,12 +171,12 @@ impl ConnectionDetails {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new ConnectionDetails object with default values.
|
/// Creates a new ConnectionDetails object with default values.
|
||||||
pub fn new(server_address: Option<&str>, adapter_set: Option<&str>) -> ConnectionDetails {
|
pub fn new(server_address: Option<&str>, adapter_set: Option<&str>) -> Result<ConnectionDetails, Box<dyn Error>> {
|
||||||
ConnectionDetails {
|
let mut connection_details = ConnectionDetails::default();
|
||||||
server_address: server_address.map(|s| s.to_string()), // convert &str to String
|
connection_details.set_server_address(server_address.map(|s| s.to_string()))?;
|
||||||
adapter_set: adapter_set.map(|s| s.to_string()), // convert &str to String
|
connection_details.set_adapter_set(adapter_set.map(|s| s.to_string()));
|
||||||
..Default::default()
|
|
||||||
}
|
Ok(connection_details)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Setter method that sets the name of the Adapter Set mounted on Lightstreamer Server to
|
/// Setter method that sets the name of the Adapter Set mounted on Lightstreamer Server to
|
||||||
@ -202,7 +203,7 @@ impl ConnectionDetails {
|
|||||||
/// * `adapter_set`: The name of the Adapter Set to be used. A `None` value is equivalent to
|
/// * `adapter_set`: The name of the Adapter Set to be used. A `None` value is equivalent to
|
||||||
/// the "DEFAULT" name.
|
/// the "DEFAULT" name.
|
||||||
pub fn set_adapter_set(&mut self, adapter_set: Option<String>) {
|
pub fn set_adapter_set(&mut self, adapter_set: Option<String>) {
|
||||||
self.adapter_set = adapter_set;
|
self.adapter_set = Some(adapter_set.unwrap_or("DEFAULT".to_string()));
|
||||||
|
|
||||||
// Notify listeners about the property change
|
// Notify listeners about the property change
|
||||||
for listener in &self.listeners {
|
for listener in &self.listeners {
|
||||||
|
@ -496,6 +496,7 @@ impl LightstreamerClient {
|
|||||||
//
|
//
|
||||||
"u" => {
|
"u" => {
|
||||||
println!("Received data update from server: '{}'", clean_text);
|
println!("Received data update from server: '{}'", clean_text);
|
||||||
|
|
||||||
},
|
},
|
||||||
//
|
//
|
||||||
// Connection confirmation from server.
|
// Connection confirmation from server.
|
||||||
@ -703,8 +704,8 @@ impl LightstreamerClient {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
server_address: Option<&str>,
|
server_address: Option<&str>,
|
||||||
adapter_set: Option<&str>,
|
adapter_set: Option<&str>,
|
||||||
) -> Result<LightstreamerClient, IllegalStateException> {
|
) -> Result<LightstreamerClient, Box<dyn Error>> {
|
||||||
let connection_details = ConnectionDetails::new(server_address, adapter_set);
|
let connection_details = ConnectionDetails::new(server_address, adapter_set)?;
|
||||||
let connection_options = ConnectionOptions::default();
|
let connection_options = ConnectionOptions::default();
|
||||||
|
|
||||||
Ok(LightstreamerClient {
|
Ok(LightstreamerClient {
|
||||||
|
@ -67,7 +67,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let mut my_subscription = Subscription::new(
|
let mut my_subscription = Subscription::new(
|
||||||
SubscriptionMode::Merge,
|
SubscriptionMode::Merge,
|
||||||
Some(vec![
|
Some(vec![
|
||||||
"item1".to_string(),
|
"item2".to_string(),
|
||||||
"item2".to_string(),
|
"item2".to_string(),
|
||||||
"item3".to_string(),
|
"item3".to_string(),
|
||||||
]),
|
]),
|
||||||
@ -124,7 +124,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if retry_counter == 5 {
|
if retry_counter == MAX_CONNECTION_ATTEMPTS {
|
||||||
println!("Failed to connect after {} retries. Exiting...", retry_counter);
|
println!("Failed to connect after {} retries. Exiting...", retry_counter);
|
||||||
} else {
|
} else {
|
||||||
println!("Exiting orderly from Lightstreamer client...");
|
println!("Exiting orderly from Lightstreamer client...");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user