bool Redis::Set(string &key, string& value, int expiretime) { redisReply* reply = NULL; log4cpp::Category& _logger = log4cpp::Category::getInstance("MAIN_LOG"); reply = (redisReply*)redisCommand(connect_, "Set %s %s", key.c_str(), value.c_str()); if (!reply){ ReConnect(); reply = (redisReply*)redisCommand(connect_, "Set %s %s", key.c_str(), value.c_str()); if (!reply){ _logger.error("Set key %s %s into redis error", key.c_str(),value.c_str()); return RESULT_ERROR; } } _logger.info("Set key %s %s into redis OK", key.c_str(), value.c_str()); freeReplyObject(reply); if(expiretime > 0){ Expire(key, expiretime); } return RESULT_OK; }
bool O2IMDB:: SetLimit(size_t n) { if (n < MIN_RECORDS) return false; Limit = n; if (Messages.size() > Limit) Expire(); return true; }
bool O2KeyDB:: SetLimit(uint64 n) { //if (n < MIN_RECORDS) // return false; Limit = n; if (Keys.size() > Limit) { Expire(); } return true; }
void GenericDrug::SimpleUpdate(float dt) { // Do everything based on fast_component ignoring slow_component LOG_DEBUG_F("Drug compartment = %0.2f\n", fast_component); // Time Decay if ( fast_component > 0 ) { fast_component -= dt; } // New Doses - remaining_doses = -1 implies infinite doses if ( remaining_doses != 0 ) { dosing_timer -= dt; LOG_DEBUG_F("Remaining doses = %d, Dosing timer = %0.3f\n", remaining_doses, dosing_timer); if ( dosing_timer <= 0 ) { // DJK: Remove or fix fraction_defaulters. It only makes sense with remaining_doses=1 <ERAD-1854> if( SMART_DRAW( fraction_defaulters ) ) { // Assume uniformly distributed dropout times, cf. Fig 3 from Kruk 2008 Trop Med Int Health 13:703 fast_component = Probability::getInstance()->fromDistribution( DistributionFunction::UNIFORM_DURATION, 1, fast_decay_time_constant ); LOG_DEBUG_F("Individual dropout time = %0.2f\n", fast_component); } else { fast_component = fast_decay_time_constant; } ResetForNextDose(dt); LOG_DEBUG_F("Distributed next dose: remaining doses = %d, Drug compartment = %0.2f, Dosing timer = %0.3f\n", remaining_doses, fast_component, dosing_timer); } } // Efficacy if ( fast_component > 0 ) { current_efficacy = 1.0; current_concentration = 1.0; } else { LOG_DEBUG("Duration of drug effectiveness is finished.\n"); current_efficacy = 0; current_concentration = 0.0; if (remaining_doses == 0) // remaining_doses = -1 implies infinite doses { LOG_DEBUG("Effectiveness of last dose is finished. Expiring drug.\n"); Expire(); } } }
bool O2IMDB:: AddMessage(O2IMessage &im) { Lock(); if (im.date == 0) { im.date = time(NULL); im.key.random(); } Messages.push_back(im); NewMessageFlag = true; Unlock(); Expire(); return true; }
uint64 O2KeyDB:: ImportFromXML(const wchar_t *filename, const char *in, uint len) { SAX2XMLReader* parser = XMLReaderFactory::createXMLReader(); O2KeyDB_SAX2Handler handler(Logger, this); parser->setContentHandler(&handler); parser->setErrorHandler(&handler); try { if (filename) { #ifdef _MSC_VER /** VC++ */ LocalFileInputSource source(filename); #else /** other compiler */ LocalFileInputSource source(reinterpret_cast<const XMLCh*>(filename)); #endif parser->parse(source); } else { MemBufInputSource source((const XMLByte*)in, len, ""); parser->parse(source); } } catch (const OutOfMemoryException &e) { if (Logger) { Logger->AddLog(O2LT_ERROR, DBName.c_str(), 0, 0, L"SAX2: Out of Memory: %s", e.getMessage()); } } catch (const XMLException &e) { Logger->AddLog(O2LT_ERROR, DBName.c_str(), 0, 0, L"SAX2: Exception: %s", e.getMessage()); } catch (...) { Logger->AddLog(O2LT_ERROR, DBName.c_str(), 0, 0, L"SAX2: Unexpected exception during parsing."); } delete parser; Expire(); return (handler.GetParseNum()); }
bool MultiInterventionDistributor::Distribute(IIndividualHumanInterventionsContext *context, ICampaignCostObserver * const pICCO ) { // ---------------------------------------------------------------------------------- // --- Putting this here because we don't want anything to happen if we are aborting // ---------------------------------------------------------------------------------- if( AbortDueToDisqualifyingInterventionStatus( context->GetParent() ) ) { return false; } // Important: Use the instance method to obtain the intervention factory obj instead of static method to cross the DLL boundary IGlobalContext *pGC = nullptr; const IInterventionFactory* ifobj = nullptr; release_assert(context->GetParent()); if (s_OK == context->GetParent()->QueryInterface(GET_IID(IGlobalContext), (void**)&pGC)) { ifobj = pGC->GetInterventionFactory(); } if (!ifobj) { throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, "The pointer to IInterventionFactory object is not valid (could be DLL specific)" ); } try { // Parse intervention_list const json::Array & interventions_array = json::QuickInterpreter(intervention_list._json).As<json::Array>(); LOG_DEBUG_F("interventions array size = %d\n", interventions_array.Size()); for( int idx=0; idx<interventions_array.Size(); idx++ ) { const json::Object& actualIntervention = json_cast<const json::Object&>(interventions_array[idx]); Configuration * tmpConfig = Configuration::CopyFromElement( actualIntervention, "campaign" ); assert( tmpConfig ); // Instantiate and distribute interventions LOG_DEBUG_F( "Attempting to instantiate intervention of class %s\n", std::string((*tmpConfig)["class"].As<json::String>()).c_str() ); IDistributableIntervention *di = const_cast<IInterventionFactory*>(ifobj)->CreateIntervention(tmpConfig); if (di) { if (!di->Distribute( context, pICCO ) ) { di->Release(); } } else { INodeDistributableIntervention* ndi = const_cast<IInterventionFactory*>(ifobj)->CreateNDIIntervention( tmpConfig ); release_assert(ndi); if( !ndi->Distribute( context->GetParent()->GetEventContext()->GetNodeEventContext(), nullptr ) ) { ndi->Release(); } } delete tmpConfig; tmpConfig = nullptr; } } catch(json::Exception &e) { // ERROR: ::cerr << "exception casting intervention_config to array! " << e.what() << std::endl; throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, e.what() ); // ( "Intervention_List json problem: intervention_list is valid json but needs to be an array." ); } // Nothing more for this class to do... Expire(); return true; }