Commit 031e73a1 authored by legoc's avatar legoc
Browse files

Enabled to define more than one requester on the same responder in one

Application instance.
parent e5bc2ea7
0.1.2
-----
* Enabled to define more than one requester on the same responder in one Application instance.
0.1.0
-----
......
......@@ -4,8 +4,8 @@
#
# -----------------------------------------------------------------------------
AC_INIT(cameo-api-cpp, 0.1.1-dev)
LIBRARY_VERSION=0:1:1
AC_INIT(cameo-api-cpp, 0.1.2-dev)
LIBRARY_VERSION=0:1:2
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_SRCDIR(src/cameo/Application.cpp)
......
......@@ -1048,8 +1048,8 @@ bool Responder::hasEnded() const {
///////////////////////////////////////////////////////////////////////////
// Requester
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)) {
Requester::Requester(const application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name, int responderId, int requesterId) :
m_impl(new RequesterImpl(application, url, requesterPort, responderPort, name, responderId, requesterId)) {
// Create the waiting here.
m_waiting.reset(m_impl->waiting());
......@@ -1065,7 +1065,8 @@ std::auto_ptr<Requester> Requester::create(Instance & instance, const std::strin
string responderEndpoint = instance.getEndpoint();
string responderPortName = ResponderImpl::RESPONDER_PREFIX + name;
string requesterPortName = RequesterImpl::getRequesterPortName(name, responderId);
int requesterId = RequesterImpl::newRequesterId();
string requesterPortName = RequesterImpl::getRequesterPortName(name, responderId, requesterId);
string strRequestType = This::m_instance.m_impl->createRequest(PROTO_CONNECTPORT);
string strRequestData = This::m_instance.m_impl->createConnectPortRequest(responderId, responderPortName);
......@@ -1104,7 +1105,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, responderId));
return auto_ptr<Requester>(new Requester(&This::m_instance, responderUrl, requesterPort, responderPort, name, responderId, requesterId));
}
const std::string& Requester::getName() const {
......@@ -1325,6 +1326,7 @@ std::ostream& operator<<(std::ostream& os, const application::Responder& respond
std::ostream& operator<<(std::ostream& os, const application::Requester& requester) {
os << "req." << requester.getName()
<< "." << requester.m_impl->m_requesterId
<< ":" << requester.m_impl->m_application->getName()
<< "." << requester.m_impl->m_application->getId()
<< "@" << requester.m_impl->m_application->getEndpoint();
......
......@@ -439,7 +439,7 @@ public:
void cancel();
private:
Requester(const application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name, int responderId);
Requester(const application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name, int responderId, int requesterId);
std::auto_ptr<RequesterImpl> m_impl;
std::auto_ptr<WaitingImpl> m_waiting;
......
......@@ -28,12 +28,15 @@ using namespace boost;
namespace cameo {
const std::string RequesterImpl::REQUESTER_PREFIX = "req.";
boost::mutex RequesterImpl::m_mutex;
int RequesterImpl::m_requesterCounter = 0;
RequesterImpl::RequesterImpl(const application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name, int responderId) :
RequesterImpl::RequesterImpl(const application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name, int responderId, int requesterId) :
m_application(application),
m_requesterPort(requesterPort),
m_name(name),
m_responderId(responderId) {
m_responderId(responderId),
m_requesterId(requesterId) {
stringstream repEndpoint;
repEndpoint << url << ":" << responderPort;
......@@ -51,10 +54,18 @@ RequesterImpl::~RequesterImpl() {
terminate();
}
std::string RequesterImpl::getRequesterPortName(const std::string& name, int responderId) {
int RequesterImpl::newRequesterId() {
boost::mutex::scoped_lock lock(m_mutex);
m_requesterCounter++;
return m_requesterCounter;
}
std::string RequesterImpl::getRequesterPortName(const std::string& name, int responderId, int requesterId) {
stringstream requesterPortName;
requesterPortName << REQUESTER_PREFIX << name << "." << responderId;
requesterPortName << REQUESTER_PREFIX << name << "." << responderId << "." << requesterId;
return requesterPortName.str();
}
......@@ -185,7 +196,7 @@ void RequesterImpl::terminate() {
if (m_requester.get() != 0) {
m_requester.reset(0);
bool success = m_application->removePort(getRequesterPortName(m_name, m_responderId));
bool success = m_application->removePort(getRequesterPortName(m_name, m_responderId, m_requesterId));
if (!success) {
cerr << "server cannot destroy requester " << m_name << endl;
}
......
......@@ -20,7 +20,7 @@
#include <string>
#include <vector>
#include <stdint.h>
#include <boost/thread.hpp>
#include "GenericWaitingImpl.h"
#include "zmq.hpp"
......@@ -33,10 +33,11 @@ namespace application {
class RequesterImpl {
public:
RequesterImpl(const application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name, int responderId);
RequesterImpl(const application::This * application, const std::string& url, int requesterPort, int responderPort, const std::string& name, int responderId, int requesterId);
~RequesterImpl();
static std::string getRequesterPortName(const std::string& name, int responderId);
static int newRequesterId();
static std::string getRequesterPortName(const std::string& name, int responderId, int requesterId);
WaitingImpl * waiting();
......@@ -55,9 +56,13 @@ public:
std::string m_responderEndpoint;
std::string m_name;
int m_responderId;
int m_requesterId;
std::auto_ptr<zmq::socket_t> m_requester;
static const std::string REQUESTER_PREFIX;
static boost::mutex m_mutex;
static int m_requesterCounter;
};
}
......
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