mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-16 18:11:49 +00:00
Enable new callback API
- OnData() channel data handler. - ConditionalRun() for devices without incoming data. - Header file with common main(), to be extended with getDevice/addCustomOptions. - Update examples (MQ/Tutorial3) to use the new API and config. - NewSimpleMessage() for simpler creation of small messages (additional copy). - Replace SetProperty/GetProperty with fConfig access. - Runtime configurable channel names for common devices. - Configurable logging interval per channel. - FairMQMultiplier for distributing same data to multiple outputs. - Cleanup state machine messages. - Cmd option to toggle signal handling. - Simpler API for send/receive timeouts. - Enable --log-to-file. - Fix coverity issues, warnings. - Various code cleanup and minor tweaks.
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "FairMQBenchmarkSampler.h"
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -28,6 +29,7 @@ FairMQBenchmarkSampler::FairMQBenchmarkSampler()
|
||||
, fNumMsgs(0)
|
||||
, fMsgCounter(0)
|
||||
, fMsgRate(1)
|
||||
, fOutChannelName()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -35,146 +37,79 @@ FairMQBenchmarkSampler::~FairMQBenchmarkSampler()
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::InitTask()
|
||||
{
|
||||
fMsgSize = fConfig->GetValue<int>("msg-size");
|
||||
fNumMsgs = fConfig->GetValue<int>("num-msgs");
|
||||
fMsgRate = fConfig->GetValue<int>("msg-rate");
|
||||
fOutChannelName = fConfig->GetValue<string>("out-channel");
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::Run()
|
||||
{
|
||||
boost::thread resetMsgCounter(boost::bind(&FairMQBenchmarkSampler::ResetMsgCounter, this));
|
||||
// boost::thread resetMsgCounter(boost::bind(&FairMQBenchmarkSampler::ResetMsgCounter, this));
|
||||
|
||||
int numSentMsgs = 0;
|
||||
|
||||
unique_ptr<FairMQMessage> baseMsg(fTransportFactory->CreateMessage(fMsgSize));
|
||||
FairMQMessagePtr baseMsg(fTransportFactory->CreateMessage(fMsgSize));
|
||||
|
||||
// store the channel reference to avoid traversing the map on every loop iteration
|
||||
const FairMQChannel& dataOutChannel = fChannels.at("data-out").at(0);
|
||||
const FairMQChannel& dataOutChannel = fChannels.at(fOutChannelName).at(0);
|
||||
|
||||
LOG(INFO) << "Starting the benchmark with message size of " << fMsgSize << " and number of messages " << fNumMsgs << ".";
|
||||
boost::timer::auto_cpu_timer timer;
|
||||
|
||||
while (CheckCurrentState(RUNNING))
|
||||
{
|
||||
unique_ptr<FairMQMessage> msg(fTransportFactory->CreateMessage());
|
||||
FairMQMessagePtr msg(fTransportFactory->CreateMessage());
|
||||
msg->Copy(baseMsg);
|
||||
|
||||
if (dataOutChannel.Send(msg) >= 0)
|
||||
{
|
||||
if (fNumMsgs > 0)
|
||||
{
|
||||
numSentMsgs++;
|
||||
if (numSentMsgs >= fNumMsgs)
|
||||
if (++numSentMsgs >= fNumMsgs)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
--fMsgCounter;
|
||||
// --fMsgCounter;
|
||||
|
||||
while (fMsgCounter == 0) {
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(1));
|
||||
}
|
||||
// while (fMsgCounter == 0) {
|
||||
// boost::this_thread::sleep(boost::posix_time::milliseconds(1));
|
||||
// }
|
||||
}
|
||||
|
||||
LOG(INFO) << "Sent " << numSentMsgs << " messages, leaving RUNNING state.";
|
||||
LOG(INFO) << "Sending time: ";
|
||||
|
||||
try
|
||||
{
|
||||
resetMsgCounter.interrupt();
|
||||
resetMsgCounter.join();
|
||||
}
|
||||
catch(boost::thread_resource_error& e)
|
||||
{
|
||||
LOG(ERROR) << e.what();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// try
|
||||
// {
|
||||
// resetMsgCounter.interrupt();
|
||||
// resetMsgCounter.join();
|
||||
// }
|
||||
// catch(boost::thread_resource_error& e)
|
||||
// {
|
||||
// LOG(ERROR) << e.what();
|
||||
// exit(EXIT_FAILURE);
|
||||
// }
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::ResetMsgCounter()
|
||||
{
|
||||
while (true) {
|
||||
try {
|
||||
fMsgCounter = fMsgRate / 100;
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(10));
|
||||
} catch (boost::thread_interrupted&) {
|
||||
LOG(DEBUG) << "Event rate limiter thread interrupted";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::SetProperty(const int key, const string& value)
|
||||
{
|
||||
switch (key)
|
||||
while (true)
|
||||
{
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
try
|
||||
{
|
||||
fMsgCounter = fMsgRate / 100;
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(10));
|
||||
}
|
||||
catch (boost::thread_interrupted&)
|
||||
{
|
||||
LOG(DEBUG) << "Event rate limiter thread interrupted";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string FairMQBenchmarkSampler::GetProperty(const int key, const string& default_ /*= ""*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::SetProperty(const int key, const int value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case MsgSize:
|
||||
fMsgSize = value;
|
||||
break;
|
||||
case MsgRate:
|
||||
fMsgRate = value;
|
||||
break;
|
||||
case NumMsgs:
|
||||
fNumMsgs = value;
|
||||
break;
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int FairMQBenchmarkSampler::GetProperty(const int key, const int default_ /*= 0*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case MsgSize:
|
||||
return fMsgSize;
|
||||
case MsgRate:
|
||||
return fMsgRate;
|
||||
case NumMsgs:
|
||||
return fNumMsgs;
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
||||
string FairMQBenchmarkSampler::GetPropertyDescription(const int key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case MsgSize:
|
||||
return "MsgSize: Size of the transfered message buffer.";
|
||||
case NumMsgs:
|
||||
return "NumMsgs: Number of messages to send.";
|
||||
case MsgRate:
|
||||
return "MsgRate: Maximum msg rate.";
|
||||
default:
|
||||
return FairMQDevice::GetPropertyDescription(key);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::ListProperties()
|
||||
{
|
||||
LOG(INFO) << "Properties of FairMQBenchmarkSampler:";
|
||||
for (int p = FairMQConfigurable::Last; p < FairMQBenchmarkSampler::Last; ++p)
|
||||
{
|
||||
LOG(INFO) << " " << GetPropertyDescription(p);
|
||||
}
|
||||
LOG(INFO) << "---------------------------";
|
||||
}
|
||||
|
@@ -26,33 +26,19 @@
|
||||
class FairMQBenchmarkSampler : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
MsgSize = FairMQDevice::Last,
|
||||
NumMsgs,
|
||||
MsgRate,
|
||||
Last
|
||||
};
|
||||
|
||||
FairMQBenchmarkSampler();
|
||||
virtual ~FairMQBenchmarkSampler();
|
||||
|
||||
void ResetMsgCounter();
|
||||
|
||||
virtual void SetProperty(const int key, const std::string& value);
|
||||
virtual std::string GetProperty(const int key, const std::string& default_ = "");
|
||||
virtual void SetProperty(const int key, const int value);
|
||||
virtual int GetProperty(const int key, const int default_ = 0);
|
||||
|
||||
virtual std::string GetPropertyDescription(const int key);
|
||||
virtual void ListProperties();
|
||||
|
||||
protected:
|
||||
int fMsgSize;
|
||||
int fNumMsgs;
|
||||
int fMsgCounter;
|
||||
int fMsgRate;
|
||||
std::string fOutChannelName;
|
||||
|
||||
virtual void InitTask();
|
||||
virtual void Run();
|
||||
};
|
||||
|
||||
|
@@ -12,17 +12,17 @@
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQMerger.h"
|
||||
#include "FairMQPoller.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQMerger::FairMQMerger()
|
||||
: fMultipart(1)
|
||||
, fInChannelName()
|
||||
, fOutChannelName()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -30,11 +30,18 @@ FairMQMerger::~FairMQMerger()
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQMerger::InitTask()
|
||||
{
|
||||
fMultipart = fConfig->GetValue<int>("multipart");
|
||||
fInChannelName = fConfig->GetValue<string>("in-channel");
|
||||
fOutChannelName = fConfig->GetValue<string>("out-channel");
|
||||
}
|
||||
|
||||
void FairMQMerger::Run()
|
||||
{
|
||||
int numInputs = fChannels.at("data-in").size();
|
||||
int numInputs = fChannels.at(fInChannelName).size();
|
||||
|
||||
std::unique_ptr<FairMQPoller> poller(fTransportFactory->CreatePoller(fChannels.at("data-in")));
|
||||
std::unique_ptr<FairMQPoller> poller(fTransportFactory->CreatePoller(fChannels.at(fInChannelName)));
|
||||
|
||||
if (fMultipart)
|
||||
{
|
||||
@@ -50,9 +57,9 @@ void FairMQMerger::Run()
|
||||
{
|
||||
FairMQParts payload;
|
||||
|
||||
if (Receive(payload, "data-in", i) >= 0)
|
||||
if (Receive(payload, fInChannelName, i) >= 0)
|
||||
{
|
||||
if (Send(payload, "data-out") < 0)
|
||||
if (Send(payload, fOutChannelName) < 0)
|
||||
{
|
||||
LOG(DEBUG) << "Transfer interrupted";
|
||||
break;
|
||||
@@ -79,11 +86,11 @@ void FairMQMerger::Run()
|
||||
// Check if the channel has data ready to be received.
|
||||
if (poller->CheckInput(i))
|
||||
{
|
||||
unique_ptr<FairMQMessage> payload(fTransportFactory->CreateMessage());
|
||||
FairMQMessagePtr payload(fTransportFactory->CreateMessage());
|
||||
|
||||
if (Receive(payload, "data-in", i) >= 0)
|
||||
if (Receive(payload, fInChannelName, i) >= 0)
|
||||
{
|
||||
if (Send(payload, "data-out") < 0)
|
||||
if (Send(payload, fOutChannelName) < 0)
|
||||
{
|
||||
LOG(DEBUG) << "Transfer interrupted";
|
||||
break;
|
||||
@@ -99,67 +106,3 @@ void FairMQMerger::Run()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQMerger::SetProperty(const int key, const string& value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string FairMQMerger::GetProperty(const int key, const string& default_ /*= ""*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQMerger::SetProperty(const int key, const int value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case Multipart:
|
||||
fMultipart = value;
|
||||
break;
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int FairMQMerger::GetProperty(const int key, const int default_ /*= 0*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case Multipart:
|
||||
return fMultipart;
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
||||
string FairMQMerger::GetPropertyDescription(const int key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case Multipart:
|
||||
return "Multipart: Handle payloads as multipart messages.";
|
||||
default:
|
||||
return FairMQDevice::GetPropertyDescription(key);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQMerger::ListProperties()
|
||||
{
|
||||
LOG(INFO) << "Properties of FairMQMerger:";
|
||||
for (int p = FairMQConfigurable::Last; p < FairMQMerger::Last; ++p)
|
||||
{
|
||||
LOG(INFO) << " " << GetPropertyDescription(p);
|
||||
}
|
||||
LOG(INFO) << "---------------------------";
|
||||
}
|
||||
|
@@ -17,30 +17,21 @@
|
||||
|
||||
#include "FairMQDevice.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class FairMQMerger : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
Multipart = FairMQDevice::Last,
|
||||
Last
|
||||
};
|
||||
|
||||
FairMQMerger();
|
||||
virtual ~FairMQMerger();
|
||||
|
||||
virtual void SetProperty(const int key, const std::string& value);
|
||||
virtual std::string GetProperty(const int key, const std::string& default_ = "");
|
||||
virtual void SetProperty(const int key, const int value);
|
||||
virtual int GetProperty(const int key, const int default_ = 0);
|
||||
|
||||
virtual std::string GetPropertyDescription(const int key);
|
||||
virtual void ListProperties();
|
||||
|
||||
protected:
|
||||
int fMultipart;
|
||||
std::string fInChannelName;
|
||||
std::string fOutChannelName;
|
||||
|
||||
virtual void Run();
|
||||
virtual void InitTask();
|
||||
};
|
||||
|
||||
#endif /* FAIRMQMERGER_H_ */
|
||||
|
110
fairmq/devices/FairMQMultiplier.cxx
Normal file
110
fairmq/devices/FairMQMultiplier.cxx
Normal file
@@ -0,0 +1,110 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQMultiplier.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQMultiplier::FairMQMultiplier()
|
||||
: fMultipart(1)
|
||||
, fNumOutputs(0)
|
||||
, fInChannelName()
|
||||
, fOutChannelNames()
|
||||
{
|
||||
}
|
||||
|
||||
FairMQMultiplier::~FairMQMultiplier()
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQMultiplier::InitTask()
|
||||
{
|
||||
fMultipart = fConfig->GetValue<int>("multipart");
|
||||
fInChannelName = fConfig->GetValue<string>("in-channel");
|
||||
fOutChannelNames = fConfig->GetValue<vector<string>>("out-channel");
|
||||
fNumOutputs = fChannels.at(fOutChannelNames.at(0)).size();
|
||||
|
||||
if (fMultipart)
|
||||
{
|
||||
OnData(fInChannelName, &FairMQMultiplier::HandleMultipartData);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnData(fInChannelName, &FairMQMultiplier::HandleSingleData);
|
||||
}
|
||||
}
|
||||
|
||||
bool FairMQMultiplier::HandleSingleData(std::unique_ptr<FairMQMessage>& payload, int /*index*/)
|
||||
{
|
||||
for (unsigned int i = 0; i < fOutChannelNames.size() - 1; ++i) // all except last channel
|
||||
{
|
||||
for (unsigned int j = 0; j < fChannels.at(fOutChannelNames.at(i)).size(); ++j) // all subChannels in a channel
|
||||
{
|
||||
FairMQMessagePtr msgCopy(fTransportFactory->CreateMessage());
|
||||
msgCopy->Copy(payload);
|
||||
|
||||
Send(msgCopy, fOutChannelNames.at(i), j);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int lastChannelSize = fChannels.at(fOutChannelNames.back()).size();
|
||||
|
||||
for (unsigned int i = 0; i < lastChannelSize - 1; ++i) // iterate over all except last subChannels of the last channel
|
||||
{
|
||||
FairMQMessagePtr msgCopy(fTransportFactory->CreateMessage());
|
||||
msgCopy->Copy(payload);
|
||||
|
||||
Send(msgCopy, fOutChannelNames.back(), i);
|
||||
}
|
||||
|
||||
Send(payload, fOutChannelNames.back(), lastChannelSize - 1); // send final message to last subChannel of last channel
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FairMQMultiplier::HandleMultipartData(FairMQParts& payload, int /*index*/)
|
||||
{
|
||||
for (unsigned int i = 0; i < fOutChannelNames.size() - 1; ++i) // all except last channel
|
||||
{
|
||||
for (unsigned int j = 0; j < fChannels.at(fOutChannelNames.at(i)).size(); ++j) // all subChannels in a channel
|
||||
{
|
||||
FairMQParts parts;
|
||||
|
||||
for (int k = 0; k < payload.Size(); ++k)
|
||||
{
|
||||
FairMQMessagePtr msgCopy(fTransportFactory->CreateMessage());
|
||||
msgCopy->Copy(payload.At(k));
|
||||
parts.AddPart(msgCopy);
|
||||
}
|
||||
|
||||
Send(parts, fOutChannelNames.at(i), j);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int lastChannelSize = fChannels.at(fOutChannelNames.back()).size();
|
||||
|
||||
for (unsigned int i = 0; i < lastChannelSize - 1; ++i) // iterate over all except last subChannels of the last channel
|
||||
{
|
||||
FairMQParts parts;
|
||||
|
||||
for (int k = 0; k < payload.Size(); ++k)
|
||||
{
|
||||
FairMQMessagePtr msgCopy(fTransportFactory->CreateMessage());
|
||||
msgCopy->Copy(payload.At(k));
|
||||
parts.AddPart(msgCopy);
|
||||
}
|
||||
|
||||
Send(parts, fOutChannelNames.back(), i);
|
||||
}
|
||||
|
||||
Send(payload, fOutChannelNames.back(), lastChannelSize - 1); // send final message to last subChannel of last channel
|
||||
|
||||
return true;
|
||||
}
|
34
fairmq/devices/FairMQMultiplier.h
Normal file
34
fairmq/devices/FairMQMultiplier.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/********************************************************************************
|
||||
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
|
||||
* *
|
||||
* This software is distributed under the terms of the *
|
||||
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
|
||||
* copied verbatim in the file "LICENSE" *
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef FAIRMQMULTIPLIER_H_
|
||||
#define FAIRMQMULTIPLIER_H_
|
||||
|
||||
#include "FairMQDevice.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class FairMQMultiplier : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
FairMQMultiplier();
|
||||
virtual ~FairMQMultiplier();
|
||||
|
||||
protected:
|
||||
int fMultipart;
|
||||
int fNumOutputs;
|
||||
std::string fInChannelName;
|
||||
std::vector<std::string> fOutChannelNames;
|
||||
|
||||
virtual void InitTask();
|
||||
|
||||
bool HandleSingleData(std::unique_ptr<FairMQMessage>&, int);
|
||||
bool HandleMultipartData(FairMQParts&, int);
|
||||
};
|
||||
|
||||
#endif /* FAIRMQMULTIPLIER_H_ */
|
@@ -12,16 +12,16 @@
|
||||
* @author A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQProxy.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQProxy::FairMQProxy()
|
||||
: fMultipart(1)
|
||||
, fInChannelName()
|
||||
, fOutChannelName()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -29,6 +29,13 @@ FairMQProxy::~FairMQProxy()
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQProxy::InitTask()
|
||||
{
|
||||
fMultipart = fConfig->GetValue<int>("multipart");
|
||||
fInChannelName = fConfig->GetValue<string>("in-channel");
|
||||
fOutChannelName = fConfig->GetValue<string>("out-channel");
|
||||
}
|
||||
|
||||
void FairMQProxy::Run()
|
||||
{
|
||||
if (fMultipart)
|
||||
@@ -36,9 +43,9 @@ void FairMQProxy::Run()
|
||||
while (CheckCurrentState(RUNNING))
|
||||
{
|
||||
FairMQParts payload;
|
||||
if (Receive(payload, "data-in") >= 0)
|
||||
if (Receive(payload, fInChannelName) >= 0)
|
||||
{
|
||||
if (Send(payload, "data-out") < 0)
|
||||
if (Send(payload, fOutChannelName) < 0)
|
||||
{
|
||||
LOG(DEBUG) << "Transfer interrupted";
|
||||
break;
|
||||
@@ -56,9 +63,9 @@ void FairMQProxy::Run()
|
||||
while (CheckCurrentState(RUNNING))
|
||||
{
|
||||
unique_ptr<FairMQMessage> payload(fTransportFactory->CreateMessage());
|
||||
if (Receive(payload, "data-in") >= 0)
|
||||
if (Receive(payload, fInChannelName) >= 0)
|
||||
{
|
||||
if (Send(payload, "data-out") < 0)
|
||||
if (Send(payload, fOutChannelName) < 0)
|
||||
{
|
||||
LOG(DEBUG) << "Transfer interrupted";
|
||||
break;
|
||||
|
@@ -17,6 +17,8 @@
|
||||
|
||||
#include "FairMQDevice.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class FairMQProxy : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
@@ -39,8 +41,11 @@ class FairMQProxy : public FairMQDevice
|
||||
|
||||
protected:
|
||||
int fMultipart;
|
||||
std::string fInChannelName;
|
||||
std::string fOutChannelName;
|
||||
|
||||
virtual void Run();
|
||||
virtual void InitTask();
|
||||
};
|
||||
|
||||
#endif /* FAIRMQPROXY_H_ */
|
||||
|
@@ -12,25 +12,31 @@
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/timer/timer.hpp>
|
||||
|
||||
#include "FairMQSink.h"
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQSink::FairMQSink()
|
||||
: fNumMsgs(0)
|
||||
, fInChannelName()
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQSink::InitTask()
|
||||
{
|
||||
fNumMsgs = fConfig->GetValue<int>("num-msgs");
|
||||
fInChannelName = fConfig->GetValue<string>("in-channel");
|
||||
}
|
||||
|
||||
void FairMQSink::Run()
|
||||
{
|
||||
int numReceivedMsgs = 0;
|
||||
// store the channel reference to avoid traversing the map on every loop iteration
|
||||
const FairMQChannel& dataInChannel = fChannels.at("data-in").at(0);
|
||||
const FairMQChannel& dataInChannel = fChannels.at(fInChannelName).at(0);
|
||||
|
||||
LOG(INFO) << "Starting the benchmark and expecting to receive " << fNumMsgs << " messages.";
|
||||
boost::timer::auto_cpu_timer timer;
|
||||
@@ -59,67 +65,3 @@ void FairMQSink::Run()
|
||||
FairMQSink::~FairMQSink()
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQSink::SetProperty(const int key, const string& value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string FairMQSink::GetProperty(const int key, const string& default_ /*= ""*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQSink::SetProperty(const int key, const int value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case NumMsgs:
|
||||
fNumMsgs = value;
|
||||
break;
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int FairMQSink::GetProperty(const int key, const int default_ /*= 0*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case NumMsgs:
|
||||
return fNumMsgs;
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
||||
string FairMQSink::GetPropertyDescription(const int key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case NumMsgs:
|
||||
return "NumMsgs: Number of messages to send.";
|
||||
default:
|
||||
return FairMQDevice::GetPropertyDescription(key);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQSink::ListProperties()
|
||||
{
|
||||
LOG(INFO) << "Properties of FairMQSink:";
|
||||
for (int p = FairMQConfigurable::Last; p < FairMQSink::Last; ++p)
|
||||
{
|
||||
LOG(INFO) << " " << GetPropertyDescription(p);
|
||||
}
|
||||
LOG(INFO) << "---------------------------";
|
||||
}
|
||||
|
@@ -22,27 +22,15 @@
|
||||
class FairMQSink : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
NumMsgs = FairMQDevice::Last,
|
||||
Last
|
||||
};
|
||||
|
||||
FairMQSink();
|
||||
virtual ~FairMQSink();
|
||||
|
||||
virtual void SetProperty(const int key, const std::string& value);
|
||||
virtual std::string GetProperty(const int key, const std::string& default_ = "");
|
||||
virtual void SetProperty(const int key, const int value);
|
||||
virtual int GetProperty(const int key, const int default_ = 0);
|
||||
|
||||
virtual std::string GetPropertyDescription(const int key);
|
||||
virtual void ListProperties();
|
||||
|
||||
protected:
|
||||
int fNumMsgs;
|
||||
std::string fInChannelName;
|
||||
|
||||
virtual void Run();
|
||||
virtual void InitTask();
|
||||
};
|
||||
|
||||
#endif /* FAIRMQSINK_H_ */
|
||||
|
@@ -12,16 +12,18 @@
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "FairMQLogger.h"
|
||||
#include "FairMQSplitter.h"
|
||||
#include "FairMQProgOptions.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQSplitter::FairMQSplitter()
|
||||
: fMultipart(1)
|
||||
, fNumOutputs(0)
|
||||
, fDirection(0)
|
||||
, fInChannelName()
|
||||
, fOutChannelName()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -29,129 +31,44 @@ FairMQSplitter::~FairMQSplitter()
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQSplitter::Run()
|
||||
void FairMQSplitter::InitTask()
|
||||
{
|
||||
int numOutputs = fChannels.at("data-out").size();
|
||||
|
||||
int direction = 0;
|
||||
fMultipart = fConfig->GetValue<int>("multipart");
|
||||
fInChannelName = fConfig->GetValue<string>("in-channel");
|
||||
fOutChannelName = fConfig->GetValue<string>("out-channel");
|
||||
fNumOutputs = fChannels.at(fOutChannelName).size();
|
||||
fDirection = 0;
|
||||
|
||||
if (fMultipart)
|
||||
{
|
||||
while (CheckCurrentState(RUNNING))
|
||||
{
|
||||
FairMQParts payload;
|
||||
|
||||
if (Receive(payload, "data-in") >= 0)
|
||||
{
|
||||
if (Send(payload, "data-out", direction) < 0)
|
||||
{
|
||||
LOG(DEBUG) << "Transfer interrupted";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(DEBUG) << "Transfer interrupted";
|
||||
break;
|
||||
}
|
||||
|
||||
++direction;
|
||||
if (direction >= numOutputs)
|
||||
{
|
||||
direction = 0;
|
||||
}
|
||||
}
|
||||
OnData(fInChannelName, &FairMQSplitter::HandleMultipartData);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (CheckCurrentState(RUNNING))
|
||||
{
|
||||
unique_ptr<FairMQMessage> payload(fTransportFactory->CreateMessage());
|
||||
|
||||
if (Receive(payload, "data-in") >= 0)
|
||||
{
|
||||
if (Send(payload, "data-out", direction) < 0)
|
||||
{
|
||||
LOG(DEBUG) << "Transfer interrupted";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(DEBUG) << "Transfer interrupted";
|
||||
break;
|
||||
}
|
||||
|
||||
++direction;
|
||||
if (direction >= numOutputs)
|
||||
{
|
||||
direction = 0;
|
||||
}
|
||||
}
|
||||
OnData(fInChannelName, &FairMQSplitter::HandleSingleData);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQSplitter::SetProperty(const int key, const string& value)
|
||||
bool FairMQSplitter::HandleSingleData(FairMQMessagePtr& payload, int /*index*/)
|
||||
{
|
||||
switch (key)
|
||||
Send(payload, fOutChannelName, fDirection);
|
||||
|
||||
if (++fDirection >= fNumOutputs)
|
||||
{
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
fDirection = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
string FairMQSplitter::GetProperty(const int key, const string& default_ /*= ""*/)
|
||||
bool FairMQSplitter::HandleMultipartData(FairMQParts& payload, int /*index*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
Send(payload, fOutChannelName, fDirection);
|
||||
|
||||
void FairMQSplitter::SetProperty(const int key, const int value)
|
||||
{
|
||||
switch (key)
|
||||
if (++fDirection >= fNumOutputs)
|
||||
{
|
||||
case Multipart:
|
||||
fMultipart = value;
|
||||
break;
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
fDirection = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int FairMQSplitter::GetProperty(const int key, const int default_ /*= 0*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case Multipart:
|
||||
return fMultipart;
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
string FairMQSplitter::GetPropertyDescription(const int key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case Multipart:
|
||||
return "Multipart: Handle payloads as multipart messages.";
|
||||
default:
|
||||
return FairMQDevice::GetPropertyDescription(key);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQSplitter::ListProperties()
|
||||
{
|
||||
LOG(INFO) << "Properties of FairMQSplitter:";
|
||||
for (int p = FairMQConfigurable::Last; p < FairMQSplitter::Last; ++p)
|
||||
{
|
||||
LOG(INFO) << " " << GetPropertyDescription(p);
|
||||
}
|
||||
LOG(INFO) << "---------------------------";
|
||||
}
|
||||
|
||||
|
@@ -17,30 +17,25 @@
|
||||
|
||||
#include "FairMQDevice.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class FairMQSplitter : public FairMQDevice
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
Multipart = FairMQDevice::Last,
|
||||
Last
|
||||
};
|
||||
|
||||
FairMQSplitter();
|
||||
virtual ~FairMQSplitter();
|
||||
|
||||
virtual void SetProperty(const int key, const std::string& value);
|
||||
virtual std::string GetProperty(const int key, const std::string& default_ = "");
|
||||
virtual void SetProperty(const int key, const int value);
|
||||
virtual int GetProperty(const int key, const int default_ = 0);
|
||||
|
||||
virtual std::string GetPropertyDescription(const int key);
|
||||
virtual void ListProperties();
|
||||
|
||||
protected:
|
||||
int fMultipart;
|
||||
int fNumOutputs;
|
||||
int fDirection;
|
||||
std::string fInChannelName;
|
||||
std::string fOutChannelName;
|
||||
|
||||
virtual void Run();
|
||||
virtual void InitTask();
|
||||
|
||||
bool HandleSingleData(std::unique_ptr<FairMQMessage>&, int);
|
||||
bool HandleMultipartData(FairMQParts&, int);
|
||||
};
|
||||
|
||||
#endif /* FAIRMQSPLITTER_H_ */
|
||||
|
Reference in New Issue
Block a user