helics  3.5.2
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 (std::function< void(int, std::string_view, std::string_view)> 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, std::string_view errorString) override final
 
 CoreBroker (bool setAsRootBroker=false) noexcept
 
 CoreBroker (std::string_view broker_name)
 
virtual ~CoreBroker ()
 
virtual void configure (std::string_view 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
 
ConnectionState getAllConnectionState () const
 
void setIdentifier (std::string_view 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 (std::string_view lfile) override final
 
virtual std::string query (std::string_view target, std::string_view queryStr, HelicsSequencingModes mode=HELICS_SEQUENCING_MODE_FAST) override final
 
virtual void setGlobal (std::string_view valueName, std::string_view value) override final
 
virtual void sendCommand (std::string_view target, std::string_view commandStr, HelicsSequencingModes mode) override final
 
virtual void makeConnections (const std::string &file) override final
 
virtual void linkEndpoints (std::string_view source, std::string_view target) override final
 
virtual void dataLink (std::string_view publication, std::string_view input) override final
 
virtual void addSourceFilterToEndpoint (std::string_view filter, std::string_view endpoint) override final
 
virtual void addDestinationFilterToEndpoint (std::string_view filter, std::string_view endpoint) override final
 
virtual void addAlias (std::string_view interfaceKey, std::string_view alias) override final
 
- Public Member Functions inherited from helics::Broker
 Broker ()=default
 
virtual ~Broker ()=default
 
- Public Member Functions inherited from helics::BrokerBase
 BrokerBase (bool DisableQueue=false) noexcept
 
 BrokerBase (std::string_view broker_name, bool DisableQueue=false)
 
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 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, std::string_view routeInfo)=0
 
virtual void removeRoute (route_id rid)=0
 
virtual std::shared_ptr< helicsCLI11AppgenerateCLI () override
 
virtual double getSimulationTime () const override
 
- Protected Member Functions inherited from helics::BrokerBase
void setTickForwarding (TickForwardingReasons reason, bool value=true)
 
BrokerState getBrokerState () const
 
bool setBrokerState (BrokerState newState)
 
bool transitionBrokerState (BrokerState expectedState, BrokerState newState)
 
virtual bool tryReconnect ()=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
 
void setErrorState (int eCode, std::string_view estring)
 
void setLoggingFile (std::string_view lfile)
 
bool getFlagValue (int32_t flag) const
 
std::pair< bool, std::vector< std::string_view > > processBaseCommands (ActionMessage &command)
 
void addBaseInformation (Json::Value &base, bool hasParent) 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< GlobalBrokerIdglobal_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< BaseTimeCoordinatortimeCoord
 object managing the time control
 
gmlc::containers::BlockingPriorityQueue< ActionMessageactionQueue
 primary routing queue
 
std::shared_ptr< LogManagermLogManager
 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
 
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
 

Friends

class TimeoutMonitor
 

Additional Inherited Members

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

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 ( std::string_view  broker_name)
explicit

constructor to set the name of the broker

◆ ~CoreBroker()

helics::CoreBroker::~CoreBroker ( )
virtual

destructor

Member Function Documentation

◆ addAlias()

void helics::CoreBroker::addAlias ( std::string_view  interfaceKey,
std::string_view  alias 
)
finaloverridevirtual

make an alias for an interface, which is a second string that may be used for making connections

Parameters
interfaceKeythe name of the original interface
aliasthe second name by which it can be used

Implements helics::Broker.

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

◆ addDestinationFilterToEndpoint()

void helics::CoreBroker::addDestinationFilterToEndpoint ( std::string_view  filter,
std::string_view  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(), helics::destination_target, helics::ActionMessage::name(), and helics::setActionFlag().

◆ addRoute()

virtual void helics::CoreBroker::addRoute ( route_id  rid,
int  interfaceId,
std::string_view  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 ( std::string_view  filter,
std::string_view  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::global_broker_id_local, helics::BrokerBase::minBrokerCount, helics::BrokerBase::minChildCount, and helics::BrokerBase::minFederateCount.

◆ clearTimeBarrier()

void helics::CoreBroker::clearTimeBarrier ( )
finaloverridevirtual

◆ configure()

void helics::CoreBroker::configure ( std::string_view  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 ( std::string_view  source,
std::string_view  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

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

Reimplemented from helics::BrokerBase.

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

References setAsRoot().

Referenced by helics::mpi::MpiBroker::generateCLI(), and helics::NetworkBroker< COMMS, baseline, tcode >::generateCLI().

◆ getAddress()

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

◆ getAllConnectionState()

ConnectionState 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

◆ getSimulationTime()

double helics::CoreBroker::getSimulationTime ( ) const
overrideprotectedvirtual

virtual function to return the current simulation time

Reimplemented from helics::BrokerBase.

◆ globalError()

void helics::CoreBroker::globalError ( int32_t  errorCode,
std::string_view  errorString 
)
finaloverridevirtual

generate a global ERROR_STATE and halt the federation

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

Implements helics::Broker.

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

◆ isConnected()

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

check if the broker is connected

Implements helics::Broker.

References helics::BrokerBase::CONNECTED, and helics::BrokerBase::TERMINATING.

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::dynamicFederation, 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 query(), and helics::TimeoutMonitor::tick().

◆ linkEndpoints()

void helics::CoreBroker::linkEndpoints ( std::string_view  source,
std::string_view  target 
)
finaloverridevirtual

create a data Link between two endpoints sending data from source to destination

Parameters
sourcethe name of the endpoint to send from
targetthe name of the endpoint to send the data to

Implements helics::Broker.

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

◆ 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, and helics::BrokerBase::TERMINATING.

◆ query()

std::string helics::CoreBroker::query ( std::string_view  target,
std::string_view  queryStr,
HelicsSequencingModes  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::addBaseInformation(), helics::bufferToJson(), helics::generateJsonErrorResponse(), getIdentifier(), isRoot(), helics::BrokerBase::mLogManager, and helics::BrokerBase::TERMINATING.

Referenced by sendCommand().

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

◆ sendCommand()

void helics::CoreBroker::sendCommand ( std::string_view  target,
std::string_view  commandStr,
HelicsSequencingModes  mode 
)
finaloverridevirtual

send a command to a specific target

the format is somewhat unspecified; target is the name of an object, typically one of "federation","root", "broker", "core", or the name of a specific object/core/broker

Parameters
targetthe specific target of the command
commandStrthe actual command
modefast (asynchronous; default) means the command goes on priority channels, ordered (synchronous) is slower but has more ordering guarantees

Implements helics::Broker.

References helics::BrokerBase::addActionMessage(), getIdentifier(), helics::BrokerBase::global_id, HELICS_SEQUENCING_MODE_ORDERED, helics::ActionMessage::payload, query(), and helics::ActionMessage::source_id.

◆ 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, helics::BrokerBase::global_id, and helics::gRootBrokerID.

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

◆ setGlobal()

void helics::CoreBroker::setGlobal ( std::string_view  valueName,
std::string_view  value 
)
finaloverridevirtual

set a federation global value

this overwrites any previous value for this name globals can be queried with a target of "global" or "global_value" 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 ( std::string_view  name)

set the local identification string for the broker

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

◆ setLogFile()

void helics::CoreBroker::setLogFile ( std::string_view  lfile)
finaloverridevirtual

◆ setLoggingCallback()

void helics::CoreBroker::setLoggingCallback ( std::function< void(int, std::string_view, std::string_view)>  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, helics::BrokerBase::global_id, helics::ActionMessage::messageID, helics::setActionFlag(), and helics::ActionMessage::source_id.

◆ setLoggingLevel()

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

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