mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
Update FairMQStateMachine & introduce FairMQChannels
Organize sockets as a map of vectors of FairMQChannels. Update FairMQStateMachine by removing SETTINGINPUT, SETTINGOUTPUT, BIND and CONNECT states and by adding INITIALIZING_TASK, RESETTING_TASK and RESETTING_DEVICE states. Run states functions in their own thread.
This commit is contained in:
parent
a2ebbbe450
commit
7fda980710
|
@ -69,7 +69,9 @@ set(SRCS
|
|||
"FairMQTransportFactory.cxx"
|
||||
"FairMQMessage.cxx"
|
||||
"FairMQSocket.cxx"
|
||||
"FairMQChannel.cxx"
|
||||
"FairMQDevice.cxx"
|
||||
"FairMQPoller.cxx"
|
||||
"devices/FairMQBenchmarkSampler.cxx"
|
||||
"devices/FairMQSink.cxx"
|
||||
"devices/FairMQBuffer.cxx"
|
||||
|
@ -79,7 +81,6 @@ set(SRCS
|
|||
"options/FairProgOptions.cxx"
|
||||
"options/FairMQProgOptions.cxx"
|
||||
"options/FairMQParser.cxx"
|
||||
"FairMQPoller.cxx"
|
||||
"examples/req-rep/FairMQExampleClient.cxx"
|
||||
"examples/req-rep/FairMQExampleServer.cxx"
|
||||
)
|
||||
|
@ -150,10 +151,10 @@ GENERATE_LIBRARY()
|
|||
|
||||
set(Exe_Names
|
||||
bsampler
|
||||
sink
|
||||
buffer
|
||||
splitter
|
||||
merger
|
||||
sink
|
||||
proxy
|
||||
example_client
|
||||
example_server
|
||||
|
@ -172,10 +173,10 @@ set(Exe_Names
|
|||
|
||||
set(Exe_Source
|
||||
run/runBenchmarkSampler.cxx
|
||||
run/runSink.cxx
|
||||
run/runBuffer.cxx
|
||||
run/runSplitter.cxx
|
||||
run/runMerger.cxx
|
||||
run/runSink.cxx
|
||||
run/runProxy.cxx
|
||||
examples/req-rep/runExampleClient.cxx
|
||||
examples/req-rep/runExampleServer.cxx
|
||||
|
|
122
fairmq/FairMQChannel.cxx
Normal file
122
fairmq/FairMQChannel.cxx
Normal file
|
@ -0,0 +1,122 @@
|
|||
/********************************************************************************
|
||||
* 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" *
|
||||
********************************************************************************/
|
||||
/**
|
||||
* FairMQChannel.cxx
|
||||
*
|
||||
* @since 2015-06-02
|
||||
* @author A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "FairMQChannel.h"
|
||||
#include "FairMQLogger.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQChannel::FairMQChannel()
|
||||
: fType("unspecified")
|
||||
, fMethod("unspecified")
|
||||
, fAddress("unspecified")
|
||||
, fSndBufSize(1000)
|
||||
, fRcvBufSize(1000)
|
||||
, fRateLogging(1)
|
||||
, fSocket()
|
||||
, fChannelName("")
|
||||
{
|
||||
}
|
||||
|
||||
FairMQChannel::FairMQChannel(const string& type, const string& method, const string& address)
|
||||
: fType(type)
|
||||
, fMethod(method)
|
||||
, fAddress(address)
|
||||
, fSndBufSize(1000)
|
||||
, fRcvBufSize(1000)
|
||||
, fRateLogging(1)
|
||||
, fSocket()
|
||||
, fChannelName("")
|
||||
{
|
||||
}
|
||||
|
||||
bool FairMQChannel::ValidateChannel()
|
||||
{
|
||||
stringstream ss;
|
||||
ss << "Validating channel " << fChannelName << "... ";
|
||||
|
||||
const string socketTypeNames[] = { "sub", "pub", "pull", "push", "req", "rep", "xsub", "xpub", "dealer", "router", "pair" };
|
||||
const set<string> socketTypes(socketTypeNames, socketTypeNames + sizeof(socketTypeNames) / sizeof(string));
|
||||
if (socketTypes.find(fType) == socketTypes.end())
|
||||
{
|
||||
ss << "INVALID";
|
||||
LOG(DEBUG) << ss.str();
|
||||
LOG(DEBUG) << "Invalid channel type: " << fType;
|
||||
return false;
|
||||
}
|
||||
|
||||
const string socketMethodNames[] = { "bind", "connect" };
|
||||
const set<string> socketMethods(socketMethodNames, socketMethodNames + sizeof(socketMethodNames) / sizeof(string));
|
||||
if (socketMethods.find(fMethod) == socketMethods.end())
|
||||
{
|
||||
ss << "INVALID";
|
||||
LOG(DEBUG) << ss.str();
|
||||
LOG(DEBUG) << "Invalid channel method: " << fMethod;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fAddress == "unspecified" && fAddress == "")
|
||||
{
|
||||
ss << "INVALID";
|
||||
LOG(DEBUG) << ss.str();
|
||||
LOG(DEBUG) << "invalid channel address: " << fAddress;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fSndBufSize < 0)
|
||||
{
|
||||
ss << "INVALID";
|
||||
LOG(DEBUG) << ss.str();
|
||||
LOG(DEBUG) << "invalid channel send buffer size: " << fSndBufSize;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fRcvBufSize < 0)
|
||||
{
|
||||
ss << "INVALID";
|
||||
LOG(DEBUG) << ss.str();
|
||||
LOG(DEBUG) << "invalid channel receive buffer size: " << fRcvBufSize;
|
||||
return false;
|
||||
}
|
||||
|
||||
ss << "VALID";
|
||||
LOG(DEBUG) << ss.str();
|
||||
return true;
|
||||
}
|
||||
|
||||
int FairMQChannel::Send(FairMQMessage* msg, const string& flag)
|
||||
{
|
||||
return fSocket->Send(msg, flag);
|
||||
}
|
||||
|
||||
int FairMQChannel::Send(FairMQMessage* msg, const int flags)
|
||||
{
|
||||
return fSocket->Send(msg, flags);
|
||||
}
|
||||
|
||||
int FairMQChannel::Receive(FairMQMessage* msg, const string& flag)
|
||||
{
|
||||
return fSocket->Receive(msg, flag);
|
||||
}
|
||||
|
||||
int FairMQChannel::Receive(FairMQMessage* msg, const int flags)
|
||||
{
|
||||
return fSocket->Receive(msg, flags);
|
||||
}
|
||||
|
||||
FairMQChannel::~FairMQChannel()
|
||||
{
|
||||
}
|
52
fairmq/FairMQChannel.h
Normal file
52
fairmq/FairMQChannel.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/********************************************************************************
|
||||
* 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" *
|
||||
********************************************************************************/
|
||||
/**
|
||||
* FairMQChannel.h
|
||||
*
|
||||
* @since 2015-06-02
|
||||
* @author A. Rybalchenko
|
||||
*/
|
||||
|
||||
#ifndef FAIRMQCHANNEL_H_
|
||||
#define FAIRMQCHANNEL_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "FairMQSocket.h"
|
||||
|
||||
class FairMQChannel
|
||||
{
|
||||
friend class FairMQDevice;
|
||||
|
||||
public:
|
||||
FairMQChannel();
|
||||
FairMQChannel(const std::string& type, const std::string& method, const std::string& address);
|
||||
virtual ~FairMQChannel();
|
||||
|
||||
bool ValidateChannel();
|
||||
|
||||
// Wrappers for the socket methods to simplify the usage of channels
|
||||
int Send(FairMQMessage* msg, const std::string& flag = "");
|
||||
int Send(FairMQMessage* msg, const int flags);
|
||||
int Receive(FairMQMessage* msg, const std::string& flag = "");
|
||||
int Receive(FairMQMessage* msg, const int flags);
|
||||
|
||||
std::string fType;
|
||||
std::string fMethod;
|
||||
std::string fAddress;
|
||||
int fSndBufSize;
|
||||
int fRcvBufSize;
|
||||
int fRateLogging;
|
||||
|
||||
FairMQSocket* fSocket;
|
||||
|
||||
private:
|
||||
std::string fChannelName;
|
||||
};
|
||||
|
||||
#endif /* FAIRMQCHANNEL_H_ */
|
|
@ -21,25 +21,25 @@ FairMQConfigurable::FairMQConfigurable()
|
|||
{
|
||||
}
|
||||
|
||||
void FairMQConfigurable::SetProperty(const int key, const string& value, const int slot /*= 0*/)
|
||||
void FairMQConfigurable::SetProperty(const int key, const string& value)
|
||||
{
|
||||
LOG(ERROR) << "Reached end of the property list. SetProperty(" << key << ", " << value << ") has no effect.";
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
string FairMQConfigurable::GetProperty(const int key, const string& default_ /*= ""*/, const int slot /*= 0*/)
|
||||
string FairMQConfigurable::GetProperty(const int key, const string& default_ /*= ""*/)
|
||||
{
|
||||
LOG(ERROR) << "Reached end of the property list. The requested property " << key << " was not found.";
|
||||
return default_;
|
||||
}
|
||||
|
||||
void FairMQConfigurable::SetProperty(const int key, const int value, const int slot /*= 0*/)
|
||||
void FairMQConfigurable::SetProperty(const int key, const int value)
|
||||
{
|
||||
LOG(ERROR) << "Reached end of the property list. SetProperty(" << key << ", " << value << ") has no effect.";
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int FairMQConfigurable::GetProperty(const int key, const int default_ /*= 0*/, const int slot /*= 0*/)
|
||||
int FairMQConfigurable::GetProperty(const int key, const int default_ /*= 0*/)
|
||||
{
|
||||
LOG(ERROR) << "Reached end of the property list. The requested property " << key << " was not found.";
|
||||
return default_;
|
||||
|
|
|
@ -25,10 +25,10 @@ class FairMQConfigurable
|
|||
Last = 1
|
||||
};
|
||||
FairMQConfigurable();
|
||||
virtual void SetProperty(const int key, const std::string& value, const int slot = 0);
|
||||
virtual std::string GetProperty(const int key, const std::string& default_ = "", const int slot = 0);
|
||||
virtual void SetProperty(const int key, const int value, const int slot = 0);
|
||||
virtual int GetProperty(const int key, const int default_ = 0, const int slot = 0);
|
||||
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 ~FairMQConfigurable();
|
||||
};
|
||||
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
* @author D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include <list>
|
||||
#include <algorithm> // for std::sort()
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/random/mersenne_twister.hpp> // for choosing random port in range
|
||||
#include <boost/random/uniform_int_distribution.hpp> // for choosing random port in range
|
||||
|
@ -23,172 +26,231 @@
|
|||
using namespace std;
|
||||
|
||||
FairMQDevice::FairMQDevice()
|
||||
: fId()
|
||||
: fChannels()
|
||||
, fId()
|
||||
, fMaxInitializationTime(120)
|
||||
, fNumIoThreads(1)
|
||||
, fNumInputs(0)
|
||||
, fNumOutputs(0)
|
||||
, fPortRangeMin(22000)
|
||||
, fPortRangeMax(32000)
|
||||
, fInputAddress()
|
||||
, fInputMethod()
|
||||
, fInputSocketType()
|
||||
, fInputSndBufSize()
|
||||
, fInputRcvBufSize()
|
||||
, fInputRateLogging()
|
||||
, fOutputAddress()
|
||||
, fOutputMethod()
|
||||
, fOutputSocketType()
|
||||
, fOutputSndBufSize()
|
||||
, fOutputRcvBufSize()
|
||||
, fOutputRateLogging()
|
||||
, fPayloadInputs(new vector<FairMQSocket*>())
|
||||
, fPayloadOutputs(new vector<FairMQSocket*>())
|
||||
, fLogIntervalInMs(1000)
|
||||
, fCommandSocket()
|
||||
, fTransportFactory(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQDevice::InitWrapper()
|
||||
{
|
||||
LOG(INFO) << "DEVICE: Initializing...";
|
||||
|
||||
fCommandSocket = fTransportFactory->CreateSocket("pair", "device-commands", 1);
|
||||
fCommandSocket->Bind("inproc://commands");
|
||||
|
||||
// List to store the uninitialized channels.
|
||||
list<FairMQChannel*> uninitializedChannels;
|
||||
for (map< string,vector<FairMQChannel> >::iterator mi = fChannels.begin(); mi != fChannels.end(); ++mi)
|
||||
{
|
||||
for (vector<FairMQChannel>::iterator vi = (mi->second).begin(); vi != (mi->second).end(); ++vi)
|
||||
{
|
||||
// set channel name: name + vector index
|
||||
stringstream ss;
|
||||
ss << mi->first << "[" << vi - (mi->second).begin() << "]";
|
||||
vi->fChannelName = ss.str();
|
||||
// fill the uninitialized list
|
||||
uninitializedChannels.push_back(&(*vi));
|
||||
}
|
||||
}
|
||||
|
||||
// go over the list of channels until all are initialized (and removed from the uninitialized list)
|
||||
int numAttempts = 0;
|
||||
int maxAttempts = fMaxInitializationTime;
|
||||
do {
|
||||
list<FairMQChannel*>::iterator itr = uninitializedChannels.begin();
|
||||
|
||||
while (itr != uninitializedChannels.end())
|
||||
{
|
||||
if ((*itr)->ValidateChannel())
|
||||
{
|
||||
if (InitChannel(*(*itr)))
|
||||
{
|
||||
uninitializedChannels.erase(itr++);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR) << "failed to initialize channel " << (*itr)->fChannelName;
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
++numAttempts;
|
||||
if (numAttempts > maxAttempts)
|
||||
{
|
||||
LOG(ERROR) << "could not initialize all channels after " << maxAttempts << " attempts";
|
||||
// TODO: goto ERROR state;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (numAttempts != 0)
|
||||
{
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
|
||||
}
|
||||
|
||||
} while (!uninitializedChannels.empty());
|
||||
|
||||
Init();
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fInitializingMutex);
|
||||
fInitializingFinished = true;
|
||||
fInitializingCondition.notify_one();
|
||||
|
||||
ChangeState(DEVICE_READY);
|
||||
}
|
||||
|
||||
void FairMQDevice::Init()
|
||||
{
|
||||
LOG(INFO) << ">>>>>>> Init <<<<<<<";
|
||||
|
||||
for (int i = 0; i < fNumInputs; ++i)
|
||||
{
|
||||
fInputAddress.push_back("ipc://default"); // default value, can be overwritten in configuration
|
||||
fInputMethod.push_back("connect"); // default value, can be overwritten in configuration
|
||||
fInputSocketType.push_back("sub"); // default value, can be overwritten in configuration
|
||||
fInputSndBufSize.push_back(10000); // default value, can be overwritten in configuration
|
||||
fInputRcvBufSize.push_back(10000); // default value, can be overwritten in configuration
|
||||
fInputRateLogging.push_back(1); // default value, can be overwritten in configuration
|
||||
}
|
||||
|
||||
for (int i = 0; i < fNumOutputs; ++i)
|
||||
bool FairMQDevice::InitChannel(FairMQChannel& ch)
|
||||
{
|
||||
fOutputAddress.push_back("ipc://default"); // default value, can be overwritten in configuration
|
||||
fOutputMethod.push_back("bind"); // default value, can be overwritten in configuration
|
||||
fOutputSocketType.push_back("pub"); // default value, can be overwritten in configuration
|
||||
fOutputSndBufSize.push_back(10000); // default value, can be overwritten in configuration
|
||||
fOutputRcvBufSize.push_back(10000); // default value, can be overwritten in configuration
|
||||
fOutputRateLogging.push_back(1); // default value, can be overwritten in configuration
|
||||
}
|
||||
}
|
||||
LOG(DEBUG) << "Initializing channel " << ch.fChannelName << " to <" << ch.fType << "> data";
|
||||
// initialize the socket
|
||||
ch.fSocket = fTransportFactory->CreateSocket(ch.fType, ch.fChannelName, 1);
|
||||
// set high water marks
|
||||
ch.fSocket->SetOption("snd-hwm", &(ch.fSndBufSize), sizeof(ch.fSndBufSize));
|
||||
ch.fSocket->SetOption("rcv-hwm", &(ch.fRcvBufSize), sizeof(ch.fRcvBufSize));
|
||||
|
||||
void FairMQDevice::InitInput()
|
||||
// TODO: make it work with ipc
|
||||
|
||||
if (ch.fMethod == "bind")
|
||||
{
|
||||
LOG(INFO) << ">>>>>>> InitInput <<<<<<<";
|
||||
|
||||
for (int i = 0; i < fNumInputs; ++i)
|
||||
{
|
||||
FairMQSocket* socket = fTransportFactory->CreateSocket(fInputSocketType.at(i), i, fNumIoThreads);
|
||||
|
||||
socket->SetOption("snd-hwm", &fInputSndBufSize.at(i), sizeof(fInputSndBufSize.at(i)));
|
||||
socket->SetOption("rcv-hwm", &fInputRcvBufSize.at(i), sizeof(fInputRcvBufSize.at(i)));
|
||||
|
||||
fPayloadInputs->push_back(socket);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQDevice::InitOutput()
|
||||
{
|
||||
LOG(INFO) << ">>>>>>> InitOutput <<<<<<<";
|
||||
|
||||
for (int i = 0; i < fNumOutputs; ++i)
|
||||
{
|
||||
FairMQSocket* socket = fTransportFactory->CreateSocket(fOutputSocketType.at(i), i, fNumIoThreads);
|
||||
|
||||
socket->SetOption("snd-hwm", &fOutputSndBufSize.at(i), sizeof(fOutputSndBufSize.at(i)));
|
||||
socket->SetOption("rcv-hwm", &fOutputRcvBufSize.at(i), sizeof(fOutputRcvBufSize.at(i)));
|
||||
|
||||
fPayloadOutputs->push_back(socket);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQDevice::Bind()
|
||||
{
|
||||
LOG(INFO) << ">>>>>>> binding <<<<<<<";
|
||||
|
||||
// number of attempts when choosing a random port
|
||||
int maxAttempts = 1000;
|
||||
int numAttempts = 0;
|
||||
|
||||
// initialize random generator
|
||||
boost::random::mt19937 gen(getpid());
|
||||
boost::random::uniform_int_distribution<> randomPort(fPortRangeMin, fPortRangeMax);
|
||||
|
||||
for (int i = 0; i < fNumOutputs; ++i)
|
||||
LOG(DEBUG) << "Binding channel " << ch.fChannelName << " on " << ch.fAddress;
|
||||
|
||||
// try to bind to the saved port. In case of failure, try random one.
|
||||
if (!ch.fSocket->Bind(ch.fAddress))
|
||||
{
|
||||
if (fOutputMethod.at(i) == "bind")
|
||||
{
|
||||
if (!fPayloadOutputs->at(i)->Bind(fOutputAddress.at(i)))
|
||||
{
|
||||
LOG(DEBUG) << "binding output #" << i << " on " << fOutputAddress.at(i) << " failed, trying to find port in range";
|
||||
LOG(INFO) << "port range: " << fPortRangeMin << " - " << fPortRangeMax;
|
||||
LOG(DEBUG) << "Could not bind to configured port, trying random port in range " << fPortRangeMin << "-" << fPortRangeMax;
|
||||
do {
|
||||
++numAttempts;
|
||||
|
||||
stringstream ss;
|
||||
ss << (int)randomPort(gen);
|
||||
string portString = ss.str();
|
||||
|
||||
size_t pos = fOutputAddress.at(i).rfind(":");
|
||||
fOutputAddress.at(i) = fOutputAddress.at(i).substr(0, pos + 1) + portString;
|
||||
if (numAttempts > maxAttempts)
|
||||
{
|
||||
LOG(ERROR) << "could not bind output " << i << " to any port in the given range";
|
||||
break;
|
||||
}
|
||||
} while (!fPayloadOutputs->at(i)->Bind(fOutputAddress.at(i)));
|
||||
}
|
||||
}
|
||||
LOG(ERROR) << "could not bind to any port in the given range after " << maxAttempts << " attempts";
|
||||
return false;
|
||||
}
|
||||
|
||||
numAttempts = 0;
|
||||
size_t pos = ch.fAddress.rfind(":");
|
||||
stringstream newPort;
|
||||
newPort << (int)randomPort(gen);
|
||||
ch.fAddress = ch.fAddress.substr(0, pos + 1) + newPort.str();
|
||||
|
||||
for (int i = 0; i < fNumInputs; ++i)
|
||||
LOG(DEBUG) << "Binding channel " << ch.fChannelName << " on " << ch.fAddress;
|
||||
} while (!ch.fSocket->Bind(ch.fAddress));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fInputMethod.at(i) == "bind")
|
||||
{
|
||||
if (!fPayloadInputs->at(i)->Bind(fInputAddress.at(i)))
|
||||
{
|
||||
LOG(DEBUG) << "binding input #" << i << " on " << fInputAddress.at(i) << " failed, trying to find port in range";
|
||||
LOG(INFO) << "port range: " << fPortRangeMin << " - " << fPortRangeMax;
|
||||
do {
|
||||
++numAttempts;
|
||||
LOG(DEBUG) << "Connecting channel " << ch.fChannelName << " to " << ch.fAddress;
|
||||
ch.fSocket->Connect(ch.fAddress);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void FairMQDevice::InitTaskWrapper()
|
||||
{
|
||||
InitTask();
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fInitializingTaskMutex);
|
||||
fInitializingTaskFinished = true;
|
||||
fInitializingTaskCondition.notify_one();
|
||||
|
||||
ChangeState(READY);
|
||||
}
|
||||
|
||||
void FairMQDevice::InitTask()
|
||||
{
|
||||
}
|
||||
|
||||
bool SortSocketsByAddress(const FairMQChannel &lhs, const FairMQChannel &rhs)
|
||||
{
|
||||
return lhs.fAddress < rhs.fAddress;
|
||||
}
|
||||
|
||||
void FairMQDevice::SortChannel(const string& name, const bool reindex)
|
||||
{
|
||||
if (fChannels.find(name) != fChannels.end())
|
||||
{
|
||||
sort(fChannels[name].begin(), fChannels[name].end(), SortSocketsByAddress);
|
||||
|
||||
if (reindex)
|
||||
{
|
||||
for (vector<FairMQChannel>::iterator vi = fChannels[name].begin(); vi != fChannels[name].end(); ++vi)
|
||||
{
|
||||
// set channel name: name + vector index
|
||||
stringstream ss;
|
||||
ss << (int)randomPort(gen);
|
||||
string portString = ss.str();
|
||||
|
||||
size_t pos = fInputAddress.at(i).rfind(":");
|
||||
fInputAddress.at(i) = fInputAddress.at(i).substr(0, pos + 1) + portString;
|
||||
if (numAttempts > maxAttempts)
|
||||
ss << name << "[" << vi - fChannels[name].begin() << "]";
|
||||
vi->fChannelName = ss.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR) << "could not bind input " << i << " to any port in the given range";
|
||||
break;
|
||||
}
|
||||
} while (!fPayloadInputs->at(i)->Bind(fInputAddress.at(i)));
|
||||
}
|
||||
}
|
||||
LOG(ERROR) << "Sorting failed: no channel with the name \"" << name << "\".";
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQDevice::Connect()
|
||||
void FairMQDevice::PrintChannel(const string& name)
|
||||
{
|
||||
LOG(INFO) << ">>>>>>> connecting <<<<<<<";
|
||||
|
||||
for (int i = 0; i < fNumOutputs; ++i)
|
||||
if (fChannels.find(name) != fChannels.end())
|
||||
{
|
||||
if (fOutputMethod.at(i) == "connect")
|
||||
for (vector<FairMQChannel>::iterator vi = fChannels[name].begin(); vi != fChannels[name].end(); ++vi)
|
||||
{
|
||||
fPayloadOutputs->at(i)->Connect(fOutputAddress.at(i));
|
||||
LOG(INFO) << vi->fChannelName << ": "
|
||||
<< vi->fType << " | "
|
||||
<< vi->fMethod << " | "
|
||||
<< vi->fAddress << " | "
|
||||
<< vi->fSndBufSize << " | "
|
||||
<< vi->fRcvBufSize << " | "
|
||||
<< vi->fRateLogging;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR) << "Printing failed: no channel with the name \"" << name << "\".";
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < fNumInputs; ++i)
|
||||
void FairMQDevice::RunWrapper()
|
||||
{
|
||||
if (fInputMethod.at(i) == "connect")
|
||||
{
|
||||
fPayloadInputs->at(i)->Connect(fInputAddress.at(i));
|
||||
}
|
||||
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
|
||||
Run();
|
||||
|
||||
try {
|
||||
rateLogger.interrupt();
|
||||
rateLogger.join();
|
||||
} catch(boost::thread_resource_error& e) {
|
||||
LOG(ERROR) << e.what();
|
||||
}
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fRunningMutex);
|
||||
fRunningFinished = true;
|
||||
fRunningCondition.notify_one();
|
||||
}
|
||||
|
||||
void FairMQDevice::Run()
|
||||
|
@ -196,60 +258,78 @@ void FairMQDevice::Run()
|
|||
}
|
||||
|
||||
void FairMQDevice::Pause()
|
||||
{
|
||||
while (GetCurrentState() == PAUSED)
|
||||
{
|
||||
try
|
||||
{
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(500));
|
||||
LOG(DEBUG) << "paused...";
|
||||
}
|
||||
catch (boost::thread_interrupted&)
|
||||
{
|
||||
LOG(INFO) << "FairMQDevice::Pause() interrupted";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQDevice::ResetTaskWrapper()
|
||||
{
|
||||
ResetTask();
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fResetTaskMutex);
|
||||
fResetTaskFinished = true;
|
||||
fResetTaskCondition.notify_one();
|
||||
|
||||
ChangeState(DEVICE_READY);
|
||||
}
|
||||
|
||||
void FairMQDevice::ResetTask()
|
||||
{
|
||||
}
|
||||
|
||||
void FairMQDevice::ResetWrapper()
|
||||
{
|
||||
Reset();
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fResetMutex);
|
||||
fResetFinished = true;
|
||||
fResetCondition.notify_one();
|
||||
|
||||
ChangeState(IDLE);
|
||||
}
|
||||
|
||||
void FairMQDevice::Reset()
|
||||
{
|
||||
}
|
||||
|
||||
// Method for setting properties represented as a string.
|
||||
void FairMQDevice::SetProperty(const int key, const string& value, const int slot /*= 0*/)
|
||||
void FairMQDevice::SetProperty(const int key, const string& value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case Id:
|
||||
fId = value;
|
||||
break;
|
||||
case InputAddress:
|
||||
fInputAddress.erase(fInputAddress.begin() + slot);
|
||||
fInputAddress.insert(fInputAddress.begin() + slot, value);
|
||||
break;
|
||||
case OutputAddress:
|
||||
fOutputAddress.erase(fOutputAddress.begin() + slot);
|
||||
fOutputAddress.insert(fOutputAddress.begin() + slot, value);
|
||||
break;
|
||||
case InputMethod:
|
||||
fInputMethod.erase(fInputMethod.begin() + slot);
|
||||
fInputMethod.insert(fInputMethod.begin() + slot, value);
|
||||
break;
|
||||
case OutputMethod:
|
||||
fOutputMethod.erase(fOutputMethod.begin() + slot);
|
||||
fOutputMethod.insert(fOutputMethod.begin() + slot, value);
|
||||
break;
|
||||
case InputSocketType:
|
||||
fInputSocketType.erase(fInputSocketType.begin() + slot);
|
||||
fInputSocketType.insert(fInputSocketType.begin() + slot, value);
|
||||
break;
|
||||
case OutputSocketType:
|
||||
fOutputSocketType.erase(fOutputSocketType.begin() + slot);
|
||||
fOutputSocketType.insert(fOutputSocketType.begin() + slot, value);
|
||||
break;
|
||||
default:
|
||||
FairMQConfigurable::SetProperty(key, value, slot);
|
||||
FairMQConfigurable::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Method for setting properties represented as an integer.
|
||||
void FairMQDevice::SetProperty(const int key, const int value, const int slot /*= 0*/)
|
||||
void FairMQDevice::SetProperty(const int key, const int value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case NumIoThreads:
|
||||
fNumIoThreads = value;
|
||||
break;
|
||||
case NumInputs:
|
||||
fNumInputs = value;
|
||||
break;
|
||||
case NumOutputs:
|
||||
fNumOutputs = value;
|
||||
case MaxInitializationTime:
|
||||
fMaxInitializationTime = value;
|
||||
break;
|
||||
case PortRangeMin:
|
||||
fPortRangeMin = value;
|
||||
|
@ -260,95 +340,41 @@ void FairMQDevice::SetProperty(const int key, const int value, const int slot /*
|
|||
case LogIntervalInMs:
|
||||
fLogIntervalInMs = value;
|
||||
break;
|
||||
case InputSndBufSize:
|
||||
fInputSndBufSize.erase(fInputSndBufSize.begin() + slot);
|
||||
fInputSndBufSize.insert(fInputSndBufSize.begin() + slot, value);
|
||||
break;
|
||||
case InputRcvBufSize:
|
||||
fInputRcvBufSize.erase(fInputRcvBufSize.begin() + slot);
|
||||
fInputRcvBufSize.insert(fInputRcvBufSize.begin() + slot, value);
|
||||
break;
|
||||
case InputRateLogging:
|
||||
case LogInputRate: // keep this for backwards compatibility for a while
|
||||
fInputRateLogging.erase(fInputRateLogging.begin() + slot);
|
||||
fInputRateLogging.insert(fInputRateLogging.begin() + slot, value);
|
||||
break;
|
||||
case OutputSndBufSize:
|
||||
fOutputSndBufSize.erase(fOutputSndBufSize.begin() + slot);
|
||||
fOutputSndBufSize.insert(fOutputSndBufSize.begin() + slot, value);
|
||||
break;
|
||||
case OutputRcvBufSize:
|
||||
fOutputRcvBufSize.erase(fOutputRcvBufSize.begin() + slot);
|
||||
fOutputRcvBufSize.insert(fOutputRcvBufSize.begin() + slot, value);
|
||||
break;
|
||||
case OutputRateLogging:
|
||||
case LogOutputRate: // keep this for backwards compatibility for a while
|
||||
fOutputRateLogging.erase(fOutputRateLogging.begin() + slot);
|
||||
fOutputRateLogging.insert(fOutputRateLogging.begin() + slot, value);
|
||||
break;
|
||||
default:
|
||||
FairMQConfigurable::SetProperty(key, value, slot);
|
||||
FairMQConfigurable::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Method for getting properties represented as an string.
|
||||
string FairMQDevice::GetProperty(const int key, const string& default_ /*= ""*/, const int slot /*= 0*/)
|
||||
string FairMQDevice::GetProperty(const int key, const string& default_ /*= ""*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case Id:
|
||||
return fId;
|
||||
case InputAddress:
|
||||
return fInputAddress.at(slot);
|
||||
case OutputAddress:
|
||||
return fOutputAddress.at(slot);
|
||||
case InputMethod:
|
||||
return fInputMethod.at(slot);
|
||||
case OutputMethod:
|
||||
return fOutputMethod.at(slot);
|
||||
case InputSocketType:
|
||||
return fInputSocketType.at(slot);
|
||||
case OutputSocketType:
|
||||
return fOutputSocketType.at(slot);
|
||||
default:
|
||||
return FairMQConfigurable::GetProperty(key, default_, slot);
|
||||
return FairMQConfigurable::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
||||
// Method for getting properties represented as an integer.
|
||||
int FairMQDevice::GetProperty(const int key, const int default_ /*= 0*/, const int slot /*= 0*/)
|
||||
int FairMQDevice::GetProperty(const int key, const int default_ /*= 0*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case NumIoThreads:
|
||||
return fNumIoThreads;
|
||||
case NumInputs:
|
||||
return fNumInputs;
|
||||
case NumOutputs:
|
||||
return fNumOutputs;
|
||||
case MaxInitializationTime:
|
||||
return fMaxInitializationTime;
|
||||
case PortRangeMin:
|
||||
return fPortRangeMin;
|
||||
case PortRangeMax:
|
||||
return fPortRangeMax;
|
||||
case LogIntervalInMs:
|
||||
return fLogIntervalInMs;
|
||||
case InputSndBufSize:
|
||||
return fInputSndBufSize.at(slot);
|
||||
case InputRcvBufSize:
|
||||
return fInputRcvBufSize.at(slot);
|
||||
case InputRateLogging:
|
||||
case LogInputRate: // keep this for backwards compatibility for a while
|
||||
return fInputRateLogging.at(slot);
|
||||
case OutputSndBufSize:
|
||||
return fOutputSndBufSize.at(slot);
|
||||
case OutputRcvBufSize:
|
||||
return fOutputRcvBufSize.at(slot);
|
||||
case OutputRateLogging:
|
||||
case LogOutputRate: // keep this for backwards compatibility for a while
|
||||
return fOutputRateLogging.at(slot);
|
||||
default:
|
||||
return FairMQConfigurable::GetProperty(key, default_, slot);
|
||||
return FairMQConfigurable::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,67 +390,55 @@ void FairMQDevice::LogSocketRates()
|
|||
|
||||
timestamp_t msSinceLastLog;
|
||||
|
||||
int numFilteredInputs = 0;
|
||||
int numFilteredOutputs = 0;
|
||||
vector<FairMQSocket*> filteredInputs;
|
||||
vector<FairMQSocket*> filteredOutputs;
|
||||
int numFilteredSockets = 0;
|
||||
vector<FairMQSocket*> filteredSockets;
|
||||
vector<string> filteredChannelNames;
|
||||
|
||||
// iterate over the channels map
|
||||
for (map< string,vector<FairMQChannel> >::iterator mi = fChannels.begin(); mi != fChannels.end(); ++mi)
|
||||
{
|
||||
// iterate over the channels vector
|
||||
for (vector<FairMQChannel>::iterator vi = (mi->second).begin(); vi != (mi->second).end(); ++vi)
|
||||
{
|
||||
if (vi->fRateLogging == 1)
|
||||
{
|
||||
filteredSockets.push_back(vi->fSocket);
|
||||
stringstream ss;
|
||||
ss << mi->first << "[" << vi - (mi->second).begin() << "]";
|
||||
filteredChannelNames.push_back(ss.str());
|
||||
++numFilteredSockets;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<unsigned long> bytesIn(numFilteredSockets);
|
||||
vector<unsigned long> msgIn(numFilteredSockets);
|
||||
vector<unsigned long> bytesOut(numFilteredSockets);
|
||||
vector<unsigned long> msgOut(numFilteredSockets);
|
||||
|
||||
vector<unsigned long> bytesInNew(numFilteredSockets);
|
||||
vector<unsigned long> msgInNew(numFilteredSockets);
|
||||
vector<unsigned long> bytesOutNew(numFilteredSockets);
|
||||
vector<unsigned long> msgOutNew(numFilteredSockets);
|
||||
|
||||
vector<double> mbPerSecIn(numFilteredSockets);
|
||||
vector<double> msgPerSecIn(numFilteredSockets);
|
||||
vector<double> mbPerSecOut(numFilteredSockets);
|
||||
vector<double> msgPerSecOut(numFilteredSockets);
|
||||
|
||||
int i = 0;
|
||||
for (vector<FairMQSocket*>::iterator itr = fPayloadInputs->begin(); itr != fPayloadInputs->end(); itr++)
|
||||
{
|
||||
if (fInputRateLogging.at(i) > 0)
|
||||
{
|
||||
filteredInputs.push_back((*itr));
|
||||
++numFilteredInputs;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
for (vector<FairMQSocket*>::iterator itr = fPayloadOutputs->begin(); itr != fPayloadOutputs->end(); itr++)
|
||||
{
|
||||
if (fOutputRateLogging.at(i) > 0)
|
||||
{
|
||||
filteredOutputs.push_back((*itr));
|
||||
++numFilteredOutputs;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
vector<unsigned long> bytesIn(numFilteredInputs);
|
||||
vector<unsigned long> msgIn(numFilteredInputs);
|
||||
vector<unsigned long> bytesOut(numFilteredOutputs);
|
||||
vector<unsigned long> msgOut(numFilteredOutputs);
|
||||
|
||||
vector<unsigned long> bytesInNew(numFilteredInputs);
|
||||
vector<unsigned long> msgInNew(numFilteredInputs);
|
||||
vector<unsigned long> bytesOutNew(numFilteredOutputs);
|
||||
vector<unsigned long> msgOutNew(numFilteredOutputs);
|
||||
|
||||
vector<double> mbPerSecIn(numFilteredInputs);
|
||||
vector<double> msgPerSecIn(numFilteredInputs);
|
||||
vector<double> mbPerSecOut(numFilteredOutputs);
|
||||
vector<double> msgPerSecOut(numFilteredOutputs);
|
||||
|
||||
i = 0;
|
||||
for (vector<FairMQSocket*>::iterator itr = filteredInputs.begin(); itr != filteredInputs.end(); itr++)
|
||||
for (vector<FairMQSocket*>::iterator itr = filteredSockets.begin(); itr != filteredSockets.end(); ++itr)
|
||||
{
|
||||
bytesIn.at(i) = (*itr)->GetBytesRx();
|
||||
msgIn.at(i) = (*itr)->GetMessagesRx();
|
||||
++i;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
for (vector<FairMQSocket*>::iterator itr = filteredOutputs.begin(); itr != filteredOutputs.end(); itr++)
|
||||
{
|
||||
bytesOut.at(i) = (*itr)->GetBytesTx();
|
||||
msgIn.at(i) = (*itr)->GetMessagesRx();
|
||||
msgOut.at(i) = (*itr)->GetMessagesTx();
|
||||
++i;
|
||||
}
|
||||
|
||||
t0 = get_timestamp();
|
||||
|
||||
while (fState == RUNNING)
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -434,32 +448,27 @@ void FairMQDevice::LogSocketRates()
|
|||
|
||||
i = 0;
|
||||
|
||||
for (vector<FairMQSocket*>::iterator itr = filteredInputs.begin(); itr != filteredInputs.end(); itr++)
|
||||
for (vector<FairMQSocket*>::iterator itr = filteredSockets.begin(); itr != filteredSockets.end(); itr++)
|
||||
{
|
||||
bytesInNew.at(i) = (*itr)->GetBytesRx();
|
||||
mbPerSecIn.at(i) = ((double)(bytesInNew.at(i) - bytesIn.at(i)) / (1024. * 1024.)) / (double)msSinceLastLog * 1000.;
|
||||
bytesIn.at(i) = bytesInNew.at(i);
|
||||
|
||||
msgInNew.at(i) = (*itr)->GetMessagesRx();
|
||||
msgPerSecIn.at(i) = (double)(msgInNew.at(i) - msgIn.at(i)) / (double)msSinceLastLog * 1000.;
|
||||
msgIn.at(i) = msgInNew.at(i);
|
||||
|
||||
LOG(DEBUG) << "#" << fId << "." << (*itr)->GetId() << ": " << msgPerSecIn.at(i) << " msg/s, " << mbPerSecIn.at(i) << " MB/s";
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
|
||||
for (vector<FairMQSocket*>::iterator itr = filteredOutputs.begin(); itr != filteredOutputs.end(); itr++)
|
||||
{
|
||||
bytesOutNew.at(i) = (*itr)->GetBytesTx();
|
||||
mbPerSecOut.at(i) = ((double)(bytesOutNew.at(i) - bytesOut.at(i)) / (1024. * 1024.)) / (double)msSinceLastLog * 1000.;
|
||||
bytesOut.at(i) = bytesOutNew.at(i);
|
||||
|
||||
msgOutNew.at(i) = (*itr)->GetMessagesTx();
|
||||
msgPerSecOut.at(i) = (double)(msgOutNew.at(i) - msgOut.at(i)) / (double)msSinceLastLog * 1000.;
|
||||
msgOut.at(i) = msgOutNew.at(i);
|
||||
|
||||
LOG(DEBUG) << "#" << fId << "." << (*itr)->GetId() << ": " << msgPerSecOut.at(i) << " msg/s, " << mbPerSecOut.at(i) << " MB/s";
|
||||
LOG(DEBUG) << filteredChannelNames.at(i) << ": "
|
||||
<< "in: " << msgPerSecIn.at(i) << " msg (" << mbPerSecIn.at(i) << " MB), "
|
||||
<< "out: " << msgPerSecOut.at(i) << " msg (" << mbPerSecOut.at(i) << " MB)";
|
||||
|
||||
++i;
|
||||
}
|
||||
|
@ -469,59 +478,57 @@ void FairMQDevice::LogSocketRates()
|
|||
}
|
||||
catch (boost::thread_interrupted&)
|
||||
{
|
||||
LOG(INFO) << "FairMQDevice::LogSocketRates() interrupted";
|
||||
// LOG(DEBUG) << "FairMQDevice::LogSocketRates() interrupted";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LOG(INFO) << ">>>>>>> stopping FairMQDevice::LogSocketRates() <<<<<<<";
|
||||
// LOG(DEBUG) << "FairMQDevice::LogSocketRates() stopping";
|
||||
}
|
||||
|
||||
void FairMQDevice::SendCommand(const string& command)
|
||||
{
|
||||
FairMQMessage* cmd = fTransportFactory->CreateMessage(command.size());
|
||||
memcpy(cmd->GetData(), command.c_str(), command.size());
|
||||
fCommandSocket->Send(cmd, 0);
|
||||
}
|
||||
|
||||
void FairMQDevice::Shutdown()
|
||||
{
|
||||
LOG(INFO) << ">>>>>>> closing inputs <<<<<<<";
|
||||
for (vector<FairMQSocket*>::iterator itr = fPayloadInputs->begin(); itr != fPayloadInputs->end(); itr++)
|
||||
LOG(DEBUG) << "Closing sockets...";
|
||||
|
||||
// iterate over the channels map
|
||||
for (map< string,vector<FairMQChannel> >::iterator mi = fChannels.begin(); mi != fChannels.end(); ++mi)
|
||||
{
|
||||
(*itr)->Close();
|
||||
// iterate over the channels vector
|
||||
for (vector<FairMQChannel>::iterator vi = (mi->second).begin(); vi != (mi->second).end(); ++vi)
|
||||
{
|
||||
vi->fSocket->Close();
|
||||
}
|
||||
}
|
||||
|
||||
LOG(INFO) << ">>>>>>> closing outputs <<<<<<<";
|
||||
for (vector<FairMQSocket*>::iterator itr = fPayloadOutputs->begin(); itr != fPayloadOutputs->end(); itr++)
|
||||
{
|
||||
(*itr)->Close();
|
||||
}
|
||||
fCommandSocket->Close();
|
||||
|
||||
LOG(DEBUG) << "Closed all sockets!";
|
||||
}
|
||||
|
||||
void FairMQDevice::Terminate()
|
||||
{
|
||||
// Termination signal has to be sent only once to any socket.
|
||||
// Find available socket and send termination signal to it.
|
||||
if (fPayloadInputs->size() > 0)
|
||||
{
|
||||
fPayloadInputs->at(0)->Terminate();
|
||||
}
|
||||
else if (fPayloadOutputs->size() > 0)
|
||||
{
|
||||
fPayloadOutputs->at(0)->Terminate();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR) << "No sockets available to terminate.";
|
||||
}
|
||||
fCommandSocket->Terminate();
|
||||
}
|
||||
|
||||
FairMQDevice::~FairMQDevice()
|
||||
{
|
||||
for (vector<FairMQSocket*>::iterator itr = fPayloadInputs->begin(); itr != fPayloadInputs->end(); itr++)
|
||||
// iterate over the channels map
|
||||
for (map< string,vector<FairMQChannel> >::iterator mi = fChannels.begin(); mi != fChannels.end(); ++mi)
|
||||
{
|
||||
delete (*itr);
|
||||
// iterate over the channels vector
|
||||
for (vector<FairMQChannel>::iterator vi = (mi->second).begin(); vi != (mi->second).end(); ++vi)
|
||||
{
|
||||
delete vi->fSocket;
|
||||
}
|
||||
}
|
||||
|
||||
for (vector<FairMQSocket*>::iterator itr = fPayloadOutputs->begin(); itr != fPayloadOutputs->end(); itr++)
|
||||
{
|
||||
delete (*itr);
|
||||
}
|
||||
|
||||
delete fPayloadInputs;
|
||||
delete fPayloadOutputs;
|
||||
delete fCommandSocket;
|
||||
}
|
||||
|
|
|
@ -18,11 +18,13 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include "FairMQConfigurable.h"
|
||||
#include "FairMQStateMachine.h"
|
||||
#include "FairMQTransportFactory.h"
|
||||
#include "FairMQSocket.h"
|
||||
#include "FairMQChannel.h"
|
||||
|
||||
class FairMQDevice : public FairMQStateMachine, public FairMQConfigurable
|
||||
{
|
||||
|
@ -30,25 +32,10 @@ class FairMQDevice : public FairMQStateMachine, public FairMQConfigurable
|
|||
enum
|
||||
{
|
||||
Id = FairMQConfigurable::Last,
|
||||
MaxInitializationTime,
|
||||
NumIoThreads,
|
||||
NumInputs,
|
||||
NumOutputs,
|
||||
PortRangeMin,
|
||||
PortRangeMax,
|
||||
InputAddress,
|
||||
InputMethod,
|
||||
InputSocketType,
|
||||
InputSndBufSize,
|
||||
InputRcvBufSize,
|
||||
InputRateLogging,
|
||||
OutputAddress,
|
||||
OutputMethod,
|
||||
OutputSocketType,
|
||||
OutputSndBufSize,
|
||||
OutputRcvBufSize,
|
||||
OutputRateLogging,
|
||||
LogInputRate, // keep this for backwards compatibility for a while
|
||||
LogOutputRate, // keep this for backwards compatibility for a while
|
||||
LogIntervalInMs,
|
||||
Last
|
||||
};
|
||||
|
@ -57,57 +44,59 @@ class FairMQDevice : public FairMQStateMachine, public FairMQConfigurable
|
|||
|
||||
virtual void LogSocketRates();
|
||||
|
||||
virtual void SetProperty(const int key, const std::string& value, const int slot = 0);
|
||||
virtual std::string GetProperty(const int key, const std::string& default_ = "", const int slot = 0);
|
||||
virtual void SetProperty(const int key, const int value, const int slot = 0);
|
||||
virtual int GetProperty(const int key, const int default_ = 0, const int slot = 0);
|
||||
void SortChannel(const std::string& name, const bool reindex = true);
|
||||
void PrintChannel(const std::string& name);
|
||||
|
||||
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 void SetTransport(FairMQTransportFactory* factory);
|
||||
|
||||
virtual ~FairMQDevice();
|
||||
|
||||
std::map< std::string,std::vector<FairMQChannel> > fChannels;
|
||||
|
||||
protected:
|
||||
std::string fId;
|
||||
|
||||
int fNumIoThreads;
|
||||
int fMaxInitializationTime;
|
||||
|
||||
int fNumInputs;
|
||||
int fNumOutputs;
|
||||
int fNumIoThreads;
|
||||
|
||||
int fPortRangeMin;
|
||||
int fPortRangeMax;
|
||||
|
||||
std::vector<std::string> fInputAddress;
|
||||
std::vector<std::string> fInputMethod;
|
||||
std::vector<std::string> fInputSocketType;
|
||||
std::vector<int> fInputSndBufSize;
|
||||
std::vector<int> fInputRcvBufSize;
|
||||
std::vector<int> fInputRateLogging;
|
||||
|
||||
std::vector<std::string> fOutputAddress;
|
||||
std::vector<std::string> fOutputMethod;
|
||||
std::vector<std::string> fOutputSocketType;
|
||||
std::vector<int> fOutputSndBufSize;
|
||||
std::vector<int> fOutputRcvBufSize;
|
||||
std::vector<int> fOutputRateLogging;
|
||||
|
||||
std::vector<FairMQSocket*>* fPayloadInputs;
|
||||
std::vector<FairMQSocket*>* fPayloadOutputs;
|
||||
|
||||
int fLogIntervalInMs;
|
||||
|
||||
FairMQSocket* fCommandSocket;
|
||||
|
||||
FairMQTransportFactory* fTransportFactory;
|
||||
|
||||
void InitWrapper();
|
||||
virtual void Init();
|
||||
virtual void Run();
|
||||
virtual void Pause();
|
||||
virtual void Shutdown();
|
||||
virtual void InitOutput();
|
||||
virtual void InitInput();
|
||||
virtual void Bind();
|
||||
virtual void Connect();
|
||||
|
||||
virtual void Terminate();
|
||||
void InitTaskWrapper();
|
||||
virtual void InitTask();
|
||||
|
||||
void RunWrapper();
|
||||
virtual void Run();
|
||||
|
||||
virtual void Pause();
|
||||
|
||||
void ResetTaskWrapper();
|
||||
virtual void ResetTask();
|
||||
|
||||
void ResetWrapper();
|
||||
virtual void Reset();
|
||||
|
||||
virtual void Shutdown();
|
||||
|
||||
void Terminate();
|
||||
void SendCommand(const std::string& command);
|
||||
|
||||
bool InitChannel(FairMQChannel&);
|
||||
|
||||
private:
|
||||
/// Copy Constructor
|
||||
|
|
|
@ -18,15 +18,18 @@
|
|||
int FairMQLogger::fMinLogLevel = FairMQLogger::DEBUG;
|
||||
|
||||
FairMQLogger::FairMQLogger()
|
||||
: os(), fLogLevel(DEBUG)
|
||||
: os()
|
||||
, fLogLevel(DEBUG)
|
||||
{
|
||||
}
|
||||
|
||||
FairMQLogger::~FairMQLogger()
|
||||
{
|
||||
if (fLogLevel >= FairMQLogger::fMinLogLevel && fLogLevel < FairMQLogger::NOLOG)
|
||||
{
|
||||
std::cout << os.str() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostringstream& FairMQLogger::Log(int type)
|
||||
{
|
||||
|
|
|
@ -40,9 +40,9 @@ class FairMQLogger
|
|||
virtual ~FairMQLogger();
|
||||
std::ostringstream& Log(int type);
|
||||
|
||||
static void SetLogLevel(int loglevel)
|
||||
static void SetLogLevel(int logLevel)
|
||||
{
|
||||
FairMQLogger::fMinLogLevel = loglevel;
|
||||
FairMQLogger::fMinLogLevel = logLevel;
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define FAIRMQSOCKET_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "FairMQMessage.h"
|
||||
|
||||
class FairMQSocket
|
||||
|
@ -37,9 +38,9 @@ class FairMQSocket
|
|||
virtual void Connect(const std::string& address) = 0;
|
||||
|
||||
virtual int Send(FairMQMessage* msg, const std::string& flag = "") = 0;
|
||||
virtual int Send(FairMQMessage* msg, const int flags) = 0;
|
||||
virtual int Send(FairMQMessage* msg, const int flags = 0) = 0;
|
||||
virtual int Receive(FairMQMessage* msg, const std::string& flag = "") = 0;
|
||||
virtual int Receive(FairMQMessage* msg, const int flags) = 0;
|
||||
virtual int Receive(FairMQMessage* msg, const int flags = 0) = 0;
|
||||
|
||||
virtual void* GetSocket() = 0;
|
||||
virtual int GetSocket(int nothing) = 0;
|
||||
|
|
|
@ -16,7 +16,13 @@
|
|||
#include "FairMQLogger.h"
|
||||
|
||||
FairMQStateMachine::FairMQStateMachine()
|
||||
: fRunningFinished(false)
|
||||
: fInitializingFinished(false)
|
||||
, fInitializingCondition()
|
||||
, fInitializingMutex()
|
||||
, fInitializingTaskFinished(false)
|
||||
, fInitializingTaskCondition()
|
||||
, fInitializingTaskMutex()
|
||||
, fRunningFinished(false)
|
||||
, fRunningCondition()
|
||||
, fRunningMutex()
|
||||
{
|
||||
|
@ -39,20 +45,17 @@ bool FairMQStateMachine::ChangeState(int event)
|
|||
{
|
||||
switch (event)
|
||||
{
|
||||
case INIT:
|
||||
process_event(FairMQFSM::INIT());
|
||||
case INIT_DEVICE:
|
||||
process_event(FairMQFSM::INIT_DEVICE());
|
||||
return true;
|
||||
case SETOUTPUT:
|
||||
process_event(FairMQFSM::SETOUTPUT());
|
||||
case DEVICE_READY:
|
||||
process_event(FairMQFSM::DEVICE_READY());
|
||||
return true;
|
||||
case SETINPUT:
|
||||
process_event(FairMQFSM::SETINPUT());
|
||||
case INIT_TASK:
|
||||
process_event(FairMQFSM::INIT_TASK());
|
||||
return true;
|
||||
case BIND:
|
||||
process_event(FairMQFSM::BIND());
|
||||
return true;
|
||||
case CONNECT:
|
||||
process_event(FairMQFSM::CONNECT());
|
||||
case READY:
|
||||
process_event(FairMQFSM::READY());
|
||||
return true;
|
||||
case RUN:
|
||||
process_event(FairMQFSM::RUN());
|
||||
|
@ -60,15 +63,27 @@ bool FairMQStateMachine::ChangeState(int event)
|
|||
case PAUSE:
|
||||
process_event(FairMQFSM::PAUSE());
|
||||
return true;
|
||||
case RESUME:
|
||||
process_event(FairMQFSM::RESUME());
|
||||
return true;
|
||||
case STOP:
|
||||
process_event(FairMQFSM::STOP());
|
||||
return true;
|
||||
case RESET_DEVICE:
|
||||
process_event(FairMQFSM::RESET_DEVICE());
|
||||
return true;
|
||||
case RESET_TASK:
|
||||
process_event(FairMQFSM::RESET_TASK());
|
||||
return true;
|
||||
case IDLE:
|
||||
process_event(FairMQFSM::IDLE());
|
||||
return true;
|
||||
case END:
|
||||
process_event(FairMQFSM::END());
|
||||
return true;
|
||||
default:
|
||||
LOG(ERROR) << "Requested unsupported state: " << event;
|
||||
LOG(ERROR) << "Supported are: INIT, SETOUTPUT, SETINPUT, BIND, CONNECT, RUN, PAUSE, STOP, END";
|
||||
LOG(ERROR) << "Requested unsupported state: " << event << std::endl
|
||||
<< "Supported are: INIT_DEVICE, INIT_TASK, RUN, PAUSE, RESUME, STOP, RESET_TASK, RESET_DEVICE, END";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -80,25 +95,21 @@ bool FairMQStateMachine::ChangeState(int event)
|
|||
|
||||
bool FairMQStateMachine::ChangeState(std::string event)
|
||||
{
|
||||
if (event == "INIT")
|
||||
if (event == "INIT_DEVICE")
|
||||
{
|
||||
return ChangeState(INIT);
|
||||
return ChangeState(INIT_DEVICE);
|
||||
}
|
||||
else if (event == "SETOUTPUT")
|
||||
if (event == "DEVICE_READY")
|
||||
{
|
||||
return ChangeState(SETOUTPUT);
|
||||
return ChangeState(DEVICE_READY);
|
||||
}
|
||||
else if (event == "SETINPUT")
|
||||
if (event == "INIT_TASK")
|
||||
{
|
||||
return ChangeState(SETINPUT);
|
||||
return ChangeState(INIT_TASK);
|
||||
}
|
||||
else if (event == "BIND")
|
||||
if (event == "READY")
|
||||
{
|
||||
return ChangeState(BIND);
|
||||
}
|
||||
else if (event == "CONNECT")
|
||||
{
|
||||
return ChangeState(CONNECT);
|
||||
return ChangeState(READY);
|
||||
}
|
||||
else if (event == "RUN")
|
||||
{
|
||||
|
@ -108,18 +119,146 @@ bool FairMQStateMachine::ChangeState(std::string event)
|
|||
{
|
||||
return ChangeState(PAUSE);
|
||||
}
|
||||
else if (event == "RESUME")
|
||||
{
|
||||
return ChangeState(RESUME);
|
||||
}
|
||||
else if (event == "STOP")
|
||||
{
|
||||
return ChangeState(STOP);
|
||||
}
|
||||
if (event == "RESET_DEVICE")
|
||||
{
|
||||
return ChangeState(RESET_DEVICE);
|
||||
}
|
||||
if (event == "RESET_TASK")
|
||||
{
|
||||
return ChangeState(RESET_TASK);
|
||||
}
|
||||
else if (event == "IDLE")
|
||||
{
|
||||
return ChangeState(IDLE);
|
||||
}
|
||||
else if (event == "END")
|
||||
{
|
||||
return ChangeState(END);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR) << "Requested unsupported state: " << event;
|
||||
LOG(ERROR) << "Supported are: INIT, SETOUTPUT, SETINPUT, BIND, CONNECT, RUN, PAUSE, STOP, END";
|
||||
LOG(ERROR) << "Requested unsupported state: " << event << std::endl
|
||||
<< "Supported are: INIT_DEVICE, INIT_TASK, RUN, PAUSE, RESUME, STOP, RESET_TASK, RESET_DEVICE, END";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQStateMachine::WaitForEndOfState(int event)
|
||||
{
|
||||
switch (event)
|
||||
{
|
||||
case INIT_DEVICE:
|
||||
{
|
||||
boost::unique_lock<boost::mutex> lock(fInitializingMutex);
|
||||
while (!fInitializingFinished)
|
||||
{
|
||||
fInitializingCondition.wait(lock);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case INIT_TASK:
|
||||
{
|
||||
boost::unique_lock<boost::mutex> initTaskLock(fInitializingTaskMutex);
|
||||
while (!fInitializingTaskFinished)
|
||||
{
|
||||
fInitializingTaskCondition.wait(initTaskLock);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RUN:
|
||||
{
|
||||
boost::unique_lock<boost::mutex> runLock(fRunningMutex);
|
||||
while (!fRunningFinished)
|
||||
{
|
||||
fRunningCondition.wait(runLock);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RESET_TASK:
|
||||
{
|
||||
boost::unique_lock<boost::mutex> runLock(fResetTaskMutex);
|
||||
while (!fResetTaskFinished)
|
||||
{
|
||||
fResetTaskCondition.wait(runLock);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RESET_DEVICE:
|
||||
{
|
||||
boost::unique_lock<boost::mutex> runLock(fResetMutex);
|
||||
while (!fResetFinished)
|
||||
{
|
||||
fResetCondition.wait(runLock);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG(ERROR) << "Requested state is either synchronous or does not exist.";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQStateMachine::WaitForEndOfState(std::string event)
|
||||
{
|
||||
if (event == "INIT_DEVICE")
|
||||
{
|
||||
return WaitForEndOfState(INIT_DEVICE);
|
||||
}
|
||||
if (event == "DEVICE_READY")
|
||||
{
|
||||
return WaitForEndOfState(DEVICE_READY);
|
||||
}
|
||||
if (event == "INIT_TASK")
|
||||
{
|
||||
return WaitForEndOfState(INIT_TASK);
|
||||
}
|
||||
if (event == "READY")
|
||||
{
|
||||
return WaitForEndOfState(READY);
|
||||
}
|
||||
else if (event == "RUN")
|
||||
{
|
||||
return WaitForEndOfState(RUN);
|
||||
}
|
||||
else if (event == "PAUSE")
|
||||
{
|
||||
return WaitForEndOfState(PAUSE);
|
||||
}
|
||||
else if (event == "RESUME")
|
||||
{
|
||||
return WaitForEndOfState(RESUME);
|
||||
}
|
||||
else if (event == "STOP")
|
||||
{
|
||||
return WaitForEndOfState(STOP);
|
||||
}
|
||||
if (event == "RESET_DEVICE")
|
||||
{
|
||||
return WaitForEndOfState(RESET_DEVICE);
|
||||
}
|
||||
if (event == "RESET_TASK")
|
||||
{
|
||||
return WaitForEndOfState(RESET_TASK);
|
||||
}
|
||||
else if (event == "IDLE")
|
||||
{
|
||||
return WaitForEndOfState(IDLE);
|
||||
}
|
||||
else if (event == "END")
|
||||
{
|
||||
return WaitForEndOfState(END);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR) << "Requested unsupported state: " << event << std::endl
|
||||
<< "Supported are: INIT_DEVICE, INIT_TASK, RUN, PAUSE, RESUME, STOP, RESET_TASK, RESET_DEVICE, END";
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
#ifndef FAIRMQSTATEMACHINE_H_
|
||||
#define FAIRMQSTATEMACHINE_H_
|
||||
|
||||
#define FAIRMQ_INTERFACE_VERSION 1
|
||||
#define FAIRMQ_INTERFACE_VERSION 2
|
||||
|
||||
#include <string>
|
||||
|
||||
|
@ -28,8 +28,6 @@
|
|||
#include <boost/msm/back/state_machine.hpp>
|
||||
#include <boost/msm/front/state_machine_def.hpp>
|
||||
#include <boost/msm/front/functor_row.hpp>
|
||||
#include <boost/msm/front/euml/common.hpp>
|
||||
#include <boost/msm/front/euml/operator.hpp>
|
||||
|
||||
#include "FairMQLogger.h"
|
||||
|
||||
|
@ -39,15 +37,19 @@ namespace msmf = boost::msm::front;
|
|||
|
||||
namespace FairMQFSM
|
||||
{
|
||||
|
||||
// defining events for the boost MSM state machine
|
||||
struct INIT {};
|
||||
struct SETOUTPUT {};
|
||||
struct SETINPUT {};
|
||||
struct BIND {};
|
||||
struct CONNECT {};
|
||||
struct PAUSE {};
|
||||
struct INIT_DEVICE {};
|
||||
struct DEVICE_READY {};
|
||||
struct INIT_TASK {};
|
||||
struct READY {};
|
||||
struct RUN {};
|
||||
struct PAUSE {};
|
||||
struct RESUME {};
|
||||
struct STOP {};
|
||||
struct RESET_TASK {};
|
||||
struct RESET_DEVICE {};
|
||||
struct IDLE {};
|
||||
struct END {};
|
||||
|
||||
// defining the boost MSM state machine
|
||||
|
@ -55,7 +57,8 @@ namespace FairMQFSM
|
|||
{
|
||||
FairMQFSM_()
|
||||
: fState()
|
||||
, fRunningStateThread()
|
||||
, fStateThread()
|
||||
, fTerminateStateThread()
|
||||
{}
|
||||
|
||||
// Destructor
|
||||
|
@ -67,171 +70,295 @@ namespace FairMQFSM
|
|||
LOG(STATE) << "Entering FairMQ state machine";
|
||||
fState = IDLE;
|
||||
}
|
||||
|
||||
template <class Event, class FSM>
|
||||
void on_exit(Event const&, FSM&)
|
||||
{
|
||||
LOG(STATE) << "Exiting FairMQ state machine";
|
||||
}
|
||||
|
||||
// The list of FSM states
|
||||
struct IDLE_FSM : public msm::front::state<> {};
|
||||
struct INITIALIZING_FSM : public msm::front::state<> {};
|
||||
struct SETTINGOUTPUT_FSM : public msm::front::state<> {};
|
||||
struct SETTINGINPUT_FSM : public msm::front::state<> {};
|
||||
struct BINDING_FSM : public msm::front::state<> {};
|
||||
struct CONNECTING_FSM : public msm::front::state<> {};
|
||||
struct WAITING_FSM : public msm::front::state<> {};
|
||||
struct INITIALIZING_DEVICE_FSM : public msm::front::state<> {};
|
||||
struct DEVICE_READY_FSM : public msm::front::state<> {};
|
||||
struct INITIALIZING_TASK_FSM : public msm::front::state<> {};
|
||||
struct READY_FSM : public msm::front::state<> {};
|
||||
struct RUNNING_FSM : public msm::front::state<> {};
|
||||
struct PAUSED_FSM : public msm::front::state<> {};
|
||||
struct RESETTING_TASK_FSM : public msm::front::state<> {};
|
||||
struct RESETTING_DEVICE_FSM : public msm::front::state<> {};
|
||||
struct EXITING_FSM : public msm::front::state<> {};
|
||||
|
||||
// Define initial state
|
||||
typedef IDLE_FSM initial_state;
|
||||
|
||||
// Actions
|
||||
struct TestFct
|
||||
{
|
||||
template <class EVT, class FSM, class SourceState, class TargetState>
|
||||
void operator()(EVT const&, FSM&, SourceState&, TargetState&)
|
||||
{
|
||||
// LOG(STATE) << "Transition from " << typeid(SourceState).name() << " to " << typeid(TargetState).name() << " with event:" << typeid(EVT).name();
|
||||
}
|
||||
};
|
||||
struct InitFct
|
||||
struct IdleFct
|
||||
{
|
||||
template <class EVT, class FSM, class SourceState, class TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
fsm.fState = INITIALIZING;
|
||||
fsm.Init();
|
||||
fsm.fState = IDLE;
|
||||
}
|
||||
};
|
||||
struct SetOutputFct
|
||||
|
||||
struct InitDeviceFct
|
||||
{
|
||||
template <class EVT, class FSM, class SourceState, class TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
fsm.fState = SETTINGOUTPUT;
|
||||
fsm.InitOutput();
|
||||
LOG(STATE) << "Entering INITIALIZING DEVICE state";
|
||||
fsm.fState = INITIALIZING_DEVICE;
|
||||
fsm.fStateThread = boost::thread(boost::bind(&FairMQFSM_::InitWrapper, &fsm));
|
||||
}
|
||||
};
|
||||
struct SetInputFct
|
||||
|
||||
struct DeviceReadyFct
|
||||
{
|
||||
template <class EVT, class FSM, class SourceState, class TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
fsm.fState = SETTINGINPUT;
|
||||
fsm.InitInput();
|
||||
fsm.fState = DEVICE_READY;
|
||||
}
|
||||
};
|
||||
struct BindFct
|
||||
|
||||
struct InitTaskFct
|
||||
{
|
||||
template <class EVT, class FSM, class SourceState, class TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
fsm.fState = BINDING;
|
||||
fsm.Bind();
|
||||
LOG(STATE) << "Entering INITIALIZING TASK state";
|
||||
fsm.fState = INITIALIZING_TASK;
|
||||
fsm.InitTaskWrapper();
|
||||
// fsm.fInitializingTaskThread = boost::thread(boost::bind(&FairMQFSM_::InitTaskWrapper, &fsm));
|
||||
}
|
||||
};
|
||||
struct ConnectFct
|
||||
|
||||
struct ReadyFct
|
||||
{
|
||||
template <class EVT, class FSM, class SourceState, class TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
fsm.fState = CONNECTING;
|
||||
fsm.Connect();
|
||||
fsm.fState = READY;
|
||||
}
|
||||
};
|
||||
|
||||
struct RunFct
|
||||
{
|
||||
template <class EVT, class FSM, class SourceState, class TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
LOG(STATE) << "Entering RUNNING state";
|
||||
fsm.fState = RUNNING;
|
||||
fsm.fRunningStateThread = boost::thread(boost::bind(&FairMQFSM_::Run, &fsm));
|
||||
fsm.fStateThread = boost::thread(boost::bind(&FairMQFSM_::RunWrapper, &fsm));
|
||||
}
|
||||
};
|
||||
|
||||
struct PauseFct
|
||||
{
|
||||
template <class EVT, class FSM, class SourceState, class TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
LOG(STATE) << "Entering PAUSED state";
|
||||
fsm.fState = PAUSED;
|
||||
fsm.SendCommand("pause");
|
||||
fsm.fStateThread.join();
|
||||
fsm.fStateThread = boost::thread(boost::bind(&FairMQFSM_::Pause, &fsm));
|
||||
}
|
||||
};
|
||||
|
||||
struct ResumeFct
|
||||
{
|
||||
template <class EVT, class FSM, class SourceState, class TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
fsm.fState = RUNNING;
|
||||
fsm.fStateThread.interrupt();
|
||||
fsm.fStateThread.join();
|
||||
LOG(STATE) << "Entering RUNNING state";
|
||||
fsm.fStateThread = boost::thread(boost::bind(&FairMQFSM_::RunWrapper, &fsm));
|
||||
}
|
||||
};
|
||||
|
||||
struct StopFct
|
||||
{
|
||||
template <class EVT, class FSM, class SourceState, class TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
fsm.fState = IDLE;
|
||||
fsm.Terminate();
|
||||
fsm.fRunningStateThread.join();
|
||||
// fsm.SendCommand("stop");
|
||||
fsm.fStateThread.join();
|
||||
}
|
||||
};
|
||||
struct PauseFct
|
||||
|
||||
struct ResetTaskFct
|
||||
{
|
||||
template <class EVT, class FSM, class SourceState, class TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
fsm.fState = WAITING;
|
||||
fsm.fRunningStateThread.join();
|
||||
fsm.Pause();
|
||||
LOG(STATE) << "Entering RESETTING TASK state";
|
||||
fsm.fState = RESETTING_TASK;
|
||||
fsm.fStateThread = boost::thread(boost::bind(&FairMQFSM_::ResetTaskWrapper, &fsm));
|
||||
}
|
||||
};
|
||||
|
||||
struct ResetDeviceFct
|
||||
{
|
||||
template <class EVT, class FSM, class SourceState, class TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
LOG(STATE) << "Entering RESETTING DEVICE state";
|
||||
fsm.fState = RESETTING_DEVICE;
|
||||
fsm.fStateThread = boost::thread(boost::bind(&FairMQFSM_::ResetWrapper, &fsm));
|
||||
}
|
||||
};
|
||||
|
||||
struct ExitingFct
|
||||
{
|
||||
template <class EVT, class FSM, class SourceState, class TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
fsm.fState = EXITING;
|
||||
|
||||
fsm.fStateThread = boost::thread(boost::bind(&FairMQFSM_::Terminate, &fsm));
|
||||
fsm.Shutdown();
|
||||
fsm.fStateThread.join();
|
||||
}
|
||||
};
|
||||
|
||||
struct ExitingRunFct
|
||||
{
|
||||
template <class EVT, class FSM, class SourceState, class TargetState>
|
||||
void operator()(EVT const&, FSM& fsm, SourceState&, TargetState&)
|
||||
{
|
||||
fsm.fState = EXITING;
|
||||
|
||||
fsm.fTerminateStateThread = boost::thread(boost::bind(&FairMQFSM_::Terminate, &fsm));
|
||||
fsm.fStateThread.join();
|
||||
fsm.Shutdown();
|
||||
fsm.fTerminateStateThread.join();
|
||||
}
|
||||
};
|
||||
|
||||
// actions to be overwritten by derived classes
|
||||
virtual void InitWrapper() {}
|
||||
virtual void Init() {}
|
||||
virtual void InitTaskWrapper() {}
|
||||
virtual void InitTask() {}
|
||||
virtual void RunWrapper() {}
|
||||
virtual void Run() {}
|
||||
virtual void Pause() {}
|
||||
virtual void ResetWrapper() {}
|
||||
virtual void Reset() {}
|
||||
virtual void ResetTaskWrapper() {}
|
||||
virtual void ResetTask() {}
|
||||
virtual void Shutdown() {}
|
||||
virtual void InitOutput() {}
|
||||
virtual void InitInput() {}
|
||||
virtual void Bind() {}
|
||||
virtual void Connect() {}
|
||||
virtual void Terminate() {} // Termination method called during StopFct action.
|
||||
virtual void SendCommand(const std::string& command) {} // Method to send commands.
|
||||
|
||||
// Transition table for FairMQFMS
|
||||
struct transition_table : mpl::vector<
|
||||
// Start Event Next Action Guard
|
||||
// +------------------+----------+------------------+-------------+---------+
|
||||
msmf::Row<IDLE_FSM, INIT, INITIALIZING_FSM, InitFct, msmf::none>,
|
||||
msmf::Row<IDLE_FSM, END, msmf::none, TestFct, msmf::none>, // this is an invalid transition...
|
||||
msmf::Row<INITIALIZING_FSM, SETOUTPUT, SETTINGOUTPUT_FSM, SetOutputFct, msmf::none>,
|
||||
msmf::Row<SETTINGOUTPUT_FSM, SETINPUT, SETTINGINPUT_FSM, SetInputFct, msmf::none>,
|
||||
msmf::Row<SETTINGINPUT_FSM, BIND, BINDING_FSM, BindFct, msmf::none>,
|
||||
msmf::Row<BINDING_FSM, CONNECT, CONNECTING_FSM, ConnectFct, msmf::none>,
|
||||
msmf::Row<CONNECTING_FSM, PAUSE, WAITING_FSM, PauseFct, msmf::none>,
|
||||
msmf::Row<CONNECTING_FSM, RUN, RUNNING_FSM, RunFct, msmf::none>,
|
||||
msmf::Row<WAITING_FSM, RUN, RUNNING_FSM, RunFct, msmf::none>,
|
||||
msmf::Row<WAITING_FSM, STOP, IDLE_FSM, StopFct, msmf::none>,
|
||||
msmf::Row<RUNNING_FSM, PAUSE, WAITING_FSM, PauseFct, msmf::none>,
|
||||
msmf::Row<RUNNING_FSM, STOP, IDLE_FSM, StopFct, msmf::none> >
|
||||
{
|
||||
};
|
||||
// +-------------------------+-------------+------------------------+---------------+---------+
|
||||
msmf::Row<IDLE_FSM, INIT_DEVICE, INITIALIZING_DEVICE_FSM, InitDeviceFct, msmf::none>,
|
||||
msmf::Row<INITIALIZING_DEVICE_FSM, DEVICE_READY, DEVICE_READY_FSM, DeviceReadyFct, msmf::none>,
|
||||
msmf::Row<DEVICE_READY_FSM, INIT_TASK, INITIALIZING_TASK_FSM, InitTaskFct, msmf::none>,
|
||||
msmf::Row<INITIALIZING_TASK_FSM, READY, READY_FSM, ReadyFct, msmf::none>,
|
||||
msmf::Row<READY_FSM, RUN, RUNNING_FSM, RunFct, msmf::none>,
|
||||
msmf::Row<RUNNING_FSM, PAUSE, PAUSED_FSM, PauseFct, msmf::none>,
|
||||
msmf::Row<PAUSED_FSM, RESUME, RUNNING_FSM, ResumeFct, msmf::none>,
|
||||
msmf::Row<RUNNING_FSM, STOP, READY_FSM, StopFct, msmf::none>,
|
||||
msmf::Row<READY_FSM, RESET_TASK, RESETTING_TASK_FSM, ResetTaskFct, msmf::none>,
|
||||
msmf::Row<RESETTING_TASK_FSM, DEVICE_READY, DEVICE_READY_FSM, DeviceReadyFct, msmf::none>,
|
||||
msmf::Row<DEVICE_READY_FSM, RESET_DEVICE, RESETTING_DEVICE_FSM, ResetDeviceFct, msmf::none>,
|
||||
msmf::Row<RESETTING_DEVICE_FSM, IDLE, IDLE_FSM, IdleFct, msmf::none>,
|
||||
msmf::Row<RUNNING_FSM, END, EXITING_FSM, ExitingRunFct, msmf::none>, // temporary
|
||||
msmf::Row<IDLE_FSM, END, EXITING_FSM, ExitingFct, msmf::none> >
|
||||
{};
|
||||
|
||||
// Replaces the default no-transition response.
|
||||
template <class FSM, class Event>
|
||||
void no_transition(Event const& e, FSM&, int state)
|
||||
{
|
||||
LOG(STATE) << "no transition from state " << state << " on event " << typeid(e).name();
|
||||
LOG(STATE) << "no transition from state " << GetStateName(state) << " on event " << typeid(e).name();
|
||||
}
|
||||
// this is to run certain functions (e.g. Run()) as separate task
|
||||
boost::thread fRunningStateThread;
|
||||
|
||||
// this is to run certain functions in a separate thread
|
||||
boost::thread fStateThread;
|
||||
boost::thread fTerminateStateThread;
|
||||
|
||||
// backward compatibility to FairMQStateMachine
|
||||
enum State
|
||||
{
|
||||
IDLE,
|
||||
INITIALIZING,
|
||||
SETTINGOUTPUT,
|
||||
SETTINGINPUT,
|
||||
BINDING,
|
||||
CONNECTING,
|
||||
WAITING,
|
||||
RUNNING
|
||||
INITIALIZING_DEVICE,
|
||||
DEVICE_READY,
|
||||
INITIALIZING_TASK,
|
||||
READY,
|
||||
RUNNING,
|
||||
PAUSED,
|
||||
RESETTING_TASK,
|
||||
RESETTING_DEVICE,
|
||||
EXITING
|
||||
};
|
||||
|
||||
std::string GetStateName(int state)
|
||||
{
|
||||
switch(state)
|
||||
{
|
||||
case IDLE:
|
||||
return "IDLE";
|
||||
case INITIALIZING_DEVICE:
|
||||
return "INITIALIZING_DEVICE";
|
||||
case DEVICE_READY:
|
||||
return "DEVICE_READY";
|
||||
case INITIALIZING_TASK:
|
||||
return "INITIALIZING_TASK";
|
||||
case READY:
|
||||
return "READY";
|
||||
case RUNNING:
|
||||
return "RUNNING";
|
||||
case PAUSED:
|
||||
return "PAUSED";
|
||||
case RESETTING_TASK:
|
||||
return "RESETTING_TASK";
|
||||
case RESETTING_DEVICE:
|
||||
return "RESETTING_DEVICE";
|
||||
case EXITING:
|
||||
return "EXITING";
|
||||
default:
|
||||
return "something went wrong...";
|
||||
}
|
||||
}
|
||||
|
||||
int GetCurrentState()
|
||||
{
|
||||
return fState;
|
||||
}
|
||||
|
||||
private:
|
||||
State fState;
|
||||
};
|
||||
|
||||
typedef msm::back::state_machine<FairMQFSM_> FairMQFSM;
|
||||
}
|
||||
} // namespace FairMQFSM
|
||||
|
||||
class FairMQStateMachine : public FairMQFSM::FairMQFSM
|
||||
{
|
||||
public:
|
||||
enum Event
|
||||
{
|
||||
INIT,
|
||||
SETOUTPUT,
|
||||
SETINPUT,
|
||||
BIND,
|
||||
CONNECT,
|
||||
PAUSE,
|
||||
INIT_DEVICE,
|
||||
DEVICE_READY,
|
||||
INIT_TASK,
|
||||
READY,
|
||||
RUN,
|
||||
PAUSE,
|
||||
RESUME,
|
||||
STOP,
|
||||
RESET_TASK,
|
||||
RESET_DEVICE,
|
||||
IDLE,
|
||||
END
|
||||
};
|
||||
FairMQStateMachine();
|
||||
|
@ -242,10 +369,29 @@ class FairMQStateMachine : public FairMQFSM::FairMQFSM
|
|||
bool ChangeState(int event);
|
||||
bool ChangeState(std::string event);
|
||||
|
||||
// condition variable to notify parent thread about end of running state.
|
||||
void WaitForEndOfState(int state);
|
||||
void WaitForEndOfState(std::string state);
|
||||
|
||||
// condition variables to notify parent thread about end of state.
|
||||
bool fInitializingFinished;
|
||||
boost::condition_variable fInitializingCondition;
|
||||
boost::mutex fInitializingMutex;
|
||||
|
||||
bool fInitializingTaskFinished;
|
||||
boost::condition_variable fInitializingTaskCondition;
|
||||
boost::mutex fInitializingTaskMutex;
|
||||
|
||||
bool fRunningFinished;
|
||||
boost::condition_variable fRunningCondition;
|
||||
boost::mutex fRunningMutex;
|
||||
bool fRunningFinished;
|
||||
|
||||
bool fResetFinished;
|
||||
boost::condition_variable fResetCondition;
|
||||
boost::mutex fResetMutex;
|
||||
|
||||
bool fResetTaskFinished;
|
||||
boost::condition_variable fResetTaskCondition;
|
||||
boost::mutex fResetTaskMutex;
|
||||
};
|
||||
|
||||
#endif /* FAIRMQSTATEMACHINE_H_ */
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <string>
|
||||
|
||||
#include "FairMQMessage.h"
|
||||
#include "FairMQChannel.h"
|
||||
#include "FairMQSocket.h"
|
||||
#include "FairMQPoller.h"
|
||||
#include "FairMQLogger.h"
|
||||
|
@ -28,8 +29,8 @@ class FairMQTransportFactory
|
|||
virtual FairMQMessage* CreateMessage() = 0;
|
||||
virtual FairMQMessage* CreateMessage(size_t size) = 0;
|
||||
virtual FairMQMessage* CreateMessage(void* data, size_t size, fairmq_free_fn *ffn = NULL, void* hint = NULL) = 0;
|
||||
virtual FairMQSocket* CreateSocket(const std::string& type, int num, int numIoThreads) = 0;
|
||||
virtual FairMQPoller* CreatePoller(const std::vector<FairMQSocket*>& inputs) = 0;
|
||||
virtual FairMQSocket* CreateSocket(const std::string& type, const std::string& name, int numIoThreads) = 0;
|
||||
virtual FairMQPoller* CreatePoller(const std::vector<FairMQChannel>& channels) = 0;
|
||||
|
||||
virtual ~FairMQTransportFactory() {};
|
||||
};
|
||||
|
|
|
@ -33,27 +33,19 @@ FairMQBenchmarkSampler::~FairMQBenchmarkSampler()
|
|||
{
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::Init()
|
||||
{
|
||||
FairMQDevice::Init();
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::Run()
|
||||
{
|
||||
LOG(INFO) << ">>>>>>> Run <<<<<<<";
|
||||
|
||||
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
boost::thread resetEventCounter(boost::bind(&FairMQBenchmarkSampler::ResetEventCounter, this));
|
||||
|
||||
void* buffer = operator new[](fEventSize);
|
||||
FairMQMessage* base_msg = fTransportFactory->CreateMessage(buffer, fEventSize);
|
||||
FairMQMessage* baseMsg = fTransportFactory->CreateMessage(buffer, fEventSize);
|
||||
|
||||
while (fState == RUNNING)
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
||||
msg->Copy(base_msg);
|
||||
msg->Copy(baseMsg);
|
||||
|
||||
fPayloadOutputs->at(0)->Send(msg);
|
||||
fChannels["data-out"].at(0).Send(msg);
|
||||
|
||||
--fEventCounter;
|
||||
|
||||
|
@ -65,28 +57,19 @@ void FairMQBenchmarkSampler::Run()
|
|||
delete msg;
|
||||
}
|
||||
|
||||
delete base_msg;
|
||||
delete baseMsg;
|
||||
|
||||
try {
|
||||
rateLogger.interrupt();
|
||||
rateLogger.join();
|
||||
resetEventCounter.interrupt();
|
||||
resetEventCounter.join();
|
||||
} catch(boost::thread_resource_error& e) {
|
||||
LOG(ERROR) << e.what();
|
||||
}
|
||||
|
||||
FairMQDevice::Shutdown();
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fRunningMutex);
|
||||
fRunningFinished = true;
|
||||
fRunningCondition.notify_one();
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::ResetEventCounter()
|
||||
{
|
||||
while (true)
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -100,61 +83,26 @@ void FairMQBenchmarkSampler::ResetEventCounter()
|
|||
}
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::Log(int intervalInMs)
|
||||
{
|
||||
timestamp_t t0;
|
||||
timestamp_t t1;
|
||||
unsigned long bytes = fPayloadOutputs->at(0)->GetBytesTx();
|
||||
unsigned long messages = fPayloadOutputs->at(0)->GetMessagesTx();
|
||||
unsigned long bytesNew = 0;
|
||||
unsigned long messagesNew = 0;
|
||||
double megabytesPerSecond = 0;
|
||||
double messagesPerSecond = 0;
|
||||
|
||||
t0 = get_timestamp();
|
||||
|
||||
while (true)
|
||||
{
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(intervalInMs));
|
||||
|
||||
t1 = get_timestamp();
|
||||
|
||||
bytesNew = fPayloadOutputs->at(0)->GetBytesTx();
|
||||
messagesNew = fPayloadOutputs->at(0)->GetMessagesTx();
|
||||
|
||||
timestamp_t timeSinceLastLog_ms = (t1 - t0) / 1000.0L;
|
||||
|
||||
megabytesPerSecond = ((double)(bytesNew - bytes) / (1024. * 1024.)) / (double)timeSinceLastLog_ms * 1000.;
|
||||
messagesPerSecond = (double)(messagesNew - messages) / (double)timeSinceLastLog_ms * 1000.;
|
||||
|
||||
LOG(DEBUG) << "send " << messagesPerSecond << " msg/s, " << megabytesPerSecond << " MB/s";
|
||||
|
||||
bytes = bytesNew;
|
||||
messages = messagesNew;
|
||||
t0 = t1;
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::SetProperty(const int key, const string& value, const int slot /*= 0*/)
|
||||
void FairMQBenchmarkSampler::SetProperty(const int key, const string& value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value, slot);
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string FairMQBenchmarkSampler::GetProperty(const int key, const string& default_ /*= ""*/, const int slot /*= 0*/)
|
||||
string FairMQBenchmarkSampler::GetProperty(const int key, const string& default_ /*= ""*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_, slot);
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQBenchmarkSampler::SetProperty(const int key, const int value, const int slot /*= 0*/)
|
||||
void FairMQBenchmarkSampler::SetProperty(const int key, const int value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
|
@ -165,12 +113,12 @@ void FairMQBenchmarkSampler::SetProperty(const int key, const int value, const i
|
|||
fEventRate = value;
|
||||
break;
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value, slot);
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int FairMQBenchmarkSampler::GetProperty(const int key, const int default_ /*= 0*/, const int slot /*= 0*/)
|
||||
int FairMQBenchmarkSampler::GetProperty(const int key, const int default_ /*= 0*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
|
@ -179,6 +127,6 @@ int FairMQBenchmarkSampler::GetProperty(const int key, const int default_ /*= 0*
|
|||
case EventRate:
|
||||
return fEventRate;
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_, slot);
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,25 +29,27 @@ class FairMQBenchmarkSampler : public FairMQDevice
|
|||
enum
|
||||
{
|
||||
InputFile = FairMQDevice::Last,
|
||||
EventRate,
|
||||
EventSize,
|
||||
EventRate,
|
||||
Last
|
||||
};
|
||||
|
||||
FairMQBenchmarkSampler();
|
||||
virtual ~FairMQBenchmarkSampler();
|
||||
|
||||
void Log(int intervalInMs);
|
||||
void ResetEventCounter();
|
||||
virtual void SetProperty(const int key, const std::string& value, const int slot = 0);
|
||||
virtual std::string GetProperty(const int key, const std::string& default_ = "", const int slot = 0);
|
||||
virtual void SetProperty(const int key, const int value, const int slot = 0);
|
||||
virtual int GetProperty(const int key, const int default_ = 0, const int slot = 0);
|
||||
|
||||
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);
|
||||
|
||||
protected:
|
||||
int fEventSize;
|
||||
int fEventRate;
|
||||
int fEventCounter;
|
||||
|
||||
virtual void Init();
|
||||
virtual void Run();
|
||||
};
|
||||
|
||||
|
|
|
@ -26,39 +26,17 @@ FairMQBuffer::FairMQBuffer()
|
|||
|
||||
void FairMQBuffer::Run()
|
||||
{
|
||||
LOG(INFO) << ">>>>>>> Run <<<<<<<";
|
||||
|
||||
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
|
||||
int received = 0;
|
||||
while (fState == RUNNING)
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
||||
|
||||
received = fPayloadInputs->at(0)->Receive(msg);
|
||||
|
||||
if (received > 0)
|
||||
if (fChannels["data-in"].at(0).Receive(msg) > 0)
|
||||
{
|
||||
fPayloadOutputs->at(0)->Send(msg);
|
||||
received = 0;
|
||||
fChannels["data-out"].at(0).Send(msg);
|
||||
}
|
||||
|
||||
delete msg;
|
||||
}
|
||||
|
||||
try {
|
||||
rateLogger.interrupt();
|
||||
rateLogger.join();
|
||||
} catch(boost::thread_resource_error& e) {
|
||||
LOG(ERROR) << e.what();
|
||||
}
|
||||
|
||||
FairMQDevice::Shutdown();
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fRunningMutex);
|
||||
fRunningFinished = true;
|
||||
fRunningCondition.notify_one();
|
||||
}
|
||||
|
||||
FairMQBuffer::~FairMQBuffer()
|
||||
|
|
|
@ -29,30 +29,22 @@ FairMQMerger::~FairMQMerger()
|
|||
|
||||
void FairMQMerger::Run()
|
||||
{
|
||||
LOG(INFO) << ">>>>>>> Run <<<<<<<";
|
||||
FairMQPoller* poller = fTransportFactory->CreatePoller(fChannels["data-in"]);
|
||||
|
||||
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
|
||||
FairMQPoller* poller = fTransportFactory->CreatePoller(*fPayloadInputs);
|
||||
|
||||
int received = 0;
|
||||
|
||||
while (fState == RUNNING)
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
||||
|
||||
poller->Poll(100);
|
||||
|
||||
for (int i = 0; i < fNumInputs; i++)
|
||||
for (int i = 0; i < fChannels["data-in"].size(); ++i)
|
||||
{
|
||||
if (poller->CheckInput(i))
|
||||
{
|
||||
received = fPayloadInputs->at(i)->Receive(msg);
|
||||
}
|
||||
if (received > 0)
|
||||
if (fChannels["data-in"].at(i).Receive(msg))
|
||||
{
|
||||
fPayloadOutputs->at(0)->Send(msg);
|
||||
received = 0;
|
||||
fChannels["data-out"].at(0).Send(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,18 +52,4 @@ void FairMQMerger::Run()
|
|||
}
|
||||
|
||||
delete poller;
|
||||
|
||||
try {
|
||||
rateLogger.interrupt();
|
||||
rateLogger.join();
|
||||
} catch(boost::thread_resource_error& e) {
|
||||
LOG(ERROR) << e.what();
|
||||
}
|
||||
|
||||
FairMQDevice::Shutdown();
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fRunningMutex);
|
||||
fRunningFinished = true;
|
||||
fRunningCondition.notify_one();
|
||||
}
|
||||
|
|
|
@ -28,37 +28,15 @@ FairMQProxy::~FairMQProxy()
|
|||
|
||||
void FairMQProxy::Run()
|
||||
{
|
||||
LOG(INFO) << ">>>>>>> Run <<<<<<<";
|
||||
|
||||
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
|
||||
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
||||
|
||||
int received = 0;
|
||||
|
||||
while (fState == RUNNING)
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
received = fPayloadInputs->at(0)->Receive(msg);
|
||||
if (received > 0)
|
||||
if (fChannels["data-in"].at(0).Receive(msg) > 0)
|
||||
{
|
||||
fPayloadOutputs->at(0)->Send(msg);
|
||||
received = 0;
|
||||
fChannels["data-out"].at(0).Send(msg);
|
||||
}
|
||||
}
|
||||
|
||||
delete msg;
|
||||
|
||||
try {
|
||||
rateLogger.interrupt();
|
||||
rateLogger.join();
|
||||
} catch(boost::thread_resource_error& e) {
|
||||
LOG(ERROR) << e.what();
|
||||
}
|
||||
|
||||
FairMQDevice::Shutdown();
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fRunningMutex);
|
||||
fRunningFinished = true;
|
||||
fRunningCondition.notify_one();
|
||||
}
|
||||
|
|
|
@ -24,34 +24,14 @@ FairMQSink::FairMQSink()
|
|||
|
||||
void FairMQSink::Run()
|
||||
{
|
||||
LOG(INFO) << ">>>>>>> Run <<<<<<<";
|
||||
|
||||
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
|
||||
int received = 0;
|
||||
|
||||
while (fState == RUNNING)
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
||||
|
||||
received = fPayloadInputs->at(0)->Receive(msg);
|
||||
fChannels["data-in"].at(0).Receive(msg);
|
||||
|
||||
delete msg;
|
||||
}
|
||||
|
||||
try {
|
||||
rateLogger.interrupt();
|
||||
rateLogger.join();
|
||||
} catch(boost::thread_resource_error& e) {
|
||||
LOG(ERROR) << e.what();
|
||||
}
|
||||
|
||||
FairMQDevice::Shutdown();
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fRunningMutex);
|
||||
fRunningFinished = true;
|
||||
fRunningCondition.notify_one();
|
||||
}
|
||||
|
||||
FairMQSink::~FairMQSink()
|
||||
|
|
|
@ -28,44 +28,22 @@ FairMQSplitter::~FairMQSplitter()
|
|||
|
||||
void FairMQSplitter::Run()
|
||||
{
|
||||
LOG(INFO) << ">>>>>>> Run <<<<<<<";
|
||||
|
||||
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
|
||||
int received = 0;
|
||||
int direction = 0;
|
||||
|
||||
while (fState == RUNNING)
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
||||
|
||||
received = fPayloadInputs->at(0)->Receive(msg);
|
||||
|
||||
if (received > 0)
|
||||
if (fChannels["data-in"].at(0).Receive(msg) > 0)
|
||||
{
|
||||
fPayloadOutputs->at(direction)->Send(msg);
|
||||
fChannels["data-out"].at(direction).Send(msg);
|
||||
direction++;
|
||||
if (direction >= fNumOutputs)
|
||||
if (direction >= fChannels["data-out"].size())
|
||||
{
|
||||
direction = 0;
|
||||
}
|
||||
received = 0;
|
||||
}
|
||||
|
||||
delete msg;
|
||||
}
|
||||
|
||||
try {
|
||||
rateLogger.interrupt();
|
||||
rateLogger.join();
|
||||
} catch(boost::thread_resource_error& e) {
|
||||
LOG(ERROR) << e.what();
|
||||
}
|
||||
|
||||
FairMQDevice::Shutdown();
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fRunningMutex);
|
||||
fRunningFinished = true;
|
||||
fRunningCondition.notify_one();
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
#include <boost/bind.hpp>
|
||||
#include "FairMQLogger.h"
|
||||
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* -------------- NOTES -----------------------
|
||||
* All policies must have a default constructor
|
||||
|
@ -38,26 +36,20 @@
|
|||
* OutputPolicy::InitOutputFile()
|
||||
**********************************************************************/
|
||||
|
||||
|
||||
|
||||
#include "FairMQDevice.h"
|
||||
|
||||
template < typename InputPolicy,
|
||||
typename OutputPolicy>
|
||||
class GenericFileSink : public FairMQDevice,
|
||||
public InputPolicy,
|
||||
public OutputPolicy
|
||||
template <typename InputPolicy, typename OutputPolicy>
|
||||
class GenericFileSink : public FairMQDevice, public InputPolicy, public OutputPolicy
|
||||
{
|
||||
public:
|
||||
GenericFileSink():
|
||||
InputPolicy(),
|
||||
OutputPolicy()
|
||||
GenericFileSink()
|
||||
: InputPolicy()
|
||||
, OutputPolicy()
|
||||
{}
|
||||
|
||||
virtual ~GenericFileSink()
|
||||
{}
|
||||
|
||||
|
||||
void SetTransport(FairMQTransportFactory* transport)
|
||||
{
|
||||
FairMQDevice::SetTransport(transport);
|
||||
|
@ -68,56 +60,32 @@ public:
|
|||
{
|
||||
InputPolicy::InitContainer(std::forward<Args>(args)...);
|
||||
}
|
||||
protected:
|
||||
|
||||
virtual void Init()
|
||||
protected:
|
||||
virtual void InitTask()
|
||||
{
|
||||
FairMQDevice::Init();
|
||||
OutputPolicy::InitOutputFile();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void Run()
|
||||
{
|
||||
MQLOG(INFO) << ">>>>>>> Run <<<<<<<";
|
||||
|
||||
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
|
||||
int received = 0;
|
||||
int receivedMsg = 0;
|
||||
|
||||
while (fState == RUNNING)
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
||||
received = fPayloadInputs->at(0)->Receive(msg);
|
||||
if(received>0)
|
||||
|
||||
if (fChannels["data-in"].at(0).Receive(msg) > 0)
|
||||
{
|
||||
OutputPolicy::AddToFile(InputPolicy::DeSerializeMsg(msg));
|
||||
receivedMsg++;
|
||||
}
|
||||
|
||||
delete msg;
|
||||
}
|
||||
|
||||
MQLOG(INFO) << "Received " << receivedMsg << " messages!";
|
||||
try
|
||||
{
|
||||
rateLogger.interrupt();
|
||||
rateLogger.join();
|
||||
}
|
||||
catch(boost::thread_resource_error& e)
|
||||
{
|
||||
MQLOG(ERROR) << e.what();
|
||||
}
|
||||
|
||||
FairMQDevice::Shutdown();
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fRunningMutex);
|
||||
fRunningFinished = true;
|
||||
fRunningCondition.notify_one();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif /* GENERICFILESINK_H */
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
*/
|
||||
|
||||
template <typename InputPolicy, typename OutputPolicy>
|
||||
GenericFileSink<InputPolicy, OutputPolicy>::GenericFileSink() :
|
||||
InputPolicy(),
|
||||
OutputPolicy()
|
||||
GenericFileSink<InputPolicy, OutputPolicy>::GenericFileSink()
|
||||
: InputPolicy()
|
||||
, OutputPolicy()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -26,9 +26,8 @@ void GenericFileSink<InputPolicy, OutputPolicy>::SetTransport(FairMQTransportFac
|
|||
|
||||
|
||||
template <typename InputPolicy, typename OutputPolicy>
|
||||
void GenericFileSink<InputPolicy, OutputPolicy>::Init()
|
||||
void GenericFileSink<InputPolicy, OutputPolicy>::InitTask()
|
||||
{
|
||||
FairMQDevice::Init();
|
||||
InitOutputFile();
|
||||
// InputPolicy::Init();
|
||||
// OutputPolicy::Init();
|
||||
|
@ -43,18 +42,12 @@ void GenericFileSink<InputPolicy, OutputPolicy>::InitOutputFile()
|
|||
template <typename InputPolicy, typename OutputPolicy>
|
||||
void GenericFileSink<InputPolicy, OutputPolicy>::Run()
|
||||
{
|
||||
MQLOG(INFO) << ">>>>>>> Run <<<<<<<";
|
||||
|
||||
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
|
||||
int received = 0;
|
||||
int receivedMsg = 0;
|
||||
|
||||
while (fState == RUNNING)
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
||||
received = fPayloadInputs->at(0)->Receive(msg);
|
||||
if(received>0)
|
||||
if (fChannels["data-in"].at(0).Receive(msg) > 0)
|
||||
{
|
||||
OutputPolicy::AddToFile(InputPolicy::DeSerializeMsg(msg));
|
||||
receivedMsg++;
|
||||
|
@ -63,20 +56,4 @@ void GenericFileSink<InputPolicy, OutputPolicy>::Run()
|
|||
}
|
||||
|
||||
MQLOG(INFO) << "Received " << receivedMsg << " messages!";
|
||||
try
|
||||
{
|
||||
rateLogger.interrupt();
|
||||
rateLogger.join();
|
||||
}
|
||||
catch(boost::thread_resource_error& e)
|
||||
{
|
||||
MQLOG(ERROR) << e.what();
|
||||
}
|
||||
|
||||
FairMQDevice::Shutdown();
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fRunningMutex);
|
||||
fRunningFinished = true;
|
||||
fRunningCondition.notify_one();
|
||||
}
|
||||
|
|
|
@ -17,17 +17,12 @@
|
|||
#include "FairMQPoller.h"
|
||||
|
||||
|
||||
template < typename MergerPolicy,
|
||||
typename InputPolicy,
|
||||
typename OutputPolicy
|
||||
>
|
||||
class GenericMerger : public FairMQDevice,
|
||||
public MergerPolicy,
|
||||
public InputPolicy,
|
||||
public OutputPolicy
|
||||
template <typename MergerPolicy, typename InputPolicy, typename OutputPolicy>
|
||||
class GenericMerger : public FairMQDevice, public MergerPolicy, public InputPolicy, public OutputPolicy
|
||||
{
|
||||
public:
|
||||
GenericMerger() : fBlockingTime(100)
|
||||
GenericMerger()
|
||||
: fBlockingTime(100)
|
||||
{}
|
||||
|
||||
virtual ~GenericMerger()
|
||||
|
@ -38,35 +33,26 @@ class GenericMerger : public FairMQDevice,
|
|||
FairMQDevice::SetTransport(transport);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
int fBlockingTime;
|
||||
|
||||
|
||||
virtual void Run()
|
||||
{
|
||||
MQLOG(INFO) << ">>>>>>> Run <<<<<<<";
|
||||
|
||||
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
|
||||
FairMQPoller* poller = fTransportFactory->CreatePoller(*fPayloadInputs);
|
||||
FairMQPoller* poller = fTransportFactory->CreatePoller(fChannels["data-in"]);
|
||||
|
||||
int received = 0;
|
||||
|
||||
while (fState == RUNNING)
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
||||
// MergerPolicy::
|
||||
poller->Poll(fBlockingTime);
|
||||
|
||||
for (int i = 0; i < fNumInputs; i++)
|
||||
for (int i = 0; i < fChannels["datain"].size(); i++)
|
||||
{
|
||||
if (poller->CheckInput(i))
|
||||
{
|
||||
received = fPayloadInputs->at(i)->Receive(msg);
|
||||
received = fChannels["data-in"].at(i).Receive(msg)
|
||||
MergerPolicy::Merge(InputPolicy::DeSerializeMsg(msg));
|
||||
}
|
||||
|
||||
|
@ -74,7 +60,7 @@ class GenericMerger : public FairMQDevice,
|
|||
|
||||
if (received > 0 && MergerPolicy::ReadyToSend())
|
||||
{
|
||||
fPayloadOutputs->at(0)->Send(OutputPolicy::SerializeMsg(MergerPolicy::GetOutputData()));
|
||||
fChannels["data-out"].at(0).Send(OutputPolicy::SerializeMsg(MergerPolicy::GetOutputData()));
|
||||
received = 0;
|
||||
}
|
||||
}
|
||||
|
@ -83,23 +69,6 @@ class GenericMerger : public FairMQDevice,
|
|||
}
|
||||
|
||||
delete poller;
|
||||
|
||||
try
|
||||
{
|
||||
rateLogger.interrupt();
|
||||
rateLogger.join();
|
||||
}
|
||||
catch(boost::thread_resource_error& e)
|
||||
{
|
||||
MQLOG(ERROR) << e.what();
|
||||
}
|
||||
|
||||
FairMQDevice::Shutdown();
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fRunningMutex);
|
||||
fRunningFinished = true;
|
||||
fRunningCondition.notify_one();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
#include "FairMQDevice.h"
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* -------------- NOTES -----------------------
|
||||
* All policies must have a default constructor
|
||||
|
@ -41,17 +40,14 @@
|
|||
*
|
||||
**********************************************************************/
|
||||
|
||||
|
||||
template < typename InputPolicy,
|
||||
typename OutputPolicy,
|
||||
typename TaskPolicy>
|
||||
class GenericProcessor: public FairMQDevice,
|
||||
public InputPolicy,
|
||||
public OutputPolicy,
|
||||
public TaskPolicy
|
||||
template <typename InputPolicy, typename OutputPolicy, typename TaskPolicy>
|
||||
class GenericProcessor : public FairMQDevice, public InputPolicy, public OutputPolicy, public TaskPolicy
|
||||
{
|
||||
public:
|
||||
GenericProcessor() : InputPolicy(), OutputPolicy(), TaskPolicy()
|
||||
GenericProcessor()
|
||||
: InputPolicy()
|
||||
, OutputPolicy()
|
||||
, TaskPolicy()
|
||||
{}
|
||||
|
||||
virtual ~GenericProcessor()
|
||||
|
@ -83,15 +79,12 @@ class GenericProcessor: public FairMQDevice,
|
|||
OutputPolicy::InitContainer(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
// *********************** TODO: implement multipart features
|
||||
void SendPart()
|
||||
{
|
||||
fPayloadOutputs->at(0)->Send(OutputPolicy::SerializeMsg(TaskPolicy::GetData()), "snd-more");
|
||||
fChannels["data-out"].at(0).Send(OutputPolicy::SerializeMsg(TaskPolicy::GetData()), "snd-more");
|
||||
OutputPolicy::CloseMessage();
|
||||
}
|
||||
|
||||
|
@ -101,13 +94,13 @@ class GenericProcessor: public FairMQDevice,
|
|||
{
|
||||
int64_t more = 0;
|
||||
size_t more_size = sizeof(more);
|
||||
fPayloadInputs->at(0)->GetOption("rcv-more", &more, &more_size);
|
||||
fChannels["data-in"].at(0).fSocket->GetOption("rcv-more", &more, &more_size);
|
||||
if (more)
|
||||
{
|
||||
InputPolicy::CloseMessage();
|
||||
// fProcessorTask->GetPayload()->CloseMessage();
|
||||
fProcessorTask->SetPayload(fTransportFactory->CreateMessage());
|
||||
return fPayloadInputs->at(0)->Receive(fProcessorTask->GetPayload());
|
||||
return fChannels["data-in"].at(0).Receive(fProcessorTask->GetPayload());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -117,9 +110,8 @@ class GenericProcessor: public FairMQDevice,
|
|||
*/
|
||||
|
||||
protected:
|
||||
virtual void Init()
|
||||
virtual void InitTask()
|
||||
{
|
||||
FairMQDevice::Init();
|
||||
// TODO: implement multipart features
|
||||
// fProcessorTask->InitTask();
|
||||
// fProcessorTask->SetSendPart(boost::bind(&FairMQProcessor::SendPart, this));
|
||||
|
@ -128,18 +120,13 @@ class GenericProcessor: public FairMQDevice,
|
|||
|
||||
virtual void Run()
|
||||
{
|
||||
MQLOG(INFO) << ">>>>>>> Run <<<<<<<";
|
||||
|
||||
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
int receivedMsgs = 0;
|
||||
int sentMsgs = 0;
|
||||
int received = 0;
|
||||
|
||||
while ( fState == RUNNING )
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
||||
|
||||
received = fPayloadInputs->at(0)->Receive(msg);
|
||||
receivedMsgs++;
|
||||
|
||||
// InputPolicy::DeSerializeMsg(msg) --> deserialize data of msg and fill output container
|
||||
|
@ -149,36 +136,21 @@ class GenericProcessor: public FairMQDevice,
|
|||
// OutputPolicy::fMessage point to msg
|
||||
OutputPolicy::SetMessage(msg);
|
||||
|
||||
if (received > 0)
|
||||
if (fChannels["data-in"].at(0).Receive(msg) > 0)
|
||||
{
|
||||
// TaskPolicy::GetOutputData() --> Get processed output container
|
||||
// OutputPolicy::message(...) --> Serialize output container and fill fMessage
|
||||
fPayloadOutputs->at(0)->Send(OutputPolicy::SerializeMsg(TaskPolicy::GetOutputData()));
|
||||
fChannels["data-out"].at(0).Send(OutputPolicy::SerializeMsg(TaskPolicy::GetOutputData()));
|
||||
sentMsgs++;
|
||||
received = 0;
|
||||
}
|
||||
|
||||
if (msg)
|
||||
{
|
||||
msg->CloseMessage();
|
||||
}
|
||||
}
|
||||
|
||||
MQLOG(INFO) << "Received " << receivedMsgs << " and sent " << sentMsgs << " messages!";
|
||||
|
||||
try
|
||||
{
|
||||
rateLogger.interrupt();
|
||||
rateLogger.join();
|
||||
}
|
||||
catch(boost::thread_resource_error& e)
|
||||
{
|
||||
MQLOG(ERROR) << e.what();
|
||||
}
|
||||
|
||||
FairMQDevice::Shutdown();
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fRunningMutex);
|
||||
fRunningFinished = true;
|
||||
fRunningCondition.notify_one();
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
* Created on November 24, 2014, 3:30 PM
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GENERICSAMPLER_H
|
||||
#define GENERICSAMPLER_H
|
||||
|
||||
|
@ -45,14 +44,10 @@
|
|||
*
|
||||
**********************************************************************/
|
||||
|
||||
template <typename SamplerPolicy,
|
||||
typename OutputPolicy>
|
||||
class GenericSampler: public FairMQDevice,
|
||||
public SamplerPolicy,
|
||||
public OutputPolicy
|
||||
template <typename SamplerPolicy, typename OutputPolicy>
|
||||
class GenericSampler : public FairMQDevice, public SamplerPolicy, public OutputPolicy
|
||||
{
|
||||
public:
|
||||
|
||||
enum
|
||||
{
|
||||
InputFile = FairMQDevice::Last,
|
||||
|
@ -63,9 +58,9 @@ class GenericSampler: public FairMQDevice,
|
|||
|
||||
GenericSampler();
|
||||
virtual ~GenericSampler();
|
||||
|
||||
virtual void SetTransport(FairMQTransportFactory* factory);
|
||||
void ResetEventCounter();
|
||||
virtual void ListenToCommands();
|
||||
|
||||
template <typename... Args>
|
||||
void SetFileProperties(Args&... args)
|
||||
|
@ -73,10 +68,10 @@ class GenericSampler: public FairMQDevice,
|
|||
SamplerPolicy::SetFileProperties(args...);
|
||||
}
|
||||
|
||||
virtual void SetProperty(const int key, const std::string& value, const int slot = 0);
|
||||
virtual std::string GetProperty(const int key, const std::string& default_ = "", const int slot = 0);
|
||||
virtual void SetProperty(const int key, const int value, const int slot = 0);
|
||||
virtual int GetProperty(const int key, const int default_ = 0, const int slot = 0);
|
||||
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);
|
||||
|
||||
/**
|
||||
* Sends the currently available output of the Sampler Task as part of a multipart message
|
||||
|
@ -87,20 +82,19 @@ class GenericSampler: public FairMQDevice,
|
|||
// temporary disabled
|
||||
//void SendPart();
|
||||
|
||||
void SetContinuous(bool flag) { fContinuous = flag; }
|
||||
void SetContinuous(bool flag);
|
||||
|
||||
protected:
|
||||
virtual void Init();
|
||||
virtual void InitTask();
|
||||
virtual void Run();
|
||||
|
||||
protected:
|
||||
std::string fInputFile; // Filename of a root file containing the simulated digis.
|
||||
std::string fParFile;
|
||||
std::string fBranch; // The name of the sub-detector branch to stream the digis from.
|
||||
int64_t fNumEvents;
|
||||
int fEventRate;
|
||||
int fEventCounter;
|
||||
bool fContinuous;
|
||||
std::string fInputFile; // Filename of a root file containing the simulated digis.
|
||||
std::string fParFile;
|
||||
std::string fBranch; // The name of the sub-detector branch to stream the digis from.
|
||||
};
|
||||
|
||||
#include "GenericSampler.tpl"
|
||||
|
|
|
@ -6,11 +6,14 @@
|
|||
*/
|
||||
|
||||
template <typename SamplerPolicy, typename OutputPolicy>
|
||||
GenericSampler<SamplerPolicy,OutputPolicy>::GenericSampler() :
|
||||
fNumEvents(0),
|
||||
fEventRate(1),
|
||||
fEventCounter(0),
|
||||
fContinuous(false)
|
||||
GenericSampler<SamplerPolicy,OutputPolicy>::GenericSampler()
|
||||
: fNumEvents(0)
|
||||
, fEventRate(1)
|
||||
, fEventCounter(0)
|
||||
, fContinuous(false)
|
||||
, fInputFile()
|
||||
, fParFile()
|
||||
, fBranch()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -27,9 +30,8 @@ void GenericSampler<SamplerPolicy,OutputPolicy>::SetTransport(FairMQTransportFac
|
|||
}
|
||||
|
||||
template <typename SamplerPolicy, typename OutputPolicy>
|
||||
void GenericSampler<SamplerPolicy,OutputPolicy>::Init()
|
||||
void GenericSampler<SamplerPolicy,OutputPolicy>::InitTask()
|
||||
{
|
||||
FairMQDevice::Init();
|
||||
SamplerPolicy::InitSampler();
|
||||
fNumEvents = SamplerPolicy::GetNumberOfEvent();
|
||||
}
|
||||
|
@ -37,11 +39,7 @@ void GenericSampler<SamplerPolicy,OutputPolicy>::Init()
|
|||
template <typename SamplerPolicy, typename OutputPolicy>
|
||||
void GenericSampler<SamplerPolicy,OutputPolicy>::Run()
|
||||
{
|
||||
LOG(INFO) << ">>>>>>> Run <<<<<<<";
|
||||
|
||||
boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
// boost::thread resetEventCounter(boost::bind(&GenericSampler::ResetEventCounter, this));
|
||||
// boost::thread commandListener(boost::bind(&GenericSampler::ListenToCommands, this));
|
||||
|
||||
int sentMsgs = 0;
|
||||
|
||||
|
@ -49,21 +47,19 @@ void GenericSampler<SamplerPolicy,OutputPolicy>::Run()
|
|||
|
||||
LOG(INFO) << "Number of events to process: " << fNumEvents;
|
||||
|
||||
// while ( fState == RUNNING ) {
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
for (int64_t eventNr = 0; eventNr < fNumEvents; ++eventNr)
|
||||
{
|
||||
//fSamplerTask->SetEventIndex(eventNr);
|
||||
FairMQMessage* msg = fTransportFactory->CreateMessage();
|
||||
OutputPolicy::SetMessage(msg);
|
||||
fPayloadOutputs->at(0)->Send(OutputPolicy::SerializeMsg(
|
||||
SamplerPolicy::GetDataBranch(eventNr)));
|
||||
fChannels["data-out"].at(0).Send(OutputPolicy::SerializeMsg(SamplerPolicy::GetDataBranch(eventNr)));
|
||||
++sentMsgs;
|
||||
|
||||
if (msg)
|
||||
{
|
||||
msg->CloseMessage();
|
||||
}
|
||||
|
||||
// Optional event rate limiting
|
||||
// --fEventCounter;
|
||||
|
@ -71,50 +67,38 @@ void GenericSampler<SamplerPolicy,OutputPolicy>::Run()
|
|||
// boost::this_thread::sleep(boost::posix_time::milliseconds(1));
|
||||
// }
|
||||
|
||||
if( fState != RUNNING ) { break; }
|
||||
if (GetCurrentState() != RUNNING)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
while ( fState == RUNNING && fContinuous );
|
||||
|
||||
// }
|
||||
}
|
||||
while ( GetCurrentState() == RUNNING && fContinuous );
|
||||
|
||||
boost::timer::cpu_times const elapsed_time(timer.elapsed());
|
||||
LOG(INFO) << "Sent everything in:\n" << boost::timer::format(elapsed_time, 2);
|
||||
LOG(INFO) << "Sent " << sentMsgs << " messages!";
|
||||
|
||||
try {
|
||||
rateLogger.interrupt();
|
||||
rateLogger.join();
|
||||
// resetEventCounter.interrupt();
|
||||
// resetEventCounter.join();
|
||||
// commandListener.interrupt();
|
||||
// commandListener.join();
|
||||
}
|
||||
catch (boost::thread_resource_error &e) {
|
||||
LOG(ERROR) << e.what();
|
||||
}
|
||||
|
||||
FairMQDevice::Shutdown();
|
||||
|
||||
// notify parent thread about end of processing.
|
||||
boost::lock_guard<boost::mutex> lock(fRunningMutex);
|
||||
fRunningFinished = true;
|
||||
fRunningCondition.notify_one();
|
||||
}
|
||||
|
||||
/*
|
||||
template <typename SamplerPolicy, typename OutputPolicy>
|
||||
void GenericSampler<SamplerPolicy,OutputPolicy>::SendPart()
|
||||
{
|
||||
fPayloadOutputs->at(0)->Send(OutputPolicy::GetMessage(), "snd-more");
|
||||
fChannels["data-out"].at(0).Send(OutputPolicy::GetMessage(), "snd-more");
|
||||
OutputPolicy::CloseMessage();
|
||||
}
|
||||
*/
|
||||
|
||||
template <typename SamplerPolicy, typename OutputPolicy>
|
||||
void GenericSampler<SamplerPolicy,OutputPolicy>::SetContinuous(bool flag)
|
||||
{
|
||||
fContinuous = flag;
|
||||
}
|
||||
|
||||
template <typename SamplerPolicy, typename OutputPolicy>
|
||||
void GenericSampler<SamplerPolicy,OutputPolicy>::ResetEventCounter()
|
||||
{
|
||||
while (true)
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -131,38 +115,7 @@ void GenericSampler<SamplerPolicy,OutputPolicy>::ResetEventCounter()
|
|||
}
|
||||
|
||||
template <typename SamplerPolicy, typename OutputPolicy>
|
||||
void GenericSampler<SamplerPolicy,OutputPolicy>::ListenToCommands()
|
||||
{
|
||||
LOG(INFO) << ">>>>>>> ListenToCommands <<<<<<<";
|
||||
|
||||
int received = 0;
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
FairMQMessage *msg = fTransportFactory->CreateMessage();
|
||||
|
||||
received = fPayloadInputs->at(0)->Receive(msg);
|
||||
|
||||
if (received > 0) {
|
||||
// command handling goes here.
|
||||
LOG(INFO) << "> received command <";
|
||||
received = 0;
|
||||
}
|
||||
|
||||
delete msg;
|
||||
|
||||
boost::this_thread::interruption_point();
|
||||
}
|
||||
catch (boost::thread_interrupted &) {
|
||||
LOG(DEBUG) << "commandListener interrupted";
|
||||
break;
|
||||
}
|
||||
}
|
||||
LOG(DEBUG) << ">>>>>>> stopping commandListener <<<<<<<";
|
||||
}
|
||||
|
||||
template <typename SamplerPolicy, typename OutputPolicy>
|
||||
void GenericSampler<SamplerPolicy,OutputPolicy>::SetProperty(const int key, const std::string& value, const int slot/*= 0*/)
|
||||
void GenericSampler<SamplerPolicy,OutputPolicy>::SetProperty(const int key, const std::string& value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
|
@ -176,13 +129,13 @@ void GenericSampler<SamplerPolicy,OutputPolicy>::SetProperty(const int key, cons
|
|||
fBranch = value;
|
||||
break;
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value, slot);
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename SamplerPolicy, typename OutputPolicy>
|
||||
std::string GenericSampler<SamplerPolicy,OutputPolicy>::GetProperty(const int key, const std::string& default_/*= ""*/, const int slot/*= 0*/)
|
||||
std::string GenericSampler<SamplerPolicy,OutputPolicy>::GetProperty(const int key, const std::string& default_/*= ""*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
|
@ -193,12 +146,12 @@ std::string GenericSampler<SamplerPolicy,OutputPolicy>::GetProperty(const int ke
|
|||
case Branch:
|
||||
return fBranch;
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_, slot);
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename SamplerPolicy, typename OutputPolicy>
|
||||
void GenericSampler<SamplerPolicy,OutputPolicy>::SetProperty(const int key, const int value, const int slot/*= 0*/)
|
||||
void GenericSampler<SamplerPolicy,OutputPolicy>::SetProperty(const int key, const int value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
|
@ -206,19 +159,19 @@ void GenericSampler<SamplerPolicy,OutputPolicy>::SetProperty(const int key, cons
|
|||
fEventRate = value;
|
||||
break;
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value, slot);
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename SamplerPolicy, typename OutputPolicy>
|
||||
int GenericSampler<SamplerPolicy,OutputPolicy>::GetProperty(const int key, const int default_/*= 0*/, const int slot/*= 0*/)
|
||||
int GenericSampler<SamplerPolicy,OutputPolicy>::GetProperty(const int key, const int default_/*= 0*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
case EventRate:
|
||||
return fEventRate;
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_, slot);
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,9 +36,7 @@ void FairMQExampleClient::CustomCleanup(void *data, void *hint)
|
|||
|
||||
void FairMQExampleClient::Run()
|
||||
{
|
||||
// boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
|
||||
while (fState == RUNNING)
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
|
||||
|
||||
|
@ -49,26 +47,17 @@ void FairMQExampleClient::Run()
|
|||
|
||||
LOG(INFO) << "Sending \"" << fText << "\" to server.";
|
||||
|
||||
fPayloadOutputs->at(0)->Send(request);
|
||||
fPayloadOutputs->at(0)->Receive(reply);
|
||||
fChannels["data"].at(0).Send(request);
|
||||
fChannels["data"].at(0).Receive(reply);
|
||||
|
||||
LOG(INFO) << "Received reply from server: \"" << string(static_cast<char*>(reply->GetData()), reply->GetSize()) << "\"";
|
||||
|
||||
delete reply;
|
||||
}
|
||||
|
||||
// rateLogger.interrupt();
|
||||
// rateLogger.join();
|
||||
|
||||
FairMQDevice::Shutdown();
|
||||
|
||||
boost::lock_guard<boost::mutex> lock(fRunningMutex);
|
||||
fRunningFinished = true;
|
||||
fRunningCondition.notify_one();
|
||||
}
|
||||
|
||||
|
||||
void FairMQExampleClient::SetProperty(const int key, const string& value, const int slot /*= 0*/)
|
||||
void FairMQExampleClient::SetProperty(const int key, const string& value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
|
@ -76,12 +65,12 @@ void FairMQExampleClient::SetProperty(const int key, const string& value, const
|
|||
fText = value;
|
||||
break;
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value, slot);
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string FairMQExampleClient::GetProperty(const int key, const string& default_ /*= ""*/, const int slot /*= 0*/)
|
||||
string FairMQExampleClient::GetProperty(const int key, const string& default_ /*= ""*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
|
@ -89,25 +78,25 @@ string FairMQExampleClient::GetProperty(const int key, const string& default_ /*
|
|||
return fText;
|
||||
break;
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_, slot);
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQExampleClient::SetProperty(const int key, const int value, const int slot /*= 0*/)
|
||||
void FairMQExampleClient::SetProperty(const int key, const int value)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
default:
|
||||
FairMQDevice::SetProperty(key, value, slot);
|
||||
FairMQDevice::SetProperty(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int FairMQExampleClient::GetProperty(const int key, const int default_ /*= 0*/, const int slot /*= 0*/)
|
||||
int FairMQExampleClient::GetProperty(const int key, const int default_ /*= 0*/)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
default:
|
||||
return FairMQDevice::GetProperty(key, default_, slot);
|
||||
return FairMQDevice::GetProperty(key, default_);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,10 +32,10 @@ class FairMQExampleClient : public FairMQDevice
|
|||
|
||||
static void CustomCleanup(void* data, void* hint);
|
||||
|
||||
virtual void SetProperty(const int key, const std::string& value, const int slot = 0);
|
||||
virtual std::string GetProperty(const int key, const std::string& default_ = "", const int slot = 0);
|
||||
virtual void SetProperty(const int key, const int value, const int slot = 0);
|
||||
virtual int GetProperty(const int key, const int default_ = 0, const int slot = 0);
|
||||
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);
|
||||
|
||||
protected:
|
||||
std::string fText;
|
||||
|
|
|
@ -31,15 +31,13 @@ void FairMQExampleServer::CustomCleanup(void *data, void *hint)
|
|||
|
||||
void FairMQExampleServer::Run()
|
||||
{
|
||||
// boost::thread rateLogger(boost::bind(&FairMQDevice::LogSocketRates, this));
|
||||
|
||||
while (fState == RUNNING)
|
||||
while (GetCurrentState() == RUNNING)
|
||||
{
|
||||
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
|
||||
|
||||
FairMQMessage* request = fTransportFactory->CreateMessage();
|
||||
|
||||
fPayloadInputs->at(0)->Receive(request);
|
||||
fChannels["data"].at(0).Receive(request);
|
||||
|
||||
LOG(INFO) << "Received request from client: \"" << string(static_cast<char*>(request->GetData()), request->GetSize()) << "\"";
|
||||
|
||||
|
@ -51,17 +49,8 @@ void FairMQExampleServer::Run()
|
|||
|
||||
FairMQMessage* reply = fTransportFactory->CreateMessage(const_cast<char*>(text->c_str()), text->length(), CustomCleanup, text);
|
||||
|
||||
fPayloadInputs->at(0)->Send(reply);
|
||||
fChannels["data"].at(0).Send(reply);
|
||||
}
|
||||
|
||||
// rateLogger.interrupt();
|
||||
// rateLogger.join();
|
||||
|
||||
FairMQDevice::Shutdown();
|
||||
|
||||
boost::lock_guard<boost::mutex> lock(fRunningMutex);
|
||||
fRunningFinished = true;
|
||||
fRunningCondition.notify_one();
|
||||
}
|
||||
|
||||
FairMQExampleServer::~FairMQExampleServer()
|
||||
|
|
|
@ -32,12 +32,11 @@ FairMQExampleClient client;
|
|||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
cout << endl << "Caught signal " << signal << endl;
|
||||
LOG(INFO) << "Caught signal " << signal;
|
||||
|
||||
client.ChangeState(FairMQExampleClient::STOP);
|
||||
client.ChangeState(FairMQExampleClient::END);
|
||||
|
||||
cout << "Shutdown complete. Bye!" << endl;
|
||||
LOG(INFO) << "Shutdown complete.";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -115,33 +114,31 @@ int main(int argc, char** argv)
|
|||
|
||||
client.SetProperty(FairMQExampleClient::Id, "client");
|
||||
client.SetProperty(FairMQExampleClient::NumIoThreads, 1);
|
||||
client.SetProperty(FairMQExampleClient::NumInputs, 0);
|
||||
client.SetProperty(FairMQExampleClient::NumOutputs, 1);
|
||||
|
||||
client.ChangeState(FairMQExampleClient::INIT);
|
||||
FairMQChannel requestChannel("req", "connect", "tcp://localhost:5005");
|
||||
requestChannel.fSndBufSize = 10000;
|
||||
requestChannel.fRcvBufSize = 10000;
|
||||
requestChannel.fRateLogging = 1;
|
||||
|
||||
client.SetProperty(FairMQExampleClient::OutputSocketType, "req", 0);
|
||||
client.SetProperty(FairMQExampleClient::OutputSndBufSize, 10000, 0);
|
||||
client.SetProperty(FairMQExampleClient::OutputRcvBufSize, 10000, 0);
|
||||
client.SetProperty(FairMQExampleClient::OutputMethod, "connect", 0);
|
||||
client.SetProperty(FairMQExampleClient::OutputAddress, "tcp://localhost:5005", 0);
|
||||
client.fChannels["data"].push_back(requestChannel);
|
||||
|
||||
client.SetProperty(FairMQExampleClient::Text, options.text);
|
||||
client.ChangeState(FairMQExampleClient::INIT_DEVICE);
|
||||
client.WaitForEndOfState(FairMQExampleClient::INIT_DEVICE);
|
||||
|
||||
client.ChangeState(FairMQExampleClient::INIT_TASK);
|
||||
client.WaitForEndOfState(FairMQExampleClient::INIT_TASK);
|
||||
|
||||
client.ChangeState(FairMQExampleClient::SETOUTPUT);
|
||||
client.ChangeState(FairMQExampleClient::SETINPUT);
|
||||
client.ChangeState(FairMQExampleClient::BIND);
|
||||
client.ChangeState(FairMQExampleClient::CONNECT);
|
||||
client.ChangeState(FairMQExampleClient::RUN);
|
||||
|
||||
// wait until the running thread has finished processing.
|
||||
boost::unique_lock<boost::mutex> lock(client.fRunningMutex);
|
||||
while (!client.fRunningFinished)
|
||||
{
|
||||
client.fRunningCondition.wait(lock);
|
||||
}
|
||||
client.WaitForEndOfState(FairMQExampleClient::RUN);
|
||||
|
||||
client.ChangeState(FairMQExampleClient::STOP);
|
||||
|
||||
client.ChangeState(FairMQExampleClient::RESET_TASK);
|
||||
client.WaitForEndOfState(FairMQExampleClient::RESET_TASK);
|
||||
|
||||
client.ChangeState(FairMQExampleClient::RESET_DEVICE);
|
||||
client.WaitForEndOfState(FairMQExampleClient::RESET_DEVICE);
|
||||
|
||||
client.ChangeState(FairMQExampleClient::END);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -30,12 +30,11 @@ FairMQExampleServer server;
|
|||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
cout << endl << "Caught signal " << signal << endl;
|
||||
LOG(INFO) << "Caught signal " << signal;
|
||||
|
||||
server.ChangeState(FairMQExampleServer::STOP);
|
||||
server.ChangeState(FairMQExampleServer::END);
|
||||
|
||||
cout << "Shutdown complete. Bye!" << endl;
|
||||
LOG(INFO) << "Caught signal " << signal;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -65,34 +64,31 @@ int main(int argc, char** argv)
|
|||
|
||||
server.SetProperty(FairMQExampleServer::Id, "server");
|
||||
server.SetProperty(FairMQExampleServer::NumIoThreads, 1);
|
||||
server.SetProperty(FairMQExampleServer::NumInputs, 1);
|
||||
server.SetProperty(FairMQExampleServer::NumOutputs, 0);
|
||||
|
||||
server.ChangeState(FairMQExampleServer::INIT);
|
||||
FairMQChannel replyChannel("rep", "bind", "tcp://*:5005");
|
||||
replyChannel.fSndBufSize = 10000;
|
||||
replyChannel.fRcvBufSize = 10000;
|
||||
replyChannel.fRateLogging = 1;
|
||||
|
||||
server.SetProperty(FairMQExampleServer::InputSocketType, "rep", 0);
|
||||
server.SetProperty(FairMQExampleServer::InputSndBufSize, 10000, 0);
|
||||
server.SetProperty(FairMQExampleServer::InputRcvBufSize, 10000, 0);
|
||||
server.SetProperty(FairMQExampleServer::InputMethod, "bind", 0);
|
||||
server.SetProperty(FairMQExampleServer::InputAddress, "tcp://*:5005", 0);
|
||||
server.fChannels["data"].push_back(replyChannel);
|
||||
|
||||
server.ChangeState(FairMQExampleServer::SETOUTPUT);
|
||||
server.ChangeState(FairMQExampleServer::SETINPUT);
|
||||
server.ChangeState(FairMQExampleServer::BIND);
|
||||
server.ChangeState(FairMQExampleServer::CONNECT);
|
||||
server.ChangeState(FairMQExampleServer::INIT_DEVICE);
|
||||
server.WaitForEndOfState(FairMQExampleServer::INIT_DEVICE);
|
||||
|
||||
LOG(INFO) << "Listening for requests!";
|
||||
server.ChangeState(FairMQExampleServer::INIT_TASK);
|
||||
server.WaitForEndOfState(FairMQExampleServer::INIT_TASK);
|
||||
|
||||
server.ChangeState(FairMQExampleServer::RUN);
|
||||
|
||||
// wait until the running thread has finished processing.
|
||||
boost::unique_lock<boost::mutex> lock(server.fRunningMutex);
|
||||
while (!server.fRunningFinished)
|
||||
{
|
||||
server.fRunningCondition.wait(lock);
|
||||
}
|
||||
server.WaitForEndOfState(FairMQExampleServer::RUN);
|
||||
|
||||
server.ChangeState(FairMQExampleServer::STOP);
|
||||
|
||||
server.ChangeState(FairMQExampleServer::RESET_TASK);
|
||||
server.WaitForEndOfState(FairMQExampleServer::RESET_TASK);
|
||||
|
||||
server.ChangeState(FairMQExampleServer::RESET_DEVICE);
|
||||
server.WaitForEndOfState(FairMQExampleServer::RESET_DEVICE);
|
||||
|
||||
server.ChangeState(FairMQExampleServer::END);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -140,8 +140,7 @@ void FairMQMessageNN::Copy(FairMQMessage* msg)
|
|||
{
|
||||
if (fMessage)
|
||||
{
|
||||
int rc = nn_freemsg(fMessage);
|
||||
if (rc < 0)
|
||||
if (nn_freemsg(fMessage) < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed freeing message, reason: " << nn_strerror(errno);
|
||||
}
|
||||
|
@ -160,8 +159,7 @@ void FairMQMessageNN::Copy(FairMQMessage* msg)
|
|||
|
||||
inline void FairMQMessageNN::Clear()
|
||||
{
|
||||
int rc = nn_freemsg(fMessage);
|
||||
if (rc < 0)
|
||||
if (nn_freemsg(fMessage) < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed freeing message, reason: " << nn_strerror(errno);
|
||||
}
|
||||
|
|
|
@ -15,32 +15,38 @@
|
|||
#include <nanomsg/nn.h>
|
||||
|
||||
#include "FairMQPollerNN.h"
|
||||
#include "FairMQLogger.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
FairMQPollerNN::FairMQPollerNN(const vector<FairMQSocket*>& inputs)
|
||||
FairMQPollerNN::FairMQPollerNN(const vector<FairMQChannel>& channels)
|
||||
: items()
|
||||
, fNumItems()
|
||||
{
|
||||
fNumItems = inputs.size();
|
||||
fNumItems = channels.size();
|
||||
items = new nn_pollfd[fNumItems];
|
||||
|
||||
for (int i = 0; i < fNumItems; i++)
|
||||
for (int i = 0; i < fNumItems; ++i)
|
||||
{
|
||||
items[i].fd = inputs.at(i)->GetSocket(1);
|
||||
items[i].fd = channels.at(i).fSocket->GetSocket(1);
|
||||
items[i].events = NN_POLLIN;
|
||||
}
|
||||
}
|
||||
|
||||
void FairMQPollerNN::Poll(int timeout)
|
||||
{
|
||||
nn_poll(items, fNumItems, timeout);
|
||||
if (nn_poll(items, fNumItems, timeout) < 0)
|
||||
{
|
||||
LOG(ERROR) << "polling failed, reason: " << nn_strerror(errno);
|
||||
}
|
||||
}
|
||||
|
||||
bool FairMQPollerNN::CheckInput(int index)
|
||||
{
|
||||
if (items[index].revents & NN_POLLIN)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -48,7 +54,9 @@ bool FairMQPollerNN::CheckInput(int index)
|
|||
bool FairMQPollerNN::CheckOutput(int index)
|
||||
{
|
||||
if (items[index].revents & NN_POLLOUT)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -56,5 +64,7 @@ bool FairMQPollerNN::CheckOutput(int index)
|
|||
FairMQPollerNN::~FairMQPollerNN()
|
||||
{
|
||||
if (items != NULL)
|
||||
{
|
||||
delete[] items;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
#include <vector>
|
||||
|
||||
#include "FairMQPoller.h"
|
||||
#include "FairMQSocket.h"
|
||||
#include "FairMQChannel.h"
|
||||
|
||||
class FairMQPollerNN : public FairMQPoller
|
||||
{
|
||||
public:
|
||||
FairMQPollerNN(const std::vector<FairMQSocket*>& inputs);
|
||||
FairMQPollerNN(const std::vector<FairMQChannel>& channels);
|
||||
|
||||
virtual void Poll(int timeout);
|
||||
virtual bool CheckInput(int index);
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
FairMQSocketNN::FairMQSocketNN(const string& type, int num, int numIoThreads)
|
||||
FairMQSocketNN::FairMQSocketNN(const string& type, const std::string& name, int numIoThreads)
|
||||
: FairMQSocket(0, 0, NN_DONTWAIT)
|
||||
, fSocket()
|
||||
, fId()
|
||||
|
@ -29,9 +29,7 @@ FairMQSocketNN::FairMQSocketNN(const string& type, int num, int numIoThreads)
|
|||
, fMessagesTx(0)
|
||||
, fMessagesRx(0)
|
||||
{
|
||||
stringstream id;
|
||||
id << type << "." << num;
|
||||
fId = id.str();
|
||||
fId = name + "." + type;
|
||||
|
||||
if (numIoThreads > 1)
|
||||
{
|
||||
|
@ -46,7 +44,7 @@ FairMQSocketNN::FairMQSocketNN(const string& type, int num, int numIoThreads)
|
|||
fSocket = nn_socket(AF_SP_RAW, GetConstant(type));
|
||||
if (fSocket == -1)
|
||||
{
|
||||
LOG(ERROR) << "failed creating socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed creating socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +53,7 @@ FairMQSocketNN::FairMQSocketNN(const string& type, int num, int numIoThreads)
|
|||
fSocket = nn_socket(AF_SP, GetConstant(type));
|
||||
if (fSocket == -1)
|
||||
{
|
||||
LOG(ERROR) << "failed creating socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed creating socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (type == "sub")
|
||||
|
@ -64,7 +62,7 @@ FairMQSocketNN::FairMQSocketNN(const string& type, int num, int numIoThreads)
|
|||
}
|
||||
}
|
||||
|
||||
LOG(INFO) << "created socket #" << fId;
|
||||
LOG(INFO) << "created socket " << fId;
|
||||
}
|
||||
|
||||
string FairMQSocketNN::GetId()
|
||||
|
@ -74,12 +72,12 @@ string FairMQSocketNN::GetId()
|
|||
|
||||
bool FairMQSocketNN::Bind(const string& address)
|
||||
{
|
||||
LOG(INFO) << "bind socket #" << fId << " on " << address;
|
||||
LOG(INFO) << "bind socket " << fId << " on " << address;
|
||||
|
||||
int eid = nn_bind(fSocket, address.c_str());
|
||||
if (eid < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed binding socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed binding socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -87,12 +85,12 @@ bool FairMQSocketNN::Bind(const string& address)
|
|||
|
||||
void FairMQSocketNN::Connect(const string& address)
|
||||
{
|
||||
LOG(INFO) << "connect socket #" << fId << " to " << address;
|
||||
LOG(INFO) << "connect socket " << fId << " to " << address;
|
||||
|
||||
int eid = nn_connect(fSocket, address.c_str());
|
||||
if (eid < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed connecting socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed connecting socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +100,7 @@ int FairMQSocketNN::Send(FairMQMessage* msg, const string& flag)
|
|||
int rc = nn_send(fSocket, &ptr, NN_MSG, 0);
|
||||
if (rc < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed sending on socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed sending on socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -120,7 +118,7 @@ int FairMQSocketNN::Send(FairMQMessage* msg, const int flags)
|
|||
int rc = nn_send(fSocket, &ptr, NN_MSG, flags);
|
||||
if (rc < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed sending on socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed sending on socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -138,7 +136,7 @@ int FairMQSocketNN::Receive(FairMQMessage* msg, const string& flag)
|
|||
int rc = nn_recv(fSocket, &ptr, NN_MSG, 0);
|
||||
if (rc < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed receiving on socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed receiving on socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -157,7 +155,7 @@ int FairMQSocketNN::Receive(FairMQMessage* msg, const int flags)
|
|||
int rc = nn_recv(fSocket, &ptr, NN_MSG, flags);
|
||||
if (rc < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed receiving on socket #" << fId << ", reason: " << nn_strerror(errno);
|
||||
LOG(ERROR) << "failed receiving on socket " << fId << ", reason: " << nn_strerror(errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
class FairMQSocketNN : public FairMQSocket
|
||||
{
|
||||
public:
|
||||
FairMQSocketNN(const std::string& type, int num, int numIoThreads); // numIoThreads is not used in nanomsg.
|
||||
FairMQSocketNN(const std::string& type, const std::string& name, int numIoThreads); // numIoThreads is not used in nanomsg.
|
||||
|
||||
virtual std::string GetId();
|
||||
|
||||
|
@ -34,9 +34,9 @@ class FairMQSocketNN : public FairMQSocket
|
|||
virtual void Connect(const std::string& address);
|
||||
|
||||
virtual int Send(FairMQMessage* msg, const std::string& flag = "");
|
||||
virtual int Send(FairMQMessage* msg, const int flags);
|
||||
virtual int Send(FairMQMessage* msg, const int flags = 0);
|
||||
virtual int Receive(FairMQMessage* msg, const std::string& flag = "");
|
||||
virtual int Receive(FairMQMessage* msg, const int flags);
|
||||
virtual int Receive(FairMQMessage* msg, const int flags = 0);
|
||||
|
||||
virtual void* GetSocket();
|
||||
virtual int GetSocket(int nothing);
|
||||
|
|
|
@ -36,12 +36,12 @@ FairMQMessage* FairMQTransportFactoryNN::CreateMessage(void* data, size_t size,
|
|||
return new FairMQMessageNN(data, size, ffn, hint);
|
||||
}
|
||||
|
||||
FairMQSocket* FairMQTransportFactoryNN::CreateSocket(const string& type, int num, int numIoThreads)
|
||||
FairMQSocket* FairMQTransportFactoryNN::CreateSocket(const string& type, const std::string& name, int numIoThreads)
|
||||
{
|
||||
return new FairMQSocketNN(type, num, numIoThreads);
|
||||
return new FairMQSocketNN(type, name, numIoThreads);
|
||||
}
|
||||
|
||||
FairMQPoller* FairMQTransportFactoryNN::CreatePoller(const vector<FairMQSocket*>& inputs)
|
||||
FairMQPoller* FairMQTransportFactoryNN::CreatePoller(const vector<FairMQChannel>& channels)
|
||||
{
|
||||
return new FairMQPollerNN(inputs);
|
||||
return new FairMQPollerNN(channels);
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ class FairMQTransportFactoryNN : public FairMQTransportFactory
|
|||
virtual FairMQMessage* CreateMessage();
|
||||
virtual FairMQMessage* CreateMessage(size_t size);
|
||||
virtual FairMQMessage* CreateMessage(void* data, size_t size, fairmq_free_fn *ffn = NULL, void* hint = NULL);
|
||||
virtual FairMQSocket* CreateSocket(const std::string& type, int num, int numIoThreads);
|
||||
virtual FairMQPoller* CreatePoller(const std::vector<FairMQSocket*>& inputs);
|
||||
virtual FairMQSocket* CreateSocket(const std::string& type, const std::string& name, int numIoThreads);
|
||||
virtual FairMQPoller* CreatePoller(const std::vector<FairMQChannel>& channels);
|
||||
|
||||
virtual ~FairMQTransportFactoryNN() {};
|
||||
};
|
||||
|
|
|
@ -35,7 +35,6 @@ FairMQBinSampler::~FairMQBinSampler()
|
|||
|
||||
void FairMQBinSampler::Init()
|
||||
{
|
||||
FairMQDevice::Init();
|
||||
}
|
||||
|
||||
void FairMQBinSampler::Run()
|
||||
|
|
|
@ -37,7 +37,6 @@ FairMQProtoSampler::~FairMQProtoSampler()
|
|||
|
||||
void FairMQProtoSampler::Init()
|
||||
{
|
||||
FairMQDevice::Init();
|
||||
}
|
||||
|
||||
void FairMQProtoSampler::Run()
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
* runBenchmarkSampler.cxx
|
||||
*
|
||||
* @since 2013-04-23
|
||||
* @author D. Klein, A. Rybalchenko
|
||||
* @author: D. Klein, A. Rybalchenko
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
@ -32,12 +32,11 @@ FairMQBenchmarkSampler sampler;
|
|||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
cout << endl << "Caught signal " << signal << endl;
|
||||
LOG(INFO) << "Caught signal " << signal;
|
||||
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::STOP);
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::END);
|
||||
|
||||
cout << "Shutdown complete. Bye!" << endl;
|
||||
LOG(INFO) << "Shutdown complete";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -55,7 +54,8 @@ typedef struct DeviceOptions
|
|||
{
|
||||
DeviceOptions() :
|
||||
id(), eventSize(0), eventRate(0), ioThreads(0),
|
||||
outputSocketType(), outputBufSize(0), outputMethod(), outputAddress() {}
|
||||
outputSocketType(), outputBufSize(0), outputMethod(), outputAddress()
|
||||
{}
|
||||
|
||||
string id;
|
||||
int eventSize;
|
||||
|
@ -80,7 +80,7 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
|||
("event-rate", bpo::value<int>()->default_value(0), "Event rate limit in maximum number of events per second")
|
||||
("io-threads", bpo::value<int>()->default_value(1), "Number of I/O threads")
|
||||
("output-socket-type", bpo::value<string>()->required(), "Output socket type: pub/push")
|
||||
("output-buff-size", bpo::value<int>()->required(), "Output buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("output-buff-size", bpo::value<int>()->default_value(1000), "Output buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("output-method", bpo::value<string>()->required(), "Output method: bind/connect")
|
||||
("output-address", bpo::value<string>()->required(), "Output address, e.g.: \"tcp://*:5555\"")
|
||||
("help", "Print help messages");
|
||||
|
@ -151,35 +151,35 @@ int main(int argc, char** argv)
|
|||
|
||||
sampler.SetTransport(transportFactory);
|
||||
|
||||
FairMQChannel channel(options.outputSocketType, options.outputMethod, options.outputAddress);
|
||||
channel.fSndBufSize = options.outputBufSize;
|
||||
channel.fRcvBufSize = options.outputBufSize;
|
||||
channel.fRateLogging = 1;
|
||||
|
||||
sampler.fChannels["data-out"].push_back(channel);
|
||||
|
||||
sampler.SetProperty(FairMQBenchmarkSampler::Id, options.id);
|
||||
sampler.SetProperty(FairMQBenchmarkSampler::EventSize, options.eventSize);
|
||||
sampler.SetProperty(FairMQBenchmarkSampler::EventRate, options.eventRate);
|
||||
sampler.SetProperty(FairMQBenchmarkSampler::NumIoThreads, options.ioThreads);
|
||||
|
||||
sampler.SetProperty(FairMQBenchmarkSampler::NumInputs, 0);
|
||||
sampler.SetProperty(FairMQBenchmarkSampler::NumOutputs, 1);
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::INIT_DEVICE);
|
||||
sampler.WaitForEndOfState(FairMQBenchmarkSampler::INIT_DEVICE);
|
||||
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::INIT);
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::INIT_TASK);
|
||||
sampler.WaitForEndOfState(FairMQBenchmarkSampler::INIT_TASK);
|
||||
|
||||
sampler.SetProperty(FairMQBenchmarkSampler::OutputSocketType, options.outputSocketType);
|
||||
sampler.SetProperty(FairMQBenchmarkSampler::OutputSndBufSize, options.outputBufSize);
|
||||
sampler.SetProperty(FairMQBenchmarkSampler::OutputMethod, options.outputMethod);
|
||||
sampler.SetProperty(FairMQBenchmarkSampler::OutputAddress, options.outputAddress);
|
||||
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::SETOUTPUT);
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::SETINPUT);
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::BIND);
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::CONNECT);
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::RUN);
|
||||
|
||||
// wait until the running thread has finished processing.
|
||||
boost::unique_lock<boost::mutex> lock(sampler.fRunningMutex);
|
||||
while (!sampler.fRunningFinished)
|
||||
{
|
||||
sampler.fRunningCondition.wait(lock);
|
||||
}
|
||||
sampler.WaitForEndOfState(FairMQBenchmarkSampler::RUN);
|
||||
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::STOP);
|
||||
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::RESET_TASK);
|
||||
sampler.WaitForEndOfState(FairMQBenchmarkSampler::RESET_TASK);
|
||||
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::RESET_DEVICE);
|
||||
sampler.WaitForEndOfState(FairMQBenchmarkSampler::RESET_DEVICE);
|
||||
|
||||
sampler.ChangeState(FairMQBenchmarkSampler::END);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -32,12 +32,11 @@ FairMQBuffer buffer;
|
|||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
cout << endl << "Caught signal " << signal << endl;
|
||||
LOG(INFO) << "Caught signal " << signal;
|
||||
|
||||
buffer.ChangeState(FairMQBuffer::STOP);
|
||||
buffer.ChangeState(FairMQBuffer::END);
|
||||
|
||||
cout << "Shutdown complete. Bye!" << endl;
|
||||
LOG(INFO) << "Shutdown complete";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -81,11 +80,11 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
|||
("id", bpo::value<string>(), "Device ID")
|
||||
("io-threads", bpo::value<int>()->default_value(1), "Number of I/O threads")
|
||||
("input-socket-type", bpo::value<string>()->required(), "Input socket type: sub/pull")
|
||||
("input-buff-size", bpo::value<int>()->required(), "Input buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("input-buff-size", bpo::value<int>()->default_value(1000), "Input buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("input-method", bpo::value<string>()->required(), "Input method: bind/connect")
|
||||
("input-address", bpo::value<string>()->required(), "Input address, e.g.: \"tcp://localhost:5555\"")
|
||||
("output-socket-type", bpo::value<string>()->required(), "Output socket type: pub/push")
|
||||
("output-buff-size", bpo::value<int>()->required(), "Output buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("output-buff-size", bpo::value<int>()->default_value(1000), "Output buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("output-method", bpo::value<string>()->required(), "Output method: bind/connect")
|
||||
("output-address", bpo::value<string>()->required(), "Output address, e.g.: \"tcp://localhost:5555\"")
|
||||
("help", "Print help messages");
|
||||
|
@ -160,38 +159,40 @@ int main(int argc, char** argv)
|
|||
|
||||
buffer.SetTransport(transportFactory);
|
||||
|
||||
FairMQChannel inputChannel(options.inputSocketType, options.inputMethod, options.inputAddress);
|
||||
inputChannel.fSndBufSize = options.inputBufSize;
|
||||
inputChannel.fRcvBufSize = options.inputBufSize;
|
||||
inputChannel.fRateLogging = 1;
|
||||
|
||||
buffer.fChannels["data-in"].push_back(inputChannel);
|
||||
|
||||
FairMQChannel outputChannel(options.outputSocketType, options.outputMethod, options.outputAddress);
|
||||
outputChannel.fSndBufSize = options.outputBufSize;
|
||||
outputChannel.fRcvBufSize = options.outputBufSize;
|
||||
outputChannel.fRateLogging = 1;
|
||||
|
||||
buffer.fChannels["data-out"].push_back(outputChannel);
|
||||
|
||||
buffer.SetProperty(FairMQBuffer::Id, options.id);
|
||||
buffer.SetProperty(FairMQBuffer::NumIoThreads, options.ioThreads);
|
||||
|
||||
buffer.SetProperty(FairMQBuffer::NumInputs, 1);
|
||||
buffer.SetProperty(FairMQBuffer::NumOutputs, 1);
|
||||
buffer.ChangeState(FairMQBuffer::INIT_DEVICE);
|
||||
buffer.WaitForEndOfState(FairMQBuffer::INIT_DEVICE);
|
||||
|
||||
buffer.ChangeState(FairMQBuffer::INIT);
|
||||
buffer.ChangeState(FairMQBuffer::INIT_TASK);
|
||||
buffer.WaitForEndOfState(FairMQBuffer::INIT_TASK);
|
||||
|
||||
buffer.SetProperty(FairMQBuffer::InputSocketType, options.inputSocketType);
|
||||
buffer.SetProperty(FairMQBuffer::InputRcvBufSize, options.inputBufSize);
|
||||
buffer.SetProperty(FairMQBuffer::InputMethod, options.inputMethod);
|
||||
buffer.SetProperty(FairMQBuffer::InputAddress, options.inputAddress);
|
||||
|
||||
buffer.SetProperty(FairMQBuffer::OutputSocketType, options.outputSocketType);
|
||||
buffer.SetProperty(FairMQBuffer::OutputSndBufSize, options.outputBufSize);
|
||||
buffer.SetProperty(FairMQBuffer::OutputMethod, options.outputMethod);
|
||||
buffer.SetProperty(FairMQBuffer::OutputAddress, options.outputAddress);
|
||||
|
||||
buffer.ChangeState(FairMQBuffer::SETOUTPUT);
|
||||
buffer.ChangeState(FairMQBuffer::SETINPUT);
|
||||
buffer.ChangeState(FairMQBuffer::BIND);
|
||||
buffer.ChangeState(FairMQBuffer::CONNECT);
|
||||
buffer.ChangeState(FairMQBuffer::RUN);
|
||||
|
||||
// wait until the running thread has finished processing.
|
||||
boost::unique_lock<boost::mutex> lock(buffer.fRunningMutex);
|
||||
while (!buffer.fRunningFinished)
|
||||
{
|
||||
buffer.fRunningCondition.wait(lock);
|
||||
}
|
||||
buffer.WaitForEndOfState(FairMQBuffer::RUN);
|
||||
|
||||
buffer.ChangeState(FairMQBuffer::STOP);
|
||||
|
||||
buffer.ChangeState(FairMQBuffer::RESET_TASK);
|
||||
buffer.WaitForEndOfState(FairMQBuffer::RESET_TASK);
|
||||
|
||||
buffer.ChangeState(FairMQBuffer::RESET_DEVICE);
|
||||
buffer.WaitForEndOfState(FairMQBuffer::RESET_DEVICE);
|
||||
|
||||
buffer.ChangeState(FairMQBuffer::END);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -32,12 +32,11 @@ FairMQMerger merger;
|
|||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
cout << endl << "Caught signal " << signal << endl;
|
||||
LOG(INFO) << "Caught signal " << signal;
|
||||
|
||||
merger.ChangeState(FairMQMerger::STOP);
|
||||
merger.ChangeState(FairMQMerger::END);
|
||||
|
||||
cout << "Shutdown complete. Bye!" << endl;
|
||||
LOG(INFO) << "Shutdown complete.";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -165,41 +164,43 @@ int main(int argc, char** argv)
|
|||
|
||||
merger.SetTransport(transportFactory);
|
||||
|
||||
for (int i = 0; i < options.inputAddress.size(); ++i)
|
||||
{
|
||||
FairMQChannel inputChannel(options.inputSocketType.at(i), options.inputMethod.at(i), options.inputAddress.at(i));
|
||||
inputChannel.fSndBufSize = options.inputBufSize.at(i);
|
||||
inputChannel.fRcvBufSize = options.inputBufSize.at(i);
|
||||
inputChannel.fRateLogging = 1;
|
||||
|
||||
merger.fChannels["data-in"].push_back(inputChannel);
|
||||
}
|
||||
|
||||
FairMQChannel outputChannel(options.outputSocketType, options.outputMethod, options.outputAddress);
|
||||
outputChannel.fSndBufSize = options.outputBufSize;
|
||||
outputChannel.fRcvBufSize = options.outputBufSize;
|
||||
outputChannel.fRateLogging = 1;
|
||||
|
||||
merger.fChannels["data-out"].push_back(outputChannel);
|
||||
|
||||
merger.SetProperty(FairMQMerger::Id, options.id);
|
||||
merger.SetProperty(FairMQMerger::NumIoThreads, options.ioThreads);
|
||||
|
||||
merger.SetProperty(FairMQMerger::NumInputs, options.numInputs);
|
||||
merger.SetProperty(FairMQMerger::NumOutputs, 1);
|
||||
merger.ChangeState(FairMQMerger::INIT_DEVICE);
|
||||
merger.WaitForEndOfState(FairMQMerger::INIT_DEVICE);
|
||||
|
||||
merger.ChangeState(FairMQMerger::INIT);
|
||||
merger.ChangeState(FairMQMerger::INIT_TASK);
|
||||
merger.WaitForEndOfState(FairMQMerger::INIT_TASK);
|
||||
|
||||
for (int i = 0; i < options.numInputs; ++i)
|
||||
{
|
||||
merger.SetProperty(FairMQMerger::InputSocketType, options.inputSocketType.at(i), i);
|
||||
merger.SetProperty(FairMQMerger::InputRcvBufSize, options.inputBufSize.at(i), i);
|
||||
merger.SetProperty(FairMQMerger::InputMethod, options.inputMethod.at(i), i);
|
||||
merger.SetProperty(FairMQMerger::InputAddress, options.inputAddress.at(i), i);
|
||||
}
|
||||
|
||||
merger.SetProperty(FairMQMerger::OutputSocketType, options.outputSocketType);
|
||||
merger.SetProperty(FairMQMerger::OutputSndBufSize, options.outputBufSize);
|
||||
merger.SetProperty(FairMQMerger::OutputMethod, options.outputMethod);
|
||||
merger.SetProperty(FairMQMerger::OutputAddress, options.outputAddress);
|
||||
|
||||
merger.ChangeState(FairMQMerger::SETOUTPUT);
|
||||
merger.ChangeState(FairMQMerger::SETINPUT);
|
||||
merger.ChangeState(FairMQMerger::BIND);
|
||||
merger.ChangeState(FairMQMerger::CONNECT);
|
||||
merger.ChangeState(FairMQMerger::RUN);
|
||||
|
||||
// wait until the running thread has finished processing.
|
||||
boost::unique_lock<boost::mutex> lock(merger.fRunningMutex);
|
||||
while (!merger.fRunningFinished)
|
||||
{
|
||||
merger.fRunningCondition.wait(lock);
|
||||
}
|
||||
merger.WaitForEndOfState(FairMQMerger::RUN);
|
||||
|
||||
merger.ChangeState(FairMQMerger::STOP);
|
||||
|
||||
merger.ChangeState(FairMQMerger::RESET_TASK);
|
||||
merger.WaitForEndOfState(FairMQMerger::RESET_TASK);
|
||||
|
||||
merger.ChangeState(FairMQMerger::RESET_DEVICE);
|
||||
merger.WaitForEndOfState(FairMQMerger::RESET_DEVICE);
|
||||
|
||||
merger.ChangeState(FairMQMerger::END);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -32,12 +32,11 @@ FairMQProxy proxy;
|
|||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
cout << endl << "Caught signal " << signal << endl;
|
||||
LOG(INFO) << "Caught signal " << signal;
|
||||
|
||||
proxy.ChangeState(FairMQProxy::STOP);
|
||||
proxy.ChangeState(FairMQProxy::END);
|
||||
|
||||
cout << "Shutdown complete. Bye!" << endl;
|
||||
LOG(INFO) << "Shutdown complete.";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -81,11 +80,11 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
|||
("id", bpo::value<string>()->required(), "Device ID")
|
||||
("io-threads", bpo::value<int>()->default_value(1), "Number of I/O threads")
|
||||
("input-socket-type", bpo::value<string>()->required(), "Input socket type: sub/pull")
|
||||
("input-buff-size", bpo::value<int>()->required(), "Input buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("input-buff-size", bpo::value<int>()->default_value(1000), "Input buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("input-method", bpo::value<string>()->required(), "Input method: bind/connect")
|
||||
("input-address", bpo::value<string>()->required(), "Input address, e.g.: \"tcp://localhost:5555\"")
|
||||
("output-socket-type", bpo::value<string>()->required(), "Output socket type: pub/push")
|
||||
("output-buff-size", bpo::value<int>()->required(), "Output buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("output-buff-size", bpo::value<int>()->default_value(1000), "Output buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("output-method", bpo::value<string>()->required(), "Output method: bind/connect")
|
||||
("output-address", bpo::value<string>()->required(), "Output address, e.g.: \"tcp://localhost:5555\"")
|
||||
("help", "Print help messages");
|
||||
|
@ -160,38 +159,40 @@ int main(int argc, char** argv)
|
|||
|
||||
proxy.SetTransport(transportFactory);
|
||||
|
||||
FairMQChannel inputChannel(options.inputSocketType, options.inputMethod, options.inputAddress);
|
||||
inputChannel.fSndBufSize = options.inputBufSize;
|
||||
inputChannel.fRcvBufSize = options.inputBufSize;
|
||||
inputChannel.fRateLogging = 1;
|
||||
|
||||
proxy.fChannels["data-in"].push_back(inputChannel);
|
||||
|
||||
FairMQChannel outputChannel(options.outputSocketType, options.outputMethod, options.outputAddress);
|
||||
outputChannel.fSndBufSize = options.outputBufSize;
|
||||
outputChannel.fRcvBufSize = options.outputBufSize;
|
||||
outputChannel.fRateLogging = 1;
|
||||
|
||||
proxy.fChannels["data-out"].push_back(outputChannel);
|
||||
|
||||
proxy.SetProperty(FairMQProxy::Id, options.id);
|
||||
proxy.SetProperty(FairMQProxy::NumIoThreads, options.ioThreads);
|
||||
|
||||
proxy.SetProperty(FairMQProxy::NumInputs, 1);
|
||||
proxy.SetProperty(FairMQProxy::NumOutputs, 1);
|
||||
proxy.ChangeState(FairMQProxy::INIT_DEVICE);
|
||||
proxy.WaitForEndOfState(FairMQProxy::INIT_DEVICE);
|
||||
|
||||
proxy.ChangeState(FairMQProxy::INIT);
|
||||
proxy.ChangeState(FairMQProxy::INIT_TASK);
|
||||
proxy.WaitForEndOfState(FairMQProxy::INIT_TASK);
|
||||
|
||||
proxy.SetProperty(FairMQProxy::InputSocketType, options.inputSocketType);
|
||||
proxy.SetProperty(FairMQProxy::InputRcvBufSize, options.inputBufSize);
|
||||
proxy.SetProperty(FairMQProxy::InputMethod, options.inputMethod);
|
||||
proxy.SetProperty(FairMQProxy::InputAddress, options.inputAddress);
|
||||
|
||||
proxy.SetProperty(FairMQProxy::OutputSocketType, options.outputSocketType);
|
||||
proxy.SetProperty(FairMQProxy::OutputSndBufSize, options.outputBufSize);
|
||||
proxy.SetProperty(FairMQProxy::OutputMethod, options.outputMethod);
|
||||
proxy.SetProperty(FairMQProxy::OutputAddress, options.outputAddress);
|
||||
|
||||
proxy.ChangeState(FairMQProxy::SETOUTPUT);
|
||||
proxy.ChangeState(FairMQProxy::SETINPUT);
|
||||
proxy.ChangeState(FairMQProxy::BIND);
|
||||
proxy.ChangeState(FairMQProxy::CONNECT);
|
||||
proxy.ChangeState(FairMQProxy::RUN);
|
||||
|
||||
// wait until the running thread has finished processing.
|
||||
boost::unique_lock<boost::mutex> lock(proxy.fRunningMutex);
|
||||
while (!proxy.fRunningFinished)
|
||||
{
|
||||
proxy.fRunningCondition.wait(lock);
|
||||
}
|
||||
proxy.WaitForEndOfState(FairMQProxy::RUN);
|
||||
|
||||
proxy.ChangeState(FairMQProxy::STOP);
|
||||
|
||||
proxy.ChangeState(FairMQProxy::RESET_TASK);
|
||||
proxy.WaitForEndOfState(FairMQProxy::RESET_TASK);
|
||||
|
||||
proxy.ChangeState(FairMQProxy::RESET_DEVICE);
|
||||
proxy.WaitForEndOfState(FairMQProxy::RESET_DEVICE);
|
||||
|
||||
proxy.ChangeState(FairMQProxy::END);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -32,12 +32,11 @@ FairMQSink sink;
|
|||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
cout << endl << "Caught signal " << signal << endl;
|
||||
LOG(INFO) << "Caught signal " << signal;
|
||||
|
||||
sink.ChangeState(FairMQSink::STOP);
|
||||
sink.ChangeState(FairMQSink::END);
|
||||
|
||||
cout << "Shutdown complete. Bye!" << endl;
|
||||
LOG(INFO) << "Shutdown complete.";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -55,7 +54,8 @@ typedef struct DeviceOptions
|
|||
{
|
||||
DeviceOptions() :
|
||||
id(), ioThreads(0),
|
||||
inputSocketType(), inputBufSize(0), inputMethod(), inputAddress() {}
|
||||
inputSocketType(), inputBufSize(0), inputMethod(), inputAddress()
|
||||
{}
|
||||
|
||||
string id;
|
||||
int ioThreads;
|
||||
|
@ -76,7 +76,7 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
|||
("id", bpo::value<string>()->required(), "Device ID")
|
||||
("io-threads", bpo::value<int>()->default_value(1), "Number of I/O threads")
|
||||
("input-socket-type", bpo::value<string>()->required(), "Input socket type: sub/pull")
|
||||
("input-buff-size", bpo::value<int>()->required(), "Input buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("input-buff-size", bpo::value<int>()->default_value(1000), "Input buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("input-method", bpo::value<string>()->required(), "Input method: bind/connect")
|
||||
("input-address", bpo::value<string>()->required(), "Input address, e.g.: \"tcp://*:5555\"")
|
||||
("help", "Print help messages");
|
||||
|
@ -139,33 +139,33 @@ int main(int argc, char** argv)
|
|||
|
||||
sink.SetTransport(transportFactory);
|
||||
|
||||
FairMQChannel channel(options.inputSocketType, options.inputMethod, options.inputAddress);
|
||||
channel.fSndBufSize = options.inputBufSize;
|
||||
channel.fRcvBufSize = options.inputBufSize;
|
||||
channel.fRateLogging = 1;
|
||||
|
||||
sink.fChannels["data-in"].push_back(channel);
|
||||
|
||||
sink.SetProperty(FairMQSink::Id, options.id);
|
||||
sink.SetProperty(FairMQSink::NumIoThreads, options.ioThreads);
|
||||
|
||||
sink.SetProperty(FairMQSink::NumInputs, 1);
|
||||
sink.SetProperty(FairMQSink::NumOutputs, 0);
|
||||
sink.ChangeState(FairMQSink::INIT_DEVICE);
|
||||
sink.WaitForEndOfState(FairMQSink::INIT_DEVICE);
|
||||
|
||||
sink.ChangeState(FairMQSink::INIT);
|
||||
sink.ChangeState(FairMQSink::INIT_TASK);
|
||||
sink.WaitForEndOfState(FairMQSink::INIT_TASK);
|
||||
|
||||
sink.SetProperty(FairMQSink::InputSocketType, options.inputSocketType);
|
||||
sink.SetProperty(FairMQSink::InputRcvBufSize, options.inputBufSize);
|
||||
sink.SetProperty(FairMQSink::InputMethod, options.inputMethod);
|
||||
sink.SetProperty(FairMQSink::InputAddress, options.inputAddress);
|
||||
|
||||
sink.ChangeState(FairMQSink::SETOUTPUT);
|
||||
sink.ChangeState(FairMQSink::SETINPUT);
|
||||
sink.ChangeState(FairMQSink::BIND);
|
||||
sink.ChangeState(FairMQSink::CONNECT);
|
||||
sink.ChangeState(FairMQSink::RUN);
|
||||
|
||||
// wait until the running thread has finished processing.
|
||||
boost::unique_lock<boost::mutex> lock(sink.fRunningMutex);
|
||||
while (!sink.fRunningFinished)
|
||||
{
|
||||
sink.fRunningCondition.wait(lock);
|
||||
}
|
||||
sink.WaitForEndOfState(FairMQSink::RUN);
|
||||
|
||||
sink.ChangeState(FairMQSink::STOP);
|
||||
|
||||
sink.ChangeState(FairMQSink::RESET_TASK);
|
||||
sink.WaitForEndOfState(FairMQSink::RESET_TASK);
|
||||
|
||||
sink.ChangeState(FairMQSink::RESET_DEVICE);
|
||||
sink.WaitForEndOfState(FairMQSink::RESET_DEVICE);
|
||||
|
||||
sink.ChangeState(FairMQSink::END);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -32,12 +32,11 @@ FairMQSplitter splitter;
|
|||
|
||||
static void s_signal_handler(int signal)
|
||||
{
|
||||
cout << endl << "Caught signal " << signal << endl;
|
||||
LOG(INFO) << "Caught signal " << signal;
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::STOP);
|
||||
splitter.ChangeState(FairMQSplitter::END);
|
||||
|
||||
cout << "Shutdown complete. Bye!" << endl;
|
||||
LOG(INFO) << "Shutdown complete.";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -56,7 +55,8 @@ typedef struct DeviceOptions
|
|||
DeviceOptions() :
|
||||
id(), ioThreads(0), numOutputs(0),
|
||||
inputSocketType(), inputBufSize(0), inputMethod(), inputAddress(),
|
||||
outputSocketType(), outputBufSize(), outputMethod(), outputAddress() {}
|
||||
outputSocketType(), outputBufSize(), outputMethod(), outputAddress()
|
||||
{}
|
||||
|
||||
string id;
|
||||
int ioThreads;
|
||||
|
@ -83,11 +83,11 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
|
|||
("io-threads", bpo::value<int>()->default_value(1), "Number of I/O threads")
|
||||
("num-outputs", bpo::value<int>()->required(), "Number of Splitter output sockets")
|
||||
("input-socket-type", bpo::value<string>()->required(), "Input socket type: sub/pull")
|
||||
("input-buff-size", bpo::value<int>()->required(), "Input buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("input-buff-size", bpo::value<int>(), "Input buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("input-method", bpo::value<string>()->required(), "Input method: bind/connect")
|
||||
("input-address", bpo::value<string>()->required(), "Input address, e.g.: \"tcp://localhost:5555\"")
|
||||
("output-socket-type", bpo::value< vector<string> >()->required(), "Output socket type: pub/push")
|
||||
("output-buff-size", bpo::value< vector<int> >()->required(), "Output buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("output-buff-size", bpo::value< vector<int> >(), "Output buffer size in number of messages (ZeroMQ)/bytes(nanomsg)")
|
||||
("output-method", bpo::value< vector<string> >()->required(), "Output method: bind/connect")
|
||||
("output-address", bpo::value< vector<string> >()->required(), "Output address, e.g.: \"tcp://localhost:5555\"")
|
||||
("help", "Print help messages");
|
||||
|
@ -165,41 +165,43 @@ int main(int argc, char** argv)
|
|||
|
||||
splitter.SetTransport(transportFactory);
|
||||
|
||||
FairMQChannel inputChannel(options.inputSocketType, options.inputMethod, options.inputAddress);
|
||||
inputChannel.fSndBufSize = options.inputBufSize;
|
||||
inputChannel.fRcvBufSize = options.inputBufSize;
|
||||
inputChannel.fRateLogging = 1;
|
||||
|
||||
splitter.fChannels["data-in"].push_back(inputChannel);
|
||||
|
||||
for (int i = 0; i < options.outputAddress.size(); ++i)
|
||||
{
|
||||
FairMQChannel outputChannel(options.outputSocketType.at(i), options.outputMethod.at(i), options.outputAddress.at(i));
|
||||
outputChannel.fSndBufSize = options.outputBufSize.at(i);
|
||||
outputChannel.fRcvBufSize = options.outputBufSize.at(i);
|
||||
outputChannel.fRateLogging = 1;
|
||||
|
||||
splitter.fChannels["data-out"].push_back(outputChannel);
|
||||
}
|
||||
|
||||
splitter.SetProperty(FairMQSplitter::Id, options.id);
|
||||
splitter.SetProperty(FairMQSplitter::NumIoThreads, options.ioThreads);
|
||||
|
||||
splitter.SetProperty(FairMQSplitter::NumInputs, 1);
|
||||
splitter.SetProperty(FairMQSplitter::NumOutputs, options.numOutputs);
|
||||
splitter.ChangeState(FairMQSplitter::INIT_DEVICE);
|
||||
splitter.WaitForEndOfState(FairMQSplitter::INIT_DEVICE);
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::INIT);
|
||||
splitter.ChangeState(FairMQSplitter::INIT_TASK);
|
||||
splitter.WaitForEndOfState(FairMQSplitter::INIT_TASK);
|
||||
|
||||
splitter.SetProperty(FairMQSplitter::InputSocketType, options.inputSocketType);
|
||||
splitter.SetProperty(FairMQSplitter::InputRcvBufSize, options.inputBufSize);
|
||||
splitter.SetProperty(FairMQSplitter::InputMethod, options.inputMethod);
|
||||
splitter.SetProperty(FairMQSplitter::InputAddress, options.inputAddress);
|
||||
|
||||
for (int i = 0; i < options.numOutputs; ++i)
|
||||
{
|
||||
splitter.SetProperty(FairMQSplitter::OutputSocketType, options.outputSocketType.at(i), i);
|
||||
splitter.SetProperty(FairMQSplitter::OutputSndBufSize, options.outputBufSize.at(i), i);
|
||||
splitter.SetProperty(FairMQSplitter::OutputMethod, options.outputMethod.at(i), i);
|
||||
splitter.SetProperty(FairMQSplitter::OutputAddress, options.outputAddress.at(i), i);
|
||||
}
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::SETOUTPUT);
|
||||
splitter.ChangeState(FairMQSplitter::SETINPUT);
|
||||
splitter.ChangeState(FairMQSplitter::BIND);
|
||||
splitter.ChangeState(FairMQSplitter::CONNECT);
|
||||
splitter.ChangeState(FairMQSplitter::RUN);
|
||||
|
||||
// wait until the running thread has finished processing.
|
||||
boost::unique_lock<boost::mutex> lock(splitter.fRunningMutex);
|
||||
while (!splitter.fRunningFinished)
|
||||
{
|
||||
splitter.fRunningCondition.wait(lock);
|
||||
}
|
||||
splitter.WaitForEndOfState(FairMQSplitter::RUN);
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::STOP);
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::RESET_TASK);
|
||||
splitter.WaitForEndOfState(FairMQSplitter::RESET_TASK);
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::RESET_DEVICE);
|
||||
splitter.WaitForEndOfState(FairMQSplitter::RESET_DEVICE);
|
||||
|
||||
splitter.ChangeState(FairMQSplitter::END);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -27,15 +27,13 @@ FairMQContextZMQ::FairMQContextZMQ(int numIoThreads)
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int rc = zmq_ctx_set(fContext, ZMQ_IO_THREADS, numIoThreads);
|
||||
if (rc != 0)
|
||||
if (zmq_ctx_set(fContext, ZMQ_IO_THREADS, numIoThreads) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed configuring context, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
||||
// Set the maximum number of allowed sockets on the context.
|
||||
rc = zmq_ctx_set(fContext, ZMQ_MAX_SOCKETS, 10000);
|
||||
if (rc != 0)
|
||||
if (zmq_ctx_set(fContext, ZMQ_MAX_SOCKETS, 10000) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed configuring context, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
@ -58,8 +56,7 @@ void FairMQContextZMQ::Close()
|
|||
return;
|
||||
}
|
||||
|
||||
int rc = zmq_ctx_destroy(fContext);
|
||||
if (rc != 0)
|
||||
if (zmq_ctx_destroy(fContext) != 0)
|
||||
{
|
||||
if (errno == EINTR) {
|
||||
LOG(ERROR) << " failed closing context, reason: " << zmq_strerror(errno);
|
||||
|
|
|
@ -23,8 +23,7 @@ using namespace std;
|
|||
FairMQMessageZMQ::FairMQMessageZMQ()
|
||||
: fMessage()
|
||||
{
|
||||
int rc = zmq_msg_init(&fMessage);
|
||||
if (rc != 0)
|
||||
if (zmq_msg_init(&fMessage) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed initializing message, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
@ -33,8 +32,7 @@ FairMQMessageZMQ::FairMQMessageZMQ()
|
|||
FairMQMessageZMQ::FairMQMessageZMQ(size_t size)
|
||||
: fMessage()
|
||||
{
|
||||
int rc = zmq_msg_init_size(&fMessage, size);
|
||||
if (rc != 0)
|
||||
if (zmq_msg_init_size(&fMessage, size) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed initializing message with size, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
@ -43,8 +41,7 @@ FairMQMessageZMQ::FairMQMessageZMQ(size_t size)
|
|||
FairMQMessageZMQ::FairMQMessageZMQ(void* data, size_t size, fairmq_free_fn *ffn, void* hint)
|
||||
: fMessage()
|
||||
{
|
||||
int rc = zmq_msg_init_data(&fMessage, data, size, ffn ? ffn : &CleanUp, hint);
|
||||
if (rc != 0)
|
||||
if (zmq_msg_init_data(&fMessage, data, size, ffn ? ffn : &CleanUp, hint) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed initializing message with data, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
@ -53,8 +50,7 @@ FairMQMessageZMQ::FairMQMessageZMQ(void* data, size_t size, fairmq_free_fn *ffn,
|
|||
void FairMQMessageZMQ::Rebuild()
|
||||
{
|
||||
CloseMessage();
|
||||
int rc = zmq_msg_init(&fMessage);
|
||||
if (rc != 0)
|
||||
if (zmq_msg_init(&fMessage) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed initializing message, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
@ -63,8 +59,7 @@ void FairMQMessageZMQ::Rebuild()
|
|||
void FairMQMessageZMQ::Rebuild(size_t size)
|
||||
{
|
||||
CloseMessage();
|
||||
int rc = zmq_msg_init_size(&fMessage, size);
|
||||
if (rc != 0)
|
||||
if (zmq_msg_init_size(&fMessage, size) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed initializing message with size, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
@ -73,8 +68,7 @@ void FairMQMessageZMQ::Rebuild(size_t size)
|
|||
void FairMQMessageZMQ::Rebuild(void* data, size_t size, fairmq_free_fn *ffn, void* hint)
|
||||
{
|
||||
CloseMessage();
|
||||
int rc = zmq_msg_init_data(&fMessage, data, size, ffn ? ffn : &CleanUp, hint);
|
||||
if (rc != 0)
|
||||
if (zmq_msg_init_data(&fMessage, data, size, ffn ? ffn : &CleanUp, hint) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed initializing message with data, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
@ -103,8 +97,7 @@ void FairMQMessageZMQ::SetMessage(void* data, size_t size)
|
|||
void FairMQMessageZMQ::Copy(FairMQMessage* msg)
|
||||
{
|
||||
// Shares the message buffer between msg and this fMessage.
|
||||
int rc = zmq_msg_copy(&fMessage, (zmq_msg_t*)msg->GetMessage());
|
||||
if (rc != 0)
|
||||
if (zmq_msg_copy(&fMessage, (zmq_msg_t*)msg->GetMessage()) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed copying message, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
@ -119,8 +112,7 @@ void FairMQMessageZMQ::Copy(FairMQMessage* msg)
|
|||
|
||||
inline void FairMQMessageZMQ::CloseMessage()
|
||||
{
|
||||
int rc = zmq_msg_close(&fMessage);
|
||||
if (rc != 0)
|
||||
if (zmq_msg_close(&fMessage) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed closing message, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
@ -133,8 +125,7 @@ void FairMQMessageZMQ::CleanUp(void* data, void* hint)
|
|||
|
||||
FairMQMessageZMQ::~FairMQMessageZMQ()
|
||||
{
|
||||
int rc = zmq_msg_close(&fMessage);
|
||||
if (rc != 0)
|
||||
if (zmq_msg_close(&fMessage) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed closing message with data, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
|
|
@ -19,16 +19,16 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
FairMQPollerZMQ::FairMQPollerZMQ(const vector<FairMQSocket*>& inputs)
|
||||
FairMQPollerZMQ::FairMQPollerZMQ(const vector<FairMQChannel>& channels)
|
||||
: items()
|
||||
, fNumItems()
|
||||
{
|
||||
fNumItems = inputs.size();
|
||||
fNumItems = channels.size();
|
||||
items = new zmq_pollitem_t[fNumItems];
|
||||
|
||||
for (int i = 0; i < fNumItems; i++)
|
||||
for (int i = 0; i < fNumItems; ++i)
|
||||
{
|
||||
items[i].socket = inputs.at(i)->GetSocket();
|
||||
items[i].socket = channels.at(i).fSocket->GetSocket();
|
||||
items[i].fd = 0;
|
||||
items[i].events = ZMQ_POLLIN;
|
||||
items[i].revents = 0;
|
||||
|
@ -37,8 +37,7 @@ FairMQPollerZMQ::FairMQPollerZMQ(const vector<FairMQSocket*>& inputs)
|
|||
|
||||
void FairMQPollerZMQ::Poll(int timeout)
|
||||
{
|
||||
int rc = zmq_poll(items, fNumItems, timeout);
|
||||
if (rc < 0)
|
||||
if (zmq_poll(items, fNumItems, timeout) < 0)
|
||||
{
|
||||
LOG(ERROR) << "polling failed, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
@ -47,7 +46,9 @@ void FairMQPollerZMQ::Poll(int timeout)
|
|||
bool FairMQPollerZMQ::CheckInput(int index)
|
||||
{
|
||||
if (items[index].revents & ZMQ_POLLIN)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -55,7 +56,9 @@ bool FairMQPollerZMQ::CheckInput(int index)
|
|||
bool FairMQPollerZMQ::CheckOutput(int index)
|
||||
{
|
||||
if (items[index].revents & ZMQ_POLLOUT)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -63,5 +66,7 @@ bool FairMQPollerZMQ::CheckOutput(int index)
|
|||
FairMQPollerZMQ::~FairMQPollerZMQ()
|
||||
{
|
||||
if (items != NULL)
|
||||
{
|
||||
delete[] items;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
#include <vector>
|
||||
|
||||
#include "FairMQPoller.h"
|
||||
#include "FairMQSocket.h"
|
||||
#include "FairMQChannel.h"
|
||||
|
||||
class FairMQPollerZMQ : public FairMQPoller
|
||||
{
|
||||
public:
|
||||
FairMQPollerZMQ(const std::vector<FairMQSocket*>& inputs);
|
||||
FairMQPollerZMQ(const std::vector<FairMQChannel>& channels);
|
||||
|
||||
virtual void Poll(int timeout);
|
||||
virtual bool CheckInput(int index);
|
||||
|
|
|
@ -19,9 +19,10 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
// Context to hold the ZeroMQ sockets
|
||||
boost::shared_ptr<FairMQContextZMQ> FairMQSocketZMQ::fContext = boost::shared_ptr<FairMQContextZMQ>(new FairMQContextZMQ(1));
|
||||
|
||||
FairMQSocketZMQ::FairMQSocketZMQ(const string& type, int num, int numIoThreads)
|
||||
FairMQSocketZMQ::FairMQSocketZMQ(const string& type, const string& name, int numIoThreads)
|
||||
: FairMQSocket(ZMQ_SNDMORE, ZMQ_RCVMORE, ZMQ_DONTWAIT)
|
||||
, fSocket(NULL)
|
||||
, fId()
|
||||
|
@ -30,12 +31,9 @@ FairMQSocketZMQ::FairMQSocketZMQ(const string& type, int num, int numIoThreads)
|
|||
, fMessagesTx(0)
|
||||
, fMessagesRx(0)
|
||||
{
|
||||
stringstream id;
|
||||
id << type << "." << num;
|
||||
fId = id.str();
|
||||
fId = name + "." + type;
|
||||
|
||||
int rc = zmq_ctx_set(fContext->GetContext(), ZMQ_IO_THREADS, numIoThreads);
|
||||
if (rc != 0)
|
||||
if (zmq_ctx_set(fContext->GetContext(), ZMQ_IO_THREADS, numIoThreads) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed configuring context, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
@ -44,12 +42,11 @@ FairMQSocketZMQ::FairMQSocketZMQ(const string& type, int num, int numIoThreads)
|
|||
|
||||
if (fSocket == NULL)
|
||||
{
|
||||
LOG(ERROR) << "failed creating socket #" << fId << ", reason: " << zmq_strerror(errno);
|
||||
LOG(ERROR) << "failed creating socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
rc = zmq_setsockopt(fSocket, ZMQ_IDENTITY, &fId, fId.length());
|
||||
if (rc != 0)
|
||||
if (zmq_setsockopt(fSocket, ZMQ_IDENTITY, &fId, fId.length()) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed setting ZMQ_IDENTITY socket option, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
@ -57,22 +54,20 @@ FairMQSocketZMQ::FairMQSocketZMQ(const string& type, int num, int numIoThreads)
|
|||
// Tell socket to try and send/receive outstanding messages for <linger> milliseconds before terminating.
|
||||
// Default value for ZeroMQ is -1, which is to wait forever.
|
||||
int linger = 500;
|
||||
rc = zmq_setsockopt(fSocket, ZMQ_LINGER, &linger, sizeof(linger));
|
||||
if (rc != 0)
|
||||
if (zmq_setsockopt(fSocket, ZMQ_LINGER, &linger, sizeof(linger)) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed setting ZMQ_LINGER socket option, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
||||
if (type == "sub")
|
||||
{
|
||||
rc = zmq_setsockopt(fSocket, ZMQ_SUBSCRIBE, NULL, 0);
|
||||
if (rc != 0)
|
||||
if (zmq_setsockopt(fSocket, ZMQ_SUBSCRIBE, NULL, 0) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed setting ZMQ_SUBSCRIBE socket option, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
}
|
||||
|
||||
LOG(INFO) << "created socket #" << fId;
|
||||
// LOG(INFO) << "created socket " << fId;
|
||||
}
|
||||
|
||||
string FairMQSocketZMQ::GetId()
|
||||
|
@ -82,16 +77,15 @@ string FairMQSocketZMQ::GetId()
|
|||
|
||||
bool FairMQSocketZMQ::Bind(const string& address)
|
||||
{
|
||||
LOG(INFO) << "bind socket #" << fId << " on " << address;
|
||||
// LOG(INFO) << "bind socket " << fId << " on " << address;
|
||||
|
||||
int rc = zmq_bind(fSocket, address.c_str());
|
||||
if (rc != 0)
|
||||
if (zmq_bind(fSocket, address.c_str()) != 0)
|
||||
{
|
||||
if (errno == EADDRINUSE) {
|
||||
// do not print error in this case, this is handled by FairMQDevice in case no connection could be established after trying a number of random ports from a range.
|
||||
return false;
|
||||
}
|
||||
LOG(ERROR) << "failed binding socket #" << fId << ", reason: " << zmq_strerror(errno);
|
||||
LOG(ERROR) << "failed binding socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -99,12 +93,11 @@ bool FairMQSocketZMQ::Bind(const string& address)
|
|||
|
||||
void FairMQSocketZMQ::Connect(const string& address)
|
||||
{
|
||||
LOG(INFO) << "connect socket #" << fId << " on " << address;
|
||||
// LOG(INFO) << "connect socket " << fId << " on " << address;
|
||||
|
||||
int rc = zmq_connect(fSocket, address.c_str());
|
||||
if (rc != 0)
|
||||
if (zmq_connect(fSocket, address.c_str()) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed connecting socket #" << fId << ", reason: " << zmq_strerror(errno);
|
||||
LOG(ERROR) << "failed connecting socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,10 +116,10 @@ int FairMQSocketZMQ::Send(FairMQMessage* msg, const string& flag)
|
|||
}
|
||||
if (zmq_errno() == ETERM)
|
||||
{
|
||||
LOG(INFO) << "terminating socket #" << fId;
|
||||
LOG(INFO) << "terminating socket " << fId;
|
||||
return -1;
|
||||
}
|
||||
LOG(ERROR) << "failed sending on socket #" << fId << ", reason: " << zmq_strerror(errno);
|
||||
LOG(ERROR) << "failed sending on socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
|
@ -145,10 +138,10 @@ int FairMQSocketZMQ::Send(FairMQMessage* msg, const int flags)
|
|||
}
|
||||
if (zmq_errno() == ETERM)
|
||||
{
|
||||
LOG(INFO) << "terminating socket #" << fId;
|
||||
LOG(INFO) << "terminating socket " << fId;
|
||||
return -1;
|
||||
}
|
||||
LOG(ERROR) << "failed sending on socket #" << fId << ", reason: " << zmq_strerror(errno);
|
||||
LOG(ERROR) << "failed sending on socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
|
@ -167,10 +160,10 @@ int FairMQSocketZMQ::Receive(FairMQMessage* msg, const string& flag)
|
|||
}
|
||||
if (zmq_errno() == ETERM)
|
||||
{
|
||||
LOG(INFO) << "terminating socket #" << fId;
|
||||
LOG(INFO) << "terminating socket " << fId;
|
||||
return -1;
|
||||
}
|
||||
LOG(ERROR) << "failed receiving on socket #" << fId << ", reason: " << zmq_strerror(errno);
|
||||
LOG(ERROR) << "failed receiving on socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
|
@ -189,24 +182,25 @@ int FairMQSocketZMQ::Receive(FairMQMessage* msg, const int flags)
|
|||
}
|
||||
if (zmq_errno() == ETERM)
|
||||
{
|
||||
LOG(INFO) << "terminating socket #" << fId;
|
||||
LOG(INFO) << "terminating socket " << fId;
|
||||
return -1;
|
||||
}
|
||||
LOG(ERROR) << "failed receiving on socket #" << fId << ", reason: " << zmq_strerror(errno);
|
||||
LOG(ERROR) << "failed receiving on socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
void FairMQSocketZMQ::Close()
|
||||
{
|
||||
// LOG(DEBUG) << "Closing socket " << fId;
|
||||
|
||||
if (fSocket == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int rc = zmq_close(fSocket);
|
||||
if (rc != 0)
|
||||
if (zmq_close(fSocket) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed closing socket, reason: " << zmq_strerror(errno);
|
||||
LOG(ERROR) << "failed closing socket " << fId << ", reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
||||
fSocket = NULL;
|
||||
|
@ -214,8 +208,7 @@ void FairMQSocketZMQ::Close()
|
|||
|
||||
void FairMQSocketZMQ::Terminate()
|
||||
{
|
||||
int rc = zmq_ctx_destroy(fContext->GetContext());
|
||||
if (rc != 0)
|
||||
if (zmq_ctx_destroy(fContext->GetContext()) != 0)
|
||||
{
|
||||
LOG(ERROR) << "failed terminating context, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
@ -234,8 +227,7 @@ int FairMQSocketZMQ::GetSocket(int nothing)
|
|||
|
||||
void FairMQSocketZMQ::SetOption(const string& option, const void* value, size_t valueSize)
|
||||
{
|
||||
int rc = zmq_setsockopt(fSocket, GetConstant(option), value, valueSize);
|
||||
if (rc < 0)
|
||||
if (zmq_setsockopt(fSocket, GetConstant(option), value, valueSize) < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed setting socket option, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
|
@ -243,8 +235,8 @@ void FairMQSocketZMQ::SetOption(const string& option, const void* value, size_t
|
|||
|
||||
void FairMQSocketZMQ::GetOption(const string& option, void* value, size_t* valueSize)
|
||||
{
|
||||
int rc = zmq_getsockopt(fSocket, GetConstant(option), value, valueSize);
|
||||
if (rc < 0) {
|
||||
if (zmq_getsockopt(fSocket, GetConstant(option), value, valueSize) < 0)
|
||||
{
|
||||
LOG(ERROR) << "failed getting socket option, reason: " << zmq_strerror(errno);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
class FairMQSocketZMQ : public FairMQSocket
|
||||
{
|
||||
public:
|
||||
FairMQSocketZMQ(const std::string& type, int num, int numIoThreads);
|
||||
FairMQSocketZMQ(const std::string& type, const std::string& name, int numIoThreads);
|
||||
|
||||
virtual std::string GetId();
|
||||
|
||||
|
@ -33,9 +33,9 @@ class FairMQSocketZMQ : public FairMQSocket
|
|||
virtual void Connect(const std::string& address);
|
||||
|
||||
virtual int Send(FairMQMessage* msg, const std::string& flag = "");
|
||||
virtual int Send(FairMQMessage* msg, const int flags);
|
||||
virtual int Send(FairMQMessage* msg, const int flags = 0);
|
||||
virtual int Receive(FairMQMessage* msg, const std::string& flag = "");
|
||||
virtual int Receive(FairMQMessage* msg, const int flags);
|
||||
virtual int Receive(FairMQMessage* msg, const int flags = 0);
|
||||
|
||||
virtual void* GetSocket();
|
||||
virtual int GetSocket(int nothing);
|
||||
|
|
|
@ -22,7 +22,7 @@ FairMQTransportFactoryZMQ::FairMQTransportFactoryZMQ()
|
|||
{
|
||||
int major, minor, patch;
|
||||
zmq_version(&major, &minor, &patch);
|
||||
LOG(INFO) << "Using ZeroMQ library, version: " << major << "." << minor << "." << patch;
|
||||
LOG(DEBUG) << "Using ZeroMQ library, version: " << major << "." << minor << "." << patch;
|
||||
}
|
||||
|
||||
FairMQMessage* FairMQTransportFactoryZMQ::CreateMessage()
|
||||
|
@ -40,12 +40,12 @@ FairMQMessage* FairMQTransportFactoryZMQ::CreateMessage(void* data, size_t size,
|
|||
return new FairMQMessageZMQ(data, size, ffn, hint);
|
||||
}
|
||||
|
||||
FairMQSocket* FairMQTransportFactoryZMQ::CreateSocket(const string& type, int num, int numIoThreads)
|
||||
FairMQSocket* FairMQTransportFactoryZMQ::CreateSocket(const string& type, const std::string& name, int numIoThreads)
|
||||
{
|
||||
return new FairMQSocketZMQ(type, num, numIoThreads);
|
||||
return new FairMQSocketZMQ(type, name, numIoThreads);
|
||||
}
|
||||
|
||||
FairMQPoller* FairMQTransportFactoryZMQ::CreatePoller(const vector<FairMQSocket*>& inputs)
|
||||
FairMQPoller* FairMQTransportFactoryZMQ::CreatePoller(const vector<FairMQChannel>& channels)
|
||||
{
|
||||
return new FairMQPollerZMQ(inputs);
|
||||
return new FairMQPollerZMQ(channels);
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ class FairMQTransportFactoryZMQ : public FairMQTransportFactory
|
|||
virtual FairMQMessage* CreateMessage();
|
||||
virtual FairMQMessage* CreateMessage(size_t size);
|
||||
virtual FairMQMessage* CreateMessage(void* data, size_t size, fairmq_free_fn *ffn = NULL, void* hint = NULL);
|
||||
virtual FairMQSocket* CreateSocket(const std::string& type, int num, int numIoThreads);
|
||||
virtual FairMQPoller* CreatePoller(const std::vector<FairMQSocket*>& inputs);
|
||||
virtual FairMQSocket* CreateSocket(const std::string& type, const std::string& name, int numIoThreads);
|
||||
virtual FairMQPoller* CreatePoller(const std::vector<FairMQChannel>& channels);
|
||||
|
||||
virtual ~FairMQTransportFactoryZMQ() {};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user