private boolean parseCounter(CounterGroupKey groupKey, int counterIndex, List<CounterKey> counters, Properties prop) { final String counterKeyBase = "counter.group" + groupKey.getIndex() + ".counter" + counterIndex; final String counterNameKey = counterKeyBase + ".names"; final String counterNamesString = prop.getProperty(counterNameKey); if (counterNamesString == null) { return false; } final String[] names = counterNamesString.split(","); final List<String> counterNames = new ArrayList<String>(); for (String name : names) { counterNames.add(name.trim()); } final String counterDescriptionKey = counterKeyBase + ".description"; final String counterDescription = prop.getProperty(counterDescriptionKey); CounterKey counter = new CounterKeyImpl(counterIndex, counterNames, counterDescription, groupKey); counters.add(counter); return true; }
public CounterGroupKey getCounterGroupByName(String groupName) { for (CounterGroupKey groupKey : groupKeys) { if (groupKey.getName().equalsIgnoreCase(groupName)) { return groupKey; } } return null; }
private int serializeGroup(byte[] buffer, int currentPos, String groupName, Map<String, Long> counterMap) throws JobCounterException { int pos = currentPos; final CounterGroupKey groupKey = getCounterGroup(groupName); if (groupKey == null) { throw new JobCounterException("Group name " + groupName + " is not defined"); } Bytes.putInt(buffer, pos, groupKey.getIndex()); pos += 4; int totalCounterNumberPos = pos; pos += 4; int totalCounters = 0; for (Map.Entry<String, Long> entry : counterMap.entrySet()) { final String counterName = entry.getKey(); final CounterKey counterKey = groupKey.getCounterKeyByName(counterName); if (counterKey == null) { continue; } final Long counterValue = entry.getValue(); Bytes.putInt(buffer, pos, counterKey.getIndex()); pos += 4; Bytes.putLong(buffer, pos, counterValue); pos += 8; ++totalCounters; } Bytes.putInt(buffer, totalCounterNumberPos, totalCounters); return pos; }
groupMap.put(groupKey.getName(), counterMap); for (int j = 0; j < totalCounters; ++j) { final int counterIndex = Bytes.toInt(bytes, pos); final long value = Bytes.toLong(bytes, pos); pos += 8; final CounterKey counterKey = groupKey.getCounterKeyByID(counterIndex); if (counterKey == null) { continue;