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

#include <CoreBroker.hpp>

+ Inheritance diagram for helics::CoreBroker:

Public Member Functions

virtual bool connect () override final
 
virtual void disconnect () override final
 
void unregister ()
 
virtual void processDisconnect (bool skipUnregister=false) override final
 
virtual bool isConnected () const override final
 
virtual void setAsRoot () override final
 
virtual bool isRoot () const override final
 
virtual bool isOpenToNewFederates () const override
 
virtual void setLoggingCallback (const std::function< void(int, const std::string &, const std::string &)> &logFunction) override final
 
virtual bool waitForDisconnect (std::chrono::milliseconds msToWait=std::chrono::milliseconds(0)) const override final
 
virtual void setTimeBarrier (Time barrierTime) override final
 
virtual void clearTimeBarrier () override final
 
virtual void globalError (int32_t errorCode, const std::string &errorString) override final
 
 CoreBroker (bool setAsRootBroker=false) noexcept
 
 CoreBroker (const std::string &broker_name)
 
virtual ~CoreBroker ()
 
virtual void configure (const std::string &configureString) override final
 
virtual void configureFromArgs (int argc, char *argv[]) override final
 
virtual void configureFromVector (std::vector< std::string > args) override final
 
bool allInitReady () const
 
connection_state getAllConnectionState () const
 
void setIdentifier (const std::string &name)
 
virtual const std::string & getIdentifier () const override final
 
virtual const std::string & getAddress () const override final
 
virtual void setLoggingLevel (int logLevel) override final
 
virtual void setLogFile (const std::string &lfile) override final
 
virtual std::string query (const std::string &target, const std::string &queryStr, helics_sequencing_mode mode=helics_sequencing_mode_fast) override final
 
virtual void setGlobal (const std::string &valueName, const std::string &value) override final
 
virtual void makeConnections (const std::string &file) override final
 
virtual void dataLink (const std::string &publication, const std::string &input) override final
 
virtual void addSourceFilterToEndpoint (const std::string &filter, const std::string &endpoint) override final
 
virtual void addDestinationFilterToEndpoint (const std::string &filter, const std::string &endpoint) override final
 
- Public Member Functions inherited from helics::Broker
 Broker ()=default
 
virtual ~Broker ()=default
 
void initialize (const std::string &configureString)
 
void initializeFromArgs (int argc, char *argv[])
 
- Public Member Functions inherited from helics::BrokerBase
 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 Member Functions

virtual void transmit (route_id route, const ActionMessage &command)=0
 
virtual void transmit (route_id route, ActionMessage &&command)=0
 
virtual void addRoute (route_id rid, int interfaceId, const std::string &routeInfo)=0
 
virtual void removeRoute (route_id rid)=0
 
virtual std::shared_ptr< helicsCLI11AppgenerateCLI () override
 
- Protected Member Functions inherited from helics::BrokerBase
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 bool tryReconnect ()=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
 
void setErrorState (int eCode, const std::string &estring)
 
void setLoggingFile (const std::string &lfile)
 
bool getFlagValue (int32_t flag) const
 

Protected Attributes

bool _gateway = false
 set to true if this broker should act as a gateway.
 
- Protected Attributes inherited from helics::BrokerBase
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
 

Additional Inherited Members

- Protected Types inherited from helics::BrokerBase
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 }
 
- Static Protected Member Functions inherited from helics::BrokerBase
static bool isReasonForTick (std::uint32_t code, TickForwardingReasons reason)
 

Detailed Description

class implementing most of the functionality of a generic broker Basically acts as a router for information, deals with stuff internally if it can and sends higher up if it can't or does something else if it is the root of the tree

Constructor & Destructor Documentation

◆ CoreBroker() [1/2]

helics::CoreBroker::CoreBroker ( bool  setAsRootBroker = false)
explicitnoexcept

default constructor

Parameters
setAsRootBrokerset to true to indicate this object is a root broker

◆ CoreBroker() [2/2]

helics::CoreBroker::CoreBroker ( const std::string &  broker_name)
explicit

constructor to set the name of the broker

◆ ~CoreBroker()

helics::CoreBroker::~CoreBroker ( )
virtual

destructor

Member Function Documentation

◆ addDestinationFilterToEndpoint()

void helics::CoreBroker::addDestinationFilterToEndpoint ( const std::string &  filter,
const std::string &  target 
)
finaloverridevirtual

create a filter connection between a named filter and a named endpoint for destination processing

Parameters
filterthe name of the filter
targetthe name of the source target

Implements helics::Broker.

References helics::BrokerBase::addActionMessage(), destination_target, helics::ActionMessage::name, and setActionFlag().

◆ addRoute()

virtual void helics::CoreBroker::addRoute ( route_id  rid,
int  interfaceId,
const std::string &  routeInfo 
)
protectedpure virtual

add a route to the type specific routing information and establish the connection

add a route to a table, the connection information is contained in the string with the described identifier

Parameters
ridthe identification of the route
interfaceIdan interface id code that can be used to identify the interface route should be added to, in most cases this should be zero since there is only one interface
routeInfoa string containing the information necessary to connect

Implemented in helics::MultiBroker.

◆ addSourceFilterToEndpoint()

void helics::CoreBroker::addSourceFilterToEndpoint ( const std::string &  filter,
const std::string &  target 
)
finaloverridevirtual

create a filter connection between a named filter and a named endpoint for messages coming from that endpoint

Parameters
filterthe name of the filter
targetthe name of the source target

Implements helics::Broker.

References helics::BrokerBase::addActionMessage(), and helics::ActionMessage::name.

◆ allInitReady()

bool helics::CoreBroker::allInitReady ( ) const

check if all the local federates are ready to be initialized

Returns
true if everyone is ready, false otherwise

References getAllConnectionState(), helics::BrokerBase::minBrokerCount, and helics::BrokerBase::minFederateCount.

◆ clearTimeBarrier()

void helics::CoreBroker::clearTimeBarrier ( )
finaloverridevirtual

◆ configure()

void helics::CoreBroker::configure ( const std::string &  configureString)
finaloverridevirtual

start up the broker with an initialization string containing commands and parameters

Implements helics::Broker.

References helics::BrokerBase::configureBase(), helics::BrokerBase::configuring, helics::BrokerBase::created, and helics::BrokerBase::parseArgs().

◆ configureFromArgs()

void helics::CoreBroker::configureFromArgs ( int  argc,
char *  argv[] 
)
finaloverridevirtual

◆ configureFromVector()

void helics::CoreBroker::configureFromVector ( std::vector< std::string >  args)
finaloverridevirtual

◆ connect()

bool helics::CoreBroker::connect ( )
finaloverridevirtual

connect the core to its broker

should be done after initialization has complete

Implements helics::Broker.

References helics::BrokerBase::configured, helics::BrokerBase::connected, and helics::BrokerBase::connecting.

◆ dataLink()

void helics::CoreBroker::dataLink ( const std::string &  source,
const std::string &  target 
)
finaloverridevirtual

create a data Link between a named publication and a named input

Parameters
sourcethe name of the publication
targetthe name of the input

Implements helics::Broker.

References helics::BrokerBase::addActionMessage(), and helics::ActionMessage::name.

◆ disconnect()

void helics::CoreBroker::disconnect ( )
finaloverridevirtual

disconnect the broker from any other brokers and communications

Implements helics::Broker.

References helics::BrokerBase::addActionMessage(), and waitForDisconnect().

◆ generateCLI()

std::shared_ptr< helicsCLI11App > helics::CoreBroker::generateCLI ( )
overrideprotectedvirtual

◆ getAddress()

const std::string & helics::CoreBroker::getAddress ( ) const
finaloverridevirtual

◆ getAllConnectionState()

connection_state helics::CoreBroker::getAllConnectionState ( ) const

get a value for the summary connection status of all the connected systems

Referenced by allInitReady().

◆ getIdentifier()

virtual const std::string& helics::CoreBroker::getIdentifier ( ) const
inlinefinaloverridevirtual

get the local identification for the broker

Implements helics::Broker.

References helics::BrokerBase::identifier.

Referenced by helics::MultiBroker::generateLocalAddressString(), query(), and helics::TimeoutMonitor::tick().

◆ globalError()

void helics::CoreBroker::globalError ( int32_t  errorCode,
const std::string &  errorString 
)
finaloverridevirtual

generate a global error and halt the federation

Parameters
errorCodethe code to use for the error
errorStringthe error message to associate with the error

Implements helics::Broker.

References helics::BrokerBase::addActionMessage(), helics::BrokerBase::getGlobalId(), helics::ActionMessage::messageID, helics::ActionMessage::payload, and helics::ActionMessage::source_id.

◆ isConnected()

bool helics::CoreBroker::isConnected ( ) const
finaloverridevirtual

check if the broker is connected

Implements helics::Broker.

References helics::BrokerBase::connected, and helics::BrokerBase::operating.

Referenced by helics::TimeoutMonitor::tick().

◆ isOpenToNewFederates()

bool helics::CoreBroker::isOpenToNewFederates ( ) const
overridevirtual

check if the broker is ready to accept new federates or cores

Implements helics::Broker.

References helics::BrokerBase::created, helics::BrokerBase::haltOperations, and helics::BrokerBase::operating.

◆ isRoot()

virtual bool helics::CoreBroker::isRoot ( ) const
inlinefinaloverridevirtual

return true if the broker is a root broker

Implements helics::Broker.

Referenced by helics::TimeoutMonitor::tick().

◆ makeConnections()

void helics::CoreBroker::makeConnections ( const std::string &  file)
finaloverridevirtual

load a file containing connection information

Parameters
filea JSON or TOML file containing connection information

Implements helics::Broker.

◆ processDisconnect()

void helics::CoreBroker::processDisconnect ( bool  skipUnregister = false)
finaloverridevirtual

disconnect the broker from any other brokers and communications if the flag is set it should not do the unregister step of the disconnection, if this is set it is presumed the unregistration has already happened or it will be taken care of manually

Implements helics::BrokerBase.

References helics::BrokerBase::configured, helics::BrokerBase::terminated, and helics::BrokerBase::terminating.

Referenced by helics::TimeoutMonitor::tick().

◆ query()

std::string helics::CoreBroker::query ( const std::string &  target,
const std::string &  queryStr,
helics_sequencing_mode  mode = helics_sequencing_mode_fast 
)
finaloverridevirtual

make a query for information from the co-simulation

the format is somewhat unspecified target is the name of an object typically one of "federation", "broker", or the name of a specific object query is a broken

Parameters
targetthe specific target of the query
queryStrthe actual query
modefast (asynchronous; default) means the query goes on priority channels, ordered (synchronous) is slower but has more ordering guarantees
Returns
a string containing the response to the query. Query is a blocking call and will not return until the query is answered so use with caution

Implements helics::Broker.

References helics::BrokerBase::addActionMessage(), helics::ActionMessage::dest_id, getIdentifier(), helics::BrokerBase::global_id, helics_sequencing_mode_fast, helics::ActionMessage::messageID, helics::ActionMessage::payload, and helics::ActionMessage::source_id.

◆ removeRoute()

virtual void helics::CoreBroker::removeRoute ( route_id  rid)
protectedpure virtual

remove or disconnect a route from use

Parameters
ridthe identification of the route

Implemented in helics::MultiBroker.

◆ setAsRoot()

void helics::CoreBroker::setAsRoot ( )
finaloverridevirtual

set the broker to be a root broker

only valid before the initialization function is called

Implements helics::Broker.

References helics::BrokerBase::connected, and helics::BrokerBase::global_id.

Referenced by generateCLI().

◆ setGlobal()

void helics::CoreBroker::setGlobal ( const std::string &  valueName,
const std::string &  value 
)
finaloverridevirtual

set a federation global value

this overwrites any previous value for this name globals can be queried with a target of "global" and queryStr of the value to Query

Parameters
valueNamethe name of the global to set
valuethe value of the global

Implements helics::Broker.

References helics::BrokerBase::global_id, helics::ActionMessage::payload, and helics::ActionMessage::source_id.

◆ setIdentifier()

void helics::CoreBroker::setIdentifier ( const std::string &  name)

set the local identification string for the broker

References helics::BrokerBase::connecting, and helics::BrokerBase::identifier.

◆ setLogFile()

void helics::CoreBroker::setLogFile ( const std::string &  lfile)
finaloverridevirtual

set the broker logging file

Implements helics::Broker.

References helics::BrokerBase::setLoggingFile().

◆ setLoggingCallback()

void helics::CoreBroker::setLoggingCallback ( const std::function< void(int, const std::string &, const std::string &)> &  logFunction)
finaloverridevirtual

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

Implements helics::Broker.

References helics::BrokerBase::actionQueue, helics::ActionMessage::counter, empty_flag, helics::BrokerBase::global_id, helics::ActionMessage::messageID, setActionFlag(), and helics::ActionMessage::source_id.

◆ setLoggingLevel()

void helics::CoreBroker::setLoggingLevel ( int  logLevel)
finaloverridevirtual

set the broker logging level

Implements helics::Broker.

References helics::BrokerBase::addActionMessage(), and helics::BrokerBase::global_id.

◆ setTimeBarrier()

void helics::CoreBroker::setTimeBarrier ( Time  barrierTime)
finaloverridevirtual

◆ transmit() [1/2]

virtual void helics::CoreBroker::transmit ( route_id  route,
ActionMessage &&  command 
)
protectedpure virtual

this function is the one that will change for various flavors of broker communication

it takes a route info- a code of where to send the data and an action message and proceeds to transmit it to the appropriate location, this variant does a move operation instead of copy

Parameters
route-the identifier for the routing information
commandthe actionMessage to transmit

Implemented in helics::MultiBroker.

◆ transmit() [2/2]

virtual void helics::CoreBroker::transmit ( route_id  route,
const ActionMessage command 
)
protectedpure virtual

this function is the one that will change for various flavors of broker communication

it takes a route info- a code of where to send the data and an action message and proceeds to transmit it to the appropriate location

Parameters
route-the identifier for the routing information
commandthe actionMessage to transmit

Implemented in helics::MultiBroker.

Referenced by helics::TimeoutMonitor::pingSub(), and helics::TimeoutMonitor::tick().

◆ unregister()

void helics::CoreBroker::unregister ( )

unregister the broker from the factory find methods

References helics::BrokerFactory::findBroker(), helics::BrokerBase::identifier, and helics::BrokerFactory::unregisterBroker().

◆ waitForDisconnect()

bool helics::CoreBroker::waitForDisconnect ( std::chrono::milliseconds  msToWait = std::chrono::milliseconds(0)) const
finaloverridevirtual

waits in the current thread until the broker is disconnected

Parameters
msToWaitthe timeout to wait for disconnect
Returns
true if the disconnect was successful false if it timed out

Implements helics::Broker.

Referenced by disconnect().


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