@Override public Counter addCounter(String name, String displayName, long value) { return realGroup.addCounter(name, displayName, value); }
@Override public Counter findCounter(String counterName, String displayName) { return realGroup.findCounter(counterName, displayName); }
@Override public String getDisplayName() { return realGroup.getDisplayName(); }
/** * Increments multiple counters by their amounts in another Counters * instance. * @param other the other Counters instance */ public synchronized void incrAllCounters(AbstractCounters<C, G> other) { for(G right : other) { String groupName = right.getName(); G left = (isFrameworkGroup(groupName) ? fgroups : groups).get(groupName); if (left == null) { left = addGroup(groupName, right.getDisplayName()); } left.incrAllCounters(right); } }
/** * Construct from another counters object. * @param <C1> type of the other counter * @param <G1> type of the other counter group * @param counters the counters object to copy * @param groupFactory the factory for new groups */ @InterfaceAudience.Private public <C1 extends Counter, G1 extends CounterGroupBase<C1>> AbstractCounters(AbstractCounters<C1, G1> counters, CounterGroupFactory<C, G> groupFactory) { this.groupFactory = groupFactory; for(G1 group: counters) { String name = group.getName(); G newGroup = groupFactory.newGroup(name, group.getDisplayName(), limits); (isFrameworkGroup(name) ? fgroups : groups).put(name, newGroup); for(Counter counter: group) { newGroup.addCounter(counter.getName(), counter.getDisplayName(), counter.getValue()); } } }
/** * Write the set of groups. * Counters ::= version #fgroups (groupId, group)* #groups (group)* */ @Override public synchronized void write(DataOutput out) throws IOException { WritableUtils.writeVInt(out, groupFactory.version()); WritableUtils.writeVInt(out, fgroups.size()); // framework groups first for (G group : fgroups.values()) { if (group.getUnderlyingGroup() instanceof FrameworkCounterGroup<?, ?>) { WritableUtils.writeVInt(out, GroupType.FRAMEWORK.ordinal()); WritableUtils.writeVInt(out, getFrameworkGroupId(group.getName())); group.write(out); } else if (group.getUnderlyingGroup() instanceof FileSystemCounterGroup<?>) { WritableUtils.writeVInt(out, GroupType.FILESYSTEM.ordinal()); group.write(out); } } if (writeAllCounters) { WritableUtils.writeVInt(out, groups.size()); for (G group : groups.values()) { Text.writeString(out, group.getName()); group.write(out); } } else { WritableUtils.writeVInt(out, 0); } }
@Override public synchronized boolean equals(Object genericRight) { if (genericRight instanceof CounterGroupBase<?>) { @SuppressWarnings("unchecked") CounterGroupBase<Counter> right = ((CounterGroupBase<Counter>) genericRight).getUnderlyingGroup(); return Iterators.elementsEqual(iterator(), right.iterator()); } return false; }
throw new IOException("Unexpected counter group type: "+ groupType); group.readFields(in); fgroups.put(group.getName(), group); G group = groupFactory.newGenericGroup( StringInterner.weakIntern(Text.readString(in)), null, limits); group.readFields(in); groups.put(group.getName(), group);
group.setDisplayName(groupDisplayName); Counter counter = group.findCounter(counterName); counter.setDisplayName(counterDisplayName); counter.increment(value);
@Override public boolean equals(Object genericRight) { if (genericRight instanceof CounterGroupBase<?>) { @SuppressWarnings("unchecked") CounterGroupBase<C> right = (CounterGroupBase<C>) genericRight; return Iterators.elementsEqual(iterator(), right.iterator()); } return false; }
/** * Returns the total number of counters, by summing the number of counters * in each group. * @return the total number of counters */ public synchronized int countCounters() { int result = 0; for (G group : this) { result += group.size(); } return result; }
/** * Find the file system counter for the given scheme and enum. * @param scheme of the file system * @param key the enum of the counter * @return the file system counter */ @InterfaceAudience.Private public synchronized C findCounter(String scheme, FileSystemCounter key) { return ((FileSystemCounterGroup<C>) getGroup( FileSystemCounter.class.getName()).getUnderlyingGroup()). findCounter(scheme, key); }
@Override public String getName() { return realGroup.getName(); }
@Override public void incrAllCounters(CounterGroupBase<Counter> rightGroup) { realGroup.incrAllCounters(rightGroup); }
@Override public void readFields(DataInput in) throws IOException { realGroup.readFields(in); }
@Override public void setDisplayName(String displayName) { realGroup.setDisplayName(displayName); }
/** * Increments multiple counters by their amounts in another Counters * instance. * @param other the other Counters instance */ public synchronized void incrAllCounters(AbstractCounters<C, G> other) { for(G right : other) { String groupName = right.getName(); G left = (isFrameworkGroup(groupName) ? fgroups : groups).get(groupName); if (left == null) { left = addGroup(groupName, right.getDisplayName()); } left.incrAllCounters(right); } }
/** * Construct from another counters object. * @param <C1> type of the other counter * @param <G1> type of the other counter group * @param counters the counters object to copy * @param groupFactory the factory for new groups */ @InterfaceAudience.Private public <C1 extends Counter, G1 extends CounterGroupBase<C1>> AbstractCounters(AbstractCounters<C1, G1> counters, CounterGroupFactory<C, G> groupFactory) { this.groupFactory = groupFactory; for(G1 group: counters) { String name = group.getName(); G newGroup = groupFactory.newGroup(name, group.getDisplayName(), limits); (isFrameworkGroup(name) ? fgroups : groups).put(name, newGroup); for(Counter counter: group) { newGroup.addCounter(counter.getName(), counter.getDisplayName(), counter.getValue()); } } }
/** * Write the set of groups. * Counters ::= version #fgroups (groupId, group)* #groups (group)* */ @Override public synchronized void write(DataOutput out) throws IOException { WritableUtils.writeVInt(out, groupFactory.version()); WritableUtils.writeVInt(out, fgroups.size()); // framework groups first for (G group : fgroups.values()) { if (group.getUnderlyingGroup() instanceof FrameworkCounterGroup<?, ?>) { WritableUtils.writeVInt(out, GroupType.FRAMEWORK.ordinal()); WritableUtils.writeVInt(out, getFrameworkGroupId(group.getName())); group.write(out); } else if (group.getUnderlyingGroup() instanceof FileSystemCounterGroup<?>) { WritableUtils.writeVInt(out, GroupType.FILESYSTEM.ordinal()); group.write(out); } } if (writeAllCounters) { WritableUtils.writeVInt(out, groups.size()); for (G group : groups.values()) { Text.writeString(out, group.getName()); group.write(out); } } else { WritableUtils.writeVInt(out, 0); } }
@Override public synchronized boolean equals(Object genericRight) { if (genericRight instanceof CounterGroupBase<?>) { @SuppressWarnings("unchecked") CounterGroupBase<Counter> right = ((CounterGroupBase<Counter>) genericRight).getUnderlyingGroup(); return Iterators.elementsEqual(iterator(), right.iterator()); } return false; }