MojErr ActivityManager::AddFocus(boost::shared_ptr<Activity> source,
	boost::shared_ptr<Activity> target)
{
	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("Add focus from [Activity %llu] to [Activity %llu]"),
		source->GetId(), target->GetId());

	if (!source->IsFocused()) {
		MojLogWarning(s_log, _T("Can't add focus from [Activity %llu] to "
			"[Activity %llu] as source is not focused"), source->GetId(),
			target->GetId());
		return MojErrInvalidArg;
	}

	if (target->IsFocused()) {
		MojLogWarning(s_log, _T("Target is already focused adding focus from "
			"[Activity %llu] to [Activity %llu]"), source->GetId(),
			target->GetId());
		return MojErrNone;
	}

	target->SetFocus(true);
	m_resourceManager->UpdateAssociations(target);
	m_focusedActivities.push_back(*target);

	return MojErrNone;
}
Esempio n. 2
0
// Expire an object from the cache.  This will cause the object to
// be deleted from the cache.  This will return false if the
// requested item is currently pinned in the cache by a subscription
// and the object will be deleted once the subscription expires.
bool
CFileCacheSet::ExpireCacheObject(const cachedObjectId_t objId) {

  MojLogTrace(s_log);

  bool retVal = true;
  const std::string typeName(GetTypeForObjectId(objId));
  if (!typeName.empty()) {
    CFileCache* fileCache = GetFileCacheForType(typeName);
    if (fileCache != NULL) {
      RemoveObjectFromIdMap(objId);
      retVal = fileCache->Expire(objId);
      if (!retVal) {
	MojLogInfo(s_log,
		   _T("ExpireCacheObject: expire deferred, object '%llu' in use"),
		   objId);
      }
    } else {
      MojLogWarning(s_log,
		    _T("ExpireCacheObject: No cache of type '%s' found for id '%llu'."),
		    typeName.c_str(), objId);
    } 
  } else {
    MojLogWarning(s_log,
		  _T("ExpireCacheObject: Cache type not found for id '%llu'."),
		  objId);
  }

  return retVal;
}
Esempio n. 3
0
// Returns the filename of a cachedObject
const std::string
CFileCacheSet::CachedObjectFilename(const cachedObjectId_t objId) {

  MojLogTrace(s_log);

  std::string retVal;
  const std::string typeName(GetTypeForObjectId(objId));
  if (!typeName.empty()) {
    CFileCache* fileCache = GetFileCacheForType(typeName);
    if (fileCache != NULL) {
      retVal = fileCache->GetObjectFilename(objId);
      MojLogInfo(s_log,
		 _T("CachedObjectFilename: Object '%llu' has name '%s'."),
		 objId, retVal.c_str());
    } else {
      MojLogWarning(s_log,
		    _T("CachedObjectFilename: No cache of type '%s' found for id '%llu'."),
		    typeName.c_str(), objId);
    }
  } else {
    MojLogWarning(s_log,
		  _T("CachedObjectFilename: Cache type not found for id '%llu'."),
		  objId);
  }

  return retVal;

}
Esempio n. 4
0
// Pin an object in the cache by allowing a client to subscribe to
// the object.  This will guarantee the object will not be removed
// from the cache while the subscription is active.  Returns the
// file path associated with the objectId.
const std::string
CFileCacheSet::SubscribeCacheObject(std::string& msgText, const cachedObjectId_t objId) {

  MojLogTrace(s_log);

  std::string retVal("");
  const std::string typeName(GetTypeForObjectId(objId));
  if (!typeName.empty()) {
    CFileCache* fileCache = GetFileCacheForType(typeName);
    if (fileCache != NULL) {
      retVal = fileCache->Subscribe(msgText, objId);
      if (msgText.empty()) {
	MojLogInfo(s_log,
		   _T("SubscribeCacheObject: Object '%llu' subscribed."), objId);
      }
    } else {
      MojLogWarning(s_log,
		   _T("SubscribeCacheObject: No cache of type '%s' found for id '%llu'."),
		    typeName.c_str(), objId);
    }
  } else {
    MojLogWarning(s_log,
		  _T("SubscribeCacheObject: Cache type not found for id '%llu'."),
		  objId);
  }

  return retVal;
}
Esempio n. 5
0
// Gets the current status of a specied cache type.  Returns the
// amount of space and the number of cached objects used by the
// items in that cache type.
bool
CFileCacheSet::GetCacheTypeStatus(const std::string& typeName,
				  cacheSize_t* size,
				  paramValue_t* numCacheObjects) {

  MojLogTrace(s_log);

  bool retVal = false;
  cacheSize_t cacheSize = 0;
  paramValue_t numObjects = 0;

  CFileCache* fileCache = GetFileCacheForType(typeName);
  if (fileCache != NULL) {
    fileCache->GetCacheStatus(&cacheSize, &numObjects);
    if (size != NULL) {
      *size = cacheSize;
    }
    if (numCacheObjects != NULL) {
      *numCacheObjects = numObjects;
    }
    
    MojLogInfo(s_log, _T("GetCacheTypeStatus: size = '%d', numobjs = '%d'"),
	       cacheSize, numObjects);
    retVal = true;
  } else {
    MojLogWarning(s_log,
		  _T("GetCacheTypeStatus: No cache of type '%s' found."),
		  typeName.c_str());
  }

  return retVal;
}
MojErr SmtpAccountDisableCommand::DeleteAccountWatchResponse(MojObject& response, MojErr err)
{
	MojLogInfo(m_log, "SmtpAccountDisable replying");

	try {
		if(err) {
			if(err == ENOENT) {
				MojLogWarning(m_log, "account watch activity doesn't exist");
			} else {
				ResponseToException(response, err);
			}
		}

		m_msg->replySuccess();
		Complete();
	} catch (const std::exception& e) {
		m_msg->replyError(err, e.what());
		Failure(e);
	} catch (...) {
		MojString error;
		error.format("uncaught exception in %s", __PRETTY_FUNCTION__);
		m_msg->replyError(MojErrInternal, error.data());
		Failure(MailException("unknown exception in cancelling activities response", __FILE__, __LINE__));
	}
	return MojErrNone;
}
MojErr SmtpAccountDisableCommand::DeleteOutboxWatchResponse(MojObject& response, MojErr err)
{
	MojLogInfo(m_log, "SmtpAccountDisable removing outbox watch");

	try {
		if(err) {
			if(err == ENOENT) {
				MojLogWarning(m_log, "outbox watch activity doesn't exist");
			} else {
				ResponseToException(response, err);
			}
		}

		MojObject payload;
		payload.put("activityName", m_accountWatchActivityName);

		m_client.SendRequest(m_deleteAccountWatchResponseSlot, "com.palm.activitymanager", "cancel", payload);
	} catch (const std::exception& e) {
		m_msg->replyError(err, e.what());
		Failure(e);
	} catch (...) {
		MojString error;
		error.format("uncaught exception in %s", __PRETTY_FUNCTION__);
		m_msg->replyError(MojErrInternal, error.data());
		Failure(MailException("unknown exception in cancelling activities response", __FILE__, __LINE__));
	}

	return MojErrNone;
}
Esempio n. 8
0
MojErr MojDbKind::preUpdate(MojObject* newObj, const MojObject* oldObj, MojDbReq& req)
{
	// update supers
	for (KindVec::ConstIterator i = m_supers.begin();
		 i != m_supers.end(); ++i) {
		MojErr err = (*i)->preUpdate(newObj, oldObj, req);
		MojErrCheck(err);
	}
	// process new obj
	if (newObj) {
		// update revSets
		for (RevSetVec::ConstIterator i = m_revSets.begin();
			 i != m_revSets.end(); ++i) {
			MojErr err = (*i)->update(newObj, oldObj);
			MojErrCheck(err);
		}
		// validate schemas
		MojSchema::Result res;
		MojErr err = m_schema.validate(*newObj, res);
		MojErrCheck(err);
		if (!res.valid()) {
			//MojErrThrowMsg(MojErrSchemaValidation, _T("schema validation failed for kind '%s': %s"), m_id.data(), res.msg().data());
			MojLogWarning(s_log, _T("schema validation failed for kind '%s': %s"), m_id.data(), res.msg().data());
		}
	}
	return MojErrNone;
}
void MojoExclusiveTrigger::Arm(boost::shared_ptr<Activity> activity)
{
    MojLogTrace(s_log);

    if (activity != m_activity.lock()) {
        MojLogWarning(s_log, _T("[Activity %llu] Attemting to arm trigger "
                                "owned by Activity %llu"), activity->GetId(),
                      m_activity.lock()->GetId());
        throw std::runtime_error("Can't arm trigger for a different "
                                 "Activity");
    }

    if (!m_subscription) {
        MojLogInfo(s_log, _T("[Activity %llu] Can't arm trigger that has no "
                             "subscription"), m_activity.lock()->GetId());
        throw std::runtime_error("Can't arm trigger that has no subscription");
    }

    m_triggered = false;

    MojLogInfo(s_log, _T("[Activity %llu] Arming Trigger on \"%s\""),
               m_activity.lock()->GetId(), m_subscription->GetURL().GetURL().data());

    if (!m_subscription->IsSubscribed()) {
        m_subscription->Subscribe();
    }
}
Esempio n. 10
0
// This defines a new cache type and will cause a new CFileCache
// object to be instantiated.  The typeName must be unique.  The sum
// of the cache loWatermarks must be less than the total cache space
// available or the cache type creation will fail.
bool
CFileCacheSet::DefineType(std::string& msgText, const std::string& typeName,
                          CCacheParamValues* params, bool dirType) {

  MojLogTrace(s_log);

  msgText = "DefineType: ";
  bool retVal = false;
  CFileCache* fileCache = GetFileCacheForType(typeName);
  if (fileCache == NULL) {
    CFileCache* newType = new CFileCache(this, typeName);
    if (newType != NULL) {
      if (newType->Configure(params, dirType)) {
        m_cacheSet.insert(std::map<const std::string,
			  CFileCache*>::value_type(typeName, newType));
        retVal = true;
        msgText += "Created type '" + typeName + "'.";
        MojLogInfo(s_log, _T("%s"), msgText.c_str());
      } else {
        delete newType;
        msgText += "Failed to configure '" + typeName + "'.";
        MojLogError(s_log, _T("%s"), msgText.c_str());
      }
    } else {
      msgText += "Failed to allocate '" + typeName + "'.";
      MojLogCritical(s_log, _T("%s"),msgText.c_str());
    }
  } else {
    msgText += "Type '" + typeName + "'" + " already exists.";
    MojLogWarning(s_log, _T("%s"), msgText.c_str());
  }

  return retVal;
}
MojErr ActivityManager::FocusActivity(boost::shared_ptr<Activity> act)
{
	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("Focus [Activity %llu]"), act->GetId());

	if (act->IsFocused()) {
		MojLogWarning(s_log, _T("[Activity %llu] is already focused"),
			act->GetId());
		return MojErrNone;
	}

	act->SetFocus(true);
	m_resourceManager->UpdateAssociations(act);

	ActivityFocusedList oldFocused;
	oldFocused.swap(m_focusedActivities);

	m_focusedActivities.push_back(*act);

	/* Remove focus from all Activities that had focus before. */
	while (!oldFocused.empty()) {
		Activity& focusedActivity = oldFocused.front();
		MojLogInfo(s_log, _T("Removing focus from previously focused "
			"[Activity %llu]"), focusedActivity.GetId());
		focusedActivity.SetFocus(false);
		m_resourceManager->UpdateAssociations(
			focusedActivity.shared_from_this());
		oldFocused.pop_front();
	}

	return MojErrNone;
}
bool ControlGroup::WriteControlFile(const std::string& controlFile,
                                    const char *buf, size_t count, std::list<int>::iterator current)
{
    int fd = open(controlFile.c_str(), O_WRONLY);
    if (fd < 0) {
        MojLogError(s_log, _T("Failed to open control file `%s': %s"),
                    controlFile.c_str(), strerror(errno));
        return false;
    }

    ssize_t ret = write(fd, buf, count);
    if (ret < 0) {

        // If the process does not exist, cgroups will return ESRCH (no such process)
        if(errno == ESRCH) {
            MojLogWarning(s_log, _T("Process '%s' to be written to file '%s' doesn't exist"), buf, controlFile.c_str());
            close(fd);
            m_processIds.erase(current);
            return true;
        }
        MojLogError(s_log, _T("Failed to write control file `%s': %s"),
                    controlFile.c_str(), strerror(errno));
        close(fd);
        return false;
    } else if ((size_t)ret != count) {
        MojLogError(s_log, _T("Short write updating control file `%s'"),
                    controlFile.c_str());
        close(fd);
        return false;
    }

    close(fd);
    return true;
}
Esempio n. 13
0
MojErr MojDbSearchCursor::loadObjects(const ObjectSet& ids)
{
    MojInt32 warns = 0;
    for (ObjectSet::ConstIterator i = ids.begin(); i != ids.end(); ++i) {
        // get item by id
        MojObject obj;
        MojDbStorageItem* item = NULL;
        bool found = false;
        MojErr err = m_storageQuery->getById(*i, item, found);
        if (err == MojErrInternalIndexOnFind) {
            warns++;
            continue;
        }

        MojErrCheck(err);
        if (found) {
            // get object from item
            err = item->toObject(obj, *m_kindEngine);
            MojErrCheck(err);
            // filter results
            if (m_queryFilter.get() && !m_queryFilter->test(obj))
                continue;
            // create object item
            MojRefCountedPtr<MojDbObjectItem> item(new MojDbObjectItem(obj));
            MojAllocCheck(item.get());
            // add to vec
            err = m_items.push(item);
            MojErrCheck(err);
        }
    }
    if (warns > 0)
        MojLogWarning(MojDb::s_log, _T("Search warnings: %d \n"), warns);
    return MojErrNone;
}
Esempio n. 14
0
MojErr MojDbIndex::addWatch(const MojDbQueryPlan& plan, MojDbCursor& cursor, MojDbWatcher* watcher, MojDbReq& req)
{
	MojAssert(watcher);
	MojLogTrace(s_log);

	// TODO: use interval tree instead of vector for watches
	MojThreadWriteGuard guard(m_lock);
	MojErr err = m_watcherVec.push(watcher);
	MojErrCheck(err);
	// update count map
	watcher->domain(req.domain());
	WatcherMap::Iterator iter;
	err = m_watcherMap.find(req.domain(), iter);
	MojErrCheck(err);
	if (iter == m_watcherMap.end()) {
		err = m_watcherMap.put(req.domain(), 1);
		MojErrCheck(err);
	} else {
		iter.value() += 1;
		if (iter.value() > WatchWarningThreshold) {
			MojLogWarning(s_log, _T("db:'%s' has %zd watches open on index '%s - %s'"),
					req.domain().data(), iter.value(), m_kind->id().data(), m_name.data());
		}
	}
	MojLogInfo(s_log, _T("DbIndex_addWatch - '%s' on index '%s - %s'"),
					req.domain().data(),  m_kind->id().data(), m_name.data());
	// drop lock before acquiring watcher mutex in init
	guard.unlock();
	watcher->init(this, plan.ranges(), plan.desc(), false);

	return MojErrNone;
}
void ActivityManager::InformActivityReady(boost::shared_ptr<Activity> act)
{
	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("[Activity %llu] Now ready to run"), act->GetId());

	if (act->m_runQueueItem.is_linked()) {
		act->m_runQueueItem.unlink();
	} else {
		MojLogWarning(s_log, _T("[Activity %llu] not found on any run queue "
			"when moving to ready state"), act->GetId());
	}

	if (act->IsImmediate()) {
		m_runQueue[RunQueueImmediate].push_back(*act);
		RunActivity(*act);
	} else {
		if (act->IsUserInitiated()) {
			m_runQueue[RunQueueReadyInteractive].push_back(*act);
		} else {
			m_runQueue[RunQueueReady].push_back(*act);
		}

		CheckReadyQueue();
	}
}
void ActivityManager::EvictBackgroundActivity(
	boost::shared_ptr<Activity> act)
{
	MojLogTrace(s_log);
	MojLogNotice(s_log, _T("Attempting to evict [Activity %llu] from "
		"background queue"), act->GetId());

	ActivityRunQueue::iterator iter;

	for (iter = m_runQueue[RunQueueBackground].begin();
		iter != m_runQueue[RunQueueBackground].end(); ++iter) {
		if (&(*iter) == &(*act)) {
			break;
		}
	}

	if (iter != m_runQueue[RunQueueBackground].end()) {
		act->m_runQueueItem.unlink();
		m_runQueue[RunQueueLongBackground].push_back(*act);
	} else {
		MojLogWarning(s_log, _T("[Activity %llu] Not found on background "
			"queue"), act->GetId());
		throw std::runtime_error("Activity not on background queue");
	}

	CheckReadyQueue();
}
Esempio n. 17
0
MojErr MojDbKind::deny(MojDbReq& req)
{
	MojLogWarning(s_log, _T("db: permission denied for caller '%s' on kind '%s'"), req.domain().data(), m_id.data());
	if (m_kindEngine->permissionEngine()->enabled()) {
		// don't leak any information in an error message
		MojErrThrow(MojErrDbPermissionDenied);
	}
	return MojErrNone;
}
Esempio n. 18
0
// Deletes an existing cache type.  All objects cached in this type
// will be deleted.  The space used by the deleted cache (in KB) is
// returned.
cacheSize_t
CFileCacheSet::DeleteType(std::string& msgText,
			  const std::string& typeName) {

  MojLogTrace(s_log);

  msgText = "DeleteType: ";
  cacheSize_t retVal = -1;
  CFileCache* fileCache = GetFileCacheForType(typeName);
  if (fileCache != NULL) {
    if (fileCache->isCleanable()) {
      cacheSize_t size;
      paramValue_t numObjs;
      fileCache->GetCacheStatus(&size, &numObjs);
      retVal = size;

      // Go through and Expire any remaining cache items
      std::vector<std::pair<cachedObjectId_t, CCacheObject*> > curObjs;
      curObjs = fileCache->GetCachedObjects();
      while(!curObjs.empty()) {
	std::pair<cachedObjectId_t, CCacheObject*> curObj = curObjs.back();
	curObjs.pop_back();
	if (!ExpireCacheObject(curObj.first)) {
	  MojLogWarning(s_log,
			_T("DeleteType: object %llu is still subscribed."),
			curObj.first);
	}
      }

      m_cacheSet.erase(typeName);
      delete fileCache;
      msgText += "Deleted type '" + typeName + "'.";
      MojLogInfo(s_log, _T("%s"), msgText.c_str());
    } else {
      msgText += "Type '" + typeName + "' has subscribed objects.";
      MojLogWarning(s_log, _T("%s"), msgText.c_str());
    }
  } else {
    msgText += "Type '" + typeName + "' does not exist.";
    MojLogWarning(s_log, _T("%s"), msgText.c_str());
  }

  return retVal;
}
bool MojoExclusiveTrigger::IsTriggered(
    boost::shared_ptr<const Activity> activity) const
{
    if (m_activity.lock() != activity) {
        MojLogWarning(s_log, _T("[Activity %llu] Checking to see if a trigger "
                                "has fired it does not own"), activity->GetId());
        return false;
    }

    return m_triggered;
}
bool MojoExclusiveTrigger::IsArmed(
    boost::shared_ptr<const Activity> activity) const
{
    if (m_activity.lock() != activity) {
        MojLogWarning(s_log, _T("[Activity %llu] Checking to see if a trigger "
                                "is armed it does not own"), activity->GetId());
        return false;
    }

    return m_subscription->IsSubscribed();
}
void MasterRequirementManager::UnregisterRequirement(const std::string& name,
	boost::shared_ptr<RequirementManager> manager)
{
	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("Unregistering [Manager %s] from [Requirement %s]"),
		manager->GetName().c_str(), name.c_str());

	RequirementMap::iterator found = m_requirements.find(name);
	if (found == m_requirements.end()) {
		MojLogWarning(s_log, _T("No manager found for [Requirement %s] "
			"attempting to unregister [Manager %s]"), name.c_str(),
			manager->GetName().c_str());
	} else if (found->second != manager) {
		MojLogWarning(s_log, _T("[Manager %s] not currently registered for "
			"[Requirement %s], it is registered to [Manager %s]"),
			manager->GetName().c_str(), name.c_str(),
			found->second->GetName().c_str());
	} else {
		m_requirements.erase(found);
	}
}
Esempio n. 22
0
MojErr MojDb::merge(const MojDbQuery& query, const MojObject& props, MojUInt32& countOut, MojUInt32 flags, MojDbReqRef req)
{
	MojLogTrace(s_log);

	countOut = 0;
	MojErr err = beginReq(req);
	MojErrCheck(err);

	MojDbCursor cursor;
	err = findImpl(query, cursor, NULL, req, OpUpdate);
	MojErrCheck(err);
	MojAssert(cursor.txn());

	MojUInt32 count = 0;
	MojUInt32 warns = 0;
	bool found = false;
	MojObject prev;
	for (;;) {
		// get prev rev from cursor
		MojDbStorageItem* prevItem = NULL;
		err = cursor.get(prevItem, found);
		if (err == MojErrInternalIndexOnFind) {
			warns++;
			continue;
		}
		MojErrCheck(err);
		if (!found)
			break;
		err = prevItem->toObject(prev, m_kindEngine);
		MojErrCheck(err);
		// merge obj into prev
		MojObject merged;
		err = mergeInto(merged, props, prev);
		MojErrCheck(err);
		// and update the db
		const MojObject& id = prevItem->id();
		err = putObj(id, merged, &prev, prevItem, req, OpUpdate);
		MojErrCheck(err);
		++count;
	}
	if (warns > 0)
		MojLogWarning(s_log, _T("Merge index_warnings: %s; count: %d\n"), query.from().data(), warns);
	err = cursor.close();
	MojErrCheck(err);
	err = req->end();
	MojErrCheck(err);

	countOut = count;

	return MojErrNone;
}
void PowerdProxy::TriggerBatteryStatusResponse(MojServiceMessage *msg,
	const MojObject& response, MojErr err)
{
	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("Attempt to trigger battery status signal generated "
		"response: %s"), MojoObjectJson(response).c_str());

	m_triggerBatteryStatus.reset();

	if (err != MojErrNone) {
		MojLogWarning(s_log, _T("Failed to trigger battery status signal!"));
		return;
	}
}
MojErr ActivityManager::UnfocusActivity(boost::shared_ptr<Activity> act)
{
	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("Unfocus [Activity %llu]"), act->GetId());

	if (!act->IsFocused()) {
		MojLogWarning(s_log, _T("Can't remove focus from [Activity %llu], "
			"which is not focused"), act->GetId());
		return MojErrInvalidArg;
	}

	act->SetFocus(false);
	m_resourceManager->UpdateAssociations(act);

	if (act->m_focusedListItem.is_linked()) {
		act->m_focusedListItem.unlink();
	} else {
		MojLogWarning(s_log, _T("[Activity %llu] not on focus list while "
			"removing focus"), act->GetId());
	}

	return MojErrNone;
}
void SmtpSyncOutboxCommand::AttachAdoptedActivity(MojRefCountedPtr<Activity> activity, const MojString& activityId, const MojString& activityName)
{
	MojLogInfo(m_log, "Attaching adopted activity, incoming activityId=%s, name=%s. WatchActivityName=%s"
		, activityId.data(), activityName.data(), m_outboxWatchActivityName.data());

	if (activityName == m_outboxWatchActivityName) {
		if(m_outboxWatchActivity.get() && activity.get()) {
			MojLogWarning(m_log, "%s: outbox activity already attached; replacing activity %s with %s", __PRETTY_FUNCTION__, AsJsonString(m_outboxWatchActivity->GetActivityId()).c_str(), AsJsonString(activity->GetActivityId()).c_str());
		}

		m_outboxWatchActivity = activity;
	} else if (activityName == m_accountWatchActivityName) {
		if(m_accountWatchActivity.get() && activity.get()) {
			MojLogWarning(m_log, "%s: account watch activity already attached; replacing activity %s with %s", __PRETTY_FUNCTION__, AsJsonString(m_accountWatchActivity->GetActivityId()).c_str(), AsJsonString(activity->GetActivityId()).c_str());
		}

		m_accountWatchActivity = activity;
	} else {
		m_manualActivities.push_back( activity );
	}
	
	m_networkStatus->ParseActivity(activity);
}
Esempio n. 26
0
// Request to change the size of an object.  This is only valid
// while the initial writable subscription is in effect.  If there
// isn't sufficient space, the resize will return the original size
// of the object and that should be taken as a failure.  On success,
// the new size will be returned.
cacheSize_t
CFileCacheSet::Resize(const cachedObjectId_t objId, cacheSize_t newSize) {

  MojLogTrace(s_log);

  cacheSize_t retVal = CachedObjectSize(objId);
  const std::string typeName(GetTypeForObjectId(objId));
  if (!typeName.empty()) {
    CFileCache* fileCache = GetFileCacheForType(typeName);
    if (fileCache != NULL) {
      retVal = fileCache->Resize(objId, newSize);
    } else {
      MojLogWarning(s_log,
		    _T("Resize: No cache of type '%s' found for id '%llu'."),
		    typeName.c_str(), objId);
    }
  } else {
    MojLogWarning(s_log,
		  _T("Resize: Cache type not found for id '%llu'."), objId);
  }

  return retVal;
}
void ActivityManager::InformActivityNotReady(boost::shared_ptr<Activity> act)
{
	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("[Activity %llu] No longer ready to run"),
		act->GetId());

	if (act->m_runQueueItem.is_linked()) {
		act->m_runQueueItem.unlink();
	} else {
		MojLogWarning(s_log, _T("[Activity %llu] not found on any run "
			"queue when moving to not ready state"), act->GetId());
	}

	m_runQueue[RunQueueScheduled].push_back(*act);
}
Esempio n. 28
0
// This updates the access time without needing to subscribe, it's
// like using touch on an existing file
bool
CFileCacheSet::Touch(const cachedObjectId_t objId) {

  MojLogTrace(s_log);

  bool retVal = false;
  const std::string typeName(GetTypeForObjectId(objId));
  if (!typeName.empty()) {
    CFileCache* fileCache = GetFileCacheForType(typeName);
    if (fileCache != NULL) {
      retVal = fileCache->Touch(objId);
      MojLogInfo(s_log, _T("Touch: Object '%llu' touched."), objId);
    } else {
      MojLogWarning(s_log,
		    _T("Touch: No cache of type '%s' found for id '%llu'."),
		    typeName.c_str(), objId);
    }
  } else {
    MojLogWarning(s_log, _T("Touch: Cache type not found for id '%llu'."),
		  objId);
  }

  return retVal;
}
Esempio n. 29
0
// Remove the client subscription of an object.  This will remove
// the guarantee that the object will be kept in the cache.
void 
CFileCacheSet::UnSubscribeCacheObject(const std::string& typeName,
				      const cachedObjectId_t objId) {

  MojLogTrace(s_log);

  if (!typeName.empty()) {
    CFileCache* fileCache = GetFileCacheForType(typeName);
    if (fileCache != NULL) {
      fileCache->UnSubscribe(objId);
      MojLogInfo(s_log,
		 _T("UnSubscribeCacheObject: Object '%llu' unsubscribed."),
		 objId);
    } else {
      MojLogWarning(s_log,
		    _T("UnSubscribeCacheObject: No cache of type '%s' found for id '%llu'."),
		    typeName.c_str(), objId);
    }
  } else {
    MojLogWarning(s_log,
		  _T("UnSubscribeCacheObject: Cache type not found for id '%llu'."),
		  objId);
  }
}
Esempio n. 30
0
// Get the configuration values for a cache type.
CCacheParamValues
CFileCacheSet::DescribeType(const std::string& typeName) {

  MojLogTrace(s_log);

  CCacheParamValues params;
  CFileCache* fileCache = GetFileCacheForType(typeName);
  if (fileCache != NULL) {
    fileCache->Describe(params);
  } else {
    MojLogWarning(s_log, _T("DescribeType: type '%s' does not exists."),
		  typeName.c_str());
  }

  return params;
}