|
neic-glass3
1.4.6
|
glass output class More...
#include <output.h>


Public Member Functions | |
| output () | |
| output constructor More... | |
| ~output () | |
| output destructor More... | |
| bool | setup (std::shared_ptr< const json::Object > config) override |
| output configuration function More... | |
| void | clear () override |
| output clear function More... | |
| void | sendToOutput (std::shared_ptr< json::Object > message) override |
| output message sending function More... | |
| bool | start () override |
| work thread start function More... | |
| bool | healthCheck () override |
| output heath check function More... | |
| void | setSiteListRequestInterval (int delay) |
| Function to set the interval for requesting the site list. More... | |
| int | getSiteListRequestInterval () |
| Function to retrieve the interval for requesting the site list. More... | |
| void | setReportInterval (int interval) |
| Function to set the interval to generate informational reports. More... | |
| int | getReportInterval () |
| Function to retrieve the interval to generate informational reports. More... | |
| void | setAssociator (glass3::util::iAssociator *associator) |
| Function to set the associator interface pointer. More... | |
| glass3::util::iAssociator * | getAssociator () |
| Function to get the associator interface pointer. More... | |
| void | setPubOnExpiration (bool pub) |
| Function to set the publish on expiration flag. More... | |
| bool | getPubOnExpiration () |
| Function to retrieve the publish on expiration flag. More... | |
| void | setImmediatePubThreshold (double threshold) |
| Function to set the immediate publication threshold. More... | |
| double | getImmediatePubThreshold () |
| Function to retrieve the immediate publication threshold. More... | |
| std::vector< int > | getPubTimes () |
| Function to retrieve the publication times. More... | |
| void | addPubTime (int pubTime) |
| Function to add a single publication time to the list. More... | |
| void | clearPubTimes () |
| Function to clear the publication times. More... | |
| bool | addTrackingData (std::shared_ptr< json::Object > data) |
| add tracking information to the output tracking cache More... | |
| std::shared_ptr< const json::Object > | getTrackingData (std::string id) |
| get tracking information from the output tracking cache by id More... | |
| std::shared_ptr< const json::Object > | getNextTrackingData () |
| get tracking information from the output tracking cache More... | |
| bool | haveTrackingData (std::shared_ptr< json::Object > data) |
| check if tracking information is in output tracking cache More... | |
| bool | haveTrackingData (std::string ID) |
| check if information is in output tracking cache by id More... | |
| bool | removeTrackingData (std::shared_ptr< const json::Object > data) |
| remove tracking information from the output tracking cache More... | |
| bool | removeTrackingData (std::string ID) |
| remove tracking information from the output tracking cache by id More... | |
| void | clearTrackingData () |
| clear output tracking cache More... | |
| bool | isDataReady (std::shared_ptr< const json::Object > data) |
| check to see if tracking information is ready for output More... | |
| bool | isDataChanged (std::shared_ptr< const json::Object > data) |
| check to see if detection data has changed More... | |
| bool | isDataPublished (std::shared_ptr< const json::Object > data, bool ignoreVersion=true) |
| check to see if tracking information has been published More... | |
| bool | isDataFinished (std::shared_ptr< const json::Object > data) |
| check to see if tracking information is finished More... | |
| void | writeOutput (std::shared_ptr< json::Object > data) |
| output writing function More... | |
| glass3::util::WorkState | work () override |
| output background work function More... | |
Public Member Functions inherited from glass3::util::ThreadBaseClass | |
| ThreadBaseClass () | |
| ThreadBaseClass constructor. More... | |
| ThreadBaseClass (std::string threadName, int sleepTimeMS=100, int numThreads=1, int checkInterval=300) | |
| An advanced constructor that sets up the ThreadBaseClass with a provided thread name, sleep between work time duration, number of threads, and statsus check interval. More... | |
| ~ThreadBaseClass () | |
| ThreadBaseClass destructor. More... | |
| virtual bool | stop () |
| work thread stop function More... | |
| int | getNumThreads () |
| Retrieves the number of work threads. More... | |
| void | setNumThreads (int numThreads) |
| Sets the number of work threads. More... | |
| void | setThreadHealth (bool health=true) |
| Function to set thread health. More... | |
| void | setSleepTime (int sleepTimeMS) |
| Sets the time to sleep between work() calls. More... | |
| int | getSleepTime () |
| Retrieves the time to sleep between work() calls. More... | |
| glass3::util::ThreadState | getWorkThreadsState () |
| Function to get the work threads state. More... | |
| void | setHealthCheckInterval (int interval) |
| Function to set work threads health check interval. More... | |
| int | getHealthCheckInterval () |
| Function to retrieve the work threads health check interval. More... | |
| bool | getTerminate () |
| Function to retrieve whether the thread should terminate. More... | |
| const std::string & | getThreadName () |
| Function to retrieve the name of the work threads. More... | |
| std::time_t | getAllLastHealthy (size_t *pThreadId) |
| Function to retrieve the oldest time any of the work threads last updated their health status as healthy. More... | |
Public Member Functions inherited from glass3::util::BaseClass | |
| BaseClass () | |
| BaseClass constructor. More... | |
| virtual | ~BaseClass () |
| BaseClass destructor. More... | |
| const std::shared_ptr< const json::Object > | getConfig () |
| bool | getSetup () |
| Retrieves the class member boolean flag indicating whether the class has been setup, set to true if setup was successful. More... | |
| const std::string & | getDefaultAgencyId () |
| Function to retrieve the name of the default agency id. More... | |
| void | setDefaultAgencyId (const std::string &id) |
| Function to set the name of the default agency id. More... | |
| const std::string & | getDefaultAuthor () |
| Function to retrieve the name of the default author. More... | |
| void | setDefaultAuthor (const std::string &author) |
| Function to set the name of the default author. More... | |
Static Public Attributes | |
| static constexpr int | k_iMinimumPublicationTime = 10 |
| The minimum time in seconds to publish an event. More... | |
Protected Member Functions | |
| void | checkEventsLoop () |
| output tracking data background work function More... | |
| virtual void | sendOutput (const std::string &type, const std::string &id, const std::string &message)=0 |
| Send output data. More... | |
| virtual void | sendHeartbeat () |
| Send heartbeats. More... | |
Protected Member Functions inherited from glass3::util::ThreadBaseClass | |
| void | setWorkThreadsState (glass3::util::ThreadState state) |
| Function to set threads state. More... | |
| void | workLoop () |
| ThreadBaseClass work loop function. More... | |
| void | setLastHealthy (std::time_t now) |
| Function to set the last time the work thread was healthy. More... | |
Additional Inherited Members | |
Protected Attributes inherited from glass3::util::ThreadBaseClass | |
| std::vector< std::thread > | m_WorkThreads |
| the std::vector that contains the work std::thread objects More... | |
| std::map< std::thread::id, std::atomic< int > > | m_ThreadHealthMap |
| A std::map containing the epoch times as std::atomic<double>> that each work thread was last marked as healthy, identified by the thread id. More... | |
Protected Attributes inherited from glass3::util::BaseClass | |
| std::shared_ptr< const json::Object > | m_Config |
| A shared pointer to the json::Object that holds the configuration. More... | |
| std::atomic< bool > | m_bIsSetup |
| the boolean flag indicating whether the class has been setup, set to true if setup was successful. More... | |
| std::string | m_DefaultAgencyID |
| A std::string containing the default agency id to use in parsing if one is not provided. More... | |
| std::string | m_DefaultAuthor |
| A std::string containing the default author to use in parsing if one is not provided. More... | |
glass output class
The glass3 output class is a class that performs the publication tracking and translation tasks for neic-glass3.
The Output class utilizes the internal glasscore Event, Cancel, and Expire messages as defined at https://github.com/usg/neic-glass3/blob/code-review/doc/internal-formats/Event.md // NOLINT https://github.com/usg/neic-glass3/blob/code-review/doc/internal-formats/Cancel.md // NOLINT https://github.com/usg/neic-glass3/blob/code-review/doc/internal-formats/Expire.md // NOLINT for publication tracking. The class uses a configurable set of fixed publication times to determine when to publish. These messages are passed to Output via the sendToOutput function from the iOutput interface
The output class generates the internal formats ReqHypo and ReqSiteList messages defined at https://github.com/usg/neic-glass3/blob/code-review/doc/internal-formats/ReqHypo.md // NOLINT https://github.com/usg/neic-glass3/blob/code-review/doc/internal-formats/ReqSiteList.md // NOLINT to request detailed event detection and site list information from glasscore via the m_Associator pointer.
The output class translates the internal glasscore Hypo, SiteList and SiteLookup messages as messages as defined at https://github.com/usg/neic-glass3/blob/code-review/doc/internal-formats/Hypo.md // NOLINT https://github.com/usg/neic-glass3/blob/code-review/doc/internal-formats/SiteList.md // NOLINT https://github.com/usg/neic-glass3/blob/code-review/doc/internal-formats/SiteLookup.md // NOLINT detection formats messages, as defined at https://github.com/usgs/earthquake-detection-formats/tree/master/format-docs
The Output class is designed to be extended in order to define application specific output mechanisms (i.e. file output).
output inherits from the glass3::util::ThreadBaseClass class. output implements the glass3::util::iOutput interface.
| glass3::output::output::output | ( | ) |
output constructor
The constructor for the output class. Initializes members to default values.
| glass3::output::output::~output | ( | ) |
output destructor
The destructor for the output class. Stops the work thread
| void glass3::output::output::addPubTime | ( | int | pubTime | ) |
Function to add a single publication time to the list.
This function adds a single publication time in seconds to the list used to determine when to generate detection messages for events. An event will not generate a message if it has not changed, and will not generate a message if all publication times have passed (unless m_bPubOnExpiration is set to true)
| pubTime | = An integer containing a times in seconds since initial report that events should generate detection messages |
| bool glass3::output::output::addTrackingData | ( | std::shared_ptr< json::Object > | data | ) |
add tracking information to the output tracking cache
Add the glasscore event message (used for tracking) as defined at https://github.com/usg/neic-glass3/blob/code-review/doc/internal-formats/Event.md // NOLINT to the tracking cache as the tracking information
| data | - A shared_ptr to a json::Object containing the glasscore event message used as the tracking information |
|
protected |
output tracking data background work function
This function is used to manage the tracking cache, and to send request data (such as hypocenters) from the associator
|
overridevirtual |
output clear function
The clear function for the output class. Resets members to default values.
Reimplemented from glass3::util::BaseClass.
Reimplemented in glass3::fileOutput, and glass3::brokerOutput.
| void glass3::output::output::clearPubTimes | ( | ) |
Function to clear the publication times.
This function clears the publication times in seconds used to determine when to generate detection messages for events.
| void glass3::output::output::clearTrackingData | ( | ) |
clear output tracking cache
Clear all tracking information from the output tracking cache.
| glass3::util::iAssociator * glass3::output::output::getAssociator | ( | ) |
Function to get the associator interface pointer.
This function gets the associator interface pointer used by output to communicate with the associator via the Associator::sendToAssociator() function
| double glass3::output::output::getImmediatePubThreshold | ( | ) |
Function to retrieve the immediate publication threshold.
This function retrieves the threshold used to determine whether output should generate a detection message when it receives an event message with a sufficent bayes value from the associator.
| std::shared_ptr< const json::Object > glass3::output::output::getNextTrackingData | ( | ) |
get tracking information from the output tracking cache
Get the first ready tracking data from the cache by starting at the beginning of the cache and evaluating each tracking data with isDataReady()
| bool glass3::output::output::getPubOnExpiration | ( | ) |
Function to retrieve the publish on expiration flag.
This function retrieves the boolean flag that indicates whether output should generate a detection message when it receives an expiration notification from the associator.
| std::vector< int > glass3::output::output::getPubTimes | ( | ) |
Function to retrieve the publication times.
This function retrieves the publication times in seconds used to determine when to generate detection messages for events. An event will not generate a message if it has not changed, and will not generate a message if all publication times have passed (unless m_bPubOnExpiration is set to true)
| int glass3::output::output::getReportInterval | ( | ) |
Function to retrieve the interval to generate informational reports.
This function retrieves the interval in seconds between logging informationalreports on output throughput and performance
| int glass3::output::output::getSiteListRequestInterval | ( | ) |
Function to retrieve the interval for requesting the site list.
This function retrieves the interval in seconds between requesting glass core's current sitelist
| std::shared_ptr< const json::Object > glass3::output::output::getTrackingData | ( | std::string | id | ) |
get tracking information from the output tracking cache by id
Get the tracking information from the cache of tracking information pending for output based on a provided id
| id | - A std::string containing the id of the tracking information to retrieve from the cache |
| bool glass3::output::output::haveTrackingData | ( | std::shared_ptr< json::Object > | data | ) |
check if tracking information is in output tracking cache
Check to see if given tracking information is already in the output tracking cache.
| data | - A shared_ptr to a json::Object containing the glasscore event message used as the tracking information |
| bool glass3::output::output::haveTrackingData | ( | std::string | ID | ) |
check if information is in output tracking cache by id
Check to see if tracking information is already in the output tracking cache by the given id.
| ID | - A std::string containing the id of the detection data to check. |
|
overridevirtual |
output heath check function
Overrides ThreadBaseClass::healthCheck to add monitoring the thread pool. Uses ThreadBaseClass::healthCheck to monitor worker threads
Reimplemented from glass3::util::ThreadBaseClass.
| bool glass3::output::output::isDataChanged | ( | std::shared_ptr< const json::Object > | data | ) |
check to see if detection data has changed
Check the given dtracking information to see if it has been changed
| data | - A shared_ptr to a json::Object containing the glasscore event message used as the tracking information to check |
| bool glass3::output::output::isDataFinished | ( | std::shared_ptr< const json::Object > | data | ) |
check to see if tracking information is finished
Check the given tracking information to see if is finished (no more publications)
| data | - A shared_ptr to a json::Object containing the glasscore event message used as the tracking information to check |
| bool glass3::output::output::isDataPublished | ( | std::shared_ptr< const json::Object > | data, |
| bool | ignoreVersion = true |
||
| ) |
check to see if tracking information has been published
Check the given tracking information to see if it has been previously published. Optionally ignore the current version when doing the check. This is used when determining whether tracking information has ever been published (i.e. when generating a retraction message)
| data | - A shared_ptr to a json::Object containing the glasscore event message used as the tracking information to check |
| ignoreVersion | - A boolen flag indicating whether to ignore the tracking current information version |
| bool glass3::output::output::isDataReady | ( | std::shared_ptr< const json::Object > | data | ) |
check to see if tracking information is ready for output
Check the given tracking information to see if it is ready for output
| data | - A shared_ptr to a json::Object containing the glasscore event message used as the tracking information to check |
| bool glass3::output::output::removeTrackingData | ( | std::shared_ptr< const json::Object > | data | ) |
remove tracking information from the output tracking cache
Remove the provided tracking information from the output tracking cache.
| data | - A shared_ptr to a json::Object containing the glasscore event message used as the tracking information to remove |
| bool glass3::output::output::removeTrackingData | ( | std::string | ID | ) |
remove tracking information from the output tracking cache by id
Remove the tracking information from the output tracking cache using the given id
| ID | - A std::string containing the id of the detection data to remove. |
|
protectedvirtual |
Send heartbeats.
This function is optionally used by an overriding class to implement a specific heartbeat method, i.e. to disk, memory, socket, kafka, etc.
Reimplemented in glass3::brokerOutput.
|
protectedpure virtual |
Send output data.
This pure virtual function is used to send output data. It is expected that the implementing class will override this function to implement a specific output method, i.e. to disk, memory, socket, kafka, etc.
| type | - A std::string containing the type of the message |
| id | - A std::string containing the id of the message |
| message | - A std::string containing the message |
Implemented in glass3::fileOutput, and glass3::brokerOutput.
|
overridevirtual |
output message sending function
The function (from glass3::util::iOutput) used by other libraries to send messages to output.
| message | - A shared_ptr to a json::Object containing the message to send to output. |
Implements glass3::util::iOutput.
| void glass3::output::output::setAssociator | ( | glass3::util::iAssociator * | associator | ) |
Function to set the associator interface pointer.
This function sets the associator interface pointer used by output to communicate with the associator via the Associator::sendToAssociator() function
| associator | = A pointer to an object that implements the glass3::util::iAssociator interface. |
| void glass3::output::output::setImmediatePubThreshold | ( | double | threshold | ) |
Function to set the immediate publication threshold.
This function sets the threshold used to determine whether output should generate a detection message when it receives an event message with a sufficent bayes value from the associator.
| threshold | - A double value containing the immediate publication threshold |
| void glass3::output::output::setPubOnExpiration | ( | bool | pub | ) |
Function to set the publish on expiration flag.
This function sets the boolean flag that indicates whether output should generate a detection message when it receives an expiration notification from the associator.
| pub | = A boolean flag indicating whether to generate a detection message on expiration |
| void glass3::output::output::setReportInterval | ( | int | interval | ) |
Function to set the interval to generate informational reports.
This function sets the interval in seconds between logging informational reports on output throughput and performance
| interval | = An integer value containing the interval in seconds |
| void glass3::output::output::setSiteListRequestInterval | ( | int | delay | ) |
Function to set the interval for requesting the site list.
This function sets the interval in seconds between requesting glass core's current site list. A negative delay indicates that the site list should not be requested
| delay | = An integer value containing the delay in seconds |
|
overridevirtual |
output configuration function
The function configures the output class.
The setup() function can be called multiple times, in order to reload or update configuration information.
| config | - A pointer to a json::Object containing to the configuration to use |
Reimplemented from glass3::util::BaseClass.
Reimplemented in glass3::fileOutput, and glass3::brokerOutput.
|
overridevirtual |
work thread start function
Overrides ThreadBaseClass::start() to create a thread to run the checkEventsLoop() function and add the thread to ThreadBaseClass list of threads, so it can be managed
Reimplemented from glass3::util::ThreadBaseClass.
|
overridevirtual |
output background work function
The function (from ThreadBaseClass) used to do background work. It is used to process messages from the associator, and to queue messages to be written out
Implements glass3::util::ThreadBaseClass.
| void glass3::output::output::writeOutput | ( | std::shared_ptr< json::Object > | data | ) |
output writing function
The function used to translate and generate output data
| data | - A shared_ptr to a json::Object containing the data to be output. |
|
static |
The minimum time in seconds to publish an event.
1.8.11