Exemple #1
0
 protected virtual void TriggerRelease(Event @event = null)
 {
     while (ReleaseQueue.Count > 0)
     {
         var release = ReleaseQueue.Peek();
         if (release.Request.IsAlive)
         {
             if (!RequestQueue.Remove(release.Request))
             {
                 throw new InvalidOperationException("Failed to cancel a request.");
             }
             BreakOffTime?.Add(Environment.ToDouble(Environment.Now - release.Request.Time));
             release.Succeed();
             ReleaseQueue.Dequeue();
         }
         else
         {
             DoRelease(release);
             if (release.IsTriggered)
             {
                 ReleaseQueue.Dequeue();
                 TriggerWhenAny();
                 TriggerWhenFull();
                 TriggerWhenChange();
             }
             else
             {
                 break;
             }
         }
     }
     Utilization?.UpdateTo(InUse / (double)Capacity);
     WIP?.UpdateTo(InUse + RequestQueue.Count);
     QueueLength?.UpdateTo(RequestQueue.Count);
 }
Exemple #2
0
 protected virtual void DoGet(ContainerGet get)
 {
     if (Level >= get.Amount)
     {
         GetWaitingTime?.Add(Environment.ToDouble(Environment.Now - get.Time));
         Level -= get.Amount;
         get.Succeed();
     }
 }
Exemple #3
0
 protected virtual void DoPut(ContainerPut put)
 {
     if (Capacity - Level >= put.Amount)
     {
         PutWaitingTime?.Add(Environment.ToDouble(Environment.Now - put.Time));
         Level += put.Amount;
         put.Succeed();
     }
 }
Exemple #4
0
 protected virtual void DoRelease(Release release)
 {
     if (!Users.Remove(release.Request))
     {
         throw new InvalidOperationException("Released request does not have a user.");
     }
     LeadTime?.Add(Environment.ToDouble(Environment.Now - release.Request.Time));
     release.Succeed();
 }
Exemple #5
0
 protected virtual void DoRequest(Request request)
 {
     if (Users.Count < Capacity)
     {
         WaitingTime?.Add(Environment.ToDouble(Environment.Now - request.Time));
         Users.Add(request);
         request.Succeed();
     }
 }
Exemple #6
0
 protected virtual void DoGet(StoreGet get)
 {
     if (Items.Count > 0)
     {
         var item = Items.Dequeue();
         GetWaitingTime?.Add(Environment.ToDouble(Environment.Now - get.Time));
         LeadTime?.Add(Environment.ToDouble(Environment.Now - item.AdmissionDate));
         get.Succeed(item.Item);
     }
 }
Exemple #7
0
 protected virtual void DoPut(StorePut put)
 {
     if (Items.Count < Capacity)
     {
         PutWaitingTime?.Add(Environment.ToDouble(Environment.Now - put.Time));
         Items.Add(new StoreItem()
         {
             AdmissionDate = Environment.Now, Item = put.Value
         });
         put.Succeed();
     }
 }
Exemple #8
0
 protected virtual void DoPut(StorePut put)
 {
     if (Items.Count < Capacity)
     {
         var pi = (PriorityItem)put.Value;
         PutWaitingTime?.Add(Environment.ToDouble(Environment.Now - put.Time));
         Items.Enqueue(new StoreItem()
         {
             AdmissionDate = Environment.Now, Item = pi.Item
         }, pi.Priority);
         put.Succeed();
     }
 }
Exemple #9
0
 protected virtual void DoRequest(ResourcePoolRequest request)
 {
     foreach (var o in Resources)
     {
         if (!request.Filter(o))
         {
             continue;
         }
         WaitingTime?.Add(Environment.ToDouble(Environment.Now - request.Time));
         Resources.Remove(o);
         request.Succeed(o);
         return;
     }
 }
Exemple #10
0
 protected virtual void DoGet(FilterStoreGet get)
 {
     for (int i = 0; i < Items.Count; i++)
     {
         var item = Items[i];
         if (!get.Filter(item.Item))
         {
             continue;
         }
         GetWaitingTime?.Add(Environment.ToDouble(Environment.Now - get.Time));
         LeadTime?.Add(Environment.ToDouble(Environment.Now - item.AdmissionDate));
         Items.RemoveAt(i);
         get.Succeed(item.Item);
         return;
     }
 }
Exemple #11
0
 protected virtual void DoRequest(PreemptiveRequest request)
 {
     if (Users.Count >= Capacity && request.Preempt)
     {
         // Check if we can preempt another process
         // MaxItems are the least important according to priorty, time, and preemption flag
         var preempt = Users.MaxItems(x => x).Last();
         if (preempt.CompareTo(request) > 0)
         {
             InterruptTime?.Add(Environment.ToDouble(Environment.Now - request.Time));
             preempt.IsPreempted = true;
             Users.Remove(preempt);
             preempt.Owner?.Interrupt(new Preempted(request.Owner, preempt.Time));
         }
     }
     if (Users.Count < Capacity)
     {
         WaitingTime?.Add(Environment.ToDouble(Environment.Now - request.Time));
         Users.Add(request);
         request.Succeed();
     }
 }
Exemple #12
0
 protected virtual void DoRelease(Release release)
 {
     Resources.Add(release.Request.Value);
     LeadTime?.Add(Environment.ToDouble(Environment.Now - release.Request.Time));
     release.Succeed();
 }