From b8fe02cb08ebc7521b8969275b5c13d9731674c7 Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Fri, 4 May 2018 14:22:27 +0200 Subject: [PATCH] Used cached default transport in FairMQDevice::Transport() --- fairmq/FairMQChannel.cxx | 24 +++++++++++------------- fairmq/FairMQChannel.h | 4 ++-- fairmq/FairMQDevice.cxx | 16 ++++++++-------- fairmq/FairMQDevice.h | 8 ++++---- fairmq/options/FairMQParser.cxx | 10 +++++----- fairmq/options/FairMQProgOptions.cxx | 2 +- 6 files changed, 31 insertions(+), 33 deletions(-) diff --git a/fairmq/FairMQChannel.cxx b/fairmq/FairMQChannel.cxx index e72e4903..fcf5d2e2 100644 --- a/fairmq/FairMQChannel.cxx +++ b/fairmq/FairMQChannel.cxx @@ -28,7 +28,7 @@ FairMQChannel::FairMQChannel() , fType("unspecified") , fMethod("unspecified") , fAddress("unspecified") - , fTransport("default") + , fTransportName("default") , fSndBufSize(1000) , fRcvBufSize(1000) , fSndKernelSize(0) @@ -49,7 +49,7 @@ FairMQChannel::FairMQChannel(const string& type, const string& method, const str , fType(type) , fMethod(method) , fAddress(address) - , fTransport("default") + , fTransportName("default") , fSndBufSize(1000) , fRcvBufSize(1000) , fSndKernelSize(0) @@ -70,7 +70,7 @@ FairMQChannel::FairMQChannel(const string& name, const string& type, std::shared , fType(type) , fMethod("unspecified") , fAddress("unspecified") - , fTransport("default") // TODO refactor, either use string representation or enum type + , fTransportName("default") // TODO refactor, either use string representation or enum type , fSndBufSize(1000) , fRcvBufSize(1000) , fSndKernelSize(0) @@ -91,7 +91,7 @@ FairMQChannel::FairMQChannel(const FairMQChannel& chan) , fType(chan.fType) , fMethod(chan.fMethod) , fAddress(chan.fAddress) - , fTransport(chan.fTransport) + , fTransportName(chan.fTransportName) , fSndBufSize(chan.fSndBufSize) , fRcvBufSize(chan.fRcvBufSize) , fSndKernelSize(chan.fSndKernelSize) @@ -111,7 +111,7 @@ FairMQChannel& FairMQChannel::operator=(const FairMQChannel& chan) fType = chan.fType; fMethod = chan.fMethod; fAddress = chan.fAddress; - fTransport = chan.fTransport; + fTransportName = chan.fTransportName; fSndBufSize = chan.fSndBufSize; fRcvBufSize = chan.fRcvBufSize; fSndKernelSize = chan.fSndKernelSize; @@ -194,16 +194,16 @@ string FairMQChannel::GetAddress() const } } -string FairMQChannel::GetTransport() const +string FairMQChannel::GetTransportName() const { try { unique_lock lock(fChannelMutex); - return fTransport; + return fTransportName; } catch (exception& e) { - LOG(error) << "Exception caught in FairMQChannel::GetTransport: " << e.what(); + LOG(error) << "Exception caught in FairMQChannel::GetTransportName: " << e.what(); exit(EXIT_FAILURE); } } @@ -332,7 +332,7 @@ void FairMQChannel::UpdateTransport(const string& transport) { unique_lock lock(fChannelMutex); fIsValid = false; - fTransport = transport; + fTransportName = transport; fModified = true; } catch (exception& e) @@ -587,13 +587,11 @@ bool FairMQChannel::ValidateChannel() } // validate channel transport - // const string channelTransportNames[] = { "default", "zeromq", "nanomsg", "shmem" }; - // const set channelTransports(channelTransportNames, channelTransportNames + sizeof(channelTransportNames) / sizeof(string)); - if (FairMQ::TransportTypes.find(fTransport) == FairMQ::TransportTypes.end()) + if (FairMQ::TransportTypes.find(fTransportName) == FairMQ::TransportTypes.end()) { ss << "INVALID"; LOG(debug) << ss.str(); - LOG(error) << "Invalid channel transport: \"" << fTransport << "\""; + LOG(error) << "Invalid channel transport: \"" << fTransportName << "\""; exit(EXIT_FAILURE); } diff --git a/fairmq/FairMQChannel.h b/fairmq/FairMQChannel.h index fb517d93..1daf33e5 100644 --- a/fairmq/FairMQChannel.h +++ b/fairmq/FairMQChannel.h @@ -92,7 +92,7 @@ class FairMQChannel /// Get channel transport ("default", "zeromq", "nanomsg" or "shmem") /// @return Returns channel transport (e.g. "default", "zeromq", "nanomsg" or "shmem") - std::string GetTransport() const; + std::string GetTransportName() const; /// Get socket send buffer size (in number of messages) /// @return Returns socket send buffer size (in number of messages) @@ -301,7 +301,7 @@ class FairMQChannel std::string fType; std::string fMethod; std::string fAddress; - std::string fTransport; + std::string fTransportName; int fSndBufSize; int fRcvBufSize; int fSndKernelSize; diff --git a/fairmq/FairMQDevice.cxx b/fairmq/FairMQDevice.cxx index 5443cc56..84d10fe8 100644 --- a/fairmq/FairMQDevice.cxx +++ b/fairmq/FairMQDevice.cxx @@ -42,7 +42,7 @@ FairMQDevice::FairMQDevice() , fPortRangeMin(22000) , fPortRangeMax(32000) , fNetworkInterface() - , fDefaultTransport("default") + , fDefaultTransportName("default") , fInitializationTimeoutInS(120) , fDataCallbacks(false) , fMsgInputs() @@ -72,7 +72,7 @@ FairMQDevice::FairMQDevice(const fair::mq::tools::Version version) , fPortRangeMin(22000) , fPortRangeMax(32000) , fNetworkInterface() - , fDefaultTransport("default") + , fDefaultTransportName("default") , fInitializationTimeoutInS(120) , fDataCallbacks(false) , fMsgInputs() @@ -246,15 +246,15 @@ bool FairMQDevice::AttachChannel(FairMQChannel& ch) { if (!ch.fTransportFactory) { - if (ch.fTransport == "default" || ch.fTransport == fDefaultTransport) + if (ch.fTransportName == "default" || ch.fTransportName == fDefaultTransportName) { LOG(debug) << ch.fName << ": using default transport"; ch.InitTransport(fTransportFactory); } else { - LOG(debug) << ch.fName << ": channel transport (" << fDefaultTransport << ") overriden to " << ch.fTransport; - ch.InitTransport(AddTransport(ch.fTransport)); + LOG(debug) << ch.fName << ": channel transport (" << fDefaultTransportName << ") overriden to " << ch.fTransportName; + ch.InitTransport(AddTransport(ch.fTransportName)); } ch.fTransportType = ch.fTransportFactory->GetType(); } @@ -804,7 +804,7 @@ void FairMQDevice::CreateOwnConfig() fNumIoThreads = fConfig->GetValue("io-threads"); fInitializationTimeoutInS = fConfig->GetValue("initialization-timeout"); fRate = fConfig->GetValue("rate"); - fDefaultTransport = fConfig->GetValue("transport"); + fDefaultTransportName = fConfig->GetValue("transport"); } void FairMQDevice::SetTransport(const string& transport) @@ -844,8 +844,8 @@ void FairMQDevice::SetConfig(FairMQProgOptions& config) fNumIoThreads = config.GetValue("io-threads"); fInitializationTimeoutInS = config.GetValue("initialization-timeout"); fRate = fConfig->GetValue("rate"); - fDefaultTransport = config.GetValue("transport"); - SetTransport(fDefaultTransport); + fDefaultTransportName = config.GetValue("transport"); + SetTransport(fDefaultTransportName); } void FairMQDevice::LogSocketRates() diff --git a/fairmq/FairMQDevice.h b/fairmq/FairMQDevice.h index 6b2bdaae..43a8c2be 100644 --- a/fairmq/FairMQDevice.h +++ b/fairmq/FairMQDevice.h @@ -196,7 +196,7 @@ class FairMQDevice : public FairMQStateMachine /// @brief Getter for default transport factory auto Transport() const -> const FairMQTransportFactory* { - return fTransports.at(fair::mq::TransportTypes[GetDefaultTransport()]).get(); + return fTransportFactory.get();; } template @@ -407,8 +407,8 @@ class FairMQDevice : public FairMQStateMachine void SetNetworkInterface(const std::string& networkInterface) { fNetworkInterface = networkInterface; } std::string GetNetworkInterface() const { return fNetworkInterface; } - void SetDefaultTransport(const std::string& defaultTransport) { fDefaultTransport = defaultTransport; } - std::string GetDefaultTransport() const { return fDefaultTransport; } + void SetDefaultTransportName(const std::string& defaultTransportName) { fDefaultTransportName = defaultTransportName; } + std::string GetDefaultTransportName() const { return fDefaultTransportName; } void SetInitializationTimeoutInS(int initializationTimeoutInS) { fInitializationTimeoutInS = initializationTimeoutInS; } int GetInitializationTimeoutInS() const { return fInitializationTimeoutInS; } @@ -472,7 +472,7 @@ class FairMQDevice : public FairMQStateMachine int fPortRangeMax; ///< Maximum value for the port range (if dynamic) std::string fNetworkInterface; ///< Network interface to use for dynamic binding - std::string fDefaultTransport; ///< Default transport for the device + std::string fDefaultTransportName; ///< Default transport for the device int fInitializationTimeoutInS; ///< Timeout for the initialization (in seconds) diff --git a/fairmq/options/FairMQParser.cxx b/fairmq/options/FairMQParser.cxx index bd2a0f74..cda5f329 100644 --- a/fairmq/options/FairMQParser.cxx +++ b/fairmq/options/FairMQParser.cxx @@ -147,7 +147,7 @@ void ChannelParser(const boost::property_tree::ptree& tree, FairMQMap& channelMa commonChannel.UpdateType(q.second.get("type", commonChannel.GetType())); commonChannel.UpdateMethod(q.second.get("method", commonChannel.GetMethod())); commonChannel.UpdateAddress(q.second.get("address", commonChannel.GetAddress())); - commonChannel.UpdateTransport(q.second.get("transport", commonChannel.GetTransport())); + commonChannel.UpdateTransport(q.second.get("transport", commonChannel.GetTransportName())); commonChannel.UpdateSndBufSize(q.second.get("sndBufSize", commonChannel.GetSndBufSize())); commonChannel.UpdateRcvBufSize(q.second.get("rcvBufSize", commonChannel.GetRcvBufSize())); commonChannel.UpdateSndKernelSize(q.second.get("sndKernelSize", commonChannel.GetSndKernelSize())); @@ -166,7 +166,7 @@ void ChannelParser(const boost::property_tree::ptree& tree, FairMQMap& channelMa LOG(debug) << "\ttype = " << commonChannel.GetType(); LOG(debug) << "\tmethod = " << commonChannel.GetMethod(); LOG(debug) << "\taddress = " << commonChannel.GetAddress(); - LOG(debug) << "\ttransport = " << commonChannel.GetTransport(); + LOG(debug) << "\ttransport = " << commonChannel.GetTransportName(); LOG(debug) << "\tsndBufSize = " << commonChannel.GetSndBufSize(); LOG(debug) << "\trcvBufSize = " << commonChannel.GetRcvBufSize(); LOG(debug) << "\tsndKernelSize = " << commonChannel.GetSndKernelSize(); @@ -208,7 +208,7 @@ void SocketParser(const boost::property_tree::ptree& tree, vector channel.UpdateType(q.second.get("type", channel.GetType())); channel.UpdateMethod(q.second.get("method", channel.GetMethod())); channel.UpdateAddress(q.second.get("address", channel.GetAddress())); - channel.UpdateTransport(q.second.get("transport", channel.GetTransport())); + channel.UpdateTransport(q.second.get("transport", channel.GetTransportName())); channel.UpdateSndBufSize(q.second.get("sndBufSize", channel.GetSndBufSize())); channel.UpdateRcvBufSize(q.second.get("rcvBufSize", channel.GetRcvBufSize())); channel.UpdateSndKernelSize(q.second.get("sndKernelSize", channel.GetSndKernelSize())); @@ -219,7 +219,7 @@ void SocketParser(const boost::property_tree::ptree& tree, vector LOG(debug) << "\ttype = " << channel.GetType(); LOG(debug) << "\tmethod = " << channel.GetMethod(); LOG(debug) << "\taddress = " << channel.GetAddress(); - LOG(debug) << "\ttransport = " << channel.GetTransport(); + LOG(debug) << "\ttransport = " << channel.GetTransportName(); LOG(debug) << "\tsndBufSize = " << channel.GetSndBufSize(); LOG(debug) << "\trcvBufSize = " << channel.GetRcvBufSize(); LOG(debug) << "\tsndKernelSize = " << channel.GetSndKernelSize(); @@ -247,7 +247,7 @@ void SocketParser(const boost::property_tree::ptree& tree, vector LOG(debug) << "\ttype = " << channel.GetType(); LOG(debug) << "\tmethod = " << channel.GetMethod(); LOG(debug) << "\taddress = " << channel.GetAddress(); - LOG(debug) << "\ttransport = " << channel.GetTransport(); + LOG(debug) << "\ttransport = " << channel.GetTransportName(); LOG(debug) << "\tsndBufSize = " << channel.GetSndBufSize(); LOG(debug) << "\trcvBufSize = " << channel.GetRcvBufSize(); LOG(debug) << "\tsndKernelSize = " << channel.GetSndKernelSize(); diff --git a/fairmq/options/FairMQProgOptions.cxx b/fairmq/options/FairMQProgOptions.cxx index 0fa5ec1a..f68bfb6b 100644 --- a/fairmq/options/FairMQProgOptions.cxx +++ b/fairmq/options/FairMQProgOptions.cxx @@ -196,7 +196,7 @@ void FairMQProgOptions::UpdateMQValues() UpdateVarMap(typeKey, channel.GetType()); UpdateVarMap(methodKey, channel.GetMethod()); UpdateVarMap(addressKey, channel.GetAddress()); - UpdateVarMap(transportKey, channel.GetTransport()); + UpdateVarMap(transportKey, channel.GetTransportName()); UpdateVarMap(sndBufSizeKey, channel.GetSndBufSize()); UpdateVarMap(rcvBufSizeKey, channel.GetRcvBufSize()); UpdateVarMap(sndKernelSizeKey, channel.GetSndKernelSize());