/** * Returns the names of all counter classes. * @return Set of counter names. */ public synchronized Iterable<String> getGroupNames() { HashSet<String> deprecated = new HashSet<String>(); for(Map.Entry<String, String> entry : legacyMap.entrySet()) { String newGroup = entry.getValue(); boolean isFGroup = isFrameworkGroup(newGroup); if(isFGroup ? fgroups.containsKey(newGroup) : groups.containsKey(newGroup)) { deprecated.add(entry.getKey()); } } return Iterables.concat(fgroups.keySet(), groups.keySet(), deprecated); }
/** * Create a new counter group * @param name of the group * @param displayName of the group * @param limits the counters limits policy object * @return a new counter group */ public G newGroup(String name, String displayName, Limits limits) { FrameworkGroupFactory<G> gf = fmap.get(name); if (gf != null) return gf.newGroup(name); if (name.equals(FS_GROUP_NAME)) { return newFileSystemGroup(); } else if (s2i.get(name) != null) { return newFrameworkGroup(s2i.get(name)); } return newGenericGroup(name, displayName, limits); }
private synchronized <T extends Enum<T>> void addFrameworkGroup(final Class<T> cls) { updateFrameworkGroupMapping(cls); fmap.put(cls.getName(), newFrameworkGroupFactory(cls)); }
@Override public synchronized void readFields(DataInput in) throws IOException { int version = WritableUtils.readVInt(in); if (version != groupFactory.version()) { throw new IOException("Counters version mismatch, expected "+ groupFactory.version() +" got "+ version); switch (groupType) { case FILESYSTEM: // with nothing group = groupFactory.newFileSystemGroup(); break; case FRAMEWORK: // with group id group = groupFactory.newFrameworkGroup(WritableUtils.readVInt(in)); break; default: // Silence dumb compiler, as it would've thrown earlier while (numGroups-- > 0) { limits.checkGroups(groups.size() + 1); G group = groupFactory.newGenericGroup( StringInterner.weakIntern(Text.readString(in)), null, limits); group.readFields(in);
boolean isFGroup = isFrameworkGroup(newGroupName); G group = isFGroup ? fgroups.get(newGroupName) : groups.get(newGroupName); if (group == null) { group = groupFactory.newGroup(newGroupName, limits); if (isFGroup) { fgroups.put(newGroupName, group);
/** * 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); } }
/** * Create a new counter group * @param name of the group * @param limits the counters limits policy object * @return a new counter group */ public G newGroup(String name, Limits limits) { return newGroup(name, ResourceBundles.getCounterGroupName(name, name), limits); }
/** * Get the id of a framework group * @param name of the group * @return the framework group id */ public static synchronized int getFrameworkGroupId(String name) { Integer i = s2i.get(name); if (i == null) throwBadFrameworkGroupNameException(name); return i; }
/** * Create a new framework group * @param id of the group * @return a new framework group */ public G newFrameworkGroup(int id) { String name; synchronized(CounterGroupFactory.class) { if (id < 0 || id >= i2s.size()) throwBadFrameGroupIdException(id); name = i2s.get(id); // should not throw here. } FrameworkGroupFactory<G> gf = fmap.get(name); if (gf == null) throwBadFrameGroupIdException(id); return gf.newGroup(name); }
@Override public synchronized void readFields(DataInput in) throws IOException { int version = WritableUtils.readVInt(in); if (version != groupFactory.version()) { throw new IOException("Counters version mismatch, expected "+ groupFactory.version() +" got "+ version); switch (groupType) { case FILESYSTEM: // with nothing group = groupFactory.newFileSystemGroup(); break; case FRAMEWORK: // with group id group = groupFactory.newFrameworkGroup(WritableUtils.readVInt(in)); break; default: // Silence dumb compiler, as it would've thrown earlier while (numGroups-- > 0) { limits.checkGroups(groups.size() + 1); G group = groupFactory.newGenericGroup( StringInterner.weakIntern(Text.readString(in)), null, limits); group.readFields(in);
boolean isFGroup = isFrameworkGroup(newGroupName); G group = isFGroup ? fgroups.get(newGroupName) : groups.get(newGroupName); if (group == null) { group = groupFactory.newGroup(newGroupName, limits); if (isFGroup) { fgroups.put(newGroupName, group);
/** * 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); } }
/** * Create a new counter group * @param name of the group * @param limits the counters limits policy object * @return a new counter group */ public G newGroup(String name, Limits limits) { return newGroup(name, ResourceBundles.getCounterGroupName(name, name), limits); }
/** * Get the id of a framework group * @param name of the group * @return the framework group id */ public static synchronized int getFrameworkGroupId(String name) { Integer i = s2i.get(name); if (i == null) throwBadFrameworkGroupNameException(name); return i; }
/** * Create a new framework group * @param id of the group * @return a new framework group */ public G newFrameworkGroup(int id) { String name; synchronized(CounterGroupFactory.class) { if (id < 0 || id >= i2s.size()) throwBadFrameGroupIdException(id); name = i2s.get(id); // should not throw here. } FrameworkGroupFactory<G> gf = fmap.get(name); if (gf == null) throwBadFrameGroupIdException(id); return gf.newGroup(name); }
@Override public synchronized void readFields(DataInput in) throws IOException { int version = WritableUtils.readVInt(in); if (version != groupFactory.version()) { throw new IOException("Counters version mismatch, expected "+ groupFactory.version() +" got "+ version); switch (groupType) { case FILESYSTEM: // with nothing group = groupFactory.newFileSystemGroup(); break; case FRAMEWORK: // with group id group = groupFactory.newFrameworkGroup(WritableUtils.readVInt(in)); break; default: // Silence dumb compiler, as it would've thrown earlier while (numGroups-- > 0) { limits.checkGroups(groups.size() + 1); G group = groupFactory.newGenericGroup( StringInterner.weakIntern(Text.readString(in)), null, limits); group.readFields(in);
/** * Create a new counter group * @param name of the group * @param displayName of the group * @param limits the counters limits policy object * @return a new counter group */ public G newGroup(String name, String displayName, Limits limits) { FrameworkGroupFactory<G> gf = fmap.get(name); if (gf != null) return gf.newGroup(name); if (name.equals(FS_GROUP_NAME)) { return newFileSystemGroup(); } else if (s2i.get(name) != null) { return newFrameworkGroup(s2i.get(name)); } return newGenericGroup(name, displayName, limits); }
boolean isFGroup = isFrameworkGroup(newGroupName); G group = isFGroup ? fgroups.get(newGroupName) : groups.get(newGroupName); if (group == null) { group = groupFactory.newGroup(newGroupName, limits); if (isFGroup) { fgroups.put(newGroupName, group);
private synchronized <T extends Enum<T>> void addFrameworkGroup(final Class<T> cls) { updateFrameworkGroupMapping(cls); fmap.put(cls.getName(), newFrameworkGroupFactory(cls)); }
/** * 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); } }