int CollectorEngine:: invokeHousekeeper (AdTypes adType) { time_t now; (void) time (&now); if (now == (time_t) -1) { dprintf (D_ALWAYS, "Error in reading system time --- aborting\n"); return 0; } CollectorHashTable *table=0; CollectorEngine::HashFunc func; if (LookupByAdType(adType, table, func)) { cleanHashTable(*table, now, func); } else { if (GENERIC_AD == adType) { CollectorHashTable *cht=0; GenericAds.startIterations(); while (GenericAds.iterate(cht)) { cleanHashTable (*cht, now, makeGenericAdHashKey); } } else { return 0; } } return 1; }
void SelectFormat::copyHashtable(Hashtable *other, UErrorCode& status) { if (U_FAILURE(status)) { return; } if (other == NULL) { cleanHashTable(); return; } if (parsedValuesHash == NULL) { initHashTable(status); if (U_FAILURE(status)) { return; } } parsedValuesHash->removeAll(); parsedValuesHash->setValueDeleter(uhash_deleteUnicodeString); int32_t pos = -1; const UHashElement* elem = NULL; // walk through the hash table and create a deep clone while ((elem = other->nextElement(pos)) != NULL){ const UHashTok otherKeyTok = elem->key; UnicodeString* otherKey = (UnicodeString*)otherKeyTok.pointer; const UHashTok otherKeyToVal = elem->value; UnicodeString* otherValue = (UnicodeString*)otherKeyToVal.pointer; parsedValuesHash->put(*otherKey, new UnicodeString(*otherValue), status); if (U_FAILURE(status)){ cleanHashTable(); return; } } }
void SelectFormat::initHashTable(UErrorCode &status) { if (U_FAILURE(status)) { return; } // has inited if (parsedValuesHash != NULL) { return; } parsedValuesHash = new Hashtable(TRUE, status); if (U_FAILURE(status)) { cleanHashTable(); return; } else { if (parsedValuesHash == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return; } } // to use hashtable->equals(), must set Value Compartor. parsedValuesHash->setValueComparator(uhash_compareCaselessUnicodeString); }
void CollectorEngine:: housekeeper() { time_t now; (void) time (&now); if (now == (time_t) -1) { dprintf (D_ALWAYS, "Housekeeper: Error in reading system time --- aborting\n"); return; } dprintf (D_ALWAYS, "Housekeeper: Ready to clean old ads\n"); dprintf (D_ALWAYS, "\tCleaning StartdAds ...\n"); cleanHashTable (StartdAds, now, makeStartdAdHashKey); dprintf (D_ALWAYS, "\tCleaning StartdPrivateAds ...\n"); cleanHashTable (StartdPrivateAds, now, makeStartdAdHashKey); dprintf (D_ALWAYS, "\tCleaning ScheddAds ...\n"); cleanHashTable (ScheddAds, now, makeScheddAdHashKey); dprintf (D_ALWAYS, "\tCleaning SubmittorAds ...\n"); cleanHashTable (SubmittorAds, now, makeScheddAdHashKey); dprintf (D_ALWAYS, "\tCleaning LicenseAds ...\n"); cleanHashTable (LicenseAds, now, makeLicenseAdHashKey); dprintf (D_ALWAYS, "\tCleaning MasterAds ...\n"); cleanHashTable (MasterAds, now, makeMasterAdHashKey); dprintf (D_ALWAYS, "\tCleaning CkptServerAds ...\n"); cleanHashTable (CkptServerAds, now, makeCkptSrvrAdHashKey); dprintf (D_ALWAYS, "\tCleaning CollectorAds ...\n"); cleanHashTable (CollectorAds, now, makeCollectorAdHashKey); dprintf (D_ALWAYS, "\tCleaning StorageAds ...\n"); cleanHashTable (StorageAds, now, makeStorageAdHashKey); dprintf (D_ALWAYS, "\tCleaning AccountingAds ...\n"); cleanHashTable (AccountingAds, now, makeAccountingAdHashKey); dprintf (D_ALWAYS, "\tCleaning NegotiatorAds ...\n"); cleanHashTable (NegotiatorAds, now, makeNegotiatorAdHashKey); dprintf (D_ALWAYS, "\tCleaning HadAds ...\n"); cleanHashTable (HadAds, now, makeHadAdHashKey); dprintf (D_ALWAYS, "\tCleaning GridAds ...\n"); cleanHashTable (GridAds, now, makeGridAdHashKey); dprintf (D_ALWAYS, "\tCleaning Generic Ads ...\n"); CollectorHashTable *cht; GenericAds.startIterations(); while (GenericAds.iterate(cht)) { cleanHashTable (*cht, now, makeGenericAdHashKey); } // cron manager event_mgr(); dprintf (D_ALWAYS, "Housekeeper: Done cleaning\n"); }
void SelectFormat::applyPattern(const UnicodeString& newPattern, UErrorCode& status) { if (U_FAILURE(status)) { return; } pattern = newPattern; enum State{ startState, keywordState, pastKeywordState, phraseState}; //Initialization UnicodeString keyword ; UnicodeString phrase ; UnicodeString* ptrPhrase ; int32_t braceCount = 0; if (parsedValuesHash == NULL) { initHashTable(status); if (U_FAILURE(status)) { return; } } parsedValuesHash->removeAll(); parsedValuesHash->setValueDeleter(uhash_deleteUnicodeString); //Process the state machine State state = startState; for (int32_t i = 0; i < pattern.length(); ++i) { //Get the character and check its type UChar ch = pattern.charAt(i); CharacterClass type = classifyCharacter(ch); //Allow any character in phrase but nowhere else if ( type == tOther ) { if ( state == phraseState ){ phrase += ch; continue; }else { status = U_PATTERN_SYNTAX_ERROR; cleanHashTable(); return; } } //Process the state machine switch (state) { //At the start of pattern case startState: switch (type) { case tSpace: break; case tStartKeyword: state = keywordState; keyword += ch; break; //If anything else is encountered, it's a syntax error default: status = U_PATTERN_SYNTAX_ERROR; cleanHashTable(); return; }//end of switch(type) break; //Handle the keyword state case keywordState: switch (type) { case tSpace: state = pastKeywordState; break; case tStartKeyword: case tContinueKeyword: keyword += ch; break; case tLeftBrace: state = phraseState; break; //If anything else is encountered, it's a syntax error default: status = U_PATTERN_SYNTAX_ERROR; cleanHashTable(); return; }//end of switch(type) break; //Handle the pastkeyword state case pastKeywordState: switch (type) { case tSpace: break; case tLeftBrace: state = phraseState; break; //If anything else is encountered, it's a syntax error default: status = U_PATTERN_SYNTAX_ERROR; cleanHashTable(); return; }//end of switch(type) break; //Handle the phrase state case phraseState: switch (type) { case tLeftBrace: braceCount++; phrase += ch; break; case tRightBrace: //Matching keyword, phrase pair found if (braceCount == 0){ //Check validity of keyword if (parsedValuesHash->get(keyword) != NULL) { status = U_DUPLICATE_KEYWORD; cleanHashTable(); return; } if (keyword.length() == 0) { status = U_PATTERN_SYNTAX_ERROR; cleanHashTable(); return; } //Store the keyword, phrase pair in hashTable ptrPhrase = new UnicodeString(phrase); parsedValuesHash->put( keyword, ptrPhrase, status); //Reinitialize keyword.remove(); phrase.remove(); ptrPhrase = NULL; state = startState; } if (braceCount > 0){ braceCount-- ; phrase += ch; } break; default: phrase += ch; }//end of switch(type) break; //Handle the default case of switch(state) default: status = U_PATTERN_SYNTAX_ERROR; cleanHashTable(); return; }//end of switch(state) } //Check if the state machine is back to startState if ( state != startState){ status = U_PATTERN_SYNTAX_ERROR; cleanHashTable(); return; } //Check if "other" keyword is present if ( !checkSufficientDefinition() ) { status = U_DEFAULT_KEYWORD_MISSING; cleanHashTable(); } return; }
SelectFormat::~SelectFormat() { cleanHashTable(); }