51 std::cout <<
"Scheduler reported a warning for the session " << session->
toString() <<
": " << warningReason;
56 std::cout <<
"Error occurred while scheduling session " << session->
toString() <<
": " << errorReason;
63 const int MinutesPerHour = 60;
69 sinceMidnight / SecondsPerHour,
70 (sinceMidnight / SecondsPerMinute) % MinutesPerHour,
71 sinceMidnight % SecondsPerMinute);
76 const int sessionActivityTimeInSeconds = 30;
89 while (session->
state() != state)
93int main(
int argc,
char * argv[])
101 > cfg{
"Session Scheduler", argc, argv };
112 BusSession busSession(sessionSettings, &sessionStateChangeTracer_);
115 BgwSession bgwSession(sessionSettings, &sessionStateChangeTracer_);
124 std::atomic<bool> stopSchedulerThread{
false };
125 std::thread schedulerThread([&]()
127 const int spinWaitMicrosecondPause = 1000;
128 while (!stopSchedulerThread)
135 std::cout <<
"Scheduling BUS session " << busSession.
toString() <<
" for automatic connection." << std::endl;
138 scheduler.
add(&busSession, sessionScheduleForBus, sessionConnectivityForBus);
140 std::cout <<
"Scheduling BGW session " << bgwSession.
toString() <<
" for automatic connection." << std::endl;
143 scheduler.
add(&bgwSession, sessionScheduleForBgw, &busSession);
145 std::cout <<
"Waiting for activity on scheduled sessions " << bgwSession.
toString() <<
'.' << std::endl << std::endl;
152 std::cout << std::endl <<
"Removing sessions from scheduling service." << std::endl;
155 scheduler.
remove(&busSession);
156 scheduler.
remove(&bgwSession);
158 stopSchedulerThread =
true;
159 schedulerThread.join();
161 std::cout << std::endl <<
"Done." << std::endl;
163 catch(
const std::exception & ex)
165 std::cerr <<
"Error: " << ex.what() << std::endl;
int main(int argc, char *argv[])
SessionSchedule constructShortTimeActivitySchedule(int delayInSeconds=5)
void waitUntilState(Session *session, SessionStateId::Enum state, unsigned pollMs=1000)
TimeOfDay operator+(TimeOfDay time, Scheduling::Seconds seconds)
Connection-related settings.
SessionScheduler events notifications.
SessionSchedulerListener * eventListener() const noexcept
SessionScheduler & add(Session *session, const SessionSchedule &schedule, const SessionConnectionSettings &connection)
Adds the session to the automatic connection management.
SessionScheduler & remove(Session *session)
Removes the session from the automatic connection management services.
void dispatchEvents()
Processes events on the Scheduler and performs the necessary session management.
Seconds sinceMidnight() const noexcept
std::string toString() const
SessionStateId::Enum state() const
static void spinWait(size_t microseconds)
Executes a single instruction during the given number of microseconds.
static void sleep(size_t milliseconds)
Suspends the execution of the current thread for the given amount of time.
void onError(const SessionScheduler &, Session *session, const std::string &errorReason) override
Notifies about an error.
SchedulingIssueDetector()=default
~SchedulingIssueDetector() override=default
void onWarning(const SessionScheduler &, Session *session, const std::string &warningReason) override
Notifies about a non-critical issue.
int Seconds
The number of seconds.
std::pair< std::unique_ptr< GatewayEmulatorThread< BusSessionGatewayListener > >, std::unique_ptr< GatewayEmulatorThread< GatewayListener > > > createEmulator(const SessionSettings &settings, const ConnectivityConfiguration &cfg, bool tcpDirect=false)
SessionSettings fillSettings(const LogonConfiguration &logonCfg, const ConnectivityConfiguration &connCfg, const SettingsConfiguration &settingsCfg)
static const std::string & toString(Enum state) noexcept
@ Established
Session is fully established.
@ Disconnected
Session is disconnected.