8#include <framework/pcore/zmq/connections/ZMQConfirmedConnection.h>
9#include <framework/pcore/zmq/messages/ZMQMessageFactory.h>
20 log(
"last_received_message",
"");
21 log(
"total_number_messages", 0l);
22 log(
"registered_workers", 0l);
23 log(
"hello_messages", 0l);
24 log(
"dead_workers", 0l);
25 log(
"all_stop_messages", 0l);
26 log(
"sent_stop_messages", 0l);
27 log(
"last_stop_sent",
"");
28 log(
"received_stop_messages", 0l);
29 log(
"all_terminate_messages", 0l);
30 log(
"sent_terminate_messages", 0l);
31 log(
"last_terminate_sent",
"");
32 log(
"received_terminate_messages", 0l);
33 log(
"received_messages_after_stop", 0l);
34 log(
"last_received_event_message",
"");
35 log(
"last_clear",
"");
36 log(
"stop_overwrites", 0l);
37 log(
"last_stop_overwrite",
"");
39 log(
"data_size", 0.0);
40 log(
"received_events", 0l);
41 log(
"event_rate", 0.0);
49 auto message = ZMQMessageFactory::fromSocket<ZMQIdMessage>(
m_socket);
50 const auto fromIdentity = message->getIdentity();
52 logTime(
"last_received_message");
54 increment(
"total_number_messages_from[" + fromIdentity +
"]");
59 if (message->isMessage(EMessageTypes::c_helloMessage)) {
64 increment(
"hello_messages_from[" + fromIdentity +
"]");
66 }
else if (message->isMessage(EMessageTypes::c_deleteWorkerMessage)) {
69 B2DEBUG(30,
"Got message from " << message->getIdentity() <<
" to kill " << message->getMessagePartAsString<2>());
70 const std::string& killedIdentity = message->getMessagePartAsString<2>();
75 increment(
"dead_worker_messaged_from[" + fromIdentity +
"]");
78 B2ERROR(
"There is not a single worker registered anymore!");
104 B2ASSERT(
"Worker without proper registration!",
107 if (message->isMessage(EMessageTypes::c_lastEventMessage)) {
111 increment(
"total_received_stop_messages");
126 }
else if (message->isMessage(EMessageTypes::c_terminateMessage)) {
130 increment(
"total_received_terminate_messages");
137 logTime(
"last_terminate_sent");
151 B2ERROR(
"Received an event after having received stop messages from every worker. This is not a good sign! I will dismiss this event and next events!");
153 increment(
"received_messages_after_stop");
154 auto t1 = std::chrono::system_clock::now();
156 if (intervalAfterAllStopMessages > std::chrono::seconds{150}) {
157 B2FATAL(
"Too many events after having received stop messages! This is abnormal. I will kill the process!");
163 const auto dataSize = message->getDataMessage().size();
165 average(
"data_size", dataSize);
166 average(
"data_size_from[" + fromIdentity +
"]", dataSize);
169 increment(
"received_events[" + fromIdentity +
"]");
172 timeit<200>(
"event_rate_from[" + fromIdentity +
"]");
174 logTime(
"last_received_event_message");
200 B2ERROR(
"Sending out a stop message although not all of the workers are finished already!");
202 logTime(
"last_stop_overwrite");
220 log(
"no_confirmation_message", 0l);
221 log(
"last_sent_event_message", 0l);
222 log(
"data_size", 0.0);
223 log(
"sent_events", 0l);
224 log(
"event_rate", 0.0);
225 log(
"timespan_waiting_for_confirmation", 0l);
239 auto current = std::chrono::system_clock::now();
244 }
else if (requireConfirmation) {
245 B2FATAL(
"Did not receive a confirmation message in time!");
247 B2WARNING(
"Did not receive a confirmation message in time!");
253 auto afterWaiting = std::chrono::system_clock::now();
260 const auto dataSize = message->getDataMessage().size();
262 average(
"data_size", dataSize);
266 logTime(
"last_sent_event_message");
276 auto acceptMessage = ZMQMessageFactory::fromSocket<ZMQNoIdMessage>(
m_socket);
277 B2ASSERT(
"Should be an accept message", acceptMessage->isMessage(EMessageTypes::c_confirmMessage));
void handleEvent(std::unique_ptr< ZMQNoIdMessage > message, bool requireConfirmation=true, int maximalWaitTime=10000)
Send the message to the output (a message without a ID as there is only a single output).
long m_timespanWaitingForConfirmation
Internal monitoring how long we were waiting for confirmation messages.
void handleIncomingData()
Blocks until it can receive the (hopefully confirmation) message from the output.
unsigned int m_waitingForConfirmation
On how many confirmation messages are we still waiting?
ZMQConfirmedOutput(const std::string &outputAddress, const std::shared_ptr< ZMQParent > &parent)
Create a new confirmed output by connecting to the address.
Specialized connection over a ZMQ socket.
std::shared_ptr< ZMQParent > m_parent
The shared ZMQParent instance.
std::unique_ptr< zmq::socket_t > m_socket
The memory of the socket. Needs to be initialized in a derived class.
void logTime(const std::string &key)
Store the current time as a string under the given key.
void increment(const std::string &key)
Increment the value with the given key (only numerical values). If not present, set to 1.
static auto createMessage(const std::string &msgIdentity, const EMessageTypes msgType, const std::unique_ptr< EvtMessage > &eventMessage)
Create an ID Message out of an identity, the type and an event message.
static unsigned int poll(const std::vector< zmq::socket_t * > &socketList, int timeout)
Poll function.
void timeit(const std::string &key)
Measure the rate of calls with the same key every AVERAGE_SIZE calls (and also display the last time ...
static void send(std::unique_ptr< zmq::socket_t > &socket, AZMQMessage message)
Send a given message over the given created socket. You need to move in the message for zero-copy.
void log(const std::string &key, const AClass &value)
Store a value under a certain key. Different types of values can be stored, namely long,...
void average(const std::string &key, double value)
Instead of storing the double value directly under the given key, store the average of the last MAX_S...
Abstract base class for different kinds of events.