Skip to content

Commit

Permalink
Remove dependency library 'lazy_static'
Browse files Browse the repository at this point in the history
  • Loading branch information
rmqtt committed Sep 3, 2023
1 parent 23cd0ef commit 6262294
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 31 deletions.
18 changes: 8 additions & 10 deletions rmqtt-plugins/rmqtt-auth-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tokio::sync::RwLock;
use config::PluginConfig;
use rmqtt::ntex::util::ByteString;
use rmqtt::reqwest::Response;
use rmqtt::{ahash, async_trait, chrono, lazy_static, log, reqwest, serde_json, tokio};
use rmqtt::{ahash, async_trait, chrono, log, reqwest, serde_json, tokio, once_cell::sync::Lazy};
use rmqtt::{
broker::hook::{Handler, HookResult, Parameter, Register, ReturnType, Type},
broker::types::{
Expand Down Expand Up @@ -505,12 +505,10 @@ impl Handler for AuthHandler {
}
}

lazy_static::lazy_static! {
static ref HTTP_CLIENT: reqwest::Client = {
reqwest::Client::builder()
.connect_timeout(Duration::from_secs(5))
.timeout(Duration::from_secs(5))
.build()
.unwrap()
};
}
static HTTP_CLIENT: Lazy<reqwest::Client> = Lazy::new(|| {
reqwest::Client::builder()
.connect_timeout(Duration::from_secs(5))
.timeout(Duration::from_secs(5))
.build()
.unwrap()
});
11 changes: 6 additions & 5 deletions rmqtt-plugins/rmqtt-cluster-raft/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ use serde::Serialize;
use rmqtt::grpc::MessageType;
use rmqtt::settings::{deserialize_duration, deserialize_duration_option, NodeAddr, Options};
use rmqtt::Result;
use rmqtt::{lazy_static, serde_json};
use rmqtt::{once_cell::sync::Lazy, serde_json};

lazy_static::lazy_static! {
pub static ref BACKOFF_STRATEGY: ExponentialBackoff = ExponentialBackoffBuilder::new()
pub(crate) static BACKOFF_STRATEGY: Lazy<ExponentialBackoff> = Lazy::new(|| {
ExponentialBackoffBuilder::new()
.with_max_elapsed_time(Some(Duration::from_secs(60)))
.with_multiplier(2.5).build();
}
.with_multiplier(2.5)
.build()
});

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct PluginConfig {
Expand Down
20 changes: 9 additions & 11 deletions rmqtt-plugins/rmqtt-web-hook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use rmqtt::{
async_trait::async_trait,
base64::{Engine as _, engine::general_purpose},
bytestring::ByteString,
chrono, futures, lazy_static, log,
once_cell::sync::OnceCell,
chrono, futures, log,
once_cell::sync::{Lazy, OnceCell},
reqwest,
rust_box::std_ext::ArcExt,
rust_box::task_exec_queue::SpawnExt,
Expand Down Expand Up @@ -280,15 +280,13 @@ impl Plugin for WebHookPlugin {
}
}

lazy_static::lazy_static! {
static ref HTTP_CLIENT: reqwest::Client = {
reqwest::Client::builder()
.connect_timeout(Duration::from_secs(8))
.timeout(Duration::from_secs(15))
.build()
.unwrap()
};
}
static HTTP_CLIENT: Lazy<reqwest::Client> = Lazy::new(|| {
reqwest::Client::builder()
.connect_timeout(Duration::from_secs(8))
.timeout(Duration::from_secs(15))
.build()
.unwrap()
});

type Message = (hook::Type, Option<TopicFilter>, serde_json::Value);

Expand Down
1 change: 0 additions & 1 deletion rmqtt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ bytes = { version = "1", features = ["serde"] }
bytestring = { version = "1", features = ["serde"] }
thiserror = "1.0"
anyhow = "1.0"
lazy_static = "1.4"
async-trait = "0.1"
parking_lot = "0.12"
serde = { version = "1.0", features = ["derive"] }
Expand Down
7 changes: 4 additions & 3 deletions rmqtt/src/grpc/server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::atomic::{AtomicIsize, Ordering};
use std::sync::Arc;

use once_cell::sync::Lazy;
use tonic::{transport, Response};

use crate::{Result, Runtime};
Expand Down Expand Up @@ -127,9 +128,9 @@ impl NodeService for NodeGrpcService {
}
}

lazy_static::lazy_static! {
pub static ref ACTIVE_REQUEST_COUNT: Arc<AtomicIsize> = Arc::new(AtomicIsize::new(0));
}
pub static ACTIVE_REQUEST_COUNT: Lazy<Arc<AtomicIsize>> = Lazy::new(|| {
Arc::new(AtomicIsize::new(0))
});

pub fn active_grpc_requests() -> isize {
ACTIVE_REQUEST_COUNT.load(Ordering::SeqCst)
Expand Down
1 change: 0 additions & 1 deletion rmqtt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub use crossbeam;
pub use dashmap;
pub use futures;
pub use itertools;
pub use lazy_static;
pub use log;
pub use ntex;
pub use ntex_mqtt;
Expand Down

0 comments on commit 6262294

Please sign in to comment.