mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 17:41:45 +00:00
FairMQ: Extend Multipart and messaging API
- Extend the multipart API to allow sending vectors of messages or helper thin wrapper FairMQParts. See example in examples/MQ/8-multipart. - NewMessage() can be used in devices instead of fTransportFactory->CreateMessage(). Possible arguments remain unchanged (no args, size or data+size). - Send()/Receive() methods can be used in devices instead of fChannels.at("chan").at(i).Send()/Receive(): Send(msg, "chan", i = 0), Receive(msg, "chan", i = 0). - Use the new methods in MQ examples and tests. - No breaking changes, but FAIRMQ_INTERFACE_VERSION is incremented to 3 to allow to check for new methods.
This commit is contained in:
@@ -39,17 +39,14 @@ void FairMQExample8Sampler::Run()
|
||||
// Set stopFlag to 1 for the first 4 messages, and to 0 for the 5th.
|
||||
counter < 5 ? header->stopFlag = 0 : header->stopFlag = 1;
|
||||
|
||||
// Create message part with the header.
|
||||
unique_ptr<FairMQMessage> headerPart(fTransportFactory->CreateMessage(header, sizeof(Ex8Header)));
|
||||
// Create message part with the body of 1000 bytes size.
|
||||
unique_ptr<FairMQMessage> dataPart(fTransportFactory->CreateMessage(1000));
|
||||
FairMQParts parts;
|
||||
parts.AddPart(NewMessage(header, sizeof(Ex8Header)));
|
||||
parts.AddPart(NewMessage(1000));
|
||||
|
||||
LOG(INFO) << "Sending header with stopFlag: " << header->stopFlag;
|
||||
LOG(INFO) << "Sending body of size: " << parts.At(1).GetSize();
|
||||
|
||||
// Schedule the header part for sending.
|
||||
fChannels.at("data-out").at(0).SendPart(headerPart);
|
||||
// Add body part (final part). `Send()` will send/queue all parts.
|
||||
fChannels.at("data-out").at(0).Send(dataPart);
|
||||
Send(parts, "data-out");
|
||||
|
||||
// Go out of the sending loop if the stopFlag was sent.
|
||||
if (counter == 5)
|
||||
|
@@ -32,21 +32,18 @@ void FairMQExample8Sink::Run()
|
||||
{
|
||||
while (CheckCurrentState(RUNNING))
|
||||
{
|
||||
unique_ptr<FairMQMessage> headerPart(fTransportFactory->CreateMessage());
|
||||
unique_ptr<FairMQMessage> bodyPart(fTransportFactory->CreateMessage());
|
||||
FairMQParts parts;
|
||||
|
||||
if (fChannels.at("data-in").at(0).Receive(headerPart) >= 0)
|
||||
if (Receive(parts, "data-in") >= 0)
|
||||
{
|
||||
if (fChannels.at("data-in").at(0).Receive(bodyPart) >= 0)
|
||||
Ex8Header header;
|
||||
header.stopFlag = (static_cast<Ex8Header*>(parts.At(0).GetData()))->stopFlag;
|
||||
LOG(INFO) << "Received header with stopFlag: " << header.stopFlag;
|
||||
LOG(INFO) << "Received body of size: " << parts.At(1).GetSize();
|
||||
if (header.stopFlag == 1)
|
||||
{
|
||||
Ex8Header header;
|
||||
header.stopFlag = (static_cast<Ex8Header*>(headerPart->GetData()))->stopFlag;
|
||||
LOG(INFO) << "Received header with stopFlag: " << header.stopFlag;
|
||||
if (header.stopFlag == 1)
|
||||
{
|
||||
LOG(INFO) << "Flag is 0, exiting Run()";
|
||||
break;
|
||||
}
|
||||
LOG(INFO) << "Flag is 0, exiting Run()";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user