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
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
00027
00028
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 EventPtr failTimeOut(new Fail());
00079 res->commands_.enqEvent(failTimeOut);
00080 }
00081 } catch (xcept::Exception &e) {
00082 moveToFailedState(e);
00083 }
00084
00085 if (res->frb_)
00086 delete res->frb_;
00087 }
00088
00089
00090
00091
00092 bool Halting::discardDataEvent(MemRef_t* bufRef) const {
00093 SharedResourcesPtr_t res = outermost_context().getSharedResources();
00094 bool returnValue = false;
00095 try {
00096 returnValue = res->resourceStructure_->discardDataEventWhileHalting(
00097 bufRef);
00098 } catch (evf::Exception& e) {
00099 moveToFailedState(e);
00100 }
00101 return returnValue;
00102 }
00103 bool Halting::discardDqmEvent(MemRef_t* bufRef) const {
00104 SharedResourcesPtr_t res = outermost_context().getSharedResources();
00105 bool returnValue = false;
00106 try {
00107 returnValue = res->resourceStructure_->discardDqmEvent(
00108 bufRef);
00109 } catch (evf::Exception& e) {
00110 moveToFailedState(e);
00111 }
00112 return returnValue;
00113 }
00114
00115
00116
00117 Halting::Halting(my_context c) :
00118 my_base(c) {
00119 safeEntryAction();
00120 }
00121
00122 Halting::~Halting() {
00123 safeExitAction();
00124 }
00125
00126
00127
00128 void Halting::do_exitActionWork() {
00129 }
00130
00131 string Halting::do_stateName() const {
00132 return string("Halting");
00133 }
00134
00135 void Halting::do_moveToFailedState(xcept::Exception& exception) const {
00136 SharedResourcesPtr_t res = outermost_context().getSharedResources();
00137 res->reasonForFailed_ = exception.what();
00138 LOG4CPLUS_ERROR(res->log_,
00139 "Moving to FAILED state! Reason: " << exception.what());
00140 EventPtr fail(new Fail());
00141 res->commands_.enqEvent(fail);
00142 }