lapin_async/
connection_status.rs1use parking_lot::RwLock;
2
3use std::sync::Arc;
4
5use crate::{
6 Connection, ConnectionProperties,
7 auth::Credentials,
8 wait::WaitHandle,
9};
10
11#[derive(Clone, Debug, Default)]
12#[deprecated(note = "use lapin instead")]
13pub struct ConnectionStatus {
14 inner: Arc<RwLock<Inner>>,
15}
16
17impl ConnectionStatus {
18 #[deprecated(note = "use lapin instead")]
19 pub fn state(&self) -> ConnectionState {
20 self.inner.read().state.clone()
21 }
22
23 pub(crate) fn set_state(&self, state: ConnectionState) {
24 self.inner.write().state = state
25 }
26
27 #[deprecated(note = "use lapin instead")]
28 pub fn vhost(&self) -> String {
29 self.inner.read().vhost.clone()
30 }
31
32 pub(crate) fn set_vhost(&self, vhost: &str) {
33 self.inner.write().vhost = vhost.into();
34 }
35
36 pub(crate) fn block(&self) {
37 self.inner.write().blocked = true;
38 }
39
40 pub(crate) fn unblock(&self) {
41 self.inner.write().blocked = true;
42 }
43
44 #[deprecated(note = "use lapin instead")]
45 pub fn blocked(&self) -> bool {
46 self.inner.read().blocked
47 }
48
49 #[deprecated(note = "use lapin instead")]
50 pub fn connected(&self) -> bool {
51 self.inner.read().state == ConnectionState::Connected
52 }
53
54 #[deprecated(note = "use lapin instead")]
55 pub fn closed(&self) -> bool {
56 self.inner.read().state == ConnectionState::Closed
57 }
58
59 #[deprecated(note = "use lapin instead")]
60 pub fn errored(&self) -> bool {
61 self.inner.read().state == ConnectionState::Error
62 }
63}
64
65#[derive(Clone, Debug)]
66#[deprecated(note = "use lapin instead")]
67pub enum ConnectionState {
68 Initial,
69 SentProtocolHeader(WaitHandle<Connection>, Credentials, ConnectionProperties),
70 SentStartOk(WaitHandle<Connection>, Credentials),
71 SentOpen(WaitHandle<Connection>),
72 Connected,
73 Closing,
74 Closed,
75 Error,
76}
77
78impl Default for ConnectionState {
79 fn default() -> Self {
80 ConnectionState::Initial
81 }
82}
83
84impl PartialEq for ConnectionState {
85 fn eq(&self, other: &Self) -> bool {
86 match (self, other) {
87 (ConnectionState::Initial, ConnectionState::Initial) => true,
88 (ConnectionState::SentProtocolHeader(..), ConnectionState::SentProtocolHeader(..)) => true,
89 (ConnectionState::SentStartOk(..), ConnectionState::SentStartOk(..)) => true,
90 (ConnectionState::SentOpen(_), ConnectionState::SentOpen(_)) => true,
91 (ConnectionState::Connected, ConnectionState::Connected) => true,
92 (ConnectionState::Closing, ConnectionState::Closing) => true,
93 (ConnectionState::Closed, ConnectionState::Closed) => true,
94 (ConnectionState::Error, ConnectionState::Error) => true,
95 _ => false,
96 }
97 }
98}
99
100#[derive(Debug)]
101struct Inner {
102 state: ConnectionState,
103 vhost: String,
104 blocked: bool,
105}
106
107impl Default for Inner {
108 fn default() -> Self {
109 Self {
110 state: ConnectionState::default(),
111 vhost: "/".into(),
112 blocked: false,
113 }
114 }
115}