aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/connection_details.rs15
-rw-r--r--src/ls_client.rs5
-rw-r--r--src/main.rs4
3 files changed, 13 insertions, 11 deletions
diff --git a/src/connection_details.rs b/src/connection_details.rs
index 228a597..916c396 100644
--- a/src/connection_details.rs
+++ b/src/connection_details.rs
@@ -1,6 +1,7 @@
use crate::client_listener::ClientListener;
use crate::error::IllegalArgumentException;
+use std::error::Error;
use std::fmt::{self, Debug, Formatter};
/// 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.
- pub fn new(server_address: Option<&str>, adapter_set: Option<&str>) -> ConnectionDetails {
- ConnectionDetails {
- server_address: server_address.map(|s| s.to_string()), // convert &str to String
- adapter_set: adapter_set.map(|s| s.to_string()), // convert &str to String
- ..Default::default()
- }
+ pub fn new(server_address: Option<&str>, adapter_set: Option<&str>) -> Result<ConnectionDetails, Box<dyn Error>> {
+ let mut connection_details = ConnectionDetails::default();
+ connection_details.set_server_address(server_address.map(|s| s.to_string()))?;
+ connection_details.set_adapter_set(adapter_set.map(|s| s.to_string()));
+
+ Ok(connection_details)
}
/// 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
/// the "DEFAULT" name.
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
for listener in &self.listeners {
diff --git a/src/ls_client.rs b/src/ls_client.rs
index f3966cf..12fcd8b 100644
--- a/src/ls_client.rs
+++ b/src/ls_client.rs
@@ -496,6 +496,7 @@ impl LightstreamerClient {
//
"u" => {
println!("Received data update from server: '{}'", clean_text);
+
},
//
// Connection confirmation from server.
@@ -703,8 +704,8 @@ impl LightstreamerClient {
pub fn new(
server_address: Option<&str>,
adapter_set: Option<&str>,
- ) -> Result<LightstreamerClient, IllegalStateException> {
- let connection_details = ConnectionDetails::new(server_address, adapter_set);
+ ) -> Result<LightstreamerClient, Box<dyn Error>> {
+ let connection_details = ConnectionDetails::new(server_address, adapter_set)?;
let connection_options = ConnectionOptions::default();
Ok(LightstreamerClient {
diff --git a/src/main.rs b/src/main.rs
index 87fd834..67276a8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -67,7 +67,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
let mut my_subscription = Subscription::new(
SubscriptionMode::Merge,
Some(vec![
- "item1".to_string(),
+ "item2".to_string(),
"item2".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);
} else {
println!("Exiting orderly from Lightstreamer client...");