Exemple #1
0
 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]);
 }
Exemple #2
0
        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);
        }
Exemple #3
0
 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();
     }
 }
Exemple #4
0
 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();
     }
 }