Belle II Software light-2406-ragdoll
|
Output connection to speak to non-zmq sockets via a ZMQ_STREAM socket. More...
#include <ZMQRawConnection.h>
Public Types | |
using | ReactorFunction = std::function< void(void)> |
Typedef of a function which will be called if a connection has a message. | |
Public Member Functions | |
ZMQRawOutput (const std::string &outputAddress, bool addEventSize, const std::shared_ptr< ZMQParent > &parent) | |
Create a new raw output connection. The bind or connect behavior is chosen according to the given address. | |
virtual void | handleEvent (zmq::message_t message) |
Pass on the message - maybe by prefixing it with a htonl-converted data size in bytes. | |
void | handleIncomingData () |
Handle incoming data: a socket (dis)connect. | |
bool | isReady () const final |
If no socket is connected, this connection is not ready. | |
std::vector< zmq::socket_t * > | getSockets () const final |
The socket used for polling is just the stored socket. | |
std::string | getEndPoint () const |
Return the connection string for this socket. | |
virtual std::string | getMonitoringJSON () const |
Convert the stored monitoring values to a JSON string ready for sending out via a message. | |
template<class AClass > | |
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, double or string. Mixtures are not allowed for a given key. | |
void | increment (const std::string &key) |
Increment the value with the given key (only numerical values). If not present, set to 1. | |
void | decrement (const std::string &key) |
Decrement the value with the given key (only numerical values). If not present, set to -1. | |
template<size_t MAX_SIZE = 100> | |
void | average (const std::string &key, double value) |
Instead of storeing the double value directly under the given key, store the average of the last MAX_SIZE values. | |
template<size_t AVERAGE_SIZE = 2000> | |
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 AVERAGE_SIZE was reached under <key>_last_measurement) | |
void | logTime (const std::string &key) |
Store the current time as a string under the given key. | |
Static Public Member Functions | |
static bool | poll (const std::map< const ZMQConnection *, ReactorFunction > &connectionList, int timeout) |
Poll on the given connections and call the attached function if a messages comes in. | |
static bool | hasMessage (const ZMQConnection *connection) |
Check if the given connection as an incoming message (right now, no waiting). | |
Protected Attributes | |
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. | |
Private Attributes | |
std::string | m_dataIdentity = "" |
Internal storage of the connected identity to no have multiple connections. | |
bool | m_addEventSize = false |
Parameter to add the event size to a message. | |
std::map< std::string, std::variant< long, double, std::string > > | m_monitoring |
Internal storage of all stored values. | |
std::unordered_map< std::string, std::tuple< std::vector< double >, size_t > > | m_averages |
Internal storage of the previous values when calculating averages. | |
std::unordered_map< std::string, std::tuple< unsigned long, std::chrono::system_clock::time_point > > | m_timeCounters |
Internal storage how often the timeit function for a given key was called and when it has last reached MAX_SIZE. | |
Output connection to speak to non-zmq sockets via a ZMQ_STREAM socket.
If a socket is connected, sends out the given message over this socket as it is. If addEventSize is true, will prefix the message with the htonl-converted size of the message in bytes. Compare this to the receiveEventMessages setting of the ZMQRawInput connection. If no socket is connected, this connection is not ready.
Please note that although it is an output connection, there will still be "incoming messages", namely whenever the socket connects or disconnects. So you need to poll on this connection. Can only send messages to a single connected socket.
Definition at line 87 of file ZMQRawConnection.h.
|
inherited |
Typedef of a function which will be called if a connection has a message.
Definition at line 34 of file ZMQConnection.h.
ZMQRawOutput | ( | const std::string & | outputAddress, |
bool | addEventSize, | ||
const std::shared_ptr< ZMQParent > & | parent | ||
) |
Create a new raw output connection. The bind or connect behavior is chosen according to the given address.
Definition at line 144 of file ZMQRawConnection.cc.
|
inherited |
Decrement the value with the given key (only numerical values). If not present, set to -1.
Definition at line 37 of file ZMQLogger.cc.
|
inherited |
Return the connection string for this socket.
Definition at line 87 of file ZMQConnection.cc.
|
virtualinherited |
Convert the stored monitoring values to a JSON string ready for sending out via a message.
Definition at line 15 of file ZMQLogger.cc.
|
finalvirtualinherited |
The socket used for polling is just the stored socket.
Implements ZMQConnection.
Definition at line 82 of file ZMQConnection.cc.
|
virtual |
Pass on the message - maybe by prefixing it with a htonl-converted data size in bytes.
Definition at line 161 of file ZMQRawConnection.cc.
void handleIncomingData | ( | ) |
Handle incoming data: a socket (dis)connect.
Definition at line 184 of file ZMQRawConnection.cc.
|
staticinherited |
Check if the given connection as an incoming message (right now, no waiting).
Definition at line 20 of file ZMQConnection.cc.
|
inherited |
Increment the value with the given key (only numerical values). If not present, set to 1.
Definition at line 32 of file ZMQLogger.cc.
|
finalvirtual |
If no socket is connected, this connection is not ready.
Reimplemented from ZMQConnection.
Definition at line 207 of file ZMQRawConnection.cc.
|
inherited |
Store the current time as a string under the given key.
Definition at line 42 of file ZMQLogger.cc.
|
staticinherited |
Poll on the given connections and call the attached function if a messages comes in.
If after timeout milliseconds still no message is received, return anyways. If timeout is 0, do not wait. If timeout is -1, wait infinitely.
Returns true if a message was received on any socket, false otherwise. Attention: in case of an interrupted system call (e.g. because a signal was received) the function might return anyways with a negative result even before the timeout!
Definition at line 27 of file ZMQConnection.cc.
|
private |
Parameter to add the event size to a message.
Definition at line 103 of file ZMQRawConnection.h.
|
privateinherited |
Internal storage of the previous values when calculating averages.
Definition at line 60 of file ZMQLogger.h.
|
private |
Internal storage of the connected identity to no have multiple connections.
Definition at line 101 of file ZMQRawConnection.h.
|
privateinherited |
Internal storage of all stored values.
Definition at line 58 of file ZMQLogger.h.
|
protectedinherited |
The shared ZMQParent instance.
Definition at line 75 of file ZMQConnection.h.
|
protectedinherited |
The memory of the socket. Needs to be initialized in a derived class.
Definition at line 77 of file ZMQConnection.h.
|
privateinherited |
Internal storage how often the timeit function for a given key was called and when it has last reached MAX_SIZE.
Definition at line 62 of file ZMQLogger.h.