Belle II Software  release-05-01-25
ZMQSimpleConnection.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <framework/pcore/zmq/connections/ZMQSimpleConnection.h>
11 #include <framework/pcore/zmq/messages/ZMQMessageFactory.h>
12 
13 using namespace Belle2;
14 
15 ZMQSimpleConnection::ZMQSimpleConnection(const std::string& monitoringAddress,
16  const std::shared_ptr<ZMQParent>& parent) : ZMQConnectionOverSocket(parent)
17 {
18  m_socket = m_parent->createSocket<ZMQ_ROUTER>(monitoringAddress, true);
19 
20  log("monitoring_counter", 0l);
21 }
22 
23 std::unique_ptr<ZMQIdMessage> ZMQSimpleConnection::handleIncomingData()
24 {
25  auto message = ZMQMessageFactory::fromSocket<ZMQIdMessage>(m_socket);
26  return message;
27 }
28 
29 void ZMQSimpleConnection::handleEvent(std::unique_ptr<ZMQIdMessage> message)
30 {
31  increment("monitoring_counter");
32  ZMQParent::send(m_socket, std::move(message));
33 }
Belle2::ZMQSimpleConnection::handleEvent
void handleEvent(std::unique_ptr< ZMQIdMessage > message)
Send the given message via the socket (the message includes the identity to send to)
Definition: ZMQSimpleConnection.cc:29
Belle2::ZMQParent::send
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:163
Belle2::ZMQConnectionOverSocket::m_parent
std::shared_ptr< ZMQParent > m_parent
The shared ZMQParent instance.
Definition: ZMQConnection.h:82
Belle2::ZMQLogger::log
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:106
Belle2::ZMQLogger::increment
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:34
Belle2::ZMQSimpleConnection::handleIncomingData
std::unique_ptr< ZMQIdMessage > handleIncomingData()
Block until there is an incoming message and return it as a ZMQIdMessage.
Definition: ZMQSimpleConnection.cc:23
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ZMQSimpleConnection::ZMQSimpleConnection
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.
Definition: ZMQSimpleConnection.cc:15
Belle2::ZMQConnectionOverSocket
Specialized connection over a ZMQ socket.
Definition: ZMQConnection.h:72
Belle2::ZMQConnectionOverSocket::m_socket
std::unique_ptr< zmq::socket_t > m_socket
The memory of the socket. Needs to be initialized in a derived class.
Definition: ZMQConnection.h:84