Belle II Software development
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{
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}
ZMQConnectionOverSocket(const std::shared_ptr< ZMQParent > &parent)
Create a new instance passing the shared ZMQParent.
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 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
static std::unique_ptr< AMessage > fromSocket(const std::unique_ptr< zmq::socket_t > &socket)
Create a message of the given type by receiving a message from the socket.
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.