-- |
-- Module     : Simulation.Aivika.Trans.GPSS.Storage
-- Copyright  : Copyright (c) 2017, David Sorokin <david.sorokin@gmail.com>
-- License    : BSD3
-- Maintainer : David Sorokin <david.sorokin@gmail.com>
-- Stability  : experimental
-- Tested with: GHC 8.0.1
--
-- This module defines the GPSS Storage entity.
--
module Simulation.Aivika.Trans.GPSS.Storage
       (-- * Storage Type
        Storage,
        -- * Creating Storage
        newStorage,
        -- * Storage Properties
        storageCapacity,
        storageEmpty,
        storageFull,
        storageContent,
        storageContentStats,
        storageUseCount,
        storageUsedContent,
        storageUtilisationCount,
        storageUtilisationCountStats,
        storageQueueCount,
        storageQueueCountStats,
        storageTotalWaitTime,
        storageWaitTime,
        storageAverageHoldingTime,
        -- * Entering-Leaving Storage
        enterStorage,
        leaveStorage,
        leaveStorageWithinEvent,
        -- * Statistics Reset
        resetStorage,
        -- * Signals
        storageContentChanged,
        storageContentChanged_,
        storageUseCountChanged,
        storageUseCountChanged_,
        storageUsedContentChanged,
        storageUsedContentChanged_,
        storageUtilisationCountChanged,
        storageUtilisationCountChanged_,
        storageQueueCountChanged,
        storageQueueCountChanged_,
        storageWaitTimeChanged,
        storageWaitTimeChanged_,
        storageChanged_) where

import Data.Monoid
import Data.Maybe

import Control.Monad
import Control.Monad.Trans
import Control.Exception

import Simulation.Aivika.Trans
import Simulation.Aivika.Trans.Internal.Specs
import Simulation.Aivika.Trans.Internal.Simulation
import Simulation.Aivika.Trans.Internal.Event
import Simulation.Aivika.Trans.Internal.Cont
import Simulation.Aivika.Trans.Internal.Process
import Simulation.Aivika.Trans.QueueStrategy
import Simulation.Aivika.Trans.Statistics
import Simulation.Aivika.Trans.Signal

import Simulation.Aivika.Trans.GPSS.Transact
import Simulation.Aivika.Trans.GPSS.TransactQueueStrategy

-- | Represents a GPSS Storage entity.
data Storage m = 
  Storage { Storage m -> Int
storageCapacity :: Int,
            -- ^ Return the storage capacity.
            Storage m -> Ref m Int
storageContentRef :: Ref m Int,
            Storage m -> Ref m (TimingStats Int)
storageContentStatsRef :: Ref m (TimingStats Int),
            Storage m -> SignalSource m Int
storageContentSource :: SignalSource m Int,
            Storage m -> Ref m Int
storageUseCountRef :: Ref m Int,
            Storage m -> SignalSource m Int
storageUseCountSource :: SignalSource m Int,
            Storage m -> Ref m Int
storageUsedContentRef :: Ref m Int,
            Storage m -> SignalSource m Int
storageUsedContentSource :: SignalSource m Int,
            Storage m -> Ref m Int
storageUtilisationCountRef :: Ref m Int,
            Storage m -> Ref m (TimingStats Int)
storageUtilisationCountStatsRef :: Ref m (TimingStats Int),
            Storage m -> SignalSource m Int
storageUtilisationCountSource :: SignalSource m Int,
            Storage m -> Ref m Int
storageQueueCountRef :: Ref m Int,
            Storage m -> Ref m (TimingStats Int)
storageQueueCountStatsRef :: Ref m (TimingStats Int),
            Storage m -> SignalSource m Int
storageQueueCountSource :: SignalSource m Int,
            Storage m -> Ref m Double
storageTotalWaitTimeRef :: Ref m Double,
            Storage m -> Ref m (SamplingStats Double)
storageWaitTimeRef :: Ref m (SamplingStats Double),
            Storage m -> SignalSource m ()
storageWaitTimeSource :: SignalSource m (),
            Storage m
-> StrategyQueue
     m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
storageDelayChain :: StrategyQueue m (TransactQueueStrategy FCFS) (StorageDelayedItem m) }

-- | Identifies an item that was delayed.
data StorageDelayedItem m =
  StorageDelayedItem { StorageDelayedItem m -> Double
delayedItemTime :: Double,
                       StorageDelayedItem m -> Int
delayedItemDecrement :: Int,
                       StorageDelayedItem m -> FrozenCont m ()
delayedItemCont :: FrozenCont m () }

instance MonadDES m => Eq (Storage m) where

  {-# INLINABLE (==) #-}
  Storage m
x == :: Storage m -> Storage m -> Bool
== Storage m
y = Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageContentRef Storage m
x Ref m Int -> Ref m Int -> Bool
forall a. Eq a => a -> a -> Bool
== Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageContentRef Storage m
y  -- unique references

-- | Create a new storage by the specified capacity.
newStorage :: MonadDES m => Int -> Event m (Storage m)
{-# INLINABLE newStorage #-}
newStorage :: Int -> Event m (Storage m)
newStorage Int
capacity =
  (Point m -> m (Storage m)) -> Event m (Storage m)
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m (Storage m)) -> Event m (Storage m))
-> (Point m -> m (Storage m)) -> Event m (Storage m)
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do let r :: Run m
r = Point m -> Run m
forall (m :: * -> *). Point m -> Run m
pointRun Point m
p
         t :: Double
t = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Ref m Int
contentRef <- Run m -> Simulation m (Ref m Int) -> m (Ref m Int)
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r (Simulation m (Ref m Int) -> m (Ref m Int))
-> Simulation m (Ref m Int) -> m (Ref m Int)
forall a b. (a -> b) -> a -> b
$ Int -> Simulation m (Ref m Int)
forall (m :: * -> *) a. MonadDES m => a -> Simulation m (Ref m a)
newRef Int
capacity
     Ref m (TimingStats Int)
contentStatsRef <- Run m
-> Simulation m (Ref m (TimingStats Int))
-> m (Ref m (TimingStats Int))
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r (Simulation m (Ref m (TimingStats Int))
 -> m (Ref m (TimingStats Int)))
-> Simulation m (Ref m (TimingStats Int))
-> m (Ref m (TimingStats Int))
forall a b. (a -> b) -> a -> b
$ TimingStats Int -> Simulation m (Ref m (TimingStats Int))
forall (m :: * -> *) a. MonadDES m => a -> Simulation m (Ref m a)
newRef (TimingStats Int -> Simulation m (Ref m (TimingStats Int)))
-> TimingStats Int -> Simulation m (Ref m (TimingStats Int))
forall a b. (a -> b) -> a -> b
$ Double -> Int -> TimingStats Int
forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t Int
capacity
     SignalSource m Int
contentSource <- Run m
-> Simulation m (SignalSource m Int) -> m (SignalSource m Int)
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r Simulation m (SignalSource m Int)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     Ref m Int
useCountRef <- Run m -> Simulation m (Ref m Int) -> m (Ref m Int)
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r (Simulation m (Ref m Int) -> m (Ref m Int))
-> Simulation m (Ref m Int) -> m (Ref m Int)
forall a b. (a -> b) -> a -> b
$ Int -> Simulation m (Ref m Int)
forall (m :: * -> *) a. MonadDES m => a -> Simulation m (Ref m a)
newRef Int
0
     SignalSource m Int
useCountSource <- Run m
-> Simulation m (SignalSource m Int) -> m (SignalSource m Int)
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r Simulation m (SignalSource m Int)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     Ref m Int
usedContentRef <- Run m -> Simulation m (Ref m Int) -> m (Ref m Int)
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r (Simulation m (Ref m Int) -> m (Ref m Int))
-> Simulation m (Ref m Int) -> m (Ref m Int)
forall a b. (a -> b) -> a -> b
$ Int -> Simulation m (Ref m Int)
forall (m :: * -> *) a. MonadDES m => a -> Simulation m (Ref m a)
newRef Int
0
     SignalSource m Int
usedContentSource <- Run m
-> Simulation m (SignalSource m Int) -> m (SignalSource m Int)
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r Simulation m (SignalSource m Int)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     Ref m Int
utilCountRef <- Run m -> Simulation m (Ref m Int) -> m (Ref m Int)
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r (Simulation m (Ref m Int) -> m (Ref m Int))
-> Simulation m (Ref m Int) -> m (Ref m Int)
forall a b. (a -> b) -> a -> b
$ Int -> Simulation m (Ref m Int)
forall (m :: * -> *) a. MonadDES m => a -> Simulation m (Ref m a)
newRef Int
0
     Ref m (TimingStats Int)
utilCountStatsRef <- Run m
-> Simulation m (Ref m (TimingStats Int))
-> m (Ref m (TimingStats Int))
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r (Simulation m (Ref m (TimingStats Int))
 -> m (Ref m (TimingStats Int)))
-> Simulation m (Ref m (TimingStats Int))
-> m (Ref m (TimingStats Int))
forall a b. (a -> b) -> a -> b
$ TimingStats Int -> Simulation m (Ref m (TimingStats Int))
forall (m :: * -> *) a. MonadDES m => a -> Simulation m (Ref m a)
newRef (TimingStats Int -> Simulation m (Ref m (TimingStats Int)))
-> TimingStats Int -> Simulation m (Ref m (TimingStats Int))
forall a b. (a -> b) -> a -> b
$ Double -> Int -> TimingStats Int
forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t Int
0
     SignalSource m Int
utilCountSource <- Run m
-> Simulation m (SignalSource m Int) -> m (SignalSource m Int)
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r Simulation m (SignalSource m Int)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     Ref m Int
queueCountRef <- Run m -> Simulation m (Ref m Int) -> m (Ref m Int)
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r (Simulation m (Ref m Int) -> m (Ref m Int))
-> Simulation m (Ref m Int) -> m (Ref m Int)
forall a b. (a -> b) -> a -> b
$ Int -> Simulation m (Ref m Int)
forall (m :: * -> *) a. MonadDES m => a -> Simulation m (Ref m a)
newRef Int
0
     Ref m (TimingStats Int)
queueCountStatsRef <- Run m
-> Simulation m (Ref m (TimingStats Int))
-> m (Ref m (TimingStats Int))
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r (Simulation m (Ref m (TimingStats Int))
 -> m (Ref m (TimingStats Int)))
-> Simulation m (Ref m (TimingStats Int))
-> m (Ref m (TimingStats Int))
forall a b. (a -> b) -> a -> b
$ TimingStats Int -> Simulation m (Ref m (TimingStats Int))
forall (m :: * -> *) a. MonadDES m => a -> Simulation m (Ref m a)
newRef (TimingStats Int -> Simulation m (Ref m (TimingStats Int)))
-> TimingStats Int -> Simulation m (Ref m (TimingStats Int))
forall a b. (a -> b) -> a -> b
$ Double -> Int -> TimingStats Int
forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t Int
0
     SignalSource m Int
queueCountSource <- Run m
-> Simulation m (SignalSource m Int) -> m (SignalSource m Int)
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r Simulation m (SignalSource m Int)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     Ref m Double
totalWaitTimeRef <- Run m -> Simulation m (Ref m Double) -> m (Ref m Double)
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r (Simulation m (Ref m Double) -> m (Ref m Double))
-> Simulation m (Ref m Double) -> m (Ref m Double)
forall a b. (a -> b) -> a -> b
$ Double -> Simulation m (Ref m Double)
forall (m :: * -> *) a. MonadDES m => a -> Simulation m (Ref m a)
newRef Double
0
     Ref m (SamplingStats Double)
waitTimeRef <- Run m
-> Simulation m (Ref m (SamplingStats Double))
-> m (Ref m (SamplingStats Double))
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r (Simulation m (Ref m (SamplingStats Double))
 -> m (Ref m (SamplingStats Double)))
-> Simulation m (Ref m (SamplingStats Double))
-> m (Ref m (SamplingStats Double))
forall a b. (a -> b) -> a -> b
$ SamplingStats Double -> Simulation m (Ref m (SamplingStats Double))
forall (m :: * -> *) a. MonadDES m => a -> Simulation m (Ref m a)
newRef SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
     SignalSource m ()
waitTimeSource <- Run m -> Simulation m (SignalSource m ()) -> m (SignalSource m ())
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r Simulation m (SignalSource m ())
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     StrategyQueue m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
delayChain <- Run m
-> Simulation
     m
     (StrategyQueue
        m (TransactQueueStrategy FCFS) (StorageDelayedItem m))
-> m (StrategyQueue
        m (TransactQueueStrategy FCFS) (StorageDelayedItem m))
forall (m :: * -> *) a. Run m -> Simulation m a -> m a
invokeSimulation Run m
r (Simulation
   m
   (StrategyQueue
      m (TransactQueueStrategy FCFS) (StorageDelayedItem m))
 -> m (StrategyQueue
         m (TransactQueueStrategy FCFS) (StorageDelayedItem m)))
-> Simulation
     m
     (StrategyQueue
        m (TransactQueueStrategy FCFS) (StorageDelayedItem m))
-> m (StrategyQueue
        m (TransactQueueStrategy FCFS) (StorageDelayedItem m))
forall a b. (a -> b) -> a -> b
$ TransactQueueStrategy FCFS
-> Simulation
     m
     (StrategyQueue
        m (TransactQueueStrategy FCFS) (StorageDelayedItem m))
forall (m :: * -> *) s a.
QueueStrategy m s =>
s -> Simulation m (StrategyQueue m s a)
newStrategyQueue (FCFS -> TransactQueueStrategy FCFS
forall s. s -> TransactQueueStrategy s
TransactQueueStrategy FCFS
FCFS)
     Storage m -> m (Storage m)
forall (m :: * -> *) a. Monad m => a -> m a
return Storage :: forall (m :: * -> *).
Int
-> Ref m Int
-> Ref m (TimingStats Int)
-> SignalSource m Int
-> Ref m Int
-> SignalSource m Int
-> Ref m Int
-> SignalSource m Int
-> Ref m Int
-> Ref m (TimingStats Int)
-> SignalSource m Int
-> Ref m Int
-> Ref m (TimingStats Int)
-> SignalSource m Int
-> Ref m Double
-> Ref m (SamplingStats Double)
-> SignalSource m ()
-> StrategyQueue
     m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
-> Storage m
Storage { storageCapacity :: Int
storageCapacity = Int
capacity,
                      storageContentRef :: Ref m Int
storageContentRef = Ref m Int
contentRef,
                      storageContentStatsRef :: Ref m (TimingStats Int)
storageContentStatsRef = Ref m (TimingStats Int)
contentStatsRef,
                      storageContentSource :: SignalSource m Int
storageContentSource = SignalSource m Int
contentSource,
                      storageUseCountRef :: Ref m Int
storageUseCountRef = Ref m Int
useCountRef,
                      storageUseCountSource :: SignalSource m Int
storageUseCountSource = SignalSource m Int
useCountSource,
                      storageUsedContentRef :: Ref m Int
storageUsedContentRef = Ref m Int
usedContentRef,
                      storageUsedContentSource :: SignalSource m Int
storageUsedContentSource = SignalSource m Int
usedContentSource,
                      storageUtilisationCountRef :: Ref m Int
storageUtilisationCountRef = Ref m Int
utilCountRef,
                      storageUtilisationCountStatsRef :: Ref m (TimingStats Int)
storageUtilisationCountStatsRef = Ref m (TimingStats Int)
utilCountStatsRef,
                      storageUtilisationCountSource :: SignalSource m Int
storageUtilisationCountSource = SignalSource m Int
utilCountSource,
                      storageQueueCountRef :: Ref m Int
storageQueueCountRef = Ref m Int
queueCountRef,
                      storageQueueCountStatsRef :: Ref m (TimingStats Int)
storageQueueCountStatsRef = Ref m (TimingStats Int)
queueCountStatsRef,
                      storageQueueCountSource :: SignalSource m Int
storageQueueCountSource = SignalSource m Int
queueCountSource,
                      storageTotalWaitTimeRef :: Ref m Double
storageTotalWaitTimeRef = Ref m Double
totalWaitTimeRef,
                      storageWaitTimeRef :: Ref m (SamplingStats Double)
storageWaitTimeRef = Ref m (SamplingStats Double)
waitTimeRef,
                      storageWaitTimeSource :: SignalSource m ()
storageWaitTimeSource = SignalSource m ()
waitTimeSource,
                      storageDelayChain :: StrategyQueue m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
storageDelayChain = StrategyQueue m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
delayChain }

-- | Whether the storage is empty, i.e. completely unused.
storageEmpty :: MonadDES m => Storage m -> Event m Bool
{-# INLINABLE storageEmpty #-}
storageEmpty :: Storage m -> Event m Bool
storageEmpty Storage m
r =
  (Point m -> m Bool) -> Event m Bool
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Bool) -> Event m Bool)
-> (Point m -> m Bool) -> Event m Bool
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Int
n <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageContentRef Storage m
r)
     Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Storage m -> Int
forall (m :: * -> *). Storage m -> Int
storageCapacity Storage m
r)

-- | Whether the storage is full, i.e. completely used.
storageFull :: MonadDES m => Storage m -> Event m Bool
{-# INLINABLE storageFull #-}
storageFull :: Storage m -> Event m Bool
storageFull Storage m
r =
  (Point m -> m Bool) -> Event m Bool
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Bool) -> Event m Bool)
-> (Point m -> m Bool) -> Event m Bool
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Int
n <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageContentRef Storage m
r)
     Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0)

-- | Return the current storage content available for use.
storageContent :: MonadDES m => Storage m -> Event m Int
{-# INLINABLE storageContent #-}
storageContent :: Storage m -> Event m Int
storageContent Storage m
r =
  (Point m -> m Int) -> Event m Int
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Int) -> Event m Int)
-> (Point m -> m Int) -> Event m Int
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageContentRef Storage m
r)

-- | Return the statistics of the storage content available for use.
storageContentStats :: MonadDES m => Storage m -> Event m (TimingStats Int)
{-# INLINABLE storageContentStats #-}
storageContentStats :: Storage m -> Event m (TimingStats Int)
storageContentStats Storage m
r =
  (Point m -> m (TimingStats Int)) -> Event m (TimingStats Int)
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m (TimingStats Int)) -> Event m (TimingStats Int))
-> (Point m -> m (TimingStats Int)) -> Event m (TimingStats Int)
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m (TimingStats Int) -> m (TimingStats Int)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (TimingStats Int) -> m (TimingStats Int))
-> Event m (TimingStats Int) -> m (TimingStats Int)
forall a b. (a -> b) -> a -> b
$ Ref m (TimingStats Int) -> Event m (TimingStats Int)
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m (TimingStats Int)
forall (m :: * -> *). Storage m -> Ref m (TimingStats Int)
storageContentStatsRef Storage m
r)

-- | Signal triggered when the 'storageContent' property changes.
storageContentChanged :: MonadDES m => Storage m -> Signal m Int
{-# INLINABLE storageContentChanged #-}
storageContentChanged :: Storage m -> Signal m Int
storageContentChanged Storage m
r =
  SignalSource m Int -> Signal m Int
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (SignalSource m Int -> Signal m Int)
-> SignalSource m Int -> Signal m Int
forall a b. (a -> b) -> a -> b
$ Storage m -> SignalSource m Int
forall (m :: * -> *). Storage m -> SignalSource m Int
storageContentSource Storage m
r

-- | Signal triggered when the 'storageContent' property changes.
storageContentChanged_ :: MonadDES m => Storage m -> Signal m ()
{-# INLINABLE storageContentChanged_ #-}
storageContentChanged_ :: Storage m -> Signal m ()
storageContentChanged_ Storage m
r =
  (Int -> ()) -> Signal m Int -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> Int -> ()
forall a b. a -> b -> a
const ()) (Signal m Int -> Signal m ()) -> Signal m Int -> Signal m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Signal m Int
forall (m :: * -> *). MonadDES m => Storage m -> Signal m Int
storageContentChanged Storage m
r

-- | Return the total use count of the storage.
storageUseCount :: MonadDES m => Storage m -> Event m Int
{-# INLINABLE storageUseCount #-}
storageUseCount :: Storage m -> Event m Int
storageUseCount Storage m
r =
  (Point m -> m Int) -> Event m Int
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Int) -> Event m Int)
-> (Point m -> m Int) -> Event m Int
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageUseCountRef Storage m
r)

-- | Signal triggered when the 'storageUseCount' property changes.
storageUseCountChanged :: MonadDES m => Storage m -> Signal m Int
{-# INLINABLE storageUseCountChanged #-}
storageUseCountChanged :: Storage m -> Signal m Int
storageUseCountChanged Storage m
r =
  SignalSource m Int -> Signal m Int
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (SignalSource m Int -> Signal m Int)
-> SignalSource m Int -> Signal m Int
forall a b. (a -> b) -> a -> b
$ Storage m -> SignalSource m Int
forall (m :: * -> *). Storage m -> SignalSource m Int
storageUseCountSource Storage m
r

-- | Signal triggered when the 'storageUseCount' property changes.
storageUseCountChanged_ :: MonadDES m => Storage m -> Signal m ()
{-# INLINABLE storageUseCountChanged_ #-}
storageUseCountChanged_ :: Storage m -> Signal m ()
storageUseCountChanged_ Storage m
r =
  (Int -> ()) -> Signal m Int -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> Int -> ()
forall a b. a -> b -> a
const ()) (Signal m Int -> Signal m ()) -> Signal m Int -> Signal m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Signal m Int
forall (m :: * -> *). MonadDES m => Storage m -> Signal m Int
storageUseCountChanged Storage m
r

-- | Return the total used content of the storage.
storageUsedContent :: MonadDES m => Storage m -> Event m Int
{-# INLINABLE storageUsedContent #-}
storageUsedContent :: Storage m -> Event m Int
storageUsedContent Storage m
r =
  (Point m -> m Int) -> Event m Int
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Int) -> Event m Int)
-> (Point m -> m Int) -> Event m Int
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageUsedContentRef Storage m
r)

-- | Signal triggered when the 'storageUsedContent' property changes.
storageUsedContentChanged :: MonadDES m => Storage m -> Signal m Int
{-# INLINABLE storageUsedContentChanged #-}
storageUsedContentChanged :: Storage m -> Signal m Int
storageUsedContentChanged Storage m
r =
  SignalSource m Int -> Signal m Int
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (SignalSource m Int -> Signal m Int)
-> SignalSource m Int -> Signal m Int
forall a b. (a -> b) -> a -> b
$ Storage m -> SignalSource m Int
forall (m :: * -> *). Storage m -> SignalSource m Int
storageUsedContentSource Storage m
r

-- | Signal triggered when the 'storageUsedContent' property changes.
storageUsedContentChanged_ :: MonadDES m => Storage m -> Signal m ()
{-# INLINABLE storageUsedContentChanged_ #-}
storageUsedContentChanged_ :: Storage m -> Signal m ()
storageUsedContentChanged_ Storage m
r =
  (Int -> ()) -> Signal m Int -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> Int -> ()
forall a b. a -> b -> a
const ()) (Signal m Int -> Signal m ()) -> Signal m Int -> Signal m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Signal m Int
forall (m :: * -> *). MonadDES m => Storage m -> Signal m Int
storageUsedContentChanged Storage m
r

-- | Return the current utilisation count of the storage.
storageUtilisationCount :: MonadDES m => Storage m -> Event m Int
{-# INLINABLE storageUtilisationCount #-}
storageUtilisationCount :: Storage m -> Event m Int
storageUtilisationCount Storage m
r =
  (Point m -> m Int) -> Event m Int
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Int) -> Event m Int)
-> (Point m -> m Int) -> Event m Int
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageUtilisationCountRef Storage m
r)

-- | Return the statistics for the utilisation count of the storage.
storageUtilisationCountStats :: MonadDES m => Storage m -> Event m (TimingStats Int)
{-# INLINABLE storageUtilisationCountStats #-}
storageUtilisationCountStats :: Storage m -> Event m (TimingStats Int)
storageUtilisationCountStats Storage m
r =
  (Point m -> m (TimingStats Int)) -> Event m (TimingStats Int)
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m (TimingStats Int)) -> Event m (TimingStats Int))
-> (Point m -> m (TimingStats Int)) -> Event m (TimingStats Int)
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m (TimingStats Int) -> m (TimingStats Int)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (TimingStats Int) -> m (TimingStats Int))
-> Event m (TimingStats Int) -> m (TimingStats Int)
forall a b. (a -> b) -> a -> b
$ Ref m (TimingStats Int) -> Event m (TimingStats Int)
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m (TimingStats Int)
forall (m :: * -> *). Storage m -> Ref m (TimingStats Int)
storageUtilisationCountStatsRef Storage m
r)

-- | Signal triggered when the 'storageUtilisationCount' property changes.
storageUtilisationCountChanged :: MonadDES m => Storage m -> Signal m Int
{-# INLINABLE storageUtilisationCountChanged #-}
storageUtilisationCountChanged :: Storage m -> Signal m Int
storageUtilisationCountChanged Storage m
r =
  SignalSource m Int -> Signal m Int
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (SignalSource m Int -> Signal m Int)
-> SignalSource m Int -> Signal m Int
forall a b. (a -> b) -> a -> b
$ Storage m -> SignalSource m Int
forall (m :: * -> *). Storage m -> SignalSource m Int
storageUtilisationCountSource Storage m
r

-- | Signal triggered when the 'storageUtilisationCount' property changes.
storageUtilisationCountChanged_ :: MonadDES m => Storage m -> Signal m ()
{-# INLINABLE storageUtilisationCountChanged_ #-}
storageUtilisationCountChanged_ :: Storage m -> Signal m ()
storageUtilisationCountChanged_ Storage m
r =
  (Int -> ()) -> Signal m Int -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> Int -> ()
forall a b. a -> b -> a
const ()) (Signal m Int -> Signal m ()) -> Signal m Int -> Signal m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Signal m Int
forall (m :: * -> *). MonadDES m => Storage m -> Signal m Int
storageUtilisationCountChanged Storage m
r

-- | Return the current queue length of the storage.
storageQueueCount :: MonadDES m => Storage m -> Event m Int
{-# INLINABLE storageQueueCount #-}
storageQueueCount :: Storage m -> Event m Int
storageQueueCount Storage m
r =
  (Point m -> m Int) -> Event m Int
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Int) -> Event m Int)
-> (Point m -> m Int) -> Event m Int
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageQueueCountRef Storage m
r)

-- | Return the statistics for the queue length of the storage.
storageQueueCountStats :: MonadDES m => Storage m -> Event m (TimingStats Int)
{-# INLINABLE storageQueueCountStats #-}
storageQueueCountStats :: Storage m -> Event m (TimingStats Int)
storageQueueCountStats Storage m
r =
  (Point m -> m (TimingStats Int)) -> Event m (TimingStats Int)
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m (TimingStats Int)) -> Event m (TimingStats Int))
-> (Point m -> m (TimingStats Int)) -> Event m (TimingStats Int)
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m (TimingStats Int) -> m (TimingStats Int)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (TimingStats Int) -> m (TimingStats Int))
-> Event m (TimingStats Int) -> m (TimingStats Int)
forall a b. (a -> b) -> a -> b
$ Ref m (TimingStats Int) -> Event m (TimingStats Int)
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m (TimingStats Int)
forall (m :: * -> *). Storage m -> Ref m (TimingStats Int)
storageQueueCountStatsRef Storage m
r)

-- | Signal triggered when the 'storageQueueCount' property changes.
storageQueueCountChanged :: MonadDES m => Storage m -> Signal m Int
{-# INLINABLE storageQueueCountChanged #-}
storageQueueCountChanged :: Storage m -> Signal m Int
storageQueueCountChanged Storage m
r =
  SignalSource m Int -> Signal m Int
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (SignalSource m Int -> Signal m Int)
-> SignalSource m Int -> Signal m Int
forall a b. (a -> b) -> a -> b
$ Storage m -> SignalSource m Int
forall (m :: * -> *). Storage m -> SignalSource m Int
storageQueueCountSource Storage m
r

-- | Signal triggered when the 'storageQueueCount' property changes.
storageQueueCountChanged_ :: MonadDES m => Storage m -> Signal m ()
{-# INLINABLE storageQueueCountChanged_ #-}
storageQueueCountChanged_ :: Storage m -> Signal m ()
storageQueueCountChanged_ Storage m
r =
  (Int -> ()) -> Signal m Int -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> Int -> ()
forall a b. a -> b -> a
const ()) (Signal m Int -> Signal m ()) -> Signal m Int -> Signal m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Signal m Int
forall (m :: * -> *). MonadDES m => Storage m -> Signal m Int
storageQueueCountChanged Storage m
r

-- | Return the total wait time of the storage.
storageTotalWaitTime :: MonadDES m => Storage m -> Event m Double
{-# INLINABLE storageTotalWaitTime #-}
storageTotalWaitTime :: Storage m -> Event m Double
storageTotalWaitTime Storage m
r =
  (Point m -> m Double) -> Event m Double
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Double) -> Event m Double)
-> (Point m -> m Double) -> Event m Double
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m Double -> m Double
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Double -> m Double) -> Event m Double -> m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Double
forall (m :: * -> *). Storage m -> Ref m Double
storageTotalWaitTimeRef Storage m
r)

-- | Return the statistics for the wait time of the storage.
storageWaitTime :: MonadDES m => Storage m -> Event m (SamplingStats Double)
{-# INLINABLE storageWaitTime #-}
storageWaitTime :: Storage m -> Event m (SamplingStats Double)
storageWaitTime Storage m
r =
  (Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double)
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m (SamplingStats Double))
 -> Event m (SamplingStats Double))
-> (Point m -> m (SamplingStats Double))
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (SamplingStats Double) -> m (SamplingStats Double))
-> Event m (SamplingStats Double) -> m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Ref m (SamplingStats Double) -> Event m (SamplingStats Double)
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m (SamplingStats Double)
forall (m :: * -> *). Storage m -> Ref m (SamplingStats Double)
storageWaitTimeRef Storage m
r)

-- | Signal triggered when the 'storageTotalWaitTime' and 'storageWaitTime' properties change.
storageWaitTimeChanged :: MonadDES m => Storage m -> Signal m (SamplingStats Double)
{-# INLINABLE storageWaitTimeChanged #-}
storageWaitTimeChanged :: Storage m -> Signal m (SamplingStats Double)
storageWaitTimeChanged Storage m
r =
  (() -> Event m (SamplingStats Double))
-> Signal m () -> Signal m (SamplingStats Double)
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (\() -> Storage m -> Event m (SamplingStats Double)
forall (m :: * -> *).
MonadDES m =>
Storage m -> Event m (SamplingStats Double)
storageWaitTime Storage m
r) (Signal m () -> Signal m (SamplingStats Double))
-> Signal m () -> Signal m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Storage m -> Signal m ()
forall (m :: * -> *). MonadDES m => Storage m -> Signal m ()
storageWaitTimeChanged_ Storage m
r

-- | Signal triggered when the 'storageTotalWaitTime' and 'storageWaitTime' properties change.
storageWaitTimeChanged_ :: MonadDES m => Storage m -> Signal m ()
{-# INLINABLE storageWaitTimeChanged_ #-}
storageWaitTimeChanged_ :: Storage m -> Signal m ()
storageWaitTimeChanged_ Storage m
r =
  SignalSource m () -> Signal m ()
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (SignalSource m () -> Signal m ())
-> SignalSource m () -> Signal m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> SignalSource m ()
forall (m :: * -> *). Storage m -> SignalSource m ()
storageWaitTimeSource Storage m
r

-- | Return the average holding time per unit.
storageAverageHoldingTime :: MonadDES m => Storage m -> Event m Double
{-# INLINABLE storageAverageHoldingTime #-}
storageAverageHoldingTime :: Storage m -> Event m Double
storageAverageHoldingTime Storage m
r =
  (Point m -> m Double) -> Event m Double
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m Double) -> Event m Double)
-> (Point m -> m Double) -> Event m Double
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do TimingStats Int
s <- Point m -> Event m (TimingStats Int) -> m (TimingStats Int)
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (TimingStats Int) -> m (TimingStats Int))
-> Event m (TimingStats Int) -> m (TimingStats Int)
forall a b. (a -> b) -> a -> b
$ Ref m (TimingStats Int) -> Event m (TimingStats Int)
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m (TimingStats Int)
forall (m :: * -> *). Storage m -> Ref m (TimingStats Int)
storageUtilisationCountStatsRef Storage m
r)
     Int
n <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageUtilisationCountRef Storage m
r)
     Int
m <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageUsedContentRef Storage m
r)
     let t :: Double
t  = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
         s' :: TimingStats Int
s' = Double -> Int -> TimingStats Int -> TimingStats Int
forall a.
TimingData a =>
Double -> a -> TimingStats a -> TimingStats a
addTimingStats Double
t Int
n TimingStats Int
s
         k :: Double
k  = TimingStats Int -> Double
forall a. TimingStats a -> Double
timingStatsSum TimingStats Int
s' Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Rational -> Double
forall a. Fractional a => Rational -> a
fromRational (Rational -> Double) -> Rational -> Double
forall a b. (a -> b) -> a -> b
$ Int -> Rational
forall a. Real a => a -> Rational
toRational Int
m)
     Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return Double
k

-- | Enter the storage.
enterStorage :: MonadDES m
                => Storage m
                -- ^ the requested storage
                -> Transact m a
                -- ^ a transact that makes the request
                -> Int
                -- ^ the content decrement
                -> Process m ()
{-# INLINABLE enterStorage #-}
enterStorage :: Storage m -> Transact m a -> Int -> Process m ()
enterStorage Storage m
r Transact m a
transact Int
decrement =
  (ProcessId m -> Cont m ()) -> Process m ()
forall (m :: * -> *) a. (ProcessId m -> Cont m a) -> Process m a
Process ((ProcessId m -> Cont m ()) -> Process m ())
-> (ProcessId m -> Cont m ()) -> Process m ()
forall a b. (a -> b) -> a -> b
$ \ProcessId m
pid ->
  (ContParams m () -> Event m ()) -> Cont m ()
forall (m :: * -> *) a. (ContParams m a -> Event m ()) -> Cont m a
Cont ((ContParams m () -> Event m ()) -> Cont m ())
-> (ContParams m () -> Event m ()) -> Cont m ()
forall a b. (a -> b) -> a -> b
$ \ContParams m ()
c ->
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do let t :: Double
t = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Bool
f <- Point m -> Event m Bool -> m Bool
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Bool -> m Bool) -> Event m Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ StrategyQueue m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
-> Event m Bool
forall (m :: * -> *) s a.
QueueStrategy m s =>
StrategyQueue m s a -> Event m Bool
strategyQueueNull (Storage m
-> StrategyQueue
     m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
forall (m :: * -> *).
Storage m
-> StrategyQueue
     m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
storageDelayChain Storage m
r)
     if Bool
f
       then Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
            ContParams m () -> Cont m () -> Event m ()
forall (m :: * -> *) a. ContParams m a -> Cont m a -> Event m ()
invokeCont ContParams m ()
c (Cont m () -> Event m ()) -> Cont m () -> Event m ()
forall a b. (a -> b) -> a -> b
$
            ProcessId m -> Process m () -> Cont m ()
forall (m :: * -> *) a. ProcessId m -> Process m a -> Cont m a
invokeProcess ProcessId m
pid (Process m () -> Cont m ()) -> Process m () -> Cont m ()
forall a b. (a -> b) -> a -> b
$
            Storage m -> Transact m a -> Int -> Process m ()
forall (m :: * -> *) a.
MonadDES m =>
Storage m -> Transact m a -> Int -> Process m ()
enterStorage' Storage m
r Transact m a
transact Int
decrement
       else do FrozenCont m ()
c <- Point m -> Event m (FrozenCont m ()) -> m (FrozenCont m ())
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (FrozenCont m ()) -> m (FrozenCont m ()))
-> Event m (FrozenCont m ()) -> m (FrozenCont m ())
forall a b. (a -> b) -> a -> b
$
                    ContParams m () -> () -> Event m () -> Event m (FrozenCont m ())
forall (m :: * -> *) a.
MonadDES m =>
ContParams m a -> a -> Event m () -> Event m (FrozenCont m a)
freezeContReentering ContParams m ()
c () (Event m () -> Event m (FrozenCont m ()))
-> Event m () -> Event m (FrozenCont m ())
forall a b. (a -> b) -> a -> b
$
                    ContParams m () -> Cont m () -> Event m ()
forall (m :: * -> *) a. ContParams m a -> Cont m a -> Event m ()
invokeCont ContParams m ()
c (Cont m () -> Event m ()) -> Cont m () -> Event m ()
forall a b. (a -> b) -> a -> b
$
                    ProcessId m -> Process m () -> Cont m ()
forall (m :: * -> *) a. ProcessId m -> Process m a -> Cont m a
invokeProcess ProcessId m
pid (Process m () -> Cont m ()) -> Process m () -> Cont m ()
forall a b. (a -> b) -> a -> b
$
                    Storage m -> Transact m a -> Int -> Process m ()
forall (m :: * -> *) a.
MonadDES m =>
Storage m -> Transact m a -> Int -> Process m ()
enterStorage Storage m
r Transact m a
transact Int
decrement
               Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
                 StrategyQueue m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
-> Int -> StorageDelayedItem m -> Event m ()
forall (m :: * -> *) s p a.
PriorityQueueStrategy m s p =>
StrategyQueue m s a -> p -> a -> Event m ()
strategyEnqueueWithPriority
                 (Storage m
-> StrategyQueue
     m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
forall (m :: * -> *).
Storage m
-> StrategyQueue
     m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
storageDelayChain Storage m
r)
                 (Transact m a -> Int
forall (m :: * -> *) a. Transact m a -> Int
transactPriority Transact m a
transact)
                 (Double -> Int -> FrozenCont m () -> StorageDelayedItem m
forall (m :: * -> *).
Double -> Int -> FrozenCont m () -> StorageDelayedItem m
StorageDelayedItem Double
t Int
decrement FrozenCont m ()
c)
               Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Int -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Int -> Event m ()
updateStorageQueueCount Storage m
r Int
1

-- | Enter the storage.
enterStorage' :: MonadDES m
                 => Storage m
                 -- ^ the requested storage
                 -> Transact m a
                 -- ^ a transact that makes the request
                 -> Int
                 -- ^ the content decrement
                 -> Process m ()
{-# INLINABLE enterStorage' #-}
enterStorage' :: Storage m -> Transact m a -> Int -> Process m ()
enterStorage' Storage m
r Transact m a
transact Int
decrement =
  (ProcessId m -> Cont m ()) -> Process m ()
forall (m :: * -> *) a. (ProcessId m -> Cont m a) -> Process m a
Process ((ProcessId m -> Cont m ()) -> Process m ())
-> (ProcessId m -> Cont m ()) -> Process m ()
forall a b. (a -> b) -> a -> b
$ \ProcessId m
pid ->
  (ContParams m () -> Event m ()) -> Cont m ()
forall (m :: * -> *) a. (ContParams m a -> Event m ()) -> Cont m a
Cont ((ContParams m () -> Event m ()) -> Cont m ())
-> (ContParams m () -> Event m ()) -> Cont m ()
forall a b. (a -> b) -> a -> b
$ \ContParams m ()
c ->
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do let t :: Double
t = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Int
a <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageContentRef Storage m
r)
     if Int
a Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
decrement
       then do FrozenCont m ()
c <- Point m -> Event m (FrozenCont m ()) -> m (FrozenCont m ())
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (FrozenCont m ()) -> m (FrozenCont m ()))
-> Event m (FrozenCont m ()) -> m (FrozenCont m ())
forall a b. (a -> b) -> a -> b
$
                    ContParams m () -> () -> Event m () -> Event m (FrozenCont m ())
forall (m :: * -> *) a.
MonadDES m =>
ContParams m a -> a -> Event m () -> Event m (FrozenCont m a)
freezeContReentering ContParams m ()
c () (Event m () -> Event m (FrozenCont m ()))
-> Event m () -> Event m (FrozenCont m ())
forall a b. (a -> b) -> a -> b
$
                    ContParams m () -> Cont m () -> Event m ()
forall (m :: * -> *) a. ContParams m a -> Cont m a -> Event m ()
invokeCont ContParams m ()
c (Cont m () -> Event m ()) -> Cont m () -> Event m ()
forall a b. (a -> b) -> a -> b
$
                    ProcessId m -> Process m () -> Cont m ()
forall (m :: * -> *) a. ProcessId m -> Process m a -> Cont m a
invokeProcess ProcessId m
pid (Process m () -> Cont m ()) -> Process m () -> Cont m ()
forall a b. (a -> b) -> a -> b
$
                    Storage m -> Transact m a -> Int -> Process m ()
forall (m :: * -> *) a.
MonadDES m =>
Storage m -> Transact m a -> Int -> Process m ()
enterStorage Storage m
r Transact m a
transact Int
decrement
               Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
                 StrategyQueue m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
-> Int -> StorageDelayedItem m -> Event m ()
forall (m :: * -> *) s p a.
PriorityQueueStrategy m s p =>
StrategyQueue m s a -> p -> a -> Event m ()
strategyEnqueueWithPriority
                 (Storage m
-> StrategyQueue
     m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
forall (m :: * -> *).
Storage m
-> StrategyQueue
     m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
storageDelayChain Storage m
r)
                 (Transact m a -> Int
forall (m :: * -> *) a. Transact m a -> Int
transactPriority Transact m a
transact)
                 (Double -> Int -> FrozenCont m () -> StorageDelayedItem m
forall (m :: * -> *).
Double -> Int -> FrozenCont m () -> StorageDelayedItem m
StorageDelayedItem Double
t Int
decrement FrozenCont m ()
c)
               Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Int -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Int -> Event m ()
updateStorageQueueCount Storage m
r Int
1
       else do Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Double -> Event m ()
forall (m :: * -> *).
MonadDES m =>
Storage m -> Double -> Event m ()
updateStorageWaitTime Storage m
r Double
0
               Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Int -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Int -> Event m ()
updateStorageContent Storage m
r (- Int
decrement)
               Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Int -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Int -> Event m ()
updateStorageUseCount Storage m
r Int
1
               Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Int -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Int -> Event m ()
updateStorageUsedContent Storage m
r Int
decrement
               Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Int -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Int -> Event m ()
updateStorageUtilisationCount Storage m
r Int
decrement
               Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ ContParams m () -> () -> Event m ()
forall (m :: * -> *) a.
MonadDES m =>
ContParams m a -> a -> Event m ()
resumeCont ContParams m ()
c ()

-- | Leave the storage.
leaveStorage :: MonadDES m
                => Storage m
                -- ^ the storage to leave
                -> Int
                -- ^ the content increment
                -> Process m ()
{-# INLINABLE leaveStorage #-}
leaveStorage :: Storage m -> Int -> Process m ()
leaveStorage Storage m
r Int
increment =
  (ProcessId m -> Cont m ()) -> Process m ()
forall (m :: * -> *) a. (ProcessId m -> Cont m a) -> Process m a
Process ((ProcessId m -> Cont m ()) -> Process m ())
-> (ProcessId m -> Cont m ()) -> Process m ()
forall a b. (a -> b) -> a -> b
$ \ProcessId m
_ ->
  (ContParams m () -> Event m ()) -> Cont m ()
forall (m :: * -> *) a. (ContParams m a -> Event m ()) -> Cont m a
Cont ((ContParams m () -> Event m ()) -> Cont m ())
-> (ContParams m () -> Event m ()) -> Cont m ()
forall a b. (a -> b) -> a -> b
$ \ContParams m ()
c ->
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Int -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Int -> Event m ()
leaveStorageWithinEvent Storage m
r Int
increment
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ ContParams m () -> () -> Event m ()
forall (m :: * -> *) a.
MonadDES m =>
ContParams m a -> a -> Event m ()
resumeCont ContParams m ()
c ()

-- | Leave the storage.
leaveStorageWithinEvent :: MonadDES m
                           => Storage m
                           -- ^ the storage to leave
                           -> Int
                           -- ^ the content increment
                           -> Event m ()
{-# INLINABLE leaveStorageWithinEvent #-}
leaveStorageWithinEvent :: Storage m -> Int -> Event m ()
leaveStorageWithinEvent Storage m
r Int
increment =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do let t :: Double
t = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Int -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Int -> Event m ()
updateStorageUtilisationCount Storage m
r (- Int
increment)
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Int -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Int -> Event m ()
updateStorageContent Storage m
r Int
increment
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Double -> Event m () -> Event m ()
forall (m :: * -> *).
EventQueueing m =>
Double -> Event m () -> Event m ()
enqueueEvent Double
t (Event m () -> Event m ()) -> Event m () -> Event m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Event m ()
tryEnterStorage Storage m
r

-- | Try to enter the storage.
tryEnterStorage :: MonadDES m => Storage m -> Event m ()
{-# INLINABLE tryEnterStorage #-}
tryEnterStorage :: Storage m -> Event m ()
tryEnterStorage Storage m
r =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do let t :: Double
t = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Int
a <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageContentRef Storage m
r)
     if Int
a Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
       then Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Event m ()
letEnterStorage Storage m
r
       else () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | Let enter the storage.
letEnterStorage :: MonadDES m => Storage m -> Event m ()
{-# INLINABLE letEnterStorage #-}
letEnterStorage :: Storage m -> Event m ()
letEnterStorage Storage m
r =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do let t :: Double
t = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Int
a <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageContentRef Storage m
r)
     Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
a Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Storage m -> Int
forall (m :: * -> *). Storage m -> Int
storageCapacity Storage m
r) (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SimulationRetry -> m ()
forall (m :: * -> *) e a.
(MonadException m, Exception e) =>
e -> m a
throwComp (SimulationRetry -> m ()) -> SimulationRetry -> m ()
forall a b. (a -> b) -> a -> b
$
       String -> SimulationRetry
SimulationRetry (String -> SimulationRetry) -> String -> SimulationRetry
forall a b. (a -> b) -> a -> b
$
       String
"The storage content cannot exceed the limited capacity: leaveStorage'"
     Maybe (StorageDelayedItem m)
x <- Point m
-> Event m (Maybe (StorageDelayedItem m))
-> m (Maybe (StorageDelayedItem m))
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (Maybe (StorageDelayedItem m))
 -> m (Maybe (StorageDelayedItem m)))
-> Event m (Maybe (StorageDelayedItem m))
-> m (Maybe (StorageDelayedItem m))
forall a b. (a -> b) -> a -> b
$
          StrategyQueue m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
-> (StorageDelayedItem m -> Bool)
-> Event m (Maybe (StorageDelayedItem m))
forall (m :: * -> *) s a.
DeletingQueueStrategy m s =>
StrategyQueue m s a -> (a -> Bool) -> Event m (Maybe a)
strategyQueueDeleteBy
          (Storage m
-> StrategyQueue
     m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
forall (m :: * -> *).
Storage m
-> StrategyQueue
     m (TransactQueueStrategy FCFS) (StorageDelayedItem m)
storageDelayChain Storage m
r)
          (\StorageDelayedItem m
i -> StorageDelayedItem m -> Int
forall (m :: * -> *). StorageDelayedItem m -> Int
delayedItemDecrement StorageDelayedItem m
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
a)
     case Maybe (StorageDelayedItem m)
x of
       Maybe (StorageDelayedItem m)
Nothing -> () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
       Just (StorageDelayedItem Double
t0 Int
decrement0 FrozenCont m ()
c0) ->
         do Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Int -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Int -> Event m ()
updateStorageQueueCount Storage m
r (-Int
1)
            Maybe (ContParams m ())
c <- Point m
-> Event m (Maybe (ContParams m ())) -> m (Maybe (ContParams m ()))
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m (Maybe (ContParams m ())) -> m (Maybe (ContParams m ())))
-> Event m (Maybe (ContParams m ())) -> m (Maybe (ContParams m ()))
forall a b. (a -> b) -> a -> b
$ FrozenCont m () -> Event m (Maybe (ContParams m ()))
forall (m :: * -> *) a.
FrozenCont m a -> Event m (Maybe (ContParams m a))
unfreezeCont FrozenCont m ()
c0
            case Maybe (ContParams m ())
c of
              Maybe (ContParams m ())
Nothing ->
                Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Event m ()
letEnterStorage Storage m
r
              Just ContParams m ()
c ->
                do Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Int -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Int -> Event m ()
updateStorageContent Storage m
r (- Int
decrement0)
                   Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Double -> Event m ()
forall (m :: * -> *).
MonadDES m =>
Storage m -> Double -> Event m ()
updateStorageWaitTime Storage m
r (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0)
                   Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Int -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Int -> Event m ()
updateStorageUtilisationCount Storage m
r Int
decrement0
                   Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Int -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Int -> Event m ()
updateStorageUseCount Storage m
r Int
1
                   Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Storage m -> Int -> Event m ()
forall (m :: * -> *). MonadDES m => Storage m -> Int -> Event m ()
updateStorageUsedContent Storage m
r Int
decrement0
                   Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Double -> Event m () -> Event m ()
forall (m :: * -> *).
EventQueueing m =>
Double -> Event m () -> Event m ()
enqueueEvent Double
t (Event m () -> Event m ()) -> Event m () -> Event m ()
forall a b. (a -> b) -> a -> b
$ ContParams m () -> () -> Event m ()
forall (m :: * -> *) a.
MonadDES m =>
ContParams m a -> a -> Event m ()
reenterCont ContParams m ()
c ()

-- | Signal triggered when one of the storage counters changes.
storageChanged_ :: MonadDES m => Storage m -> Signal m ()
{-# INLINABLE storageChanged_ #-}
storageChanged_ :: Storage m -> Signal m ()
storageChanged_ Storage m
r =
  Storage m -> Signal m ()
forall (m :: * -> *). MonadDES m => Storage m -> Signal m ()
storageContentChanged_ Storage m
r Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  Storage m -> Signal m ()
forall (m :: * -> *). MonadDES m => Storage m -> Signal m ()
storageUsedContentChanged_ Storage m
r Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  Storage m -> Signal m ()
forall (m :: * -> *). MonadDES m => Storage m -> Signal m ()
storageUtilisationCountChanged_ Storage m
r Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  Storage m -> Signal m ()
forall (m :: * -> *). MonadDES m => Storage m -> Signal m ()
storageQueueCountChanged_ Storage m
r

-- | Update the storage content and its statistics.
updateStorageContent :: MonadDES m => Storage m -> Int -> Event m ()
{-# INLINABLE updateStorageContent #-}
updateStorageContent :: Storage m -> Int -> Event m ()
updateStorageContent Storage m
r Int
delta =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Int
a <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageContentRef Storage m
r)
     let a' :: Int
a' = Int
a Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
delta
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m Int -> Int -> Event m ()
forall (m :: * -> *) a. MonadDES m => Ref m a -> a -> Event m ()
writeRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageContentRef Storage m
r) Int
a'
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m (TimingStats Int)
-> (TimingStats Int -> TimingStats Int) -> Event m ()
forall (m :: * -> *) a.
MonadDES m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Storage m -> Ref m (TimingStats Int)
forall (m :: * -> *). Storage m -> Ref m (TimingStats Int)
storageContentStatsRef Storage m
r) ((TimingStats Int -> TimingStats Int) -> Event m ())
-> (TimingStats Int -> TimingStats Int) -> Event m ()
forall a b. (a -> b) -> a -> b
$
       Double -> Int -> TimingStats Int -> TimingStats Int
forall a.
TimingData a =>
Double -> a -> TimingStats a -> TimingStats a
addTimingStats (Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p) Int
a'
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m Int -> Int -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Storage m -> SignalSource m Int
forall (m :: * -> *). Storage m -> SignalSource m Int
storageContentSource Storage m
r) Int
a'

-- | Update the storage use count.
updateStorageUseCount :: MonadDES m => Storage m -> Int -> Event m ()
{-# INLINABLE updateStorageUseCount #-}
updateStorageUseCount :: Storage m -> Int -> Event m ()
updateStorageUseCount Storage m
r Int
delta =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Int
a <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageUseCountRef Storage m
r)
     let a' :: Int
a' = Int
a Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
delta
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m Int -> Int -> Event m ()
forall (m :: * -> *) a. MonadDES m => Ref m a -> a -> Event m ()
writeRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageUseCountRef Storage m
r) Int
a'
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m Int -> Int -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Storage m -> SignalSource m Int
forall (m :: * -> *). Storage m -> SignalSource m Int
storageUseCountSource Storage m
r) Int
a'

-- | Update the storage used content.
updateStorageUsedContent :: MonadDES m => Storage m -> Int -> Event m ()
{-# INLINABLE updateStorageUsedContent #-}
updateStorageUsedContent :: Storage m -> Int -> Event m ()
updateStorageUsedContent Storage m
r Int
delta =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Int
a <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageUsedContentRef Storage m
r)
     let a' :: Int
a' = Int
a Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
delta
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m Int -> Int -> Event m ()
forall (m :: * -> *) a. MonadDES m => Ref m a -> a -> Event m ()
writeRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageUsedContentRef Storage m
r) Int
a'
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m Int -> Int -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Storage m -> SignalSource m Int
forall (m :: * -> *). Storage m -> SignalSource m Int
storageUsedContentSource Storage m
r) Int
a'

-- | Update the storage queue length and its statistics.
updateStorageQueueCount :: MonadDES m => Storage m -> Int -> Event m ()
{-# INLINABLE updateStorageQueueCount #-}
updateStorageQueueCount :: Storage m -> Int -> Event m ()
updateStorageQueueCount Storage m
r Int
delta =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Int
a <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageQueueCountRef Storage m
r)
     let a' :: Int
a' = Int
a Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
delta
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m Int -> Int -> Event m ()
forall (m :: * -> *) a. MonadDES m => Ref m a -> a -> Event m ()
writeRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageQueueCountRef Storage m
r) Int
a'
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m (TimingStats Int)
-> (TimingStats Int -> TimingStats Int) -> Event m ()
forall (m :: * -> *) a.
MonadDES m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Storage m -> Ref m (TimingStats Int)
forall (m :: * -> *). Storage m -> Ref m (TimingStats Int)
storageQueueCountStatsRef Storage m
r) ((TimingStats Int -> TimingStats Int) -> Event m ())
-> (TimingStats Int -> TimingStats Int) -> Event m ()
forall a b. (a -> b) -> a -> b
$
       Double -> Int -> TimingStats Int -> TimingStats Int
forall a.
TimingData a =>
Double -> a -> TimingStats a -> TimingStats a
addTimingStats (Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p) Int
a'
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m Int -> Int -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Storage m -> SignalSource m Int
forall (m :: * -> *). Storage m -> SignalSource m Int
storageQueueCountSource Storage m
r) Int
a'

-- | Update the storage utilisation count and its statistics.
updateStorageUtilisationCount :: MonadDES m => Storage m -> Int -> Event m ()
{-# INLINABLE updateStorageUtilisationCount #-}
updateStorageUtilisationCount :: Storage m -> Int -> Event m ()
updateStorageUtilisationCount Storage m
r Int
delta =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Int
a <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageUtilisationCountRef Storage m
r)
     let a' :: Int
a' = Int
a Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
delta
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m Int -> Int -> Event m ()
forall (m :: * -> *) a. MonadDES m => Ref m a -> a -> Event m ()
writeRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageUtilisationCountRef Storage m
r) Int
a'
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m (TimingStats Int)
-> (TimingStats Int -> TimingStats Int) -> Event m ()
forall (m :: * -> *) a.
MonadDES m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Storage m -> Ref m (TimingStats Int)
forall (m :: * -> *). Storage m -> Ref m (TimingStats Int)
storageUtilisationCountStatsRef Storage m
r) ((TimingStats Int -> TimingStats Int) -> Event m ())
-> (TimingStats Int -> TimingStats Int) -> Event m ()
forall a b. (a -> b) -> a -> b
$
       Double -> Int -> TimingStats Int -> TimingStats Int
forall a.
TimingData a =>
Double -> a -> TimingStats a -> TimingStats a
addTimingStats (Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p) Int
a'
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m Int -> Int -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Storage m -> SignalSource m Int
forall (m :: * -> *). Storage m -> SignalSource m Int
storageUtilisationCountSource Storage m
r) Int
a'

-- | Update the storage wait time and its statistics.
updateStorageWaitTime :: MonadDES m => Storage m -> Double -> Event m ()
{-# INLINABLE updateStorageWaitTime #-}
updateStorageWaitTime :: Storage m -> Double -> Event m ()
updateStorageWaitTime Storage m
r Double
delta =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Double
a <- Point m -> Event m Double -> m Double
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Double -> m Double) -> Event m Double -> m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Double
forall (m :: * -> *). Storage m -> Ref m Double
storageTotalWaitTimeRef Storage m
r)
     let a' :: Double
a' = Double
a Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
delta
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m Double -> Double -> Event m ()
forall (m :: * -> *) a. MonadDES m => Ref m a -> a -> Event m ()
writeRef (Storage m -> Ref m Double
forall (m :: * -> *). Storage m -> Ref m Double
storageTotalWaitTimeRef Storage m
r) Double
a'
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       Ref m (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall (m :: * -> *) a.
MonadDES m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Storage m -> Ref m (SamplingStats Double)
forall (m :: * -> *). Storage m -> Ref m (SamplingStats Double)
storageWaitTimeRef Storage m
r) ((SamplingStats Double -> SamplingStats Double) -> Event m ())
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall a b. (a -> b) -> a -> b
$
       Double -> SamplingStats Double -> SamplingStats Double
forall a. SamplingData a => a -> SamplingStats a -> SamplingStats a
addSamplingStats Double
delta
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m () -> () -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Storage m -> SignalSource m ()
forall (m :: * -> *). Storage m -> SignalSource m ()
storageWaitTimeSource Storage m
r) ()

-- | Reset the statistics.
resetStorage :: MonadDES m => Storage m -> Event m ()
{-# INLINABLE resetStorage #-}
resetStorage :: Storage m -> Event m ()
resetStorage Storage m
r =
  (Point m -> m ()) -> Event m ()
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ()) -> Event m ())
-> (Point m -> m ()) -> Event m ()
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do let t :: Double
t = Point m -> Double
forall (m :: * -> *). Point m -> Double
pointTime Point m
p
     Int
content <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageContentRef Storage m
r)
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m (TimingStats Int) -> TimingStats Int -> Event m ()
forall (m :: * -> *) a. MonadDES m => Ref m a -> a -> Event m ()
writeRef (Storage m -> Ref m (TimingStats Int)
forall (m :: * -> *). Storage m -> Ref m (TimingStats Int)
storageContentStatsRef Storage m
r) (TimingStats Int -> Event m ()) -> TimingStats Int -> Event m ()
forall a b. (a -> b) -> a -> b
$
       Double -> Int -> TimingStats Int
forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t Int
content
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Int -> Event m ()
forall (m :: * -> *) a. MonadDES m => Ref m a -> a -> Event m ()
writeRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageUseCountRef Storage m
r) Int
0
     let usedContent :: Int
usedContent = Storage m -> Int
forall (m :: * -> *). Storage m -> Int
storageCapacity Storage m
r Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
content
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Int -> Event m ()
forall (m :: * -> *) a. MonadDES m => Ref m a -> a -> Event m ()
writeRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageUsedContentRef Storage m
r) Int
usedContent
     Int
utilCount <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageUtilisationCountRef Storage m
r)
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m (TimingStats Int) -> TimingStats Int -> Event m ()
forall (m :: * -> *) a. MonadDES m => Ref m a -> a -> Event m ()
writeRef (Storage m -> Ref m (TimingStats Int)
forall (m :: * -> *). Storage m -> Ref m (TimingStats Int)
storageUtilisationCountStatsRef Storage m
r) (TimingStats Int -> Event m ()) -> TimingStats Int -> Event m ()
forall a b. (a -> b) -> a -> b
$
       Double -> Int -> TimingStats Int
forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t Int
utilCount
     Int
queueCount <- Point m -> Event m Int -> m Int
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m Int -> m Int) -> Event m Int -> m Int
forall a b. (a -> b) -> a -> b
$ Ref m Int -> Event m Int
forall (m :: * -> *) a. MonadDES m => Ref m a -> Event m a
readRef (Storage m -> Ref m Int
forall (m :: * -> *). Storage m -> Ref m Int
storageQueueCountRef Storage m
r)
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m (TimingStats Int) -> TimingStats Int -> Event m ()
forall (m :: * -> *) a. MonadDES m => Ref m a -> a -> Event m ()
writeRef (Storage m -> Ref m (TimingStats Int)
forall (m :: * -> *). Storage m -> Ref m (TimingStats Int)
storageQueueCountStatsRef Storage m
r) (TimingStats Int -> Event m ()) -> TimingStats Int -> Event m ()
forall a b. (a -> b) -> a -> b
$
       Double -> Int -> TimingStats Int
forall a. TimingData a => Double -> a -> TimingStats a
returnTimingStats Double
t Int
queueCount
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Double -> Event m ()
forall (m :: * -> *) a. MonadDES m => Ref m a -> a -> Event m ()
writeRef (Storage m -> Ref m Double
forall (m :: * -> *). Storage m -> Ref m Double
storageTotalWaitTimeRef Storage m
r) Double
0
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$ Ref m (SamplingStats Double) -> SamplingStats Double -> Event m ()
forall (m :: * -> *) a. MonadDES m => Ref m a -> a -> Event m ()
writeRef (Storage m -> Ref m (SamplingStats Double)
forall (m :: * -> *). Storage m -> Ref m (SamplingStats Double)
storageWaitTimeRef Storage m
r) SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m Int -> Int -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Storage m -> SignalSource m Int
forall (m :: * -> *). Storage m -> SignalSource m Int
storageUseCountSource Storage m
r) Int
0
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m Int -> Int -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Storage m -> SignalSource m Int
forall (m :: * -> *). Storage m -> SignalSource m Int
storageUsedContentSource Storage m
r) Int
usedContent
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m Int -> Int -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Storage m -> SignalSource m Int
forall (m :: * -> *). Storage m -> SignalSource m Int
storageUtilisationCountSource Storage m
r) Int
utilCount
     Point m -> Event m () -> m ()
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m () -> m ()) -> Event m () -> m ()
forall a b. (a -> b) -> a -> b
$
       SignalSource m () -> () -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Storage m -> SignalSource m ()
forall (m :: * -> *). Storage m -> SignalSource m ()
storageWaitTimeSource Storage m
r) ()