Commit 40a5e299 authored by legoc's avatar legoc
Browse files

Refined internal requester port name by adding the responder id.

parent 1f17f7b3
......@@ -9,4 +9,5 @@
* Renamed ERROR into FAILURE.
* Implementation of unmanaged applications.
* Implemented This static instance without pointer so that it is not necessary to call This::terminate() except if the destruction of the static instance is not automatic.
* Added two binary parts message for publisher/subscriber and requester/responder.
\ No newline at end of file
* Added two binary parts message for publisher/subscriber and requester/responder.
* Refined internal requester port name by adding the responder id.
\ No newline at end of file
......@@ -1017,8 +1017,8 @@ bool Responder::hasEnded() const {
///////////////////////////////////////////////////////////////////////////
// Requester
Requester::Requester(const application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name) :
m_impl(new RequesterImpl(application, url, requesterPort, responderPort, name)) {
Requester::Requester(const application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name, int responderId) :
m_impl(new RequesterImpl(application, url, requesterPort, responderPort, name, responderId)) {
// Create the waiting here.
m_waiting.reset(m_impl->waiting());
......@@ -1034,7 +1034,7 @@ std::auto_ptr<Requester> Requester::create(Instance & instance, const std::strin
string responderEndpoint = instance.getEndpoint();
string responderPortName = ResponderImpl::RESPONDER_PREFIX + name;
string requesterPortName = RequesterImpl::REQUESTER_PREFIX + name;
string requesterPortName = RequesterImpl::getRequesterPortName(name, responderId);
string strRequestType = This::m_instance.m_impl->createRequest(PROTO_CONNECTPORT);
string strRequestData = This::m_instance.m_impl->createConnectPortRequest(responderId, responderPortName);
......@@ -1073,7 +1073,7 @@ std::auto_ptr<Requester> Requester::create(Instance & instance, const std::strin
throw RequesterCreationException(requestResponse.message());
}
return auto_ptr<Requester>(new Requester(&This::m_instance, responderUrl, requesterPort, responderPort, name));
return auto_ptr<Requester>(new Requester(&This::m_instance, responderUrl, requesterPort, responderPort, name, responderId));
}
const std::string& Requester::getName() const {
......
......@@ -429,7 +429,7 @@ public:
void cancel();
private:
Requester(const application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name);
Requester(const application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name, int responderId);
std::auto_ptr<RequesterImpl> m_impl;
std::auto_ptr<WaitingImpl> m_waiting;
......
......@@ -29,10 +29,11 @@ namespace cameo {
const std::string RequesterImpl::REQUESTER_PREFIX = "req.";
RequesterImpl::RequesterImpl(const application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name) :
RequesterImpl::RequesterImpl(const application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name, int responderId) :
m_application(application),
m_requesterPort(requesterPort),
m_name(name) {
m_name(name),
m_responderId(responderId) {
stringstream repEndpoint;
repEndpoint << url << ":" << responderPort;
......@@ -50,6 +51,14 @@ RequesterImpl::~RequesterImpl() {
terminate();
}
std::string RequesterImpl::getRequesterPortName(const std::string& name, int responderId) {
stringstream requesterPortName;
requesterPortName << REQUESTER_PREFIX << name << "." << responderId;
return requesterPortName.str();
}
WaitingImpl * RequesterImpl::waiting() {
return new GenericWaitingImpl(bind(&RequesterImpl::cancel, this));
}
......@@ -176,7 +185,7 @@ void RequesterImpl::terminate() {
if (m_requester.get() != 0) {
m_requester.reset(0);
bool success = m_application->removePort(REQUESTER_PREFIX + m_name);
bool success = m_application->removePort(getRequesterPortName(m_name, m_responderId));
if (!success) {
cerr << "server cannot destroy requester " << m_name << endl;
}
......
......@@ -33,9 +33,11 @@ namespace application {
class RequesterImpl {
public:
RequesterImpl(const application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name);
RequesterImpl(const application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name, int responderId);
~RequesterImpl();
static std::string getRequesterPortName(const std::string& name, int responderId);
WaitingImpl * waiting();
void sendBinary(const std::string& request);
......@@ -52,6 +54,7 @@ public:
int m_requesterPort;
std::string m_responderEndpoint;
std::string m_name;
int m_responderId;
std::auto_ptr<zmq::socket_t> m_requester;
static const std::string REQUESTER_PREFIX;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment