18 using std::ostringstream;
19 using namespace evf::rb_statemachine;
28 LOG4CPLUS_INFO(res->log_,
"--> ResourceBroker: NEW STATE: " <<
stateName());
29 outermost_context().setExternallyVisibleState(
stateName());
30 outermost_context().setInternalStateName(
stateName());
40 LOG4CPLUS_INFO(res->log_,
"Start stopping :) ...");
41 res->resourceStructure_->setStopFlag(
true);
42 res->resourceStructure_->shutDownClients();
45 gettimeofday(&then, 0);
46 while (!res->resourceStructure_->isReadyToShutDown()) {
47 ::usleep(res->resourceStructureTimeout_.value_ * 10);
48 gettimeofday(&now, 0);
49 if ((
unsigned int) (now.tv_sec - then.tv_sec)
50 > res->resourceStructureTimeout_.value_ / 10000) {
51 cout <<
"times: " << now.tv_sec <<
" " << then.tv_sec <<
" "
52 << res->resourceStructureTimeout_.value_ / 10000
54 LOG4CPLUS_WARN(res->log_,
55 "Some Process did not detach - going to Emergency stop! resource status:"
56 << res->resourceStructure_->printStatus() );
65 if (!res->tryLockRSAccess())
break;
68 if (!count) XCEPT_RAISE(
evf::Exception,
"Can not acquire RS lock for the emergency stop!");
72 res->unlockRSAccess();
78 if (res->resourceStructure_->isReadyToShutDown()) {
83 if (res->allowI2ODiscards_) {
85 res->allowI2ODiscards_ =
false;
87 res->resourceStructure_->releaseResources();
89 res->resourceStructure_->resetPendingAllocates();
91 res->resourceStructure_->resetIPC();
94 res->unlockRSAccess();
96 LOG4CPLUS_INFO(res->log_,
"Finished stopping!");
98 res->commands_.enqEvent(stopDone);
110 bool returnValue =
false;
112 returnValue = res->resourceStructure_->discardDataEvent(bufRef);
120 bool returnValue =
false;
122 returnValue = res->resourceStructure_->discardDqmEvent(bufRef);
143 IPCMethod* resourceStructure = res->resourceStructure_;
145 LOG4CPLUS_WARN(res->log_,
"in Emergency stop - handle non-clean stops");
149 res->allowI2ODiscards_ =
false;
152 auto lk = resourceStructure->lockCrashHandlerTimed(10);
157 vector < pid_t > client_prc_ids = resourceStructure->
clientPrcIds();
158 for (
UInt_t i = 0;
i < client_prc_ids.size();
i++) {
159 pid_t
pid = client_prc_ids[
i];
160 cout <<
"B: killing process " <<
i <<
" pid= " << pid << endl;
164 res->nbTimeoutsWithoutEvent_++;
166 res->nbTimeoutsWithEvent_++;
172 "Timed out accessing the EP Crash Handler in emergency stop. SM discards not arriving?");
175 LOG4CPLUS_WARN(res->log_,
"in Emergency stop - running lastResort");
180 std::ostringstream ostr;
181 ostr <<
"EmergencyStop: failed to shut down ResourceTable. Debug info mask:" << std::hex << shutdownStatus;
182 res->reasonForFailed_ = ostr.str();
186 res->printWorkLoopStatus();
189 LOG4CPLUS_WARN(res->log_,
"Deleting the resource structure!");
190 delete res->resourceStructure_;
191 res->resourceStructure_ = 0;
193 cout <<
"cycle through resourcetable config " << endl;
194 res->configureResources(outermost_context().getApp());
196 if (res->shmInconsistent_)
198 cout <<
"done with emergency stop" << endl;
207 return std::string(
"Stopping");
212 res->reasonForFailed_ = exception.what();
213 LOG4CPLUS_FATAL(res->log_,
214 "Moving to FAILED state! Reason: " << exception.what());
216 res->commands_.enqEvent(fail);
virtual std::vector< pid_t > clientPrcIds() const =0
virtual void lastResort()=0
boost::shared_ptr< SharedResources > SharedResourcesPtr_t
toolbox::mem::Reference MemRef_t
boost::shared_ptr< boost::statechart::event_base > EventPtr
virtual void do_moveToFailedState(xcept::Exception &exception) const
virtual bool discardDataEvent(MemRef_t *bufRef) const
void emergencyStop() const
virtual void do_stateNotify()
bool isReadyToShutDown() const
virtual bool discardDqmEvent(MemRef_t *bufRef) const
virtual bool handleCrashedEP(UInt_t runNumber, pid_t pid)=0
void moveToFailedState(xcept::Exception &exception) const
virtual void do_entryActionWork()
virtual std::string do_stateName() const
virtual void do_exitActionWork()
virtual void do_stateAction() const
std::string stateName() const