helics  2.8.1
Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
helics::BrokerBase Class Referenceabstract

#include <BrokerBase.hpp>

+ Inheritance diagram for helics::BrokerBase:

Public Member Functions

 BrokerBase (bool DisableQueue=false) noexcept
 
 BrokerBase (const std::string &broker_name, bool DisableQueue=false)
 
int parseArgs (int argc, char *argv[])
 
int parseArgs (std::vector< std::string > args)
 
int parseArgs (const std::string &initializationString)
 
virtual void configureBase ()
 
void addActionMessage (const ActionMessage &m)
 
void addActionMessage (ActionMessage &&m)
 
void setLoggerFunction (std::function< void(int, const std::string &, const std::string &)> logFunction)
 
void logFlush ()
 
bool isRunning () const
 
void setLogLevel (int32_t level)
 
void setLogLevels (int32_t consoleLevel, int32_t fileLevel)
 
global_broker_id getGlobalId () const
 
std::function< void(int, const std::string &, const std::string &)> getLoggingCallback () const
 
void joinAllThreads ()
 
std::size_t currentMessageCounter () const
 

Protected Types

enum  broker_state_t : int16_t {
  broker_state_t::created = -6, broker_state_t::configuring = -5, broker_state_t::configured = -4, broker_state_t::connecting = -3,
  broker_state_t::connected = -2, broker_state_t::initializing = -1, broker_state_t::operating = 0, broker_state_t::terminating = 1,
  broker_state_t::terminated = 3, broker_state_t::errored = 7
}
 
enum  TickForwardingReasons : uint32_t { none = 0, no_comms = 0x01, ping_response = 0x02, query_timeout = 0x04 }
 

Protected Member Functions

void setTickForwarding (TickForwardingReasons reason, bool value=true)
 
broker_state_t getBrokerState () const
 
bool setBrokerState (broker_state_t newState)
 
bool transitionBrokerState (broker_state_t expectedState, broker_state_t newState)
 
virtual void processDisconnect (bool skipUnregister=false)=0
 
virtual bool tryReconnect ()=0
 
virtual void processCommand (ActionMessage &&cmd)=0
 
virtual void processPriorityCommand (ActionMessage &&command)=0
 
virtual bool sendToLogger (global_federate_id federateID, int logLevel, const std::string &name, const std::string &message) const
 
void saveProfilingData (const std::string &message)
 
void writeProfilingData ()
 
void generateNewIdentifier ()
 
virtual std::string generateLocalAddressString () const =0
 
virtual std::shared_ptr< helicsCLI11AppgenerateCLI ()
 
void setErrorState (int eCode, const std::string &estring)
 
void setLoggingFile (const std::string &lfile)
 
bool getFlagValue (int32_t flag) const
 

Static Protected Member Functions

static bool isReasonForTick (std::uint32_t code, TickForwardingReasons reason)
 

Protected Attributes

std::atomic< global_broker_idglobal_id
 the unique identifier for the broker(core or broker) More...
 
global_broker_id global_broker_id_local {}
 
global_broker_id higher_broker_id {0}
 the id code of the broker 1 level about this broker
 
std::atomic< int32_t > maxLogLevel
 the logging level to use levels >=this will be ignored More...
 
int32_t consoleLogLevel {1}
 the logging level for console display
 
int32_t fileLogLevel {1}
 the logging level for logging to a file
 
int32_t minFederateCount
 the minimum number of federates that must connect before entering init mode More...
 
int32_t minBrokerCount
 the minimum number of brokers that must connect before entering init mode More...
 
int32_t maxFederateCount {(std::numeric_limits<int32_t>::max)()}
 
int32_t maxBrokerCount {(std::numeric_limits<int32_t>::max)()}
 
int32_t maxIterationCount {10000}
 the maximum number of iterative loops that are allowed
 
Time tickTimer {5.0}
 the length of each heartbeat tick
 
Time timeout {30.0}
 timeout to wait to establish a broker connection before giving up
 
Time networkTimeout {-1.0}
 timeout to establish a socket connection before giving up
 
Time queryTimeout {15.0}
 
Time errorDelay {10.0}
 time to delay before terminating after error state
 
std::string identifier
 an identifier for the broker
 
std::string brokerKey
 
std::string address
 network location of the broker
 
std::shared_ptr< spdlog::logger > consoleLogger
 default logging object to use if the logging callback is not specified
 
std::shared_ptr< spdlog::logger > fileLogger
 default logging object to use if the logging callback is not specified
 
std::thread queueProcessingThread
 thread for running the broker
 
std::function< void(int, const std::string &, const std::string &)> loggerFunction
 
std::atomic< bool > haltOperations
 flag indicating that no further message should be processed More...
 
bool restrictive_time_policy
 flag indicating the broker should use a conservative time policy More...
 
bool terminate_on_error
 flag indicating that the federation should halt on any error More...
 
bool debugging {false}
 flag indicating operation in a user debugging mode
 
std::string logFile
 the file to log message to
 
std::unique_ptr< ForwardingTimeCoordinatortimeCoord
 object managing the time control
 
gmlc::containers::BlockingPriorityQueue< ActionMessageactionQueue
 primary routing queue
 
bool noAutomaticID {false}
 the broker should not automatically generate an ID
 
bool hasTimeDependency {false}
 set to true if the broker has Time dependencies
 
bool enteredExecutionMode
 flag indicating that the broker has entered execution mode More...
 
bool waitingForBrokerPingReply {false}
 flag indicating we are waiting for a ping reply
 
bool hasFilters {false}
 flag indicating filters come through the broker
 
bool no_ping {false}
 indicator that the broker is not very responsive to ping requests
 
bool uuid_like {false}
 will be set to true if the name looks like a uuid
 
bool useJsonSerialization {false}
 
bool enable_profiling {false}
 indicator that profiling is enabled
 
decltype(std::chrono::steady_clock::now()) errorTimeStart
 time when the error condition started related to the errorDelay
 
std::atomic< int > lastErrorCode {0}
 storage for last error code
 
std::string lastErrorString
 storage for last error string
 

Friends

class TimeoutMonitor
 
const friend std::string & brokerStateName (broker_state_t state)
 

Detailed Description

base class for broker like objects

Member Enumeration Documentation

◆ broker_state_t

enum helics::BrokerBase::broker_state_t : int16_t
strongprotected

enumeration of the possible core states

Enumerator
created 

the broker has been created

configuring 

the broker is in the processing of configuring

configured 

the broker itself has been configured and is ready to connect

connecting 

the connection process has started

connected 

the connection process has completed

initializing 

the enter initialization process has started

operating 

normal operating conditions

terminating 

the termination process has started

terminated 

the termination process has started

errored 

an error was encountered

Member Function Documentation

◆ addActionMessage() [1/2]

void helics::BrokerBase::addActionMessage ( ActionMessage &&  m)

move a action Message into the commandQueue

References actionQueue, and helics::isPriorityCommand().

◆ addActionMessage() [2/2]

void helics::BrokerBase::addActionMessage ( const ActionMessage m)

add an action Message to the process queue

if (m.action() == CMD_TIME_REQUEST && m.actionTime>timeZero) {

References actionQueue, and helics::isPriorityCommand().

Referenced by helics::CommonCore::addDependency(), helics::CommonCore::addDestinationFilterToEndpoint(), helics::CoreBroker::addDestinationFilterToEndpoint(), helics::CommonCore::addDestinationTarget(), helics::CommonCore::addSourceFilterToEndpoint(), helics::CoreBroker::addSourceFilterToEndpoint(), helics::CommonCore::addSourceTarget(), helics::CoreBroker::clearTimeBarrier(), helics::CommonCore::closeHandle(), configureBase(), helics::CommonCore::dataLink(), helics::CoreBroker::dataLink(), helics::CoreBroker::disconnect(), helics::CommonCore::disconnect(), helics::CommonCore::enterExecutingMode(), helics::CommonCore::enterInitializingMode(), helics::CommonCore::finalize(), helics::CoreBroker::globalError(), helics::TimeoutMonitor::pingReply(), helics::TimeoutMonitor::pingSub(), helics::CommonCore::processDisconnect(), helics::CommonCore::query(), helics::CoreBroker::query(), helics::CommonCore::registerFederate(), helics::CommonCore::removeTarget(), helics::CommonCore::requestTimeIterative(), helics::CommonCore::send(), helics::CommonCore::sendEvent(), helics::CommonCore::sendMessage(), setErrorState(), helics::CommonCore::setFlagOption(), helics::CommonCore::setGlobal(), helics::CommonCore::setIntegerProperty(), helics::CommonCore::setLoggingLevel(), helics::CoreBroker::setLoggingLevel(), helics::CoreBroker::setTimeBarrier(), helics::TimeoutMonitor::tick(), and helics::CommonCore::timeRequest().

◆ configureBase()

void helics::BrokerBase::configureBase ( )
virtual

◆ currentMessageCounter()

std::size_t helics::BrokerBase::currentMessageCounter ( ) const
inline

get the number of messages that have been processed internally

◆ generateCLI()

std::shared_ptr< helicsCLI11App > helics::BrokerBase::generateCLI ( )
protectedvirtual

◆ generateLocalAddressString()

virtual std::string helics::BrokerBase::generateLocalAddressString ( ) const
protectedpure virtual

◆ generateNewIdentifier()

void helics::BrokerBase::generateNewIdentifier ( )
protected

generate a new random id

References identifier, and uuid_like.

◆ getFlagValue()

bool helics::BrokerBase::getFlagValue ( int32_t  flag) const
protected

get the value of a particular flag

References helics_flag_dumplog, and helics_flag_force_logging_flush.

Referenced by helics::CommonCore::getFlagOption().

◆ getGlobalId()

global_broker_id helics::BrokerBase::getGlobalId ( ) const
inline

get the internal global broker id

References global_id.

Referenced by helics::CoreBroker::globalError().

◆ getLoggingCallback()

std::function< void(int, const std::string &, const std::string &)> helics::BrokerBase::getLoggingCallback ( ) const

generate a callback function for the logging purposes

References global_id, and sendToLogger().

◆ isReasonForTick()

static bool helics::BrokerBase::isReasonForTick ( std::uint32_t  code,
TickForwardingReasons  reason 
)
inlinestaticprotected

check whether a code contains a specific reason

◆ isRunning()

bool helics::BrokerBase::isRunning ( ) const
inline

check if the main processing loop of a broker is running

◆ joinAllThreads()

void helics::BrokerBase::joinAllThreads ( )

◆ logFlush()

void helics::BrokerBase::logFlush ( )

flush the loggers

References consoleLogger, and fileLogger.

◆ parseArgs() [1/3]

int helics::BrokerBase::parseArgs ( const std::string &  initializationString)

parse configuration information from a string of command line like arguments

Returns
0 for OK, positive numbers for expected information calls and negative number for error

References generateCLI().

◆ parseArgs() [2/3]

int helics::BrokerBase::parseArgs ( int  argc,
char *  argv[] 
)

parse configuration information from command line arguments

Returns
0 for OK, positive numbers for expected information calls and negative number for error

References generateCLI().

Referenced by helics::CommonCore::configure(), helics::CoreBroker::configure(), helics::CommonCore::configureFromArgs(), helics::CoreBroker::configureFromArgs(), helics::CommonCore::configureFromVector(), and helics::CoreBroker::configureFromVector().

◆ parseArgs() [3/3]

int helics::BrokerBase::parseArgs ( std::vector< std::string >  args)

parse configuration information from a vector of command line like arguments

Returns
0 for OK, positive numbers for expected information calls and negative number for error

References generateCLI().

◆ processCommand()

virtual void helics::BrokerBase::processCommand ( ActionMessage &&  cmd)
protectedpure virtual

process a single command action

cmd may be modified by this function

Implemented in helics::CommonCore.

◆ processDisconnect()

virtual void helics::BrokerBase::processDisconnect ( bool  skipUnregister = false)
protectedpure virtual

process a disconnect signal

Implemented in helics::CommonCore, and helics::CoreBroker.

◆ processPriorityCommand()

virtual void helics::BrokerBase::processPriorityCommand ( ActionMessage &&  command)
protectedpure virtual

function to process a priority command independent of the main queue

called when processing a priority command. The priority command has a response message which gets sent this mainly deals with some of the registration functions

Parameters
commandthe command to process

Implemented in helics::CommonCore.

◆ saveProfilingData()

void helics::BrokerBase::saveProfilingData ( const std::string &  message)
protected

save a profiling message

References helics::parent_broker_id, sendToLogger(), and warning.

◆ sendToLogger()

bool helics::BrokerBase::sendToLogger ( global_federate_id  federateID,
int  logLevel,
const std::string &  name,
const std::string &  message 
) const
protectedvirtual

◆ setErrorState()

void helics::BrokerBase::setErrorState ( int  eCode,
const std::string &  estring 
)
protected

◆ setLoggerFunction()

void helics::BrokerBase::setLoggerFunction ( std::function< void(int, const std::string &, const std::string &)>  logFunction)

set the logging callback function

Parameters
logFunctiona function with a signature of void(int level, const std::string &source, const std::string &message) the function takes a level indicating the logging level string with the source name and a string with the message

References loggerFunction.

◆ setLoggingFile()

void helics::BrokerBase::setLoggingFile ( const std::string &  lfile)
protected

set the logging file if using the default logger

References fileLogger, identifier, and logFile.

Referenced by helics::CommonCore::setLogFile(), and helics::CoreBroker::setLogFile().

◆ setLogLevel()

void helics::BrokerBase::setLogLevel ( int32_t  level)

set the logging level

References setLogLevels().

◆ setLogLevels()

void helics::BrokerBase::setLogLevels ( int32_t  consoleLevel,
int32_t  fileLevel 
)

set the logging levels

Parameters
consoleLevelthe logging level for the console display
fileLevelthe logging level for the log file

References consoleLogLevel, fileLogLevel, and maxLogLevel.

Referenced by setLogLevel().

◆ setTickForwarding()

void helics::BrokerBase::setTickForwarding ( TickForwardingReasons  reason,
bool  value = true 
)
protected

set tick forwarding for a specific reason

◆ tryReconnect()

bool helics::BrokerBase::tryReconnect ( )
protectedpure virtual

in the case of connection failure with a broker this function will try a reconnect procedure

◆ writeProfilingData()

void helics::BrokerBase::writeProfilingData ( )
protected

write profiler data to file

Friends And Related Function Documentation

◆ brokerStateName

const friend std::string& brokerStateName ( broker_state_t  state)
friend

helper function to generate the name of a state as a string

Member Data Documentation

◆ brokerKey

std::string helics::BrokerBase::brokerKey
protected

a key that all joining federates must have to connect if empty no key is required

Referenced by helics::CommonCore::connect().

◆ enteredExecutionMode

bool helics::BrokerBase::enteredExecutionMode
protected
Initial value:
{
false}

flag indicating that the broker has entered execution mode

◆ global_broker_id_local

global_broker_id helics::BrokerBase::global_broker_id_local {}
protected

◆ global_id

std::atomic<global_broker_id> helics::BrokerBase::global_id
protected

◆ haltOperations

std::atomic<bool> helics::BrokerBase::haltOperations
protected
Initial value:
{
false}

flag indicating that no further message should be processed

Referenced by helics::CoreBroker::isOpenToNewFederates(), and helics::MultiBroker::~MultiBroker().

◆ loggerFunction

std::function<void(int, const std::string&, const std::string&)> helics::BrokerBase::loggerFunction
protected

a logging function for logging or printing messages

Referenced by sendToLogger(), and setLoggerFunction().

◆ maxLogLevel

std::atomic<int32_t> helics::BrokerBase::maxLogLevel
protected
Initial value:
{
1}

the logging level to use levels >=this will be ignored

Referenced by sendToLogger(), and setLogLevels().

◆ minBrokerCount

int32_t helics::BrokerBase::minBrokerCount
protected
Initial value:
{
0}

the minimum number of brokers that must connect before entering init mode

Referenced by helics::CoreBroker::allInitReady().

◆ minFederateCount

int32_t helics::BrokerBase::minFederateCount
protected
Initial value:
{
1}

the minimum number of federates that must connect before entering init mode

Referenced by helics::CoreBroker::allInitReady(), and helics::CommonCore::allInitReady().

◆ queryTimeout

Time helics::BrokerBase::queryTimeout {15.0}
protected

timeout for queries, if the query isn't answered within this time period respond with timeout error

◆ restrictive_time_policy

bool helics::BrokerBase::restrictive_time_policy
protected
Initial value:
{
false}

flag indicating the broker should use a conservative time policy

Referenced by configureBase().

◆ terminate_on_error

bool helics::BrokerBase::terminate_on_error
protected
Initial value:
{
false}

flag indicating that the federation should halt on any error

◆ useJsonSerialization

bool helics::BrokerBase::useJsonSerialization {false}
protected

specify that outgoing connection should use json serialization

Referenced by helics::CommonCore::connect().


The documentation for this class was generated from the following files:
helics::parent_broker_id
constexpr global_broker_id parent_broker_id
Definition: global_federate_id.hpp:60