forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession_info.hh
145 lines (122 loc) · 4.15 KB
/
session_info.hh
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Modified by Cloudius Systems.
* Copyright 2015 Cloudius Systems.
*/
#pragma once
#include "gms/inet_address.hh"
#include "streaming/stream_summary.hh"
#include "streaming/stream_session_state.hh"
#include "streaming/progress_info.hh"
#include <vector>
#include <map>
namespace streaming {
/**
* Stream session info.
*/
class session_info {
public:
using inet_address = gms::inet_address;
inet_address peer;
int session_index;
inet_address connecting;
/** Immutable collection of receiving summaries */
std::vector<stream_summary> receiving_summaries;
/** Immutable collection of sending summaries*/
std::vector<stream_summary> sending_summaries;
/** Current session state */
stream_session_state state;
std::map<sstring, progress_info> receiving_files;
std::map<sstring, progress_info> sending_files;
session_info() = default;
session_info(inet_address peer_, int session_index_, inet_address connecting_,
std::vector<stream_summary> receiving_summaries_,
std::vector<stream_summary> sending_summaries_,
stream_session_state state_)
: peer(peer_)
, connecting(connecting_)
, receiving_summaries(std::move(receiving_summaries_))
, sending_summaries(std::move(sending_summaries_))
, state(state_) {
}
bool is_failed() const {
return state == stream_session_state::FAILED;
}
/**
* Update progress of receiving/sending file.
*
* @param newProgress new progress info
*/
void update_progress(progress_info new_progress);
std::vector<progress_info> get_receiving_files();
std::vector<progress_info> get_sending_files();
/**
* @return total number of files already received.
*/
long get_total_files_received() {
return get_total_files_completed(get_receiving_files());
}
/**
* @return total number of files already sent.
*/
long get_total_files_sent() {
return get_total_files_completed(get_sending_files());
}
/**
* @return total size(in bytes) already received.
*/
long get_total_size_received() {
return get_total_size_in_progress(get_receiving_files());
}
/**
* @return total size(in bytes) already sent.
*/
long get_total_size_sent() {
return get_total_size_in_progress(get_sending_files());
}
/**
* @return total number of files to receive in the session
*/
long get_total_files_to_receive() {
return get_total_files(receiving_summaries);
}
/**
* @return total number of files to send in the session
*/
long getTotalFilesToSend() {
return get_total_files(sending_summaries);
}
/**
* @return total size(in bytes) to receive in the session
*/
long get_total_size_to_receive() {
return get_total_sizes(receiving_summaries);
}
/**
* @return total size(in bytes) to send in the session
*/
long get_total_size_to_send() {
return get_total_sizes(sending_summaries);
}
private:
long get_total_size_in_progress(std::vector<progress_info> files);
long get_total_files(std::vector<stream_summary>& summaries);
long get_total_sizes(std::vector<stream_summary>& summaries);
long get_total_files_completed(std::vector<progress_info> files);
};
} // namespace streaming