/* * Unmap Service Id */ bool CDbManager::unmapService(NLNET::TServiceId serviceId) { if (serviceId.get() > 256 || _ServiceMap[serviceId.get()] == INVALID_DATABASE_ID) return false; TDatabaseId id = _ServiceMap[serviceId.get()]; _ServiceMap[serviceId.get()] = INVALID_DATABASE_ID; CDatabase* db = getDatabase(id); if (db != NULL) { db->mapToService(TServiceId(0xffff)); db->releaseAll(); } return true; }
/* * Release all ranges owned by a service */ void CRangeMirrorManager::releaseRangesByService( NLNET::TServiceId declaratorServiceId ) { uint nbReleased = 0; TRangeListByDataSet::iterator ids; for ( ids=_RangeListByDataSet.begin(); ids!=_RangeListByDataSet.end(); ++ids ) { while ( GET_RANGE_LIST(ids).releaseOneRange( declaratorServiceId ) ) ++nbReleased; } nlinfo( "RangeMirrorManager: released %u ranges of owner %hu", nbReleased, declaratorServiceId.get() ); }
/* * Reacquire ranges after a service failure or shutdown * * Warning: this will fail if some services acquire some ranges before any reacquisition! */ void CRangeMirrorManager::reacquireRanges( NLNET::CMessage& msgin, NLNET::TServiceId mirrorServiceId ) { uint nbReacquired = 0; uint16 nbServices; msgin.serial( nbServices ); for ( uint i=0; i!=(uint)nbServices; ++i ) { NLNET::TServiceId serviceId; uint16 nbRanges; msgin.serial( serviceId ); msgin.serial( nbRanges ); for ( uint r=0; r!=(uint)nbRanges; ++r ) { string datasetname; TDataSetIndex first, last; msgin.serial( datasetname ); msgin.serial( first, last ); TRangeListByDataSet::iterator ids = _RangeListByDataSet.find( datasetname ); if ( ids != _RangeListByDataSet.end() ) { if ( ! CUnifiedNetwork::getInstance()->getServiceName( serviceId ).empty() ) { GET_RANGE_LIST(ids).reacquireRange( serviceId, mirrorServiceId, first, last ); ++nbReacquired; } else { nlinfo( "RangeMirrorManager: skipping offline service %hu when reacquiring", serviceId.get() ); } } else { nlwarning( "RangeMirrorManager: dataset %s not found", datasetname.c_str() ); } } } nlinfo( "RangeMirrorManager: reacquired %u ranges for MS-%hu", nbReacquired, mirrorServiceId.get() ); }
/* * Reacquire ranges */ void CRangeList::reacquireRange( NLNET::TServiceId ownerServiceId, NLNET::TServiceId mirrorServiceId, TDataSetIndex first, TDataSetIndex last ) { TDataSetIndex prevlast(first-1); TRangeList::iterator irl = _RangeList.begin(); while ( ! rangeInserted( ownerServiceId, mirrorServiceId, last-first+1, prevlast, irl ) ) { prevlast = (*irl).Last; ++irl; } if ( ! ((*irl).Last < (uint32)_TotalMaxRows) ) { nlwarning( "Failed to reacquire range [%d,%d] for %hu", first, last, ownerServiceId.get() ); _RangeList.erase( irl ); } }
//--------------------------------------------------- // agsDisconnect : //--------------------------------------------------- void CCreatureManager::agsDisconnect( NLNET::TServiceId serviceId ) { TMapCreatures::iterator it = _Creatures.begin(); while( it != _Creatures.end() ) { if( (*it).first.getDynamicId() == serviceId.get() ) { TMapCreatures::iterator itTmp = it; ++it, delete (*itTmp).second; _Creatures.erase( itTmp ); } else { ++it; } } } // agsDisconnect //
// assign manager to a specified service and begin execution void CAIManager::assign(NLNET::TServiceId serviceId) { // make sure that the manager isn't assigned to a service already if (isAssigned()) { nlwarning("Cannot assign manager %04d (%s) to service %d as already assigned to %d", id(), name().c_str(), serviceId.get(), _service.get()); return; } // flag me as assigned _isAssigned=true; _service=serviceId; // transfer control to the service's assignMgr() method CAIService *service=CAIService::getServiceById(serviceId); if (service!=NULL) service->assignMgr(id()); }
/* * Release ranges by MS */ void CRangeList::releaseRangesByMS( NLNET::TServiceId msId, std::vector<TRowRange>& erasedRanges ) { TRangeList::iterator irl; for ( irl=_RangeList.begin(); irl!=_RangeList.end(); ) { if ( (*irl).MirrorServiceId == msId ) { nlinfo( "RangeMirrorManager: releasing range for %hu (MS-%hu down)", (*irl).OwnerServiceId.get(), msId.get() ); erasedRanges.push_back( *irl ); irl = _RangeList.erase( irl ); } else ++irl; } }
/* * Release a range */ void CRangeMirrorManager::releaseRanges( const std::vector<string>& datasetNames, NLNET::TServiceId declaratorServiceId, NLNET::TServiceId mirrorServiceId ) { for ( sint i=0; i!=(sint)datasetNames.size(); ++i ) { TRangeListByDataSet::iterator ids = _RangeListByDataSet.find( datasetNames[i] ); if ( ids != _RangeListByDataSet.end() ) { uint nbReleased = 0; // Release ranges while ( GET_RANGE_LIST(ids).releaseOneRange( declaratorServiceId ) ) ++nbReleased; } } // Save ranges into xml file //saveRanges(); nlinfo( "RangeMirrorManager: released %u ranges of owner %hu (via MS %hu)", datasetNames.size(), declaratorServiceId.get(), mirrorServiceId.get() ); }
/* * Get a range */ void CRangeMirrorManager::getRange( const std::vector<string>& datasetNames, sint32 nbRows, NLNET::TServiceId declaratorServiceId, NLNET::TServiceId mirrorServiceId, uint8 entityTypeId ) { CMessage msgout( "RG" ); msgout.serial( declaratorServiceId ); msgout.serial( entityTypeId ); //nlassert( datasetNames.size() < 256 ); uint8 nbDatasets = (uint8)datasetNames.size(); uint nbErrors = 0; string errorStr; msgout.serial( nbDatasets ); for ( sint i=0; i!=nbDatasets; ++i ) { TDataSetIndex first, last; TRangeListByDataSet::iterator ids = _RangeListByDataSet.find( datasetNames[i] ); if ( ids != _RangeListByDataSet.end() ) { // Acquire range if ( ! GET_RANGE_LIST(ids).acquireRange( declaratorServiceId, mirrorServiceId, nbRows, &first, &last ) ) { errorStr = NLMISC::toString( "Cannot acquire requested range of %d rows in %s, index limit reached (declarator=%hu entityTypeId=%hu) (check 'max number of rows' in dataset file)", nbRows, ((*ids).first).c_str(), declaratorServiceId.get(), (uint16)entityTypeId, nbRows ); nlwarning( errorStr.c_str() ); displayRanges(); //#ifdef NL_OS_WINDOWS //nlstop; //#endif first = INVALID_DATASET_INDEX; last = INVALID_DATASET_INDEX; ++nbErrors; } } else { nlwarning( "RangeMirrorManager: dataset %s not found", datasetNames[i].c_str() ); first = INVALID_DATASET_INDEX; last = INVALID_DATASET_INDEX; ++nbErrors; #ifdef NL_OS_WINDOWS nlstop; #endif } // Answer mirror service msgout.serial( const_cast<string&>(datasetNames[i]) ); msgout.serial( first, last ); if ( ! errorStr.empty() ) { msgout.serial( errorStr ); errorStr.clear(); } // Save ranges into xml file //saveRanges(); } // Send answer CUnifiedNetwork::getInstance()->send( mirrorServiceId, msgout ); nlinfo( "RangeMirrorManager: got %u ranges for owner %hu (via MS %hu) (%u errors)", ((uint)nbDatasets)-nbErrors, declaratorServiceId.get(), mirrorServiceId.get(), nbErrors ); }
static void cbServiceUp(const std::string& serviceName, NLNET::TServiceId sid, void *) { ServiceMap[sid]= serviceName; } static void cbServiceDown(const std::string& serviceName, NLNET::TServiceId sid, void *) { ServiceMap.erase(sid); } //----------------------------------------------------------------------------- // executeRemoteCommand //----------------------------------------------------------------------------- void executeRemoteCommand(NLNET::TServiceId sid,const CSString& cmdLine) { // make sure the service we're trying to talk to is up DROP_IF(ServiceMap.find(sid)==ServiceMap.end(),"Failed to send command to unknown remote service: "+NLMISC::toString(sid.get()),return); // display a little debug message... nldebug("Sending command to service: %s(%d): %s", ServiceMap[sid].c_str(), sid.get(), cmdLine.c_str()); // compose and send the command execution message CMessage msgout("EXEC_COMMAND"); msgout.serial(const_cast<CSString&>(cmdLine)); CUnifiedNetwork::getInstance()->send(sid,msgout); }
void CMsgAIManagerUp::callback (const std::string &serviceName, NLNET::TServiceId sid) { nlinfo("Service %d: Manager Up: %04d",sid.get(), MgrId); }
void CMsgAIServiceUp::callback (const std::string &serviceName, NLNET::TServiceId sid) { nlinfo("AI Service Up: %02d (CPU rating: %f RAMrating %f)", sid.get(), ProcessorAllocation,RamAllocation); for (uint i=0;i<ManagersRunning.size();i++) nlinfo("-- Running Manager: %04d",ManagersRunning[i]); }