mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-16 12:45:04 +01:00
more
This commit is contained in:
parent
08ba799d23
commit
f860714b2b
9 changed files with 64 additions and 24 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{methods, methods::Method, newtype_id, GlobalData, Queue};
|
||||
use crate::{consumer::Consumer, methods, methods::Method, newtype_id, GlobalData, Queue};
|
||||
use bytes::Bytes;
|
||||
use parking_lot::Mutex;
|
||||
use smallvec::SmallVec;
|
||||
|
|
@ -54,6 +54,7 @@ pub struct ConnectionInner {
|
|||
pub channels: Mutex<HashMap<ChannelNum, Channel>>,
|
||||
pub exclusive_queues: Vec<Queue>,
|
||||
pub event_sender: ConEventSender,
|
||||
pub consuming: Mutex<Vec<Consumer>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -78,15 +79,22 @@ impl ConnectionInner {
|
|||
id,
|
||||
peer_addr,
|
||||
global_data,
|
||||
channels: Mutex::new(HashMap::new()),
|
||||
channels: Mutex::default(),
|
||||
exclusive_queues: vec![],
|
||||
event_sender,
|
||||
consuming: Mutex::default(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn close(&self) {
|
||||
// todo: make a better system that prevents all leaks
|
||||
|
||||
let mut global_data = self.global_data.lock();
|
||||
global_data.connections.remove(&self.id);
|
||||
self.consuming
|
||||
.lock()
|
||||
.iter()
|
||||
.for_each(|consumer| drop(consumer.queue.consumers.lock().remove(&consumer.id)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
use crate::{newtype_id, Channel};
|
||||
use crate::{newtype_id, Channel, Queue};
|
||||
|
||||
newtype_id!(
|
||||
pub ConsumerId
|
||||
);
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Consumer {
|
||||
pub id: ConsumerId,
|
||||
pub tag: String,
|
||||
pub channel: Channel,
|
||||
pub queue: Queue,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
use crate::{consumer::Consumer, message::Message, newtype, newtype_id, ChannelId};
|
||||
use crate::{
|
||||
consumer::{Consumer, ConsumerId},
|
||||
message::Message,
|
||||
newtype, newtype_id, ChannelId,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
collections::HashMap,
|
||||
sync::{atomic::AtomicUsize, Arc},
|
||||
};
|
||||
|
||||
|
|
@ -32,7 +37,7 @@ pub struct RawQueue {
|
|||
/// The queue can always be manually deleted.
|
||||
/// If auto-delete is enabled, it keeps track of the consumer count.
|
||||
pub deletion: QueueDeletion,
|
||||
pub consumers: Mutex<Vec<Consumer>>,
|
||||
pub consumers: Mutex<HashMap<ConsumerId, Consumer>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue