Re-delegate services after config changes.

This commit is contained in:
Gunnar Beutner 2012-06-27 10:59:08 +02:00
parent a9d865c94f
commit 6f9342a261
4 changed files with 16 additions and 9 deletions

View File

@ -317,6 +317,9 @@ void Socket::ReadThreadProc(void)
lock.lock(); lock.lock();
if (GetFD() == INVALID_SOCKET)
return;
if (rc < 0) { if (rc < 0) {
HandleSocketError(SocketException("select() failed", GetError())); HandleSocketError(SocketException("select() failed", GetError()));
return; return;
@ -362,6 +365,9 @@ void Socket::WriteThreadProc(void)
lock.lock(); lock.lock();
if (GetFD() == INVALID_SOCKET)
return;
if (rc < 0) { if (rc < 0) {
HandleSocketError(SocketException("select() failed", GetError())); HandleSocketError(SocketException("select() failed", GetError()));
return; return;

View File

@ -33,21 +33,12 @@ public:
typedef shared_ptr<Socket> Ptr; typedef shared_ptr<Socket> Ptr;
typedef weak_ptr<Socket> WeakPtr; typedef weak_ptr<Socket> WeakPtr;
//typedef list<Socket::WeakPtr> CollectionType;
//static Socket::CollectionType Sockets;
~Socket(void); ~Socket(void);
//boost::signal<void (const Socket::Ptr&)> OnReadable;
//boost::signal<void (const Socket::Ptr&)> OnWritable;
//boost::signal<void (const Socket::Ptr&)> OnException;
boost::signal<void (const Socket::Ptr&, const std::exception&)> OnError; boost::signal<void (const Socket::Ptr&, const std::exception&)> OnError;
boost::signal<void (const Socket::Ptr&)> OnClosed; boost::signal<void (const Socket::Ptr&)> OnClosed;
virtual void Start(void); virtual void Start(void);
//virtual void Stop(void);
void Close(void); void Close(void);

View File

@ -30,6 +30,7 @@ string DelegationComponent::GetName(void) const
void DelegationComponent::Start(void) void DelegationComponent::Start(void)
{ {
m_AllServices = boost::make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("service")); m_AllServices = boost::make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("service"));
m_AllServices->OnObjectCommitted.connect(boost::bind(&DelegationComponent::ObjectCommittedHandler, this, _2));
m_AllServices->Start(); m_AllServices->Start();
m_DelegationTimer = boost::make_shared<Timer>(); m_DelegationTimer = boost::make_shared<Timer>();
@ -55,6 +56,14 @@ void DelegationComponent::Stop(void)
mgr->UnregisterEndpoint(m_DelegationEndpoint); mgr->UnregisterEndpoint(m_DelegationEndpoint);
} }
void DelegationComponent::ObjectCommittedHandler(const ConfigObject::Ptr& object)
{
Service service(object);
/* object was updated, clear its checker to make sure it's re-delegated by the delegation timer */
service.SetChecker("");
}
void DelegationComponent::AssignService(const Endpoint::Ptr& checker, const Service& service) void DelegationComponent::AssignService(const Endpoint::Ptr& checker, const Service& service)
{ {
RequestMessage request; RequestMessage request;

View File

@ -41,6 +41,7 @@ private:
void NewEndpointHandler(const Endpoint::Ptr& endpoint); void NewEndpointHandler(const Endpoint::Ptr& endpoint);
void SessionEstablishedHandler(const Endpoint::Ptr& endpoint); void SessionEstablishedHandler(const Endpoint::Ptr& endpoint);
void ObjectCommittedHandler(const ConfigObject::Ptr& object);
void DelegationTimerHandler(void); void DelegationTimerHandler(void);
vector<Endpoint::Ptr> GetCheckerCandidates(const Service& service) const; vector<Endpoint::Ptr> GetCheckerCandidates(const Service& service) const;