void Selector::onSuccess(Behavior* behavior) { const uint32_t idx = indexOf(behavior); if(!indexIsCurrent(idx)) { terminateFromIndex(idx+1); } notifySuccess(); }
void SequentialComposite::run() { // The composite has no children. if(getChildren().empty()) { notifySuccess(); } // Start by scheduling the first child for execution. else { mScheduler.enqueue(getChildren()[mCurrentBehavior]); setStatus(StatusWaiting); } }
void Sequence::onSuccess(Behavior* behavior) { const uint32_t idx = indexOf(behavior); if(!indexIsCurrent(idx)) { terminateFromIndex(idx+1); } if(currentIsLastBehavior()) { notifySuccess(); } else { scheduleNextBehavior(); } }
void Parallel::run() { if(getChildren().empty()) { notifySuccess(); return; } // Schedule all the child behaviors at once. // Reversed to keep the execution sequence left-to-right using our sequential scheduler. for(std::vector<Behavior*>::const_reverse_iterator it = getChildren().rbegin(); it != getChildren().rend(); ++it) { mScheduler.enqueue(*it); } setStatus(StatusWaiting); }
void Parallel::onSuccess(Behavior* behavior) { // Set the corresponding flags for the behavior. const uint32_t idx = indexOf(behavior); ReturnCode before = mCodes[idx]; mCodes[idx] = ReturnCodeSuccess; if(allChildrenSucceeded()) { // Signal successful execution only after all children have succeeded. notifySuccess(); } else if(before == ReturnCodeFailure && !anyChildrenFailed()) { // This behavior previously failed the parallel node. // Schedule the parallel node to run again to restart all terminated nodes and // tell the parent node that this node has an uncertain state (again). setStatus(StatusRunning); notifyReset(); } }
void Decorator::onSuccess(Behavior* behavior) { UNUSED(behavior); notifySuccess(); }
SenderState SenderThread::processVersionMismatch() { WTLOG(INFO) << "entered PROCESS_VERSION_MISMATCH state "; WDT_CHECK(threadStats_.getLocalErrorCode() == ABORT); auto negotiationStatus = wdtParent_->getNegotiationStatus(); WDT_CHECK_NE(negotiationStatus, V_MISMATCH_FAILED) << "Thread should have ended in case of version mismatch"; if (negotiationStatus == V_MISMATCH_RESOLVED) { WTLOG(WARNING) << "Protocol version already negotiated, but " "transfer still aborted due to version mismatch"; return END; } WDT_CHECK_EQ(negotiationStatus, V_MISMATCH_WAIT); // Need a barrier here to make sure all the negotiated protocol versions // have been collected auto barrier = controller_->getBarrier(VERSION_MISMATCH_BARRIER); barrier->execute(); WTVLOG(1) << "cleared the protocol version barrier"; auto execFunnel = controller_->getFunnel(VERSION_MISMATCH_FUNNEL); while (true) { auto status = execFunnel->getStatus(); switch (status) { case FUNNEL_START: { WTLOG(INFO) << "started the funnel for version mismatch"; wdtParent_->setProtoNegotiationStatus(V_MISMATCH_FAILED); if (transferHistoryController_->handleVersionMismatch() != OK) { execFunnel->notifySuccess(); return END; } int negotiatedProtocol = 0; for (int threadProtocolVersion : wdtParent_->getNegotiatedProtocols()) { if (threadProtocolVersion > 0) { if (negotiatedProtocol > 0 && negotiatedProtocol != threadProtocolVersion) { WTLOG(ERROR) << "Different threads negotiated different protocols " << negotiatedProtocol << " " << threadProtocolVersion; execFunnel->notifySuccess(); return END; } negotiatedProtocol = threadProtocolVersion; } } WDT_CHECK_GT(negotiatedProtocol, 0); WLOG_IF(INFO, negotiatedProtocol != threadProtocolVersion_) << *this << " Changing protocol version to " << negotiatedProtocol << ", previous version " << threadProtocolVersion_; wdtParent_->setProtocolVersion(negotiatedProtocol); threadProtocolVersion_ = wdtParent_->getProtocolVersion(); setFooterType(); threadStats_.setRemoteErrorCode(OK); wdtParent_->setProtoNegotiationStatus(V_MISMATCH_RESOLVED); wdtParent_->clearAbort(); execFunnel->notifySuccess(); return CONNECT; } case FUNNEL_PROGRESS: { execFunnel->wait(); break; } case FUNNEL_END: { negotiationStatus = wdtParent_->getNegotiationStatus(); WDT_CHECK_NE(negotiationStatus, V_MISMATCH_WAIT); if (negotiationStatus == V_MISMATCH_FAILED) { return END; } if (negotiationStatus == V_MISMATCH_RESOLVED) { threadProtocolVersion_ = wdtParent_->getProtocolVersion(); threadStats_.setRemoteErrorCode(OK); return CONNECT; } } } } }