@Override
	public Map<String, MutableInt> getAvailableAgentCountMap(String userId) {
		Map<String, RegionInfo> regions = regionService.getAll();
		Map<String, MutableInt> availShareAgents = newHashMap();
		Map<String, MutableInt> availUserOwnAgent = newHashMap();

		regions.forEach((region, regionInfo) -> {
			regionInfo.getSubregion().forEach(subregion -> {
				availShareAgents.put(region + "." + subregion, new MutableInt(0));
				availUserOwnAgent.put(region + "." + subregion, new MutableInt(0));
			});
			availShareAgents.put(region, new MutableInt(0));
			availUserOwnAgent.put(region, new MutableInt(0));
		});

		for (AgentInfo agentInfo : getAllActive()) {
			// Skip all agents which are disapproved, inactive or
			// have no region prefix.
			if (!agentInfo.isApproved()) {
				continue;
			}

			String agentRegion = agentInfo.getRegion();
			String agentSubregion = agentInfo.getSubregion();

			if (isBlank(agentRegion) || !regions.containsKey(agentRegion)) {
				continue;
			}

			// It's my own agent
			String agentFullRegion = isEmpty(agentSubregion) ? agentRegion : agentRegion + "." + agentSubregion;
			if (isDedicatedAgent(agentInfo, userId)) {
				incrementAgentCount(availUserOwnAgent, agentFullRegion);
			} else if (isCommonAgent(agentInfo)) {
				incrementAgentCount(availShareAgents, agentFullRegion);
			}
		}

		int maxAgentSizePerConsole = agentManager.getMaxAgentSizePerConsole();

		regions.forEach((region, regionInfo) -> {
			regionInfo.getSubregion().forEach(subregion -> {
				String agentFullRegion = region + "." + subregion;
				MutableInt mutableInt = availShareAgents.get(agentFullRegion);
				int shareAgentCount = mutableInt.intValue();
				mutableInt.setValue(Math.min(shareAgentCount, maxAgentSizePerConsole));
				mutableInt.add(availUserOwnAgent.get(agentFullRegion));
			});
			MutableInt mutableInt = availShareAgents.get(region);
			int shareAgentCount = mutableInt.intValue();
			mutableInt.setValue(Math.min(shareAgentCount, maxAgentSizePerConsole));
			mutableInt.add(availUserOwnAgent.get(region));
		});

		return availShareAgents;
	}
Get the available agent count map in all regions of the user, including
the free agents and user specified agents.

@param userId current user id
@return user available agent count map
ngrinder-controller/src/main/java/org/ngrinder/agent/service/AgentService.java