Set<AgentInfo> selectAgent(User user, Set<AgentInfo> allFreeAgents, int agentCount) {
		Set<AgentInfo> recentlyUsedAgents = hazelcastService.getOrDefault(DIST_MAP_NAME_RECENTLY_USED_AGENTS, user.getUserId(), emptySet());

		Comparator<AgentInfo> recentlyUsedPriorityComparator = (agent1, agent2) -> {
			if (recentlyUsedAgents.contains(agent1)) {
				return -1;
			}
			if (recentlyUsedAgents.contains(agent2)) {
				return 1;
			}
			return 0;
		};

		Stream<AgentInfo> freeDedicatedAgentStream = allFreeAgents
			.stream()
			.filter(agentInfo -> isDedicatedAgent(agentInfo, user.getUserId()))
			.sorted(recentlyUsedPriorityComparator);

		Stream<AgentInfo> freeAgentStream = allFreeAgents
			.stream()
			.filter(this::isCommonAgent)
			.sorted(recentlyUsedPriorityComparator);

		return concat(freeDedicatedAgentStream, freeAgentStream)
			.limit(agentCount)
			.collect(toSet());
	}
Select agent. This method return agent set which is belong to the given user first and then share agent set.

Priority of agent selection.
1. dedicated agent of recently used.
2. dedicated agent.
3. public agent of recently used.
4. public agent.

@param user          user
@param allFreeAgents available agents
@param agentCount    number of agents
@return selected agents.
ngrinder-controller/src/main/java/org/ngrinder/agent/service/AgentService.java