CarobNS::WatchedControllers Class Reference

Provides a list of controllers and maintains their state (up or down), launching appropriatly methods from callback given callback instance. More...

#include <WatchedControllers.hpp>

List of all members.

Public Member Functions

 WatchedControllers (const std::vector< ControllerInfo > &controllersPrm, int64_t initTime, int controllerTimeout, ControllerStateChangedCallback *cbPtr)
 Creates a new list of watched controllers with the given set of controllers and an initial lastTimeSeen value.
 ~WatchedControllers ()
 Deletes the callback.
void addController (const ControllerInfo &ctrl, int64_t lastTimeSeen)
 Adds a controller to the list and associates the given lastTimeSeenValue to it.
void removeController (const ControllerInfo &ctrl)
 Removes the selected controller and its associated lastTimeSeen.
void setControllerResponsed (const SocketAddress &ctrlAddr, int64_t newTime)
 Associates given lastTimeSeen value to specified controller and update its state: if the controller was considered as down, calls the ControllerStateChangedCallback#onControllerUp(const ControllerInfo&).
void lookForDeadControllers (int64_t currentTime)
 Updates all controllers state according to the given time.
void setControllerDown (const SocketAddress &ctrlAddr)
 Forces the given controller to be considered as down.
std::vector< SocketAddressgetControllerAddresses () const
 Returns a 'safe' read-only iterator on controllers' ControllerInfo.

Classes

class  ControllerAndState
 Holds a controller, its lastTimeSeen variable and its state (up or down).


Detailed Description

Provides a list of controllers and maintains their state (up or down), launching appropriatly methods from callback given callback instance.


To each controller is associated a lastTimeSeen value corresponding to the last time the controller responded to a ping. Their state is updated each time the lastTimeSeen value is accessed (read or written). At init time, all controllers are considered as up (responding to pings). Controllers can also be forced as 'no more responding to pings' (ie. down)


Constructor & Destructor Documentation

CarobNS::WatchedControllers::WatchedControllers ( const std::vector< ControllerInfo > &  controllersPrm,
int64_t  initTime,
int  controllerTimeout,
ControllerStateChangedCallback cbPtr 
)

Creates a new list of watched controllers with the given set of controllers and an initial lastTimeSeen value.


Parameters:
controllersPrm set of controllers identified by their ControllerInfo
initTime initial lastTimeSeen value, typically clock()
controllerTimeout delay after which a controller will be considered as failing if it did not respond to pings
cbPtr Callback implementation to call when a controller state changes


Member Function Documentation

void CarobNS::WatchedControllers::addController ( const ControllerInfo ctrl,
int64_t  lastTimeSeen 
)

Adds a controller to the list and associates the given lastTimeSeenValue to it.

Note that this operation is thread-safe, thus can slow-down other concurrent operations like removeController(const ControllerInfo&), setControllerResponsed(const SocketAddress&, int64_t)

Parameters:
ctrl controller to be added
lastTimeSeen initial time to associate to this controller. Typically the result of gettimeofday()

std::vector<SocketAddress> CarobNS::WatchedControllers::getControllerAddresses (  )  const

Returns a 'safe' read-only iterator on controllers' ControllerInfo.


Creates a copy of the controller hashmap keys and returns a iterator on it. This way, the iterator will not be affected by hashmap operations

Returns:
a vector of all monitored controllers

void CarobNS::WatchedControllers::lookForDeadControllers ( int64_t  currentTime  ) 

Updates all controllers state according to the given time.


Iterates through the controller list and (if the controller was not already considered as down) if the lastTimeSeen value is older than the given time minus controller_timeout, the controller will the be considered as failing, and ControllerStateChangedCallback#onControllerDown(const ControllerInfo&) will be called.

Parameters:
currentTime reference time to compare to last time seen values. Typically the result of gettimeofday()

void CarobNS::WatchedControllers::setControllerDown ( const SocketAddress ctrlAddr  ) 

Forces the given controller to be considered as down.


If the given controller was already down, does nothing. Otherwise, marks it as dead and calls ControllerStateChangedCallback#onControllerDown(const ControllerInfo&)

Parameters:
ctrlAddr controller socket address to consider as failing

void CarobNS::WatchedControllers::setControllerResponsed ( const SocketAddress ctrlAddr,
int64_t  newTime 
)

Associates given lastTimeSeen value to specified controller and update its state: if the controller was considered as down, calls the ControllerStateChangedCallback#onControllerUp(const ControllerInfo&).

Parameters:
ctrlAddr controller socket address to be updated
newTime time to associate to this controller. Typically the result of gettimeofday()
See also:
ControllerStateChangedCallback


The documentation for this class was generated from the following file:
Generated on Fri Mar 9 17:40:20 2007 for Carob by  doxygen 1.4.7