28 using namespace basis;
50 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
68 sequence_record(
int seq = 0) : _sequence(seq) {}
86 host_record(
const machine_uid &host)
91 void clean_up(
int coalesce_time) {
102 for (
int s0 = 0; s0 < zap_point; s0++) {
106 if (_received_to < seq)
110 ids.
zap(0, zap_point - 1);
113 for (
int s1 = 0; s1 < ids.
elements(); s1++) {
114 sequence_record *seq;
116 if (!_sequences.
find(
id, seq))
continue;
117 if (_received_to + 1 == seq->_sequence) {
127 for (
int s2 = 0; s2 < ids.
elements(); s2++) {
128 sequence_record *seq;
130 if (!_sequences.
find(
id, seq))
continue;
131 if (seq->_when <
time_stamp(-coalesce_time)) {
133 if (_received_to < seq->_sequence)
134 _received_to = seq->_sequence;
144 +
", active=" + _last_active.
text_form();
148 for (
int i = 0; i < ids.
elements(); i++) {
149 sequence_record *found;
150 if (!_sequences.
find(ids[i], found))
152 to_return +=
astring(parser_bits::platform_eol_to_chars()) +
"\t"
167 class host_history :
public amorph<host_record>
170 virtual ~host_history() {}
174 int find_host(
const machine_uid &to_find) {
175 for (
int i = 0; i < elements(); i++) {
176 if (borrow(i)->_host == to_find)
return i;
178 return common::NOT_FOUND;
181 bool whack_host(
const machine_uid &to_find) {
182 int indy = find_host(to_find);
188 void clean_up(
int silence_time,
int coalesce_time) {
189 for (
int h = 0; h < elements(); h++) {
190 host_record &rec = *borrow(h);
192 if (rec._last_active <
time_stamp(-silence_time)) {
198 rec.clean_up(coalesce_time);
202 bool add_sequence(
const machine_uid &to_find,
int sequence,
203 int silence_time,
int coalesce_time) {
205 int indy = find_host(to_find);
207 host_record *rec =
new host_record(to_find);
209 indy = find_host(to_find);
211 LOG(
astring(
"*** failure to add a host to the tracker: ")
216 host_record &rec = *borrow(indy);
217 if (borrow(indy)->_received_to + 1 == sequence) {
219 rec._received_to = sequence;
220 }
else if (sequence - borrow(indy)->_received_to >
CLEANING_SPAN) {
223 rec._received_to = sequence;
224 #ifdef DEBUG_SEQUENCE_TRACKER
225 LOG(
"sequence is wildly different, cleaning.");
227 clean_up(silence_time, coalesce_time);
230 rec._sequences.add(sequence,
new sequence_record(sequence));
231 if (rec._sequences.elements() >
MAX_ITEMS) {
233 clean_up(silence_time, coalesce_time);
242 for (
int i = 0; i < elements(); i++) {
244 if (i < elements() - 1)
245 to_return += parser_bits::platform_eol_to_chars();
254 sequence_tracker::sequence_tracker(
int coalesce_time,
int silence_time)
255 : _coalesce_time(coalesce_time),
256 _silence_time(silence_time),
257 _hosts(new host_history),
271 return _hosts->text_form(
verbose);
277 if (!_hosts->add_sequence(host, sequence, _silence_time, _coalesce_time)) {
286 int indy = _hosts->find_host(host);
288 host_record &rec = *_hosts->borrow(indy);
289 if (sequence <= rec._received_to)
return true;
290 sequence_record *found;
291 return !!rec._sequences.find(sequence, found);
297 _hosts->clean_up(_silence_time, _coalesce_time);
a_sprintf is a specialization of astring that provides printf style support.
outcome zap(int start, int end)
Deletes from "this" the objects inclusively between "start" and "end".
Provides a dynamically resizable ASCII character string.
virtual void text_form(base_string &state_fill) const
Provides a text view of all the important info owned by this object.
auto_synchronizer simplifies concurrent code by automatically unlocking.
bool have_seen(const machine_uid &host, int sequence)
void add_pair(const machine_uid &host, int sequence)
basis::astring text_form(bool verbose=false) const
int elements() const
the number of valid items we found by traversing the hash table.
bool find(const key_type &key, contents *&item_found) const
locates the item specified by the "key", if possible.
bool zap(int key)
overrides base zap() method plus keeps id list updated.
const int_set & ids() const
A simple object that wraps a templated set of ints.
int elements() const
Returns the number of elements in this set.
Represents a point in time relative to the operating system startup time.
basis::astring text_form(stamp_display_style style=STAMP_RELATIVE) const
returns a simple textual representation of the time_stamp.
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
bool negative(const type &a)
negative returns true if "a" is less than zero.
A logger that sends to the console screen using the standard output device.
Provides access to the operating system's socket methods.
const int MAX_BITS_FOR_SEQ_HASH
A dynamic container class that holds any kind of object via pointers.