| helics 3.6.1

Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static 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 (std::string_view broker_name, bool DisableQueue=false)
void | loadInfoFromToml (const std::string &toml, bool runArgParser=true)
void | loadInfoFromJson (const std::string &json, bool runArgParser=true)
int | parseArgs (int argc, char *argv[])
int | parseArgs (std::vector< std::string > args)
int | parseArgs (std::string_view initializationString)
virtual void | configureBase ()
void | addActionMessage (const ActionMessage &message)
void | addActionMessage (ActionMessage &&message)
void | setLoggerFunction (std::function< void(int level, std::string_view identifier, std::string_view message)> logFunction)
void | logFlush ()
bool | isRunning () const
void | setLogLevel (int32_t level)
void | setLogLevels (int32_t consoleLevel, int32_t fileLevel)
GlobalBrokerId | getGlobalId () const
std::function< void(int, std::string_view, std::string_view)> | getLoggingCallback () const
void | joinAllThreads ()
std::size_t | currentMessageCounter () const

## Protected Types
enum class | BrokerState : int16_t { CREATED = -10 , CONFIGURING = -7 , CONFIGURED = -6 , CONNECTING = -4 , CONNECTED = -3 , INITIALIZING = -1 , OPERATING = 0 , CONNECTED_ERROR = 3 , TERMINATING = 4 , TERMINATING_ERROR = 5 , TERMINATED = 6 , ERRORED = 7 }
enum class | TickForwardingReasons : uint32_t { NONE = 0 , NO_COMMS = 0x01 , PING_RESPONSE = 0x02 , QUERY_TIMEOUT = 0x04 , GRANT_TIMEOUT = 0x08 , DISCONNECT_TIMEOUT = 0x10 }

## Protected Member Functions
void | setTickForwarding (TickForwardingReasons reason, bool value=true)
BrokerState | getBrokerState () const
bool | setBrokerState (BrokerState newState)
bool | transitionBrokerState (BrokerState expectedState, BrokerState newState)
virtual void | processDisconnect (bool skipUnregister=false)=0
virtual bool | tryReconnect ()=0
virtual void | processCommand (ActionMessage &&cmd)=0
virtual void | processPriorityCommand (ActionMessage &&command)=0
bool | sendToLogger (GlobalFederateId federateID, int logLevel, std::string_view name, std::string_view message, bool fromRemote=false) const
void | saveProfilingData (std::string_view message)
void | writeProfilingData ()
void | generateNewIdentifier ()
virtual std::string | generateLocalAddressString () const =0
virtual std::shared_ptr< helicsCLI11App > | generateCLI ()
void | setErrorState (int eCode, std::string_view estring)
void | setLoggingFile (std::string_view lfile)
bool | getFlagValue (int32_t flag) const
virtual double | getSimulationTime () const
std::pair< bool, std::vector< std::string_view > > | processBaseCommands (ActionMessage &command)
void | addBaseInformation (nlohmann::json &base, bool hasParent) const

## Static Protected Member Functions
static bool | isReasonForTick (std::uint32_t code, TickForwardingReasons reason)

## Protected Attributes
std::atomic< GlobalBrokerId > | global_id {parent_broker_id}
GlobalBrokerId | global_broker_id_local {}
GlobalBrokerId | higher_broker_id {0}
| the id code of the broker 1 level about this broker
std::atomic< int32_t > | maxLogLevel {HELICS_LOG_LEVEL_NO_PRINT}
int32_t | minFederateCount {1}
int32_t | minBrokerCount {0}
int32_t | maxFederateCount {(std::numeric_limits<int32_t>::max)()}
int32_t | maxBrokerCount {(std::numeric_limits<int32_t>::max)()}
int32_t | minChildCount {0}
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 {0.0}
| time to delay before terminating after error state
Time | grantTimeout {-1.0}
| timeout for triggering diagnostic action waiting for a time grant
Time | maxCoSimDuration {-1.0}
| the maximum lifetime (wall clock time) of the co-simulation
std::string | identifier
| an identifier for the broker
std::string | brokerKey
std::string | address
| network location of the broker
std::thread | queueProcessingThread
std::atomic< bool > | haltOperations {false}
| flag indicating that no further message should be processed
bool | restrictive_time_policy {false}
| flag indicating the broker should use a conservative time policy
bool | terminate_on_error {false}
| flag indicating that the federation should halt on any error
bool | debugging {false}
| flag indicating operation in a user debugging mode
bool | observer {false}
| flag indicating that the broker is an observer only
bool | globalTime {false}
| flag indicating that the broker should use a global time coordinator
bool | asyncTime {false}
| flag indicating the use of async time keeping
bool | dynamicFederation {false}
| flag indicating that the broker supports dynamic federates
bool | disableDynamicSources {false}
| flag disabling dynamic data sources
std::unique_ptr< BaseTimeCoordinator > | timeCoord
| object managing the time control
gmlc::containers::BlockingPriorityQueue< ActionMessage > | actionQueue
| primary routing queue
std::shared_ptr< LogManager > | mLogManager
| object to handle the logging considerations
bool | noAutomaticID {false}
| the broker should not automatically generate an ID
bool | hasTimeDependency {false}
bool | enteredExecutionMode {false}
| flag indicating that the broker has entered execution mode
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
bool | allowRemoteControl {true}
bool | errorOnUnmatchedConnections {false}
| error if there are unmatched connections on init
bool | globalDisconnect {false}
decltype(std::chrono::steady_clock::now()) | errorTimeStart
| time when the error condition started; related to the errorDelay
decltype(std::chrono::steady_clock::now()) | disconnectTime
| time when the disconnect started
std::atomic< int > | lastErrorCode {0}
| storage for last error code
std::string | lastErrorString
| storage for last error string
std::string | configString
| storage for a config file location
bool | fileInUse {false}

## Static Protected Attributes
static constexpr double | mInvalidSimulationTime {-98763.2}

## Friends
class | TimeoutMonitor
const std::string & | brokerStateName (BrokerState state)

## Detailed Description

base class for broker like objects

## Member Enumeration Documentation

## ◆ BrokerState

enum helics::BrokerBase::BrokerState : int16_t
| strong protected

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
CONNECTED_ERROR | error state but still connected
TERMINATING | the termination process has started
TERMINATING_ERROR | the termination process has started while in an error state
TERMINATED | the termination process has started
ERRORED | an error was encountered

## Member Function Documentation

## ◆ addActionMessage() [1/2]

void helics::BrokerBase::addActionMessage | ( | ActionMessage && | message | ) |

move a action Message into the commandQueue

References helics::isPriorityCommand().

## ◆ addActionMessage() [2/2]

void helics::BrokerBase::addActionMessage | ( | const ActionMessage & | message | ) |

add an action Message to the process queue

References helics::isPriorityCommand().

Referenced by helics::CommonCore::addAlias(), helics::CoreBroker::addAlias(), 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(), helics::CoreBroker::dataLink(), helics::CommonCore::dataLink(), helics::CommonCore::disconnect(), helics::CoreBroker::disconnect(), helics::CommonCore::enterExecutingMode(), helics::CommonCore::enterInitializingMode(), helics::CommonCore::finalize(), helics::CoreBroker::globalError(), helics::CommonCore::linkEndpoints(), helics::CoreBroker::linkEndpoints(), helics::TimeoutMonitor::pingReply(), helics::TimeoutMonitor::pingSub(), helics::CommonCore::processDisconnect(), helics::CommonCore::registerFederate(), helics::CommonCore::removeTarget(), helics::CommonCore::requestTimeIterative(), helics::CoreBroker::sendCommand(), helics::CommonCore::sendCommand(), helics::CommonCore::sendMessage(), helics::CommonCore::sendTo(), helics::CommonCore::sendToAt(), helics::CommonCore::setFederateTag(), helics::CommonCore::setFlagOption(), helics::CommonCore::setGlobal(), helics::CommonCore::setIntegerProperty(), helics::CommonCore::setInterfaceTag(), helics::CommonCore::setLogFile(), helics::CoreBroker::setLogFile(), helics::CoreBroker::setTimeBarrier(), helics::TimeoutMonitor::tick(), and helics::CommonCore::timeRequest().

## ◆ addBaseInformation()

void helics::BrokerBase::addBaseInformation | ( | nlohmann::json & | base,
|  | bool | hasParent
| ) |  | const
| protected

add some base information to a json structure

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

## ◆ configureBase()

void helics::BrokerBase::configureBase | ( |  | ) |
| virtual

configure the base of all brokers and cores

References helics::timeZero.

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

## ◆ 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 | ( |  | ) |
| protected virtual

generate a CLI11 Application for subprocesses for processing of command line arguments

Reimplemented in helics::NetworkCore< COMMS, baseline >, helics::NetworkBroker< COMMS, baseline, tcode >, helics::mpi::MpiCore, helics::mpi::MpiBroker, and helics::CoreBroker.

Referenced by helics::mpi::MpiCore::generateCLI().

## ◆ generateLocalAddressString()

virtual std::string helics::BrokerBase::generateLocalAddressString | ( |  | ) | const
| protected pure virtual

generate the local address information

Implemented in helics::NetworkCore< COMMS, baseline >, helics::NetworkBroker< COMMS, baseline, tcode >, helics::mpi::MpiCore, helics::mpi::MpiBroker, and helics::MultiBroker.

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

## ◆ generateNewIdentifier()

void helics::BrokerBase::generateNewIdentifier | ( |  | ) |
| protected

generate a new random id

## ◆ 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()

GlobalBrokerId helics::BrokerBase::getGlobalId | ( |  | ) | const
| inline

get the internal global broker id

References global_id.

Referenced by helics::CoreBroker::globalError(), helics::CommonCore::sendCommand(), and helics::CommonCore::setFederateTag().

## ◆ getLoggingCallback()

std::function< void(int, std::string_view, std::string_view)> helics::BrokerBase::getLoggingCallback | ( |  | ) | const

generate a callback function for the logging purposes

## ◆ getSimulationTime()

virtual double helics::BrokerBase::getSimulationTime | ( |  | ) | const
| inline protected virtual

virtual function to return the current simulation time

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

## ◆ isReasonForTick()

static bool helics::BrokerBase::isReasonForTick | ( | std::uint32_t | code,
|  | TickForwardingReasons | reason
| ) |  |
| inline static protected

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 | ( |  | ) |

close all the threads

Referenced by helics::CommonCore::~CommonCore(), helics::CommsBroker< COMMS, BrokerT >::~CommsBroker(), and helics::MultiBroker::~MultiBroker().

## ◆ loadInfoFromJson()

void helics::BrokerBase::loadInfoFromJson | ( | const std::string & | json,
|  | bool | runArgParser = `true`
| ) |  |

load broker information from a JSON string either a file or JSON string

Parameters

  json | a string containing the name of the JSON file or JSON contents

## ◆ loadInfoFromToml()

void helics::BrokerBase::loadInfoFromToml | ( | const std::string & | toml,
|  | bool | runArgParser = `true`
| ) |  |

load broker information object from a toml string either a file or toml string

Parameters

  toml | a string containing the name of the toml file or toml contents

## ◆ logFlush()

void helics::BrokerBase::logFlush | ( |  | ) |

flush the loggers

## ◆ parseArgs() [1/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

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

## ◆ parseArgs() [2/3]

int helics::BrokerBase::parseArgs | ( | std::string_view | 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

## ◆ 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

## ◆ processBaseCommands()

std::pair< bool, std::vector< std::string_view > > helics::BrokerBase::processBaseCommands | ( | ActionMessage & | command | ) |
| protected

process some common commands that can be processed by the broker base

References helics::ActionMessage::payload, and helics::SmallBuffer::to_string().

## ◆ processCommand()

virtual void helics::BrokerBase::processCommand | ( | ActionMessage && | cmd | ) |
| protected pure 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` | ) |
| protected pure virtual

process a disconnect signal

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

## ◆ processPriorityCommand()

virtual void helics::BrokerBase::processPriorityCommand | ( | ActionMessage && | command | ) |
| protected pure 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

  command | the command to process

Implemented in helics::CommonCore.

## ◆ saveProfilingData()

void helics::BrokerBase::saveProfilingData | ( | std::string_view | message | ) |
| protected

save a profiling message

References helics::parent_broker_id, and helics::PROFILING.

## ◆ sendToLogger()

bool helics::BrokerBase::sendToLogger | ( | GlobalFederateId | federateID,
|  | int | logLevel,
|  | std::string_view | name,
|  | std::string_view | message,
|  | bool | fromRemote = `false`
| ) |  | const
| protected

send a Message to the logging system

Returns
  true if the message was actually logged

Parameters

  fromRemote | set to true if the message to be logged came from a different object

Referenced by helics::CommonCore::registerFederate(), and helics::TimeoutMonitor::tick().

## ◆ setErrorState()

void helics::BrokerBase::setErrorState | ( | int | eCode,
|  | std::string_view | estring
| ) |  |
| protected

set the broker error state and error string

References HELICS_ERROR_TERMINATED, HELICS_ERROR_USER_ABORT, HELICS_LOG_LEVEL_ERROR, and helics::timeZero.

## ◆ setLoggerFunction()

void helics::BrokerBase::setLoggerFunction | ( | std::function< void(int level, std::string_view identifier, std::string_view message)> | logFunction | ) |

set the logging callback function

Parameters

  logFunction | a function with a signature of void(int level, std::string_view identifier, std::string_view message) the function takes a level indicating the logging level string with the source name and a string with the message

## ◆ setLoggingFile()

void helics::BrokerBase::setLoggingFile | ( | std::string_view | lfile | ) |
| protected

set the logging file if using the default logger

## ◆ setLogLevel()

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

set the logging level

## ◆ setLogLevels()

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

set the logging levels

Parameters

  consoleLevel | the logging level for the console display
  fileLevel | the logging level for the log file

## ◆ setTickForwarding()

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

set tick forwarding for a specific reason

## ◆ tryReconnect()

bool helics::BrokerBase::tryReconnect | ( |  | ) |
| protected pure 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

References helics::ERROR_LEVEL, and helics::parent_broker_id.

## Friends And Related Function Documentation

## ◆ brokerStateName

const std::string& brokerStateName | ( | BrokerState | state | ) |
| friend

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

## Member Data Documentation

## ◆ allowRemoteControl

bool helics::BrokerBase::allowRemoteControl {true}
| protected

if true allows some remote operation

## ◆ 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().

## ◆ global_broker_id_local

GlobalBrokerId helics::BrokerBase::global_broker_id_local {}
| protected

meant to be the same as global_id but not atomically protected

Referenced by helics::CoreBroker::allInitReady(), helics::CommonCore::checkInFlightQueriesForDisconnect(), helics::TimeoutMonitor::pingSub(), helics::CommonCore::processDisconnect(), and helics::TimeoutMonitor::tick().

## ◆ global_id

std::atomic<GlobalBrokerId> helics::BrokerBase::global_id {parent_broker_id}
| protected

the unique identifier for the broker(core or broker)

Referenced by helics::CoreBroker::clearTimeBarrier(), getGlobalId(), helics::CommonCore::logMessage(), helics::TimeoutMonitor::pingSub(), helics::CoreBroker::sendCommand(), helics::CommonCore::sendMessage(), helics::CoreBroker::setAsRoot(), helics::CoreBroker::setGlobal(), helics::CommonCore::setIntegerProperty(), helics::CommonCore::setLogFile(), helics::CoreBroker::setLogFile(), helics::CommonCore::setLoggingCallback(), helics::CoreBroker::setLoggingCallback(), helics::CommonCore::setLoggingLevel(), helics::CoreBroker::setLoggingLevel(), and helics::CoreBroker::setTimeBarrier().

## ◆ globalDisconnect

bool helics::BrokerBase::globalDisconnect {false}
| protected

if true specify that federates should stay connected until a global disconnect operation

## ◆ hasTimeDependency

bool helics::BrokerBase::hasTimeDependency {false}
| protected

set to true if the broker has Time dependencies

## ◆ maxLogLevel

std::atomic<int32_t> helics::BrokerBase::maxLogLevel {HELICS_LOG_LEVEL_NO_PRINT}
| protected

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

## ◆ minBrokerCount

int32_t helics::BrokerBase::minBrokerCount {0}
| protected

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

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

## ◆ minChildCount

int32_t helics::BrokerBase::minChildCount {0}
| protected

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

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

## ◆ minFederateCount

int32_t helics::BrokerBase::minFederateCount {1}
| protected

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

Referenced by helics::CommonCore::allInitReady(), and helics::CoreBroker::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

## ◆ queueProcessingThread

std::thread helics::BrokerBase::queueProcessingThread
| protected

thread for running the broker

## ◆ useJsonSerialization

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

specify that outgoing connection should use json serialization

Referenced by helics::NetworkBroker< COMMS, baseline, tcode >::brokerConnect(), and helics::CommonCore::connect().

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

- BrokerBase.hpp
- BrokerBase.cpp