Belle II Software light-2406-ragdoll
ZMQSimpleConnection.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <framework/pcore/zmq/connections/ZMQSimpleConnection.h>
9#include <framework/pcore/zmq/messages/ZMQMessageFactory.h>
10
11using namespace Belle2;
12
13ZMQSimpleConnection::ZMQSimpleConnection(const std::string& monitoringAddress,
14 const std::shared_ptr<ZMQParent>& parent) : ZMQConnectionOverSocket(parent)
15{
16 m_socket = m_parent->createSocket<ZMQ_ROUTER>(monitoringAddress, true);
17
18 log("monitoring_counter", 0l);
19}
20
21std::unique_ptr<ZMQIdMessage> ZMQSimpleConnection::handleIncomingData()
22{
23 auto message = ZMQMessageFactory::fromSocket<ZMQIdMessage>(m_socket);
24 return message;
25}
26
27void ZMQSimpleConnection::handleEvent(std::unique_ptr<ZMQIdMessage> message)
28{
29 increment("monitoring_counter");
30 ZMQParent::send(m_socket, std::move(message));
31}
Specialized connection over a ZMQ socket.
Definition: ZMQConnection.h:63
std::shared_ptr< ZMQParent > m_parent
The shared ZMQParent instance.
Definition: ZMQConnection.h:75
std::unique_ptr< zmq::socket_t > m_socket
The memory of the socket. Needs to be initialized in a derived class.
Definition: ZMQConnection.h:77
void increment(const std::string &key)
Increment the value with the given key (only numerical values). If not present, set to 1.
Definition: ZMQLogger.cc:32
std::unique_ptr< ZMQIdMessage > handleIncomingData()
Block until there is an incoming message and return it as a ZMQIdMessage.
void handleEvent(std::unique_ptr< ZMQIdMessage > message)
Send the given message via the socket (the message includes the identity to send to)
ZMQSimpleConnection(const std::string &monitoringAddress, const std::shared_ptr< ZMQParent > &parent)
Create a new simple connection with a ZMQ_ROUTER socket binding to the given address.
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.
Definition: ZMQParent.h:153
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,...
Definition: ZMQLogger.h:96
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24