1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use format::frame::Frame;
use std::collections::{HashMap,HashSet,VecDeque};
use generated::Class;
use api::{Answer,ChannelState};
use queue::*;
#[derive(Clone,Debug,PartialEq)]
pub struct Channel {
pub id: u16,
pub state: ChannelState,
pub frame_queue: VecDeque<Frame>,
pub send_flow: bool,
pub receive_flow: bool,
pub queues: HashMap<String,Queue>,
pub prefetch_size: u32,
pub prefetch_count: u16,
pub awaiting: VecDeque<Answer>,
pub confirm: bool,
pub message_count: u64,
pub acked: HashSet<u64>,
pub nacked: HashSet<u64>,
pub unacked: HashSet<u64>,
}
impl Channel {
pub fn new(channel_id: u16) -> Channel {
Channel {
id: channel_id,
state: ChannelState::Initial,
frame_queue: VecDeque::new(),
send_flow: true,
receive_flow: true,
queues: HashMap::new(),
prefetch_size: 0,
prefetch_count: 0,
awaiting: VecDeque::new(),
confirm: false,
message_count: 0,
acked: HashSet::new(),
nacked: HashSet::new(),
unacked: HashSet::new(),
}
}
pub fn global() -> Channel {
Channel::new(0)
}
pub fn received_method(&mut self, m: Class) {
trace!("channel[{}] received {:?}", self.id, m);
self.frame_queue.push_back(Frame::Method(self.id,m));
}
pub fn is_connected(&self) -> bool {
self.state != ChannelState::Initial && self.state != ChannelState::Closed && self.state != ChannelState::Error
}
}