Quick Links:

bal | bbl | bdl | bsl

Public Member Functions | Friends

balm::PublicationScheduler Class Reference

#include <balm_publicationscheduler.h>

List of all members.

Public Member Functions

 BSLMF_NESTED_TRAIT_DECLARATION (PublicationScheduler, bslma::UsesBslmaAllocator)
 PublicationScheduler (MetricsManager *metricsManager, bdlmt::TimerEventScheduler *eventScheduler, bslma::Allocator *basicAllocator=0)
 ~PublicationScheduler ()
void scheduleCategory (const char *category, const bsls::TimeInterval &interval)
void scheduleCategory (const Category *category, const bsls::TimeInterval &interval)
void setDefaultSchedule (const bsls::TimeInterval &interval)
int cancelCategorySchedule (const char *category)
int cancelCategorySchedule (const Category *category)
int clearDefaultSchedule ()
void cancelAll ()
MetricsManagermanager ()
bool findCategorySchedule (bsls::TimeInterval *result, const char *category) const
bool findCategorySchedule (bsls::TimeInterval *result, const Category *category) const
bool getDefaultSchedule (bsls::TimeInterval *result) const
int getCategorySchedule (bsl::vector< bsl::pair< const Category *, bsls::TimeInterval > > *result) const
int getCategorySchedule (std::vector< std::pair< const Category *, bsls::TimeInterval > > *result) const
const MetricsManagermanager () const
bsl::ostream & print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const

Friends

class PublicationScheduler_Proctor

Detailed Description

This class defines a mechanism for scheduling the periodic publication of metrics. Each publication scheduler object is supplied the address of a MetricsManager and a bdlmt::TimerEventScheduler at construction. The metrics manager is used to publish metrics, while the timer-event scheduler provides the underlying scheduling mechanism. Metrics are scheduled for publication using the scheduleCategory and setDefaultSchedule methods. The scheduleCategory method schedules an individual category to be publisher periodically at the provided interval, whereas setDefaultSchedule schedules the periodic publication of any category not given an individual schedule. The publication scheduler will create a recurring timer for each unique time interval supplied, and will group together categories that share a common time interval into a single call to MetricsManager::publish. Note that it is left unspecified whether publication events that occur on a common multiple of different intervals will be grouped into a single invocation of MetricsManager::publish.

See Component balm_publicationscheduler


Constructor & Destructor Documentation

balm::PublicationScheduler::PublicationScheduler ( MetricsManager metricsManager,
bdlmt::TimerEventScheduler eventScheduler,
bslma::Allocator basicAllocator = 0 
)

Create a publication scheduler that will use the specified metricsManager to publish metrics, and the specified eventScheduler to supply timer events. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

balm::PublicationScheduler::~PublicationScheduler (  ) 

Destroy this publication scheduler and cancel any pending publications. Note that, if any metrics are currently being published, this operation will block until all of their publications have completed.


Member Function Documentation

balm::PublicationScheduler::BSLMF_NESTED_TRAIT_DECLARATION ( PublicationScheduler  ,
bslma::UsesBslmaAllocator   
)
void balm::PublicationScheduler::scheduleCategory ( const char *  category,
const bsls::TimeInterval interval 
)

Schedule the specified null-terminated string category to be published periodically at the specified interval using the MetricManager supplied at construction. If category has already been scheduled, change the scheduled period to interval; any previously scheduled publication of category is either canceled or completed (atomically) prior to rescheduling. If a category is rescheduled with the same interval as it is currently scheduled, this operation has no effect. The behavior is undefined unless bsls::TimeInterval(0, 0) < interval.

void balm::PublicationScheduler::scheduleCategory ( const Category category,
const bsls::TimeInterval interval 
)

Schedule the specified category to be published periodically at the specified interval using the MetricManager supplied at construction. If category has already been scheduled, change the scheduled period to interval; any previously scheduled publication of category is either canceled or completed (atomically) prior to rescheduling. If a category is rescheduled with the same interval as it is currently scheduled, this operation has no effect. The behavior is undefined unless bsls::TimeInterval(0, 0) < interval and category is a valid address supplied by the balm::MetricRegistry owned by the MetricsManager object supplied at construction.

void balm::PublicationScheduler::setDefaultSchedule ( const bsls::TimeInterval interval  ) 

Set, to the specified interval, the default interval for metrics to be periodically published using the MetricsManager supplied at construction. This method schedules every metric category not given a individual schedule (using scheduleCategory), to be published periodically until that category is either given an individual schedule, or the default schedule is canceled (using either clearDefaultSchedule or cancelAllPublications). If a default publication has already been scheduled, change its schedule to interval; any previously scheduled publication is either canceled or completed (atomically) before rescheduling. If the default publication is rescheduled with the same interval as it is currently scheduled, this operation has no effect. The behavior is undefined unless bsls::TimeInterval(0, 0) < interval. Note that, to exclude a category from any publication, clients can disable the category using the MetricsManager object supplied at construction.

int balm::PublicationScheduler::cancelCategorySchedule ( const char *  category  ) 

Cancel the periodic publication of the specified null-terminated string category. Return 0 on success, and a non-zero value if the category is not scheduled for publication. Any scheduled publication of category is either canceled or completed before this method returns. Note that if a default publication schedule has been set (using setDefaultSchedule), then category will continue to be published as part of that scheduled default publication; to exclude a category from any publication, clients can disable the category using the MetricsManager object supplied at construction.

int balm::PublicationScheduler::cancelCategorySchedule ( const Category category  ) 

Cancel the periodic publication of the specified category. Return 0 on success, and a non-zero value if the category is not scheduled for publication. Any scheduled publication of category is either canceled or completed before this method returns. The behavior is undefined unless category is a valid address supplied by the balm::MetricRegistry owned by metricsManager. Note that if a default publication schedule has been set (using setDefaultSchedule), then category will continue to be published as part of that scheduled default publication; to exclude a category from any publication, clients can disable the category using the MetricsManager object supplied at construction.

int balm::PublicationScheduler::clearDefaultSchedule (  ) 

If the default publication schedule has been set (using setDefaultSchedule), cancel that periodic default publication, and return 0. This method has no effect and will return a non-zero value if a default publication schedule has not been set. Any scheduled publication is either canceled or completed before this method returns.

void balm::PublicationScheduler::cancelAll (  ) 

Cancel all periodic publication of metrics. This operation (atomically) clears the default publication schedule and cancels the publication schedule of any category individually scheduled using the scheduleCategory method. Any scheduled publication is either canceled or completed before this method returns.

MetricsManager* balm::PublicationScheduler::manager (  ) 

Return the address of the modifiable metrics manager for which this publication scheduler publishes metrics.

bool balm::PublicationScheduler::findCategorySchedule ( bsls::TimeInterval result,
const char *  category 
) const

Load into the specified result the individual schedule interval (set using the scheduleCategory method) that corresponds to the specified null-terminated string category, if found, and return true, or (if not found) return false with no effect. This method will return false and will not modify result if category is published as part of the default scheduled publication.

bool balm::PublicationScheduler::findCategorySchedule ( bsls::TimeInterval result,
const Category category 
) const

Load into the specified result the individual schedule interval (set using the scheduleCategory method) that corresponds to the specified category, if found, and return true, or (if not found) return false with no effect. This method will return false and will not modify result if category is published as part of the default scheduled publication. The behavior is undefined unless category is a valid address supplied by the balm::MetricRegistry owned by the MetricsManager object supplied at construction.

bool balm::PublicationScheduler::getDefaultSchedule ( bsls::TimeInterval result  )  const

Load into the specified result the default scheduled interval, (set using the setDefaultSchedule method), for periodically publishing metrics, if found, and return true, or (if not found) return false with no effect.

int balm::PublicationScheduler::getCategorySchedule ( bsl::vector< bsl::pair< const Category *, bsls::TimeInterval > > *  result  )  const
int balm::PublicationScheduler::getCategorySchedule ( std::vector< std::pair< const Category *, bsls::TimeInterval > > *  result  )  const

Load into the specified result a representation of the current schedule for publishing categories being followed by this scheduler and return the number of scheduled categories. The schedule is represented using a series of (category address, time interval) pairs; each pair in the series indicates the periodic time interval that the associated category will be published. Note that the result of this operation contains only those categories scheduled using the scheduleCategory operation, and does not include categories published as part of the default publication.

const MetricsManager* balm::PublicationScheduler::manager (  )  const

Return the address of the non-modifiable metrics manager for which this publication scheduler will publish metrics.

bsl::ostream& balm::PublicationScheduler::print ( bsl::ostream &  stream,
int  level = 0,
int  spacesPerLevel = 4 
) const

Print a formatted string describing the current state of this PublicationScheduler object to the specified stream at the (absolute value of) the optionally specified indentation level and return a reference to stream. If level is specified, optionally specify spacesPerLevel, the number of spaces per indentation level for this and all of its nested objects. If level is negative, suppress indentation of the first line. If spacesPerLevel is negative, suppress all indentation AND format the entire output on one line. If stream is not valid on entry, this operation has no effect. Note that this is provided primarily for debugging purposes.


Friends And Related Function Documentation

friend class PublicationScheduler_Proctor [friend]

The documentation for this class was generated from the following file: