TEST(AsyncTimeout, cancel_make) { int value = 0; int const expected = 10; EventBase manager; auto observer = AsyncTimeout::make( manager, [&]() noexcept { value = expected; } ); std::weak_ptr<RequestContext> rctx_weak_ptr; { RequestContextScopeGuard rctx_guard; rctx_weak_ptr = RequestContext::saveContext(); observer->scheduleTimeout(std::chrono::milliseconds(100)); observer->cancelTimeout(); } // Ensure that RequestContext created for the scope has been released and // deleted. EXPECT_EQ(rctx_weak_ptr.expired(), true); manager.loop(); EXPECT_NE(expected, value); }
IOxfReactive::TakeEventStatus Controller::Timing_processEvent() { IOxfReactive::TakeEventStatus res = eventNotConsumed; if(Timing_active == Time) { if(IS_EVENT_TYPE_OF(OMTimeoutEventId)) { if(getCurrentEvent() == Timing_timeout) { NOTIFY_TRANSITION_STARTED("13"); if(Timing_timeout != NULL) { Timing_timeout->cancel(); Timing_timeout = NULL; } //#[ state ROOT.On.Timing.Time.(Exit) Reduce_time(); //#] NOTIFY_STATE_EXITED("ROOT.On.Timing.Time"); NOTIFY_STATE_ENTERED("ROOT.On.Timing.Time"); Timing_subState = Time; Timing_active = Time; Timing_timeout = scheduleTimeout(1000, "ROOT.On.Timing.Time"); NOTIFY_TRANSITION_TERMINATED("13"); res = eventConsumed; } } } return res; }
void FastCGIServer::stop() { if (getStatus() != RunStatus::RUNNING) return; // nothing to do setStatus(RunStatus::STOPPING); m_worker.getEventBase()->runInEventBaseThread([&] { // Shutdown the server socket. Unfortunately, we will drop all unaccepted // connections; there is no way to do a partial shutdown of a server socket m_socket->stopAccepting(); if (RuntimeOption::ServerGracefulShutdownWait > 0) { // Gracefully drain any incomplete requests. We cannot go offline until // they are finished as we own their dispatcher and event base. if (m_acceptor) { m_acceptor->drainAllConnections(); } std::chrono::seconds s(RuntimeOption::ServerGracefulShutdownWait); std::chrono::milliseconds m(s); scheduleTimeout(m); } else { // Drop all connections. We cannot shutdown until they stop because we // own their dispatcher and event base. if (m_acceptor) { m_acceptor->forceStop(); } terminateServer(); } }); }
IOxfReactive::TakeEventStatus Karussell::rootState_processEvent() { IOxfReactive::TakeEventStatus res = eventNotConsumed; // State idle if(rootState_active == idle) { if(IS_EVENT_TYPE_OF(OMTimeoutEventId)) { if(getCurrentEvent() == rootState_timeout) { NOTIFY_TRANSITION_STARTED("1"); cancel(rootState_timeout); //#[ state idle.(Exit) dreht = true; //#] NOTIFY_STATE_EXITED("ROOT.idle"); //#[ transition 1 drehen(); //#] NOTIFY_STATE_ENTERED("ROOT.idle"); rootState_subState = idle; rootState_active = idle; //#[ state idle.(Entry) dreht = false; //#] rootState_timeout = scheduleTimeout(1000, "ROOT.idle"); NOTIFY_TRANSITION_TERMINATED("1"); res = eventConsumed; } } } return res; }
void Controller::Timing_entDef() { NOTIFY_STATE_ENTERED("ROOT.On.Timing"); NOTIFY_TRANSITION_STARTED("12"); NOTIFY_STATE_ENTERED("ROOT.On.Timing.Time"); Timing_subState = Time; Timing_active = Time; Timing_timeout = scheduleTimeout(1000, "ROOT.On.Timing.Time"); NOTIFY_TRANSITION_TERMINATED("12"); }
void ProxygenServer::vmStopped() { m_shutdownState = ShutdownState::DRAINING_WRITES; if (!drained() && RuntimeOption::ServerGracefulShutdownWait > 0) { m_worker.getEventBase()->runInEventBaseThread([&] { std::chrono::seconds s(RuntimeOption::ServerGracefulShutdownWait); VLOG(4) << this << ": scheduling graceful timeout=" << s.count() << " port=" << m_port; scheduleTimeout(s); }); } else { forceStop(); } }
void Karussell::rootState_entDef() { { NOTIFY_STATE_ENTERED("ROOT"); NOTIFY_TRANSITION_STARTED("0"); NOTIFY_STATE_ENTERED("ROOT.idle"); rootState_subState = idle; rootState_active = idle; //#[ state idle.(Entry) dreht = false; //#] rootState_timeout = scheduleTimeout(1000, "ROOT.idle"); NOTIFY_TRANSITION_TERMINATED("0"); } }
TEST(AsyncTimeout, make) { int value = 0; int const expected = 10; EventBase manager; auto observer = AsyncTimeout::make( manager, [&]() noexcept { value = expected; } ); observer->scheduleTimeout(std::chrono::milliseconds(100)); manager.loop(); EXPECT_EQ(expected, value); }
void TestDataSetDAO::testCRUDDataSet() { // get the transactor std::auto_ptr<te::da::DataSourceTransactor> transactor = terrama2::core::ApplicationController::getInstance().getTransactor(); // create a new data provider and save it t the database terrama2::core::DataProviderPtr dataProvider(new terrama2::core::DataProvider("Server 1", terrama2::core::DataProvider::FTP_TYPE)); terrama2::core::DataProviderDAO::save(dataProvider, *transactor); // create a new dataset and save it to the database terrama2::core::DataSetPtr dataSet(new terrama2::core::DataSet(dataProvider, "Queimadas", terrama2::core::DataSet::OCCURENCE_TYPE)); te::dt::TimeDuration dataFrequency(2,0,0); dataSet->setDataFrequency(dataFrequency); terrama2::core::DataSetDAO::save(dataSet, *transactor); // assure we have a valid dataset identifier QVERIFY2(dataSet->id() > 0, "Id must be different than zero after save()!"); te::dt::TimeDuration schedule(12,0,0); dataSet->setSchedule(schedule); te::dt::TimeDuration scheduleTimeout(0,30,0); dataSet->setScheduleTimeout(scheduleTimeout); te::dt::TimeDuration scheduleRetry(0,5,0); dataSet->setScheduleRetry(scheduleRetry); dataSet->setStatus(terrama2::core::DataSet::ACTIVE); dataSet->setDescription("Description..."); dataSet->setName("New queimadas"); terrama2::core::DataSetDAO::update(dataSet, *transactor); terrama2::core::DataSetPtr findDataSet = terrama2::core::DataSetDAO::find(dataSet->id(), *transactor); QVERIFY2(dataSet->name() == findDataSet->name(), "Name must be the same!"); QVERIFY2(dataSet->status() == findDataSet->status(), "Status must be the same!"); QVERIFY2(dataSet->scheduleTimeout() == findDataSet->scheduleTimeout(), "Schedule timeout must be the same!"); QVERIFY2(dataSet->schedule() == findDataSet->schedule(), "Schedule must be the same!"); QVERIFY2(dataSet->scheduleRetry() == findDataSet->scheduleRetry(), "Schedule retry must be the same!"); QVERIFY2(dataSet->dataFrequency() == findDataSet->dataFrequency(), "Data frequency must be the same!"); }
void UnresolvedNhopsProber::timeoutExpired() noexcept { std::lock_guard<std::mutex> g(lock_); auto state = sw_->getState(); for (const auto& ridAndNhopsRefCounts : nhops2RouteCount_) { for (const auto& nhopAndRefCount : ridAndNhopsRefCounts.second) { const auto& nhop = nhopAndRefCount.first; auto intf = state->getInterfaces()->getInterfaceIf(nhop.intf); if (!intf) { continue; // interface got unconfigured } // Probe all nexthops for which either don't have a L2 entry // or the entry is not resolved (port == 0). Note that we do // not exclude pending entries here since in case of recursive // routes we might get packets with destination set to prefix // that needs to be resolved recursively. In ARP and NDP code // we do not do route lookup when deciding to send ARP/NDP requests. // So we would only try to ARP/NDP for the destination if it // is in one of the interface subnets (which it won't be else // we won't have needed recursive resolution). So ARP/NDP for // all unresolved next hops. We could also consider doing route // lookups in ARP/NDP code, but by probing all unresolved next // hops we effectively do the same thing, since the next hops // probed come from after the route was (recursively) resolved. auto vlan = state->getVlans()->getVlanIf(intf->getVlanID()); CHECK(vlan); // must have vlan for configrued inteface if (nhop.nexthop.isV4()) { auto nhop4 = nhop.nexthop.asV4(); auto arpEntry = vlan->getArpTable()->getEntryIf(nhop4); if (!arpEntry || arpEntry->getPort() == 0) { VLOG(2) <<" Sending probe for unresolved next hop: " << nhop4; ArpHandler::sendArpRequest(sw_, vlan, nhop4); } } else { auto nhop6 = nhop.nexthop.asV6(); auto ndpEntry = vlan->getNdpTable()->getEntryIf(nhop6); if (!ndpEntry || ndpEntry->getPort() == 0) { VLOG(2) <<" Sending probe for unresolved next hop: " << nhop6; IPv6Handler::sendNeighborSolicitation(sw_, nhop6, vlan); } } } } scheduleTimeout(interval_); }
void ConnectionManager::addConnection(ManagedConnection* connection, bool timeout) { CHECK_NOTNULL(connection); ConnectionManager* oldMgr = connection->getConnectionManager(); if (oldMgr != this) { if (oldMgr) { // 'connection' was being previously managed in a different thread. // We must remove it from that manager before adding it to this one. oldMgr->removeConnection(connection); } conns_.push_back(*connection); connection->setConnectionManager(this); if (callback_) { callback_->onConnectionAdded(*this); } } if (timeout) { scheduleTimeout(connection); } }
void Controller::state_10_entDef() { NOTIFY_STATE_ENTERED("ROOT.On.state_10"); NOTIFY_TRANSITION_STARTED("9"); NOTIFY_STATE_ENTERED("ROOT.On.state_10.On_000"); state_10_subState = On_000; state_10_active = On_000; //#[ state ROOT.On.state_10.On_000.(Entry) if(x==false && y==false && z==false) { Reset(); NS_RED=1; EW_GREEN=1; NS_REDTIME=5; EW_GREENTIME=5; NS_MSG=" STOP"; EW_MSG=" GO"; } //#] state_10_timeout = scheduleTimeout(5000, "ROOT.On.state_10.On_000"); NOTIFY_TRANSITION_TERMINATED("9"); }
void ProxygenServer::stopListening(bool hard) { m_shutdownState = ShutdownState::DRAINING_READS; #define SHUT_FBLISTEN 3 /* * Modifications to the Linux kernel to support shutting down a listen * socket for new connections only, but anything which has completed * the TCP handshake will still be accepted. This allows for un-accepted * connections to be queued and then wait until all queued requests are * actively being processed. */ // triggers acceptStopped/sets acceptor state to Draining if (hard) { m_httpServerSocket.reset(); m_httpsServerSocket.reset(); } else { if (m_httpServerSocket) { m_httpServerSocket->stopAccepting(SHUT_FBLISTEN); } if (m_httpsServerSocket) { m_httpsServerSocket->stopAccepting(SHUT_FBLISTEN); } } if (RuntimeOption::ServerShutdownListenWait > 0) { std::chrono::seconds s(RuntimeOption::ServerShutdownListenWait); VLOG(4) << this << ": scheduling shutdown listen timeout=" << s.count() << " port=" << m_port; scheduleTimeout(s); if (RuntimeOption::ServerShutdownEOMWait > 0) { int delayMilliSeconds = RuntimeOption::ServerShutdownEOMWait * 1000; m_worker.getEventBase()->runAfterDelay( [this] { abortPendingTransports(); }, delayMilliSeconds); } } else { doShutdown(); } }
void timeoutExpired() noexcept override { sendRouteAdvertisement(); scheduleTimeout(interval_); }
bool AsyncTimeout::scheduleTimeout(uint32_t milliseconds) { return scheduleTimeout(TimeoutManager::timeout_type(milliseconds)); }
IOxfReactive::TakeEventStatus Controller::state_10_processEvent() { IOxfReactive::TakeEventStatus res = eventNotConsumed; switch (state_10_active) { case On_000: { if(IS_EVENT_TYPE_OF(OMTimeoutEventId)) { if(getCurrentEvent() == state_10_timeout) { NOTIFY_TRANSITION_STARTED("3"); if(state_10_timeout != NULL) { state_10_timeout->cancel(); state_10_timeout = NULL; } NOTIFY_STATE_EXITED("ROOT.On.state_10.On_000"); //#[ transition 3 z=true; //#] NOTIFY_STATE_ENTERED("ROOT.On.state_10.On_001"); state_10_subState = On_001; state_10_active = On_001; //#[ state ROOT.On.state_10.On_001.(Entry) if(x==false && y==false && z==true) { Reset(); NS_ORANGE=1; EW_ORANGE=1; NS_ORANGETIME=5; EW_ORANGETIME=5; NS_MSG=" READY"; EW_MSG=" WAIT"; } //#] state_10_timeout = scheduleTimeout(5000, "ROOT.On.state_10.On_001"); NOTIFY_TRANSITION_TERMINATED("3"); res = eventConsumed; } } } break; case On_001: { if(IS_EVENT_TYPE_OF(OMTimeoutEventId)) { if(getCurrentEvent() == state_10_timeout) { NOTIFY_TRANSITION_STARTED("4"); if(state_10_timeout != NULL) { state_10_timeout->cancel(); state_10_timeout = NULL; } NOTIFY_STATE_EXITED("ROOT.On.state_10.On_001"); //#[ transition 4 y=true; //#] NOTIFY_STATE_ENTERED("ROOT.On.state_10.On_011"); state_10_subState = On_011; state_10_active = On_011; //#[ state ROOT.On.state_10.On_011.(Entry) if(x==false && y==true && z==true) { Reset(); EW_RED=1; NS_GREEN=1; EW_REDTIME=10; NS_GREENTIME=10; EW_MSG=" STOP"; NS_MSG=" GO"; } //#] state_10_timeout = scheduleTimeout(5000, "ROOT.On.state_10.On_011"); NOTIFY_TRANSITION_TERMINATED("4"); res = eventConsumed; } } } break; case On_011: { if(IS_EVENT_TYPE_OF(OMTimeoutEventId)) { if(getCurrentEvent() == state_10_timeout) { NOTIFY_TRANSITION_STARTED("5"); if(state_10_timeout != NULL) { state_10_timeout->cancel(); state_10_timeout = NULL; } NOTIFY_STATE_EXITED("ROOT.On.state_10.On_011"); //#[ transition 5 x=true; //#] NOTIFY_STATE_ENTERED("ROOT.On.state_10.On_111"); state_10_subState = On_111; state_10_active = On_111; //#[ state ROOT.On.state_10.On_111.(Entry) if(x==true && y==true && z==true) { Reset(); EW_RED=1; NS_GREEN=1; EW_REDTIME=5; NS_GREENTIME=5; EW_MSG=" STOP"; NS_MSG=" GO"; } //#] state_10_timeout = scheduleTimeout(5000, "ROOT.On.state_10.On_111"); NOTIFY_TRANSITION_TERMINATED("5"); res = eventConsumed; } } } break; case On_100: { if(IS_EVENT_TYPE_OF(OMTimeoutEventId)) { if(getCurrentEvent() == state_10_timeout) { NOTIFY_TRANSITION_STARTED("8"); if(state_10_timeout != NULL) { state_10_timeout->cancel(); state_10_timeout = NULL; } NOTIFY_STATE_EXITED("ROOT.On.state_10.On_100"); //#[ transition 8 x=false; //#] NOTIFY_STATE_ENTERED("ROOT.On.state_10.On_000"); state_10_subState = On_000; state_10_active = On_000; //#[ state ROOT.On.state_10.On_000.(Entry) if(x==false && y==false && z==false) { Reset(); NS_RED=1; EW_GREEN=1; NS_REDTIME=5; EW_GREENTIME=5; NS_MSG=" STOP"; EW_MSG=" GO"; } //#] state_10_timeout = scheduleTimeout(5000, "ROOT.On.state_10.On_000"); NOTIFY_TRANSITION_TERMINATED("8"); res = eventConsumed; } } } break; case On_110: { if(IS_EVENT_TYPE_OF(OMTimeoutEventId)) { if(getCurrentEvent() == state_10_timeout) { NOTIFY_TRANSITION_STARTED("7"); if(state_10_timeout != NULL) { state_10_timeout->cancel(); state_10_timeout = NULL; } NOTIFY_STATE_EXITED("ROOT.On.state_10.On_110"); //#[ transition 7 y=false; //#] NOTIFY_STATE_ENTERED("ROOT.On.state_10.On_100"); state_10_subState = On_100; state_10_active = On_100; //#[ state ROOT.On.state_10.On_100.(Entry) if(x==true && y==false && z==false) { Reset(); NS_RED=1; EW_GREEN=1; NS_REDTIME=10; EW_GREENTIME=10; NS_MSG=" STOP"; EW_MSG=" GO"; } //#] state_10_timeout = scheduleTimeout(5000, "ROOT.On.state_10.On_100"); NOTIFY_TRANSITION_TERMINATED("7"); res = eventConsumed; } } } break; case On_111: { if(IS_EVENT_TYPE_OF(OMTimeoutEventId)) { if(getCurrentEvent() == state_10_timeout) { NOTIFY_TRANSITION_STARTED("6"); if(state_10_timeout != NULL) { state_10_timeout->cancel(); state_10_timeout = NULL; } NOTIFY_STATE_EXITED("ROOT.On.state_10.On_111"); //#[ transition 6 z=false; //#] NOTIFY_STATE_ENTERED("ROOT.On.state_10.On_110"); state_10_subState = On_110; state_10_active = On_110; //#[ state ROOT.On.state_10.On_110.(Entry) if(x==true && y==true && z==false) { Reset(); NS_ORANGE=1; EW_ORANGE=1; NS_ORANGETIME=5; EW_ORANGETIME=5; NS_MSG=" WAIT"; EW_MSG=" READY"; } //#] state_10_timeout = scheduleTimeout(5000, "ROOT.On.state_10.On_110"); NOTIFY_TRANSITION_TERMINATED("6"); res = eventConsumed; } } } break; default: break; } return res; }
IOxfReactive::TakeEventStatus Dosierer::rootState_processEvent() { IOxfReactive::TakeEventStatus res = eventNotConsumed; switch (rootState_active) { // State Idle case Idle: { if(IS_EVENT_TYPE_OF(evRun_System_id)) { NOTIFY_TRANSITION_STARTED("1"); NOTIFY_STATE_EXITED("ROOT.Idle"); NOTIFY_STATE_ENTERED("ROOT.Running"); rootState_subState = Running; rootState_active = Running; //#[ state Running.(Entry) dosiere(); //#] rootState_timeout = scheduleTimeout(100, "ROOT.Running"); NOTIFY_TRANSITION_TERMINATED("1"); res = eventConsumed; } } break; // State Running case Running: { if(IS_EVENT_TYPE_OF(evStop_System_id)) { NOTIFY_TRANSITION_STARTED("2"); cancel(rootState_timeout); NOTIFY_STATE_EXITED("ROOT.Running"); NOTIFY_STATE_ENTERED("ROOT.Idle"); rootState_subState = Idle; rootState_active = Idle; NOTIFY_TRANSITION_TERMINATED("2"); res = eventConsumed; } else if(IS_EVENT_TYPE_OF(OMTimeoutEventId)) { if(getCurrentEvent() == rootState_timeout) { NOTIFY_TRANSITION_STARTED("3"); cancel(rootState_timeout); NOTIFY_STATE_EXITED("ROOT.Running"); //#[ transition 3 runde++; //#] NOTIFY_STATE_ENTERED("ROOT.Running"); rootState_subState = Running; rootState_active = Running; //#[ state Running.(Entry) dosiere(); //#] rootState_timeout = scheduleTimeout(100, "ROOT.Running"); NOTIFY_TRANSITION_TERMINATED("3"); res = eventConsumed; } } } break; default: break; } return res; }
bool AsyncTimeout::scheduleTimeout(uint32_t milliseconds) { return scheduleTimeout(std::chrono::milliseconds(milliseconds)); }
void Controller::state_10_entHist() { if(state_10_lastState != OMNonState) { state_10_subState = state_10_lastState; switch (state_10_subState) { case On_000: { NOTIFY_STATE_ENTERED("ROOT.On.state_10.On_000"); state_10_subState = On_000; state_10_active = On_000; //#[ state ROOT.On.state_10.On_000.(Entry) if(x==false && y==false && z==false) { Reset(); NS_RED=1; EW_GREEN=1; NS_REDTIME=5; EW_GREENTIME=5; NS_MSG=" STOP"; EW_MSG=" GO"; } //#] state_10_timeout = scheduleTimeout(5000, "ROOT.On.state_10.On_000"); } break; case On_001: { NOTIFY_STATE_ENTERED("ROOT.On.state_10.On_001"); state_10_subState = On_001; state_10_active = On_001; //#[ state ROOT.On.state_10.On_001.(Entry) if(x==false && y==false && z==true) { Reset(); NS_ORANGE=1; EW_ORANGE=1; NS_ORANGETIME=5; EW_ORANGETIME=5; NS_MSG=" READY"; EW_MSG=" WAIT"; } //#] state_10_timeout = scheduleTimeout(5000, "ROOT.On.state_10.On_001"); } break; case On_011: { NOTIFY_STATE_ENTERED("ROOT.On.state_10.On_011"); state_10_subState = On_011; state_10_active = On_011; //#[ state ROOT.On.state_10.On_011.(Entry) if(x==false && y==true && z==true) { Reset(); EW_RED=1; NS_GREEN=1; EW_REDTIME=10; NS_GREENTIME=10; EW_MSG=" STOP"; NS_MSG=" GO"; } //#] state_10_timeout = scheduleTimeout(5000, "ROOT.On.state_10.On_011"); } break; case On_100: { NOTIFY_STATE_ENTERED("ROOT.On.state_10.On_100"); state_10_subState = On_100; state_10_active = On_100; //#[ state ROOT.On.state_10.On_100.(Entry) if(x==true && y==false && z==false) { Reset(); NS_RED=1; EW_GREEN=1; NS_REDTIME=10; EW_GREENTIME=10; NS_MSG=" STOP"; EW_MSG=" GO"; } //#] state_10_timeout = scheduleTimeout(5000, "ROOT.On.state_10.On_100"); } break; case On_110: { NOTIFY_STATE_ENTERED("ROOT.On.state_10.On_110"); state_10_subState = On_110; state_10_active = On_110; //#[ state ROOT.On.state_10.On_110.(Entry) if(x==true && y==true && z==false) { Reset(); NS_ORANGE=1; EW_ORANGE=1; NS_ORANGETIME=5; EW_ORANGETIME=5; NS_MSG=" WAIT"; EW_MSG=" READY"; } //#] state_10_timeout = scheduleTimeout(5000, "ROOT.On.state_10.On_110"); } break; case On_111: { NOTIFY_STATE_ENTERED("ROOT.On.state_10.On_111"); state_10_subState = On_111; state_10_active = On_111; //#[ state ROOT.On.state_10.On_111.(Entry) if(x==true && y==true && z==true) { Reset(); EW_RED=1; NS_GREEN=1; EW_REDTIME=5; NS_GREENTIME=5; EW_MSG=" STOP"; NS_MSG=" GO"; } //#] state_10_timeout = scheduleTimeout(5000, "ROOT.On.state_10.On_111"); } break; default: break; } } else { OMNotifier::notifyToOutput("\nInternal Error - No last state in history\n\n"); } }