private ResourceUsage.UsageByLabel GetAndAddIfMissing(string label) { if (!usages.Contains(label)) { ResourceUsage.UsageByLabel u = new ResourceUsage.UsageByLabel(label); usages[label] = u; return(u); } return(usages[label]); }
public ResourceUsage() { // short for no-label :) ReentrantReadWriteLock Lock = new ReentrantReadWriteLock(); readLock = Lock.ReadLock(); writeLock = Lock.WriteLock(); usages = new Dictionary <string, ResourceUsage.UsageByLabel>(); usages[Nl] = new ResourceUsage.UsageByLabel(Nl); }
private void _dec(string label, ResourceUsage.ResourceType type, Org.Apache.Hadoop.Yarn.Api.Records.Resource res) { try { writeLock.Lock(); ResourceUsage.UsageByLabel usage = GetAndAddIfMissing(label); Resources.SubtractFrom(usage.resArr[type.idx], res); } finally { writeLock.Unlock(); } }
private Org.Apache.Hadoop.Yarn.Api.Records.Resource _get(string label, ResourceUsage.ResourceType type) { try { readLock.Lock(); ResourceUsage.UsageByLabel usage = usages[label]; if (null == usage) { return(Resources.None()); } return(Normalize(usage.resArr[type.idx])); } finally { readLock.Unlock(); } }