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:
Alexey Rybalchenko
2015-04-29 13:25:42 +02:00
parent a2ebbbe450
commit 7fda980710
54 changed files with 1674 additions and 1573 deletions

View File

@@ -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");
@@ -88,7 +88,7 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
bpo::variables_map vm;
bpo::store(bpo::parse_command_line(_argc, _argv, desc), vm);
if ( vm.count("help") )
if (vm.count("help"))
{
LOG(INFO) << "FairMQ Benchmark Sampler" << endl << desc;
return false;
@@ -96,28 +96,28 @@ inline bool parse_cmd_line(int _argc, char* _argv[], DeviceOptions* _options)
bpo::notify(vm);
if ( vm.count("id") )
if (vm.count("id"))
_options->id = vm["id"].as<string>();
if ( vm.count("event-size") )
if (vm.count("event-size"))
_options->eventSize = vm["event-size"].as<int>();
if ( vm.count("event-rate") )
if (vm.count("event-rate"))
_options->eventRate = vm["event-rate"].as<int>();
if ( vm.count("io-threads") )
if (vm.count("io-threads"))
_options->ioThreads = vm["io-threads"].as<int>();
if ( vm.count("output-socket-type") )
if (vm.count("output-socket-type"))
_options->outputSocketType = vm["output-socket-type"].as<string>();
if ( vm.count("output-buff-size") )
if (vm.count("output-buff-size"))
_options->outputBufSize = vm["output-buff-size"].as<int>();
if ( vm.count("output-method") )
if (vm.count("output-method"))
_options->outputMethod = vm["output-method"].as<string>();
if ( vm.count("output-address") )
if (vm.count("output-address"))
_options->outputAddress = vm["output-address"].as<string>();
return true;
@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;