CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/EventFilter/ResourceBroker/src/Halting.cc

Go to the documentation of this file.
00001 
00006 #include "EventFilter/ResourceBroker/interface/RBStateMachine.h"
00007 #include "EvffedFillerRB.h"
00008 
00009 #include <iostream>
00010 
00011 using std::string;
00012 using std::cout;
00013 using std::endl;
00014 using namespace evf::rb_statemachine;
00015 
00016 // entry action, state notification, state action
00017 //______________________________________________________________________________
00018 void Halting::do_entryActionWork() {
00019 }
00020 
00021 void Halting::do_stateNotify() {
00022         SharedResourcesPtr_t res = outermost_context().getSharedResources();
00023         LOG4CPLUS_INFO(res->log_, "--> ResourceBroker: NEW STATE: " << stateName());
00024         outermost_context().setExternallyVisibleState(stateName());
00025         outermost_context().setInternalStateName(stateName());
00026         // RCMS notification no longer required here
00027         // this is done in FUResourceBroker in SOAP reply
00028         //outermost_context().rcmsStateChangeNotify();
00029 }
00030 
00031 void Halting::do_stateAction() const {
00032         SharedResourcesPtr_t res = outermost_context().getSharedResources();
00033         try {
00034                 LOG4CPLUS_INFO(res->log_, "Start halting ...");
00035                 if (res->resourceStructure_->isActive()) {
00036                         res->resourceStructure_->shutDownClients();
00037                         UInt_t count = 0;
00038                         while (count < 10) {
00039                                 if (res->resourceStructure_->isReadyToShutDown()) {
00040                                         res->lock();
00041 
00042                                         delete res->resourceStructure_;
00043                                         res->resourceStructure_ = 0;
00044 
00045                                         res->unlock();
00046                                         LOG4CPLUS_INFO(
00047                                                         res->log_,
00048                                                         count + 1
00049                                                                         << ". try to destroy resource table succeeded!");
00050                                         break;
00051                                 } else {
00052                                         count++;
00053 
00054                                         LOG4CPLUS_DEBUG(
00055                                                         res->log_,
00056                                                         count
00057                                                                         << ". try to destroy resource table failed ...");
00058 
00059 					::sleep(1);
00060                                 }
00061                         }
00062                 } else {
00063                         res->lock();
00064 
00065                         delete res->resourceStructure_;
00066                         res->resourceStructure_ = 0;
00067 
00068                         res->unlock();
00069                 }
00070 
00071                 if (0 == res->resourceStructure_) {
00072                         LOG4CPLUS_INFO(res->log_, "Finished halting!");
00073                         EventPtr haltDone(new HaltDone());
00074                         res->commands_.enqEvent(haltDone);
00075                 } else {
00076                         res->reasonForFailed_
00077                                         = "halting FAILED: ResourceTable shutdown timed out.";
00078                         LOG4CPLUS_FATAL(res->log_,
00079                                                 "Moving to FAILED state! Reason: " << res->reasonForFailed_.value_);
00080                         EventPtr failTimeOut(new Fail());
00081                         res->commands_.enqEvent(failTimeOut);
00082                 }
00083         } catch (xcept::Exception &e) {
00084                 moveToFailedState(e);
00085         }
00086 
00087         if (res->frb_)
00088                 delete res->frb_;
00089 }
00090 
00091 /*
00092  * I2O capability
00093  */
00094 bool Halting::discardDataEvent(MemRef_t* bufRef) const {
00095         SharedResourcesPtr_t res = outermost_context().getSharedResources();
00096         bool returnValue = false;
00097         try {
00098                 returnValue = res->resourceStructure_->discardDataEventWhileHalting(
00099                                 bufRef);
00100         } catch (evf::Exception& e) {
00101                 moveToFailedState(e);
00102         }
00103         return returnValue;
00104 }
00105 bool Halting::discardDqmEvent(MemRef_t* bufRef) const {
00106         SharedResourcesPtr_t res = outermost_context().getSharedResources();
00107         bool returnValue = false;
00108         try {
00109                 returnValue = res->resourceStructure_->discardDqmEvent(bufRef);
00110                 //returnValue = res->resourceStructure_->discardDqmEventWhileHalting(bufRef);
00111         } catch (evf::Exception& e) {
00112                 moveToFailedState(e);
00113         }
00114         return returnValue;
00115 }
00116 
00117 // construction / destruction
00118 //______________________________________________________________________________
00119 Halting::Halting(my_context c) :
00120         my_base(c) {
00121         safeEntryAction();
00122 }
00123 
00124 Halting::~Halting() {
00125         safeExitAction();
00126 }
00127 
00128 // exit action, state name, move to failed state
00129 //______________________________________________________________________________
00130 void Halting::do_exitActionWork() {
00131 }
00132 
00133 string Halting::do_stateName() const {
00134         return string("Halting");
00135 }
00136 
00137 void Halting::do_moveToFailedState(xcept::Exception& exception) const {
00138         SharedResourcesPtr_t res = outermost_context().getSharedResources();
00139         res->reasonForFailed_ = exception.what();
00140         LOG4CPLUS_FATAL(res->log_,
00141                         "Moving to FAILED state! Reason: " << exception.what());
00142         EventPtr fail(new Fail());
00143         res->commands_.enqEvent(fail);
00144 }