void Group::restart(const Options &options, RestartMethod method) { boost::container::vector<Callback> actions; assert(isAlive()); P_DEBUG("Restarting group " << getName()); // If there is currently a restarter thread or a spawner thread active, // the following tells them to abort their current work as soon as possible. restartsInitiated++; processesBeingSpawned = 0; m_spawning = false; m_restarting = true; uuid = generateUuid(pool); detachAll(actions); getPool()->interruptableThreads.create_thread( boost::bind(&Group::finalizeRestart, this, shared_from_this(), this->options.copyAndPersist().clearPerRequestFields(), options.copyAndPersist().clearPerRequestFields(), method, getContext()->getSpawningKitFactory(), restartsInitiated, actions), "Group restarter: " + getName(), POOL_HELPER_THREAD_STACK_SIZE ); }
Group::Group(Pool *_pool, const Options &_options) : pool(_pool), uuid(generateUuid(_pool)) { info.context = _pool->getContext(); info.group = this; info.name = _options.getAppGroupName().toString(); generateSecret(_pool, info.secret); resetOptions(_options); enabledCount = 0; disablingCount = 0; disabledCount = 0; nEnabledProcessesTotallyBusy = 0; spawner = getContext()->getSpawningKitFactory()->create(options); restartsInitiated = 0; processesBeingSpawned = 0; m_spawning = false; m_restarting = false; lifeStatus.store(ALIVE, boost::memory_order_relaxed); lastRestartFileMtime = 0; lastRestartFileCheckTime = 0; alwaysRestartFileExists = false; if (options.restartDir.empty()) { restartFile = options.appRoot + "/tmp/restart.txt"; alwaysRestartFile = options.appRoot + "/tmp/always_restart.txt"; } else if (options.restartDir[0] == '/') { restartFile = options.restartDir + "/restart.txt"; alwaysRestartFile = options.restartDir + "/always_restart.txt"; } else { restartFile = options.appRoot + "/" + options.restartDir + "/restart.txt"; alwaysRestartFile = options.appRoot + "/" + options.restartDir + "/always_restart.txt"; } detachedProcessesCheckerActive = false; }
bool ClientController::sendRequestOutsideDialog( client_ptr client, const string& clientMsgId, const string& startLine, const string& headers, const string& body, string& transactionId, string& dialogId ) { generateUuid( transactionId ) ; if( 0 != startLine.find("ACK") ) { addAppTransaction( client, transactionId ) ; } addApiRequest( client, clientMsgId ) ; bool rc = m_pController->getDialogController()->sendRequestOutsideDialog( clientMsgId, startLine, headers, body, transactionId, dialogId) ; return rc ; }
/* getMachineId will return an uuid as a string. * If the uuid is not created yet, it will generate it and store it * in machine_id file. * Otherwise it will read the file to retrieve the uuid and cache it * for further uses. * If the file is removed, a new file with a different uuid will be * created. */ std::string getMachineId() { static bool initialized = false; static std::string idString; if (initialized) return idString; static boost::mutex mutex; boost::mutex::scoped_lock lock(mutex); if (initialized) return idString; const qi::Path idFilePath(qi::path::userWritableConfPath("qimessaging", "machine_id")); boost::filesystem::ifstream idFile(idFilePath); if (idFile) { idFile >> idString; idFile.close(); initialized = true; if (!idString.empty()) { return idString; } //else machine id is empty... qiLogWarning() << "machine_id is empty, generating a new one"; } boost::filesystem::ofstream newIdFile(idFilePath); idString = generateUuid(); if (newIdFile) { newIdFile << idString; newIdFile.close(); initialized = true; } else { qiLogError() << "Unable to create file: '" << idFilePath << "'"; } return idString; }
int DrachtioController::processRequestOutsideDialog( nta_leg_t* defaultLeg, nta_incoming_t* irq, sip_t const *sip) { DR_LOG(log_debug) << "processRequestOutsideDialog" << endl ; int rc = validateSipMessage( sip ) ; if( 0 != rc ) { return rc ; } switch (sip->sip_request->rq_method ) { case sip_method_invite: { /* TODO: should support optional config to only allow invites from defined addresses */ /* system-wide minimum session-expires is 90 seconds */ if( sip->sip_session_expires && sip->sip_session_expires->x_delta < 90 ) { nta_incoming_treply( irq, SIP_422_SESSION_TIMER_TOO_SMALL, SIPTAG_MIN_SE_STR("90"), TAG_END() ) ; return 0; } string transactionId ; generateUuid( transactionId ) ; nta_incoming_treply( irq, SIP_100_TRYING, TAG_END() ) ; if( !m_pClientController->route_request_outside_dialog( irq, sip, transactionId ) ) { DR_LOG(log_error) << "No providers available for invite" << endl ; return 503 ; } nta_leg_t* leg = nta_leg_tcreate(m_nta, legCallback, this, SIPTAG_CALL_ID(sip->sip_call_id), SIPTAG_CSEQ(sip->sip_cseq), SIPTAG_TO(sip->sip_from), SIPTAG_FROM(sip->sip_to), TAG_END()); if( NULL == leg ) { DR_LOG(log_error) << "Error creating a leg for origination" << endl ; //TODO: we got a client out there with a dead INVITE now... return 500 ; } boost::shared_ptr<SipDialog> dlg = boost::make_shared<SipDialog>( leg, irq, sip ) ; dlg->setTransactionId( transactionId ) ; string contactStr ; generateOutgoingContact( sip->sip_contact, contactStr ) ; nta_leg_server_route( leg, sip->sip_record_route, sip->sip_contact ) ; m_pDialogController->addIncomingInviteTransaction( leg, irq, sip, transactionId, dlg ) ; } break ; case sip_method_ack: /* success case: call has been established */ nta_incoming_destroy( irq ) ; return 0 ; case sip_method_register: case sip_method_message: case sip_method_options: case sip_method_notify: { string transactionId ; generateUuid( transactionId ) ; if( !m_pClientController->route_request_outside_dialog( irq, sip, transactionId ) ) { DR_LOG(log_error) << "No providers available for register" << endl ; return 503 ; } m_pDialogController->addIncomingRequestTransaction( irq, transactionId ) ; return 0 ; } case sip_method_bye: case sip_method_cancel: DR_LOG(log_error) << "Received BYE or CANCEL for unknown dialog: " << sip->sip_call_id->i_id << endl ; return 481 ; default: DR_LOG(log_error) << "DrachtioController::processRequestOutsideDialog - unsupported method type: " << sip->sip_request->rq_method_name << ": " << sip->sip_call_id->i_id << endl ; return 501 ; break ; } return 0 ; }