mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +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:
@@ -17,19 +17,14 @@
|
||||
#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()
|
||||
{}
|
||||
|
||||
@@ -37,44 +32,35 @@ 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::
|
||||
// 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));
|
||||
}
|
||||
|
||||
|
||||
OutputPolicy::SetMessage(msg);
|
||||
|
||||
if ( received > 0 && MergerPolicy::ReadyToSend() )
|
||||
|
||||
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,25 +69,8 @@ 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();
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* GENERICMERGER_H */
|
||||
#endif /* GENERICMERGER_H */
|
||||
|
||||
|
Reference in New Issue
Block a user