void LibClasses::init() { CStopWatch pomtime; createHandler(bth, "Bonus type", pomtime); createHandler(generaltexth, "General text", pomtime); createHandler(heroh, "Hero", pomtime); createHandler(arth, "Artifact", pomtime); createHandler(creh, "Creature", pomtime); createHandler(townh, "Town", pomtime); createHandler(objh, "Object", pomtime); createHandler(dobjinfo, "Def information", pomtime); createHandler(spellh, "Spell", pomtime); modh->loadActiveMods(); modh->reload(); //FIXME: make sure that everything is ok after game restart //TODO: This should be done every time mod config changes IS_AI_ENABLED = false; }
bool Metadata::writeTokenType(const otp::storage::OTPTokenType& type) { bool result = false; if(haveType()) { // already in desired state, then nothing needs to be done. if((typeWritten() && m_typeWrite == type) || (!typeWritten() && m_typeRead == type)) { result = true; } else { if(m_dbManager) { const auto newHandler = m_dbManager->handler(type); if(newHandler) { result = convertHandler(newHandler); m_dataWrite.insert(otp::storage::Storage::OTP_TOKEN_TYPE, QVariant((qlonglong) type)); m_typeWrite = type; } } } } else { if(createHandler(type)) { m_dataWrite.insert(otp::storage::Storage::OTP_TOKEN_TYPE, QVariant((qlonglong) type)); m_typeWrite = type; result = true; } } return result; }
int main() { signal(SIGQUIT, sigHandler); signal(SIGINT, sigHandler); signal(SIGALRM, sigHandler); signal(SIGUSR1, sigHandler); signal(SIGUSR2, sigHandler); createHandler(); return 0; }
std::shared_ptr<LogHandler> TestLogHandlerFactory::updateHandler( const std::shared_ptr<LogHandler>& existingHandler, const Options& options) { // Only re-use an existing handler in-place if it is a TestLogHandler // and if the new options contain reuse_handler auto existing = std::dynamic_pointer_cast<TestLogHandler>(existingHandler); if (!existing || !get_ptr(options, "reuse_handler")) { return createHandler(options); } existing->setOptions(options); return existing; }
bool Metadata::establishTokenType(otp::storage::OTPTokenType& type) { QVariant v; if(m_dbManager && m_dbManager->readType(m_entryId, v) && !v.isNull()) { const auto result = (otp::storage::OTPTokenType) v.toLongLong(); if(createHandler(result)) { type = result; return true; } } return false; }
int ILoopController::exec() { CHECK(!handler_); CHECK(!loop_); handler_ = createHandler(); if (!handler_) { return EXIT_FAILURE; } loop_ = createServer(handler_); if (!loop_) { delete handler_; handler_ = nullptr; return EXIT_FAILURE; } return loop_->exec(); }
void Server::accept() { std::cout << "start listening" << std::endl; m_acceptor.async_accept(m_socket, [this](const boost::system::error_code& ec) { if (!ec) { auto handler = createHandler(); if (handler) { m_handlers.insert({handler->getConnID(), handler}); std::cout << "current connect count: " << m_handlers.size() << " conn_id: " << handler->getConnID() << std::endl; handler->start(); } else { std::cout << "too much connection" << m_handlers.size() << std::endl; refuseAccept(std::move(m_socket)); } } accept(); }); }
HttpServer::HttpServer(void *sslCTX /* = NULL */) : m_stopped(false), m_stopReason(nullptr), m_sslCTX(sslCTX), m_watchDog(this, &HttpServer::watchDog) { // enabling mutex profiling, but it's not turned on LockProfiler::s_pfunc_profile = server_stats_log_mutex; int startingThreadCount = RuntimeOption::ServerThreadCount; uint32_t additionalThreads = 0; if (RuntimeOption::ServerWarmupThrottleRequestCount > 0 && RuntimeOption::ServerThreadCount > kNumProcessors) { startingThreadCount = kNumProcessors; additionalThreads = RuntimeOption::ServerThreadCount - startingThreadCount; } auto serverFactory = ServerFactoryRegistry::getInstance()->getFactory (RuntimeOption::ServerType); ServerOptions options (RuntimeOption::ServerIP, RuntimeOption::ServerPort, startingThreadCount); options.m_serverFD = RuntimeOption::ServerPortFd; options.m_sslFD = RuntimeOption::SSLPortFd; options.m_takeoverFilename = RuntimeOption::TakeoverFilename; m_pageServer = serverFactory->createServer(options); m_pageServer->addTakeoverListener(this); if (additionalThreads) { auto handlerFactory = boost::make_shared<WarmupRequestHandlerFactory>( m_pageServer, additionalThreads, RuntimeOption::ServerWarmupThrottleRequestCount, RuntimeOption::RequestTimeoutSeconds); m_pageServer->setRequestHandlerFactory([handlerFactory] { return handlerFactory->createHandler(); }); } else { m_pageServer->setRequestHandlerFactory<HttpRequestHandler>( RuntimeOption::RequestTimeoutSeconds); } if (RuntimeOption::EnableSSL && m_sslCTX) { assert(SSLInit::IsInited()); m_pageServer->enableSSL(m_sslCTX, RuntimeOption::SSLPort); } m_adminServer = ServerFactoryRegistry::createServer (RuntimeOption::ServerType, RuntimeOption::ServerIP, RuntimeOption::AdminServerPort, RuntimeOption::AdminThreadCount); m_adminServer->setRequestHandlerFactory<AdminRequestHandler>( RuntimeOption::RequestTimeoutSeconds); for (unsigned int i = 0; i < RuntimeOption::SatelliteServerInfos.size(); i++) { SatelliteServerInfoPtr info = RuntimeOption::SatelliteServerInfos[i]; SatelliteServerPtr satellite = SatelliteServer::Create(info); if (satellite) { if (info->getType() == SatelliteServer::Type::KindOfDanglingPageServer) { m_danglings.push_back(satellite); } else { m_satellites.push_back(satellite); } } } if (RuntimeOption::XboxServerPort != 0) { SatelliteServerInfoPtr xboxInfo(new XboxServerInfo()); SatelliteServerPtr satellite = SatelliteServer::Create(xboxInfo); if (satellite) { m_satellites.push_back(satellite); } } if (RuntimeOption::EnableStaticContentCache) { StaticContentCache::TheCache.load(); } hphp_process_init(); Server::InstallStopSignalHandlers(m_pageServer); Server::InstallStopSignalHandlers(m_adminServer); if (!RuntimeOption::StartupDocument.empty()) { Hdf hdf; hdf["cmd"] = static_cast<int>(Transport::Method::GET); hdf["url"] = RuntimeOption::StartupDocument; hdf["remote_host"] = RuntimeOption::ServerIP; ReplayTransport rt; rt.replayInput(hdf); HttpRequestHandler handler(0); handler.handleRequest(&rt); int code = rt.getResponseCode(); if (code == 200) { Logger::Info("StartupDocument %s returned 200 OK: %s", RuntimeOption::StartupDocument.c_str(), rt.getResponse().c_str()); } else { Logger::Error("StartupDocument %s failed %d: %s", RuntimeOption::StartupDocument.c_str(), code, rt.getResponse().data()); return; } } for (unsigned int i = 0; i < RuntimeOption::ThreadDocuments.size(); i++) { ServiceThreadPtr thread (new ServiceThread(RuntimeOption::ThreadDocuments[i])); m_serviceThreads.push_back(thread); } for (unsigned int i = 0; i < RuntimeOption::ThreadLoopDocuments.size(); i++) { ServiceThreadPtr thread (new ServiceThread(RuntimeOption::ThreadLoopDocuments[i], true)); m_serviceThreads.push_back(thread); } }
bool FileTransferHandlerManager::ensureHandler(FileTransfer transfer) { createHandler(transfer); return transfer.handler() != nullptr; }
void FileTransferHandlerManager::createHandlers(Account account) { for (auto &&transfer : m_fileTransferManager->items()) if (transfer.peer().contactAccount() == account) createHandler(transfer); }
void FileTransferHandlerManager::fileTransferAboutToBeAdded(FileTransfer fileTransfer) { createHandler(fileTransfer); }
void initializeDriverRouter(::izenelib::driver::Router& router, IService* service, bool enableTest) { { CommandsController commands; const std::string controllerName("commands"); typedef ::izenelib::driver::ActionHandler<CommandsController> handler_type; typedef std::auto_ptr<handler_type> handler_ptr; handler_ptr indexHandler( new handler_type( commands, &CommandsController::index ) ); router.map( controllerName, "index", indexHandler.get() ); indexHandler.release(); handler_ptr miningHandler( new handler_type( commands, &CommandsController::mining ) ); router.map( controllerName, "mining", miningHandler.get() ); miningHandler.release(); handler_ptr optimize_indexHandler( new handler_type( commands, &CommandsController::optimize_index ) ); router.map( controllerName, "optimize_index", optimize_indexHandler.get() ); optimize_indexHandler.release(); handler_ptr train_ctr_modelHandler( new handler_type( commands, &CommandsController::train_ctr_model ) ); router.map( controllerName, "train_ctr_model", train_ctr_modelHandler.get() ); train_ctr_modelHandler.release(); } { DocumentsController documents; const std::string controllerName("documents"); typedef ::izenelib::driver::ActionHandler<DocumentsController> handler_type; typedef std::auto_ptr<handler_type> handler_ptr; handler_ptr createHandler( new handler_type( documents, &DocumentsController::create ) ); router.map( controllerName, "create", createHandler.get() ); createHandler.release(); handler_ptr destroyHandler( new handler_type( documents, &DocumentsController::destroy ) ); router.map( controllerName, "destroy", destroyHandler.get() ); destroyHandler.release(); handler_ptr getHandler( new handler_type( documents, &DocumentsController::get ) ); router.map( controllerName, "get", getHandler.get() ); getHandler.release(); handler_ptr get_doc_countHandler( new handler_type( documents, &DocumentsController::get_doc_count ) ); router.map( controllerName, "get_doc_count", get_doc_countHandler.get() ); get_doc_countHandler.release(); handler_ptr get_freq_group_labelsHandler( new handler_type( documents, &DocumentsController::get_freq_group_labels ) ); router.map( controllerName, "get_freq_group_labels", get_freq_group_labelsHandler.get() ); get_freq_group_labelsHandler.release(); handler_ptr get_key_countHandler( new handler_type( documents, &DocumentsController::get_key_count ) ); router.map( controllerName, "get_key_count", get_key_countHandler.get() ); get_key_countHandler.release(); handler_ptr indexHandler( new handler_type( documents, &DocumentsController::index ) ); router.map( controllerName, "index", indexHandler.get() ); indexHandler.release(); handler_ptr log_group_labelHandler( new handler_type( documents, &DocumentsController::log_group_label ) ); router.map( controllerName, "log_group_label", log_group_labelHandler.get() ); log_group_labelHandler.release(); handler_ptr searchHandler( new handler_type( documents, &DocumentsController::search ) ); router.map( controllerName, "search", searchHandler.get() ); searchHandler.release(); handler_ptr set_top_group_labelHandler( new handler_type( documents, &DocumentsController::set_top_group_label ) ); router.map( controllerName, "set_top_group_label", set_top_group_labelHandler.get() ); set_top_group_labelHandler.release(); handler_ptr updateHandler( new handler_type( documents, &DocumentsController::update ) ); router.map( controllerName, "update", updateHandler.get() ); updateHandler.release(); handler_ptr update_inplaceHandler( new handler_type( documents, &DocumentsController::update_inplace ) ); router.map( controllerName, "update_inplace", update_inplaceHandler.get() ); update_inplaceHandler.release(); handler_ptr visitHandler( new handler_type( documents, &DocumentsController::visit ) ); router.map( controllerName, "visit", visitHandler.get() ); visitHandler.release(); } { StatusController status; const std::string controllerName("status"); typedef ::izenelib::driver::ActionHandler<StatusController> handler_type; typedef std::auto_ptr<handler_type> handler_ptr; handler_ptr get_distribute_statusHandler( new handler_type( status, &StatusController::get_distribute_status ) ); router.map( controllerName, "get_distribute_status", get_distribute_statusHandler.get() ); get_distribute_statusHandler.release(); handler_ptr indexHandler( new handler_type( status, &StatusController::index ) ); router.map( controllerName, "index", indexHandler.get() ); indexHandler.release(); } { CollectionController collection; const std::string controllerName("collection"); typedef ::izenelib::driver::ActionHandler<CollectionController> handler_type; typedef std::auto_ptr<handler_type> handler_ptr; handler_ptr add_sharding_nodesHandler( new handler_type( collection, &CollectionController::add_sharding_nodes ) ); router.map( controllerName, "add_sharding_nodes", add_sharding_nodesHandler.get() ); add_sharding_nodesHandler.release(); handler_ptr backup_allHandler( new handler_type( collection, &CollectionController::backup_all ) ); router.map( controllerName, "backup_all", backup_allHandler.get() ); backup_allHandler.release(); handler_ptr check_collectionHandler( new handler_type( collection, &CollectionController::check_collection ) ); router.map( controllerName, "check_collection", check_collectionHandler.get() ); check_collectionHandler.release(); handler_ptr create_collectionHandler( new handler_type( collection, &CollectionController::create_collection ) ); router.map( controllerName, "create_collection", create_collectionHandler.get() ); create_collectionHandler.release(); handler_ptr delete_collectionHandler( new handler_type( collection, &CollectionController::delete_collection ) ); router.map( controllerName, "delete_collection", delete_collectionHandler.get() ); delete_collectionHandler.release(); handler_ptr rebuild_collectionHandler( new handler_type( collection, &CollectionController::rebuild_collection ) ); router.map( controllerName, "rebuild_collection", rebuild_collectionHandler.get() ); rebuild_collectionHandler.release(); handler_ptr rebuild_from_scdHandler( new handler_type( collection, &CollectionController::rebuild_from_scd ) ); router.map( controllerName, "rebuild_from_scd", rebuild_from_scdHandler.get() ); rebuild_from_scdHandler.release(); handler_ptr start_collectionHandler( new handler_type( collection, &CollectionController::start_collection ) ); router.map( controllerName, "start_collection", start_collectionHandler.get() ); start_collectionHandler.release(); handler_ptr stop_collectionHandler( new handler_type( collection, &CollectionController::stop_collection ) ); router.map( controllerName, "stop_collection", stop_collectionHandler.get() ); stop_collectionHandler.release(); handler_ptr update_collection_confHandler( new handler_type( collection, &CollectionController::update_collection_conf ) ); router.map( controllerName, "update_collection_conf", update_collection_confHandler.get() ); update_collection_confHandler.release(); handler_ptr update_sharding_confHandler( new handler_type( collection, &CollectionController::update_sharding_conf ) ); router.map( controllerName, "update_sharding_conf", update_sharding_confHandler.get() ); update_sharding_confHandler.release(); } }
void LibClasses::init() { CStopWatch pomtime, totalTime; modh->initializeConfig(); createHandler(bth, "Bonus type", pomtime); createHandler(generaltexth, "General text", pomtime); createHandler(heroh, "Hero", pomtime); createHandler(arth, "Artifact", pomtime); createHandler(creh, "Creature", pomtime); createHandler(townh, "Town", pomtime); createHandler(objh, "Object", pomtime); createHandler(objtypeh, "Object types information", pomtime); createHandler(spellh, "Spell", pomtime); createHandler(terviewh, "Terrain view pattern", pomtime); logGlobal->infoStream()<<"\tInitializing handlers: "<< totalTime.getDiff(); modh->load(); createHandler(tplh, "Template", pomtime); //templates need already resolved identifiers (refactor?) modh->afterLoad(); //FIXME: make sure that everything is ok after game restart //TODO: This should be done every time mod config changes IS_AI_ENABLED = false; }