mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-16 04:35:03 +01:00
things
This commit is contained in:
parent
93ce632b5d
commit
4346db648f
24 changed files with 224 additions and 209 deletions
|
|
@ -1,12 +1,12 @@
|
|||
use crate::methods::Method;
|
||||
use crate::{methods, newtype_id, GlobalData, Handle, Queue};
|
||||
use crate::{methods, methods::Method, newtype_id, GlobalData, Queue};
|
||||
use bytes::Bytes;
|
||||
use parking_lot::Mutex;
|
||||
use smallvec::SmallVec;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt::{Display, Formatter},
|
||||
net::SocketAddr,
|
||||
sync::Arc,
|
||||
};
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
newtype_id!(pub ConnectionId);
|
||||
|
|
@ -43,16 +43,14 @@ impl Display for ChannelNum {
|
|||
}
|
||||
}
|
||||
|
||||
pub type ConnectionHandle = Handle<Connection>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Connection {
|
||||
pub id: ConnectionId,
|
||||
pub peer_addr: SocketAddr,
|
||||
pub global_data: GlobalData,
|
||||
pub channels: HashMap<ChannelNum, ChannelHandle>,
|
||||
pub channels: HashMap<ChannelNum, Channel>,
|
||||
pub exclusive_queues: Vec<Queue>,
|
||||
_method_queue: MethodSender,
|
||||
_events: ConEventSender,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -61,25 +59,25 @@ pub enum QueuedMethod {
|
|||
WithContent(Method, ContentHeader, SmallVec<[Bytes; 1]>),
|
||||
}
|
||||
|
||||
pub type MethodSender = mpsc::Sender<(ChannelNum, QueuedMethod)>;
|
||||
pub type MethodReceiver = mpsc::Receiver<(ChannelNum, QueuedMethod)>;
|
||||
pub type ConEventSender = mpsc::Sender<(ChannelNum, QueuedMethod)>;
|
||||
pub type ConEventReceiver = mpsc::Receiver<(ChannelNum, QueuedMethod)>;
|
||||
|
||||
impl Connection {
|
||||
#[must_use]
|
||||
pub fn new_handle(
|
||||
pub fn new(
|
||||
id: ConnectionId,
|
||||
peer_addr: SocketAddr,
|
||||
global_data: GlobalData,
|
||||
method_queue: MethodSender,
|
||||
) -> ConnectionHandle {
|
||||
Arc::new(Mutex::new(Self {
|
||||
method_queue: ConEventSender,
|
||||
) -> Arc<Connection> {
|
||||
Arc::new(Self {
|
||||
id,
|
||||
peer_addr,
|
||||
global_data,
|
||||
channels: HashMap::new(),
|
||||
exclusive_queues: vec![],
|
||||
_method_queue: method_queue,
|
||||
}))
|
||||
_events: method_queue,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn close(&self) {
|
||||
|
|
@ -88,33 +86,31 @@ impl Connection {
|
|||
}
|
||||
}
|
||||
|
||||
pub type ChannelHandle = Handle<Channel>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Channel {
|
||||
pub id: ChannelId,
|
||||
pub num: ChannelNum,
|
||||
pub connection: ConnectionHandle,
|
||||
pub connection: Connection,
|
||||
pub global_data: GlobalData,
|
||||
method_queue: MethodSender,
|
||||
method_queue: ConEventSender,
|
||||
}
|
||||
|
||||
impl Channel {
|
||||
#[must_use]
|
||||
pub fn new_handle(
|
||||
pub fn new(
|
||||
id: ChannelId,
|
||||
num: ChannelNum,
|
||||
connection: ConnectionHandle,
|
||||
connection: Connection,
|
||||
global_data: GlobalData,
|
||||
method_queue: MethodSender,
|
||||
) -> ChannelHandle {
|
||||
Arc::new(Mutex::new(Self {
|
||||
method_queue: ConEventSender,
|
||||
) -> Arc<Channel> {
|
||||
Arc::new(Self {
|
||||
id,
|
||||
num,
|
||||
connection,
|
||||
global_data,
|
||||
method_queue,
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn close(&self) {
|
||||
|
|
@ -130,6 +126,7 @@ impl Channel {
|
|||
}
|
||||
}
|
||||
|
||||
/// A content frame header.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ContentHeader {
|
||||
pub class_id: u16,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{newtype_id, ChannelHandle};
|
||||
use crate::{newtype_id, Channel};
|
||||
|
||||
newtype_id!(
|
||||
pub ConsumerId
|
||||
|
|
@ -8,5 +8,5 @@ newtype_id!(
|
|||
pub struct Consumer {
|
||||
pub id: ConsumerId,
|
||||
pub tag: String,
|
||||
pub channel: ChannelHandle,
|
||||
pub channel: Channel,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,16 +8,15 @@ pub mod message;
|
|||
pub mod methods;
|
||||
pub mod queue;
|
||||
|
||||
use crate::connection::{ChannelHandle, ConnectionHandle};
|
||||
use crate::queue::{Queue, QueueName};
|
||||
use crate::{
|
||||
connection::{Channel, Connection},
|
||||
queue::{Queue, QueueName},
|
||||
};
|
||||
use connection::{ChannelId, ConnectionId};
|
||||
use parking_lot::Mutex;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
use uuid::Uuid;
|
||||
|
||||
type Handle<T> = Arc<Mutex<T>>;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct GlobalData {
|
||||
inner: Arc<Mutex<GlobalDataInner>>,
|
||||
|
|
@ -44,8 +43,8 @@ impl GlobalData {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct GlobalDataInner {
|
||||
pub connections: HashMap<ConnectionId, ConnectionHandle>,
|
||||
pub channels: HashMap<ChannelId, ChannelHandle>,
|
||||
pub connections: HashMap<ConnectionId, Connection>,
|
||||
pub channels: HashMap<ChannelId, Channel>,
|
||||
pub queues: HashMap<QueueName, Queue>,
|
||||
/// Todo: This is just for testing and will be removed later!
|
||||
pub default_exchange: HashMap<String, Queue>,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use crate::connection::ContentHeader;
|
||||
use crate::newtype_id;
|
||||
use crate::{connection::ContentHeader, newtype_id};
|
||||
use bytes::Bytes;
|
||||
use smallvec::SmallVec;
|
||||
use std::sync::Arc;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
use crate::consumer::Consumer;
|
||||
use crate::message::Message;
|
||||
use crate::{newtype, newtype_id, ChannelId};
|
||||
use crate::{consumer::Consumer, message::Message, newtype, newtype_id, ChannelId};
|
||||
use parking_lot::Mutex;
|
||||
use std::borrow::Borrow;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::Arc;
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
sync::{atomic::AtomicUsize, Arc},
|
||||
};
|
||||
|
||||
pub type Queue = Arc<RawQueue>;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue