⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gloadbalancer.cpp

📁 GiPS是一个面向数据密集型应用的分布式文件系统
💻 CPP
字号:
#include "GLoadBalancer.h"
#include <algorithm>

using namespace std;
using namespace Cluster;
using namespace ClientMaster;

bool
balanceCompare(const PClerkState clerkA, const PClerkState clerkB)
{
	return clerkA->blockNum < clerkB->blockNum;
}

GLoadBalancer::GLoadBalancer(LoadTable* loadTable) : m_loadTable(loadTable)
{
}

desIPList*
GLoadBalancer::chooseClerk(int num)
{
	desIPList* candidates = new desIPList();
	sort(m_loadTable->begin(), m_loadTable->end(), balanceCompare);

	for (LoadTable::iterator it = m_loadTable->begin(); it != m_loadTable->end(); it++)
	{
		candidates->push_back((*it)->clerkIP);
		if (candidates->size() == num)
			break;
	}

	return candidates;
}

desIPList*
GLoadBalancer::chooseClerk(int num, desIPList ipList)
{
	cout << "Load Table size: " << m_loadTable->size() << endl;
	desIPList* candidates = new desIPList();
	sort(m_loadTable->begin(), m_loadTable->end(), balanceCompare);

	for (LoadTable::iterator it = m_loadTable->begin(); it != m_loadTable->end(); it++)
	{
		string ip = (*it)->clerkIP;
		bool flag = true;
		for (desIPList::iterator iter = ipList.begin(); iter != ipList.end(); iter++)
		{
			if (!iter->compare(ip))
			{
				flag = false;
				break;
			}
		}
		
		if (flag)
			candidates->push_back(ip);

		if (candidates->size() == num)
			break;
	}

	return candidates;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -