Exemplo n.º 1
0
	size_t pick(const hashT &target, NodeListT &dest, size_t limit)
	{
		//stopwatch sw("pick");
		typedef std::map<hashT,T*> SortedNodePListT; 
		SortedNodePListT sorted_list;

		Lock();
		{
			typename NodeListT::iterator it = InternalList.begin();
			for ( ; it != InternalList.end(); it++) 
			{
				hashT _xor;
				hash_xor(_xor, target, it->id);
				sorted_list.insert(typename SortedNodePListT::value_type(_xor, &(*it)));
			}
			size_t i = 0;
			typename SortedNodePListT::iterator sit = sorted_list.begin();
			for ( ; sit != sorted_list.end() && i < limit; sit++, i++) {
				dest.push_back(*(sit->second));
			}
		}
        	Unlock();

		return (dest.size());
	};
void SvCreator::attachOrphanedNodesToRoot(NodeListT& nodes, NodeT& root)
{
  for (NodeListT::Iterator node = nodes.begin(); node != nodes.end(); ++node) {
    if (node->parent.isEmpty()) {
      node->parent = root.id;
      if (! root.child_nodes.isEmpty())
        root.child_nodes.append(ngrt4n::CHILD_Q_SEP);
      root.child_nodes.append(node->id);
    }
  }
}
Exemplo n.º 3
0
	void remove(const T &node)
	{
		typename NodeListT::iterator it;
        	Lock();
        	{
			it = std::find(InternalList.begin(), InternalList.end(), node);

			if (it != InternalList.end())
				InternalList.erase(it);
		}
		Unlock();
	};
Exemplo n.º 4
0
	bool get_front(T &node)
	{
		bool ret = false;
		Lock();
		if (!InternalList.empty()) 
		{
			node = InternalList.front();
			ret = true;
		}
		Unlock();
		return ret;
	};
Exemplo n.º 5
0
	bool pop_front(void)
	{
		bool ret = false;
		Lock();
		if (!InternalList.empty()) 
		{
			InternalList.pop_front();
			ret = true;
		}
		Unlock();
		return (ret);
	};
Exemplo n.º 6
0
	size_t count(void)
	{
        	Lock();
        	size_t ret = InternalList.size();
        	Unlock();
        	return (ret);
	};
Exemplo n.º 7
0
	size_t get_nodes(NodeListT &out)
	    {
		Lock();
		out = InternalList;
		Unlock();
		return (out.size());
	    };
int SvCreator::extractNagiosBPIGroupMembers(const QString& parentServiceId,
                                            const QString& sourceId,
                                            const QString& bpiGroupMembersChain,
                                            NodeListT& bpnodes,
                                            NodeListT& cnodes,
                                            QString& childNodesChain,
                                            bool& hasCluster)
{
  int childCount = 0;
  hasCluster = false;
  QStringList members = bpiGroupMembersChain.split(",");
  if (! members.isEmpty()) {

    Q_FOREACH(const QString& member, members) {

      if (member.isEmpty()) continue;

      bool isClusterMember = member.endsWith(";&");
      bool isEssentialMember = member.endsWith(";|");
      bool isGroupMember = member.startsWith("$");
      int start = isGroupMember ? 1 : 0;
      int count = (isClusterMember || isEssentialMember) ? member.size() - (start + 2) : member.size() - start;
      if (isClusterMember) hasCluster = true;

      QString memberId = member.mid(start, count);
      QString currentChildNodeId = "";

      if (isGroupMember) {
        NodeListT::Iterator memberNode = bpnodes.find(memberId);
        if (memberNode == bpnodes.end()) {
          memberNode = bpnodes.insert(memberId, createNode(memberId, memberId, parentServiceId));
        } else {
          memberNode->parent = parentServiceId;
        }
        memberNode->weight = isEssentialMember ? ngrt4n::WEIGHT_MAX: ngrt4n::WEIGHT_UNIT;
        currentChildNodeId = memberId.trimmed();
      } else {
        QStringList fields = memberId.split(";");
        if (fields.size() == 2) {
          currentChildNodeId = ngrt4n::genNodeId();
          QString generatedNodeName = QString("%1 on %2").arg(fields[1], fields[0]);
          NodeT cnode = createNode(currentChildNodeId, generatedNodeName, parentServiceId);
          cnode.type = NodeType::ITService;
          cnode.child_nodes = QString("%1:%2/%3").arg(sourceId, fields[0].trimmed(), fields[1].trimmed());
          cnode.weight = isEssentialMember ? ngrt4n::WEIGHT_MAX: ngrt4n::WEIGHT_UNIT;
          cnodes.insert(cnode.id, cnode);
        } else {
          showStatusMsg(tr("Bad service entry %1").arg(memberId), true);
          childCount = -1;
          break;
        }
      }

      if (childNodesChain.isEmpty()) {
        childNodesChain = currentChildNodeId;
      } else {
        childNodesChain += QString::fromStdString(ngrt4n::CHILD_SEP) + currentChildNodeId;
      }
      ++childCount;
    }
  }
Exemplo n.º 9
0
	void clear(void)
	{
		Lock();
		InternalList.clear();
		Unlock();
	};
Exemplo n.º 10
0
	bool push(const T &node)
	{
		if (!node.valid())
			return false;

		bool proceeded = false;
		Lock();
		{
			typename NodeListT::iterator it;
			it = std::find(InternalList.begin(), InternalList.end(), node);

			if (it != InternalList.end()) 
			{
				//既存なら最後尾へ
				T mnode(*it);
				InternalList.erase(it);

				mnode.marge(node);
				mnode.lastlink = time(NULL);
				InternalList.push_back(mnode);
				proceeded = true;
			}
			else if (InternalList.size() < Capacity) 
			{
				//リストに余裕があるなら最後尾に追加
				T newnode(node);
				newnode.lastlink = time(NULL);
                		InternalList.push_back(newnode);
                		proceeded = true;
            		}
#if !USEPING
			else 
			{
				pop_front();
				T newnode(node);
				newnode.lastlink = time(NULL);
				InternalList.push_back(newnode);
                		proceeded = true;
			}
#endif
		}
		Unlock();
		
#if USEPING
		if (proceeded)
		    return true;
		
		//リストの一番上のノード=最古ノードの生存確認
		T head;
		get_front(head);
			bool alive = ping(head);
		
		if (alive) {
		    //最古ノードが生きている:最古ノードを最後尾へ
		    //※対象ノードは追加しない
		    pop_front();
				head.lastlink = time(NULL);
		    Lock();
		    InternalList.push_back(head);
		    Unlock();
		}
		else 
		{
		    //最古ノードが死んでいる:対象ノードを最後尾に追加
		    pop_front();
			T newnode(node);
				newnode.lastlink = time(NULL);
		    Lock();
	    InternalList.push_back(newnode);
	    Unlock();
	}
#endif
	return true;
	};