-- |
-- Module     : Simulation.Aivika.Trans.Server
-- Copyright  : Copyright (c) 2009-2017, David Sorokin <david.sorokin@gmail.com>
-- License    : BSD3
-- Maintainer : David Sorokin <david.sorokin@gmail.com>
-- Stability  : experimental
-- Tested with: GHC 8.0.1
--
-- It models the server that prodives a service.
module Simulation.Aivika.Trans.Server
       (-- * Server
        Server,
        newServer,
        newStateServer,
        newPreemptibleServer,
        newPreemptibleStateServer,
        -- * Processing
        serverProcessor,
        -- * Server Properties and Activities
        serverInitState,
        serverState,
        serverTotalInputWaitTime,
        serverTotalProcessingTime,
        serverTotalOutputWaitTime,
        serverTotalPreemptionTime,
        serverInputWaitTime,
        serverProcessingTime,
        serverOutputWaitTime,
        serverPreemptionTime,
        serverInputWaitFactor,
        serverProcessingFactor,
        serverOutputWaitFactor,
        serverPreemptionFactor,
        -- * Statistics Reset
        resetServer,
        -- * Summary
        serverSummary,
        -- * Derived Signals for Properties
        serverStateChanged,
        serverStateChanged_,
        serverTotalInputWaitTimeChanged,
        serverTotalInputWaitTimeChanged_,
        serverTotalProcessingTimeChanged,
        serverTotalProcessingTimeChanged_,
        serverTotalOutputWaitTimeChanged,
        serverTotalOutputWaitTimeChanged_,
        serverTotalPreemptionTimeChanged,
        serverTotalPreemptionTimeChanged_,
        serverInputWaitTimeChanged,
        serverInputWaitTimeChanged_,
        serverProcessingTimeChanged,
        serverProcessingTimeChanged_,
        serverOutputWaitTimeChanged,
        serverOutputWaitTimeChanged_,
        serverPreemptionTimeChanged,
        serverPreemptionTimeChanged_,
        serverInputWaitFactorChanged,
        serverInputWaitFactorChanged_,
        serverProcessingFactorChanged,
        serverProcessingFactorChanged_,
        serverOutputWaitFactorChanged,
        serverOutputWaitFactorChanged_,
        serverPreemptionFactorChanged,
        serverPreemptionFactorChanged_,
        -- * Basic Signals
        serverInputReceived,
        serverTaskPreemptionBeginning,
        serverTaskPreemptionEnding,
        serverTaskProcessed,
        serverOutputProvided,
        -- * Overall Signal
        serverChanged_) where

import Data.Monoid

import Control.Monad
import Control.Arrow

import Simulation.Aivika.Trans.Ref.Base
import Simulation.Aivika.Trans.DES
import Simulation.Aivika.Trans.Parameter
import Simulation.Aivika.Trans.Simulation
import Simulation.Aivika.Trans.Dynamics
import Simulation.Aivika.Trans.Internal.Specs
import Simulation.Aivika.Trans.Internal.Event
import Simulation.Aivika.Trans.Signal
import Simulation.Aivika.Trans.Cont
import Simulation.Aivika.Trans.Process
import Simulation.Aivika.Trans.Processor
import Simulation.Aivika.Trans.Stream
import Simulation.Aivika.Trans.Statistics

-- | It models a server that takes @a@ and provides @b@ having state @s@ within underlying computation @m@.
data Server m s a b =
  Server { Server m s a b -> s
serverInitState :: s,
           -- ^ The initial state of the server.
           Server m s a b -> Ref m s
serverStateRef :: Ref m s,
           -- ^ The current state of the server.
           Server m s a b -> s -> a -> Process m (s, b)
serverProcess :: s -> a -> Process m (s, b),
           -- ^ Provide @b@ by specified @a@.
           Server m s a b -> Bool
serverProcessPreemptible :: Bool,
           -- ^ Whether the process can be preempted.
           Server m s a b -> Ref m Double
serverTotalInputWaitTimeRef :: Ref m Double,
           -- ^ The counted total time spent in awating the input.
           Server m s a b -> Ref m Double
serverTotalProcessingTimeRef :: Ref m Double,
           -- ^ The counted total time spent to process the input and prepare the output.
           Server m s a b -> Ref m Double
serverTotalOutputWaitTimeRef :: Ref m Double,
           -- ^ The counted total time spent for delivering the output.
           Server m s a b -> Ref m Double
serverTotalPreemptionTimeRef :: Ref m Double,
           -- ^ The counted total time spent being preempted and waiting for the proceeding. 
           Server m s a b -> Ref m (SamplingStats Double)
serverInputWaitTimeRef :: Ref m (SamplingStats Double),
           -- ^ The statistics for the time spent in awaiting the input.
           Server m s a b -> Ref m (SamplingStats Double)
serverProcessingTimeRef :: Ref m (SamplingStats Double),
           -- ^ The statistics for the time spent to process the input and prepare the output.
           Server m s a b -> Ref m (SamplingStats Double)
serverOutputWaitTimeRef :: Ref m (SamplingStats Double),
           -- ^ The statistics for the time spent for delivering the output.
           Server m s a b -> Ref m (SamplingStats Double)
serverPreemptionTimeRef :: Ref m (SamplingStats Double),
           -- ^ The statistics for the time spent being preempted.
           Server m s a b -> SignalSource m a
serverInputReceivedSource :: SignalSource m a,
           -- ^ A signal raised when the server recieves a new input to process.
           Server m s a b -> SignalSource m a
serverTaskPreemptionBeginningSource :: SignalSource m a,
           -- ^ A signal raised when the task was preempted.
           Server m s a b -> SignalSource m a
serverTaskPreemptionEndingSource :: SignalSource m a,
           -- ^ A signal raised when the task was proceeded after it had been preempted earlier.
           Server m s a b -> SignalSource m (a, b)
serverTaskProcessedSource :: SignalSource m (a, b),
           -- ^ A signal raised when the input is processed and
           -- the output is prepared for deliverying.
           Server m s a b -> SignalSource m (a, b)
serverOutputProvidedSource :: SignalSource m (a, b)
           -- ^ A signal raised when the server has supplied the output.
         }

-- | Create a new server that can provide output @b@ by input @a@.
--
-- By default, it is assumed that the server process cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newServer :: MonadDES m
             => (a -> Process m b)
             -- ^ provide an output by the specified input
             -> Simulation m (Server m () a b)
{-# INLINABLE newServer #-}
newServer :: (a -> Process m b) -> Simulation m (Server m () a b)
newServer = Bool -> (a -> Process m b) -> Simulation m (Server m () a b)
forall (m :: * -> *) a b.
MonadDES m =>
Bool -> (a -> Process m b) -> Simulation m (Server m () a b)
newPreemptibleServer Bool
False

-- | Create a new server that can provide output @b@ by input @a@
-- starting from state @s@.
--
-- By default, it is assumed that the server process cannot be preempted,
-- because the handling of possible task preemption is rather costly
-- operation.
newStateServer :: MonadDES m
                  => (s -> a -> Process m (s, b))
                  -- ^ provide a new state and output by the specified 
                  -- old state and input
                  -> s
                  -- ^ the initial state
                  -> Simulation m (Server m s a b)
{-# INLINABLE newStateServer #-}
newStateServer :: (s -> a -> Process m (s, b)) -> s -> Simulation m (Server m s a b)
newStateServer = Bool
-> (s -> a -> Process m (s, b))
-> s
-> Simulation m (Server m s a b)
forall (m :: * -> *) s a b.
MonadDES m =>
Bool
-> (s -> a -> Process m (s, b))
-> s
-> Simulation m (Server m s a b)
newPreemptibleStateServer Bool
False

-- | Create a new preemptible server that can provide output @b@ by input @a@.
newPreemptibleServer :: MonadDES m
                        => Bool
                        -- ^ whether the server process can be preempted
                        -> (a -> Process m b)
                        -- ^ provide an output by the specified input
                        -> Simulation m (Server m () a b)
{-# INLINABLE newPreemptibleServer #-}
newPreemptibleServer :: Bool -> (a -> Process m b) -> Simulation m (Server m () a b)
newPreemptibleServer Bool
preemptible a -> Process m b
provide =
  ((() -> a -> Process m ((), b))
 -> () -> Simulation m (Server m () a b))
-> ()
-> (() -> a -> Process m ((), b))
-> Simulation m (Server m () a b)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Bool
-> (() -> a -> Process m ((), b))
-> ()
-> Simulation m (Server m () a b)
forall (m :: * -> *) s a b.
MonadDES m =>
Bool
-> (s -> a -> Process m (s, b))
-> s
-> Simulation m (Server m s a b)
newPreemptibleStateServer Bool
preemptible) () ((() -> a -> Process m ((), b)) -> Simulation m (Server m () a b))
-> (() -> a -> Process m ((), b)) -> Simulation m (Server m () a b)
forall a b. (a -> b) -> a -> b
$ \()
s a
a ->
  do b
b <- a -> Process m b
provide a
a
     ((), b) -> Process m ((), b)
forall (m :: * -> *) a. Monad m => a -> m a
return (()
s, b
b)

-- | Create a new preemptible server that can provide output @b@ by input @a@
-- starting from state @s@.
newPreemptibleStateServer :: MonadDES m
                             => Bool
                             -- ^ whether the server process can be preempted
                             -> (s -> a -> Process m (s, b))
                             -- ^ provide a new state and output by the specified 
                             -- old state and input
                             -> s
                             -- ^ the initial state
                             -> Simulation m (Server m s a b)
{-# INLINABLE newPreemptibleStateServer #-}
newPreemptibleStateServer :: Bool
-> (s -> a -> Process m (s, b))
-> s
-> Simulation m (Server m s a b)
newPreemptibleStateServer Bool
preemptible s -> a -> Process m (s, b)
provide s
state =
  do Ref m s
r0 <- s -> Simulation m (Ref m s)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef s
state
     Ref m Double
r1 <- Double -> Simulation m (Ref m Double)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
0
     Ref m Double
r2 <- Double -> Simulation m (Ref m Double)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
0
     Ref m Double
r3 <- Double -> Simulation m (Ref m Double)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
0
     Ref m Double
r4 <- Double -> Simulation m (Ref m Double)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
0
     Ref m (SamplingStats Double)
r5 <- SamplingStats Double -> Simulation m (Ref m (SamplingStats Double))
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
     Ref m (SamplingStats Double)
r6 <- SamplingStats Double -> Simulation m (Ref m (SamplingStats Double))
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
     Ref m (SamplingStats Double)
r7 <- SamplingStats Double -> Simulation m (Ref m (SamplingStats Double))
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
     Ref m (SamplingStats Double)
r8 <- SamplingStats Double -> Simulation m (Ref m (SamplingStats Double))
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef SamplingStats Double
forall a. SamplingData a => SamplingStats a
emptySamplingStats
     SignalSource m a
s1 <- Simulation m (SignalSource m a)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     SignalSource m a
s2 <- Simulation m (SignalSource m a)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     SignalSource m a
s3 <- Simulation m (SignalSource m a)
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     SignalSource m (a, b)
s4 <- Simulation m (SignalSource m (a, b))
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     SignalSource m (a, b)
s5 <- Simulation m (SignalSource m (a, b))
forall (m :: * -> *) a.
MonadDES m =>
Simulation m (SignalSource m a)
newSignalSource
     let server :: Server m s a b
server = Server :: forall (m :: * -> *) s a b.
s
-> Ref m s
-> (s -> a -> Process m (s, b))
-> Bool
-> Ref m Double
-> Ref m Double
-> Ref m Double
-> Ref m Double
-> Ref m (SamplingStats Double)
-> Ref m (SamplingStats Double)
-> Ref m (SamplingStats Double)
-> Ref m (SamplingStats Double)
-> SignalSource m a
-> SignalSource m a
-> SignalSource m a
-> SignalSource m (a, b)
-> SignalSource m (a, b)
-> Server m s a b
Server { serverInitState :: s
serverInitState = s
state,
                           serverStateRef :: Ref m s
serverStateRef = Ref m s
r0,
                           serverProcess :: s -> a -> Process m (s, b)
serverProcess = s -> a -> Process m (s, b)
provide,
                           serverProcessPreemptible :: Bool
serverProcessPreemptible = Bool
preemptible,
                           serverTotalInputWaitTimeRef :: Ref m Double
serverTotalInputWaitTimeRef = Ref m Double
r1,
                           serverTotalProcessingTimeRef :: Ref m Double
serverTotalProcessingTimeRef = Ref m Double
r2,
                           serverTotalOutputWaitTimeRef :: Ref m Double
serverTotalOutputWaitTimeRef = Ref m Double
r3,
                           serverTotalPreemptionTimeRef :: Ref m Double
serverTotalPreemptionTimeRef = Ref m Double
r4,
                           serverInputWaitTimeRef :: Ref m (SamplingStats Double)
serverInputWaitTimeRef = Ref m (SamplingStats Double)
r5,
                           serverProcessingTimeRef :: Ref m (SamplingStats Double)
serverProcessingTimeRef = Ref m (SamplingStats Double)
r6,
                           serverOutputWaitTimeRef :: Ref m (SamplingStats Double)
serverOutputWaitTimeRef = Ref m (SamplingStats Double)
r7,
                           serverPreemptionTimeRef :: Ref m (SamplingStats Double)
serverPreemptionTimeRef = Ref m (SamplingStats Double)
r8,
                           serverInputReceivedSource :: SignalSource m a
serverInputReceivedSource = SignalSource m a
s1,
                           serverTaskPreemptionBeginningSource :: SignalSource m a
serverTaskPreemptionBeginningSource = SignalSource m a
s2,
                           serverTaskPreemptionEndingSource :: SignalSource m a
serverTaskPreemptionEndingSource = SignalSource m a
s3,
                           serverTaskProcessedSource :: SignalSource m (a, b)
serverTaskProcessedSource = SignalSource m (a, b)
s4,
                           serverOutputProvidedSource :: SignalSource m (a, b)
serverOutputProvidedSource = SignalSource m (a, b)
s5 }
     Server m s a b -> Simulation m (Server m s a b)
forall (m :: * -> *) a. Monad m => a -> m a
return Server m s a b
server

-- | Return a processor for the specified server.
--
-- The processor updates the internal state of the server. The usual case is when 
-- the processor is applied only once in a chain of data processing. Otherwise; 
-- every time the processor is used, the state of the server changes. Sometimes 
-- it can be indeed useful if you want to aggregate the statistics for different 
-- servers simultaneously, but it would be more preferable to avoid this.
--
-- If you connect different server processors returned by this function in a chain 
-- with help of '>>>' or other category combinator then this chain will act as one 
-- whole, where the first server will take a new task only after the last server 
-- finishes its current task and requests for the next one from the previous processor 
-- in the chain. This is not always that thing you might need.
--
-- To model a sequence of the server processors working independently, you
-- should use the 'processorSeq' function which separates the processors with help of
-- the 'prefetchProcessor' that plays a role of a small one-place buffer in that case.
--
-- The queue processors usually have the prefetching capabilities per se, where
-- the items are already stored in the queue. Therefore, the server processor
-- should not be prefetched if it is connected directly to the queue processor.
serverProcessor :: MonadDES m => Server m s a b -> Processor m a b
{-# INLINABLE serverProcessor #-}
serverProcessor :: Server m s a b -> Processor m a b
serverProcessor Server m s a b
server =
  (Stream m a -> Stream m b) -> Processor m a b
forall (m :: * -> *) a b.
(Stream m a -> Stream m b) -> Processor m a b
Processor ((Stream m a -> Stream m b) -> Processor m a b)
-> (Stream m a -> Stream m b) -> Processor m a b
forall a b. (a -> b) -> a -> b
$ \Stream m a
xs -> s -> Maybe (Double, a, b) -> Stream m a -> Stream m b
loop (Server m s a b -> s
forall (m :: * -> *) s a b. Server m s a b -> s
serverInitState Server m s a b
server) Maybe (Double, a, b)
forall a. Maybe a
Nothing Stream m a
xs
  where
    loop :: s -> Maybe (Double, a, b) -> Stream m a -> Stream m b
loop s
s Maybe (Double, a, b)
r Stream m a
xs =
      Process m (b, Stream m b) -> Stream m b
forall (m :: * -> *) a. Process m (a, Stream m a) -> Stream m a
Cons (Process m (b, Stream m b) -> Stream m b)
-> Process m (b, Stream m b) -> Stream m b
forall a b. (a -> b) -> a -> b
$
      do Double
t0 <- Dynamics m Double -> Process m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
         Event m () -> Process m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m () -> Process m ()) -> Event m () -> Process m ()
forall a b. (a -> b) -> a -> b
$
           case Maybe (Double, a, b)
r of
             Maybe (Double, a, b)
Nothing -> () -> Event m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
             Just (Double
t', a
a', b
b') ->
               do Ref m Double -> (Double -> Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalOutputWaitTimeRef Server m s a b
server) (Double -> Double -> Double
forall a. Num a => a -> a -> a
+ (Double
t0 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t'))
                  Ref m (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverOutputWaitTimeRef Server m s a b
server) ((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
t0 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t')
                  SignalSource m (a, b) -> (a, b) -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Server m s a b -> SignalSource m (a, b)
forall (m :: * -> *) s a b. Server m s a b -> SignalSource m (a, b)
serverOutputProvidedSource Server m s a b
server) (a
a', b
b')
         -- get input
         (a
a, Stream m a
xs') <- Stream m a -> Process m (a, Stream m a)
forall (m :: * -> *) a. Stream m a -> Process m (a, Stream m a)
runStream Stream m a
xs
         Double
t1 <- Dynamics m Double -> Process m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
         Event m () -> Process m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m () -> Process m ()) -> Event m () -> Process m ()
forall a b. (a -> b) -> a -> b
$
           do Ref m Double -> (Double -> Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalInputWaitTimeRef Server m s a b
server) (Double -> Double -> Double
forall a. Num a => a -> a -> a
+ (Double
t1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0))
              Ref m (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverInputWaitTimeRef Server m s a b
server) ((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
t1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t0)
              SignalSource m a -> a -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Server m s a b -> SignalSource m a
forall (m :: * -> *) s a b. Server m s a b -> SignalSource m a
serverInputReceivedSource Server m s a b
server) a
a
         -- provide the service
         (s
s', b
b, Double
dt) <-
           if Server m s a b -> Bool
forall (m :: * -> *) s a b. Server m s a b -> Bool
serverProcessPreemptible Server m s a b
server
           then Server m s a b -> s -> a -> Process m (s, b, Double)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> s -> a -> Process m (s, b, Double)
serverProcessPreempting Server m s a b
server s
s a
a
           else do (s
s', b
b) <- Server m s a b -> s -> a -> Process m (s, b)
forall (m :: * -> *) s a b.
Server m s a b -> s -> a -> Process m (s, b)
serverProcess Server m s a b
server s
s a
a
                   (s, b, Double) -> Process m (s, b, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (s
s', b
b, Double
0)
         Double
t2 <- Dynamics m Double -> Process m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
         Event m () -> Process m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m () -> Process m ()) -> Event m () -> Process m ()
forall a b. (a -> b) -> a -> b
$
           do Ref m s -> s -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Server m s a b -> Ref m s
forall (m :: * -> *) s a b. Server m s a b -> Ref m s
serverStateRef Server m s a b
server) (s -> Event m ()) -> s -> Event m ()
forall a b. (a -> b) -> a -> b
$! s
s'
              Ref m Double -> (Double -> Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalProcessingTimeRef Server m s a b
server) (Double -> Double -> Double
forall a. Num a => a -> a -> a
+ (Double
t2 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
dt))
              Ref m (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverProcessingTimeRef Server m s a b
server) ((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
t2 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
dt)
              SignalSource m (a, b) -> (a, b) -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Server m s a b -> SignalSource m (a, b)
forall (m :: * -> *) s a b. Server m s a b -> SignalSource m (a, b)
serverTaskProcessedSource Server m s a b
server) (a
a, b
b)
         (b, Stream m b) -> Process m (b, Stream m b)
forall (m :: * -> *) a. Monad m => a -> m a
return (b
b, s -> Maybe (Double, a, b) -> Stream m a -> Stream m b
loop s
s' ((Double, a, b) -> Maybe (Double, a, b)
forall a. a -> Maybe a
Just (Double
t2, a
a, b
b)) Stream m a
xs')

-- | Process the input with ability to handle a possible preemption.
serverProcessPreempting :: MonadDES m => Server m s a b -> s -> a -> Process m (s, b, Double)
{-# INLINABLE serverProcessPreempting #-}
serverProcessPreempting :: Server m s a b -> s -> a -> Process m (s, b, Double)
serverProcessPreempting Server m s a b
server s
s a
a =
  do ProcessId m
pid <- Process m (ProcessId m)
forall (m :: * -> *). MonadDES m => Process m (ProcessId m)
processId
     Double
t1  <- Dynamics m Double -> Process m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
     Ref m Double
rs  <- Simulation m (Ref m Double) -> Process m (Ref m Double)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m Double) -> Process m (Ref m Double))
-> Simulation m (Ref m Double) -> Process m (Ref m Double)
forall a b. (a -> b) -> a -> b
$ Double -> Simulation m (Ref m Double)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
0
     Ref m Double
r1  <- Simulation m (Ref m Double) -> Process m (Ref m Double)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
SimulationLift t m =>
Simulation m a -> t m a
liftSimulation (Simulation m (Ref m Double) -> Process m (Ref m Double))
-> Simulation m (Ref m Double) -> Process m (Ref m Double)
forall a b. (a -> b) -> a -> b
$ Double -> Simulation m (Ref m Double)
forall (m :: * -> *) a. MonadRef m => a -> Simulation m (Ref m a)
newRef Double
t1
     DisposableEvent m
h1  <- Event m (DisposableEvent m) -> Process m (DisposableEvent m)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m (DisposableEvent m) -> Process m (DisposableEvent m))
-> Event m (DisposableEvent m) -> Process m (DisposableEvent m)
forall a b. (a -> b) -> a -> b
$
            Signal m () -> (() -> Event m ()) -> Event m (DisposableEvent m)
forall (m :: * -> *) a.
Signal m a -> (a -> Event m ()) -> Event m (DisposableEvent m)
handleSignal (ProcessId m -> Signal m ()
forall (m :: * -> *). MonadDES m => ProcessId m -> Signal m ()
processPreemptionBeginning ProcessId m
pid) ((() -> Event m ()) -> Event m (DisposableEvent m))
-> (() -> Event m ()) -> Event m (DisposableEvent m)
forall a b. (a -> b) -> a -> b
$ \() ->
            do Double
t1 <- Dynamics m Double -> Event m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
               Ref m Double -> Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef Ref m Double
r1 Double
t1
               SignalSource m a -> a -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Server m s a b -> SignalSource m a
forall (m :: * -> *) s a b. Server m s a b -> SignalSource m a
serverTaskPreemptionBeginningSource Server m s a b
server) a
a
     DisposableEvent m
h2  <- Event m (DisposableEvent m) -> Process m (DisposableEvent m)
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m (DisposableEvent m) -> Process m (DisposableEvent m))
-> Event m (DisposableEvent m) -> Process m (DisposableEvent m)
forall a b. (a -> b) -> a -> b
$
            Signal m () -> (() -> Event m ()) -> Event m (DisposableEvent m)
forall (m :: * -> *) a.
Signal m a -> (a -> Event m ()) -> Event m (DisposableEvent m)
handleSignal (ProcessId m -> Signal m ()
forall (m :: * -> *). MonadDES m => ProcessId m -> Signal m ()
processPreemptionEnding ProcessId m
pid) ((() -> Event m ()) -> Event m (DisposableEvent m))
-> (() -> Event m ()) -> Event m (DisposableEvent m)
forall a b. (a -> b) -> a -> b
$ \() ->
            do Double
t1 <- Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef Ref m Double
r1
               Double
t2 <- Dynamics m Double -> Event m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
DynamicsLift t m =>
Dynamics m a -> t m a
liftDynamics Dynamics m Double
forall (m :: * -> *). Monad m => Dynamics m Double
time
               let dt :: Double
dt = Double
t2 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
t1
               Ref m Double -> (Double -> Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef Ref m Double
rs (Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
dt)
               Ref m Double -> (Double -> Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalPreemptionTimeRef Server m s a b
server) (Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
dt)
               Ref m (SamplingStats Double)
-> (SamplingStats Double -> SamplingStats Double) -> Event m ()
forall (m :: * -> *) a.
MonadRef m =>
Ref m a -> (a -> a) -> Event m ()
modifyRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverPreemptionTimeRef Server m s a b
server) ((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
dt
               SignalSource m a -> a -> Event m ()
forall (m :: * -> *) a. SignalSource m a -> a -> Event m ()
triggerSignal (Server m s a b -> SignalSource m a
forall (m :: * -> *) s a b. Server m s a b -> SignalSource m a
serverTaskPreemptionEndingSource Server m s a b
server) a
a 
     let m1 :: Process m (s, b, Double)
m1 =
           do (s
s', b
b) <- Server m s a b -> s -> a -> Process m (s, b)
forall (m :: * -> *) s a b.
Server m s a b -> s -> a -> Process m (s, b)
serverProcess Server m s a b
server s
s a
a
              Double
dt <- Event m Double -> Process m Double
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m Double -> Process m Double)
-> Event m Double -> Process m Double
forall a b. (a -> b) -> a -> b
$ Ref m Double -> Event m Double
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef Ref m Double
rs
              (s, b, Double) -> Process m (s, b, Double)
forall (m :: * -> *) a. Monad m => a -> m a
return (s
s', b
b, Double
dt)
         m2 :: Process m ()
m2 =
           Event m () -> Process m ()
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
EventLift t m =>
Event m a -> t m a
liftEvent (Event m () -> Process m ()) -> Event m () -> Process m ()
forall a b. (a -> b) -> a -> b
$
           do DisposableEvent m -> Event m ()
forall (m :: * -> *). DisposableEvent m -> Event m ()
disposeEvent DisposableEvent m
h1
              DisposableEvent m -> Event m ()
forall (m :: * -> *). DisposableEvent m -> Event m ()
disposeEvent DisposableEvent m
h2
     Process m (s, b, Double)
-> Process m () -> Process m (s, b, Double)
forall (m :: * -> *) a b.
MonadDES m =>
Process m a -> Process m b -> Process m a
finallyProcess Process m (s, b, Double)
m1 Process m ()
m2

-- | Return the current state of the server.
--
-- See also 'serverStateChanged' and 'serverStateChanged_'.
serverState :: MonadDES m => Server m s a b -> Event m s
{-# INLINABLE serverState #-}
serverState :: Server m s a b -> Event m s
serverState Server m s a b
server =
  (Point m -> m s) -> Event m s
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m s) -> Event m s) -> (Point m -> m s) -> Event m s
forall a b. (a -> b) -> a -> b
$ \Point m
p -> Point m -> Event m s -> m s
forall (m :: * -> *) a. Point m -> Event m a -> m a
invokeEvent Point m
p (Event m s -> m s) -> Event m s -> m s
forall a b. (a -> b) -> a -> b
$ Ref m s -> Event m s
forall (m :: * -> *) a. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m s
forall (m :: * -> *) s a b. Server m s a b -> Ref m s
serverStateRef Server m s a b
server)
  
-- | Signal when the 'serverState' property value has changed.
serverStateChanged :: MonadDES m => Server m s a b -> Signal m s
{-# INLINABLE serverStateChanged #-}
serverStateChanged :: Server m s a b -> Signal m s
serverStateChanged Server m s a b
server =
  (() -> Event m s) -> Signal m () -> Signal m s
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m s -> () -> Event m s
forall a b. a -> b -> a
const (Event m s -> () -> Event m s) -> Event m s -> () -> Event m s
forall a b. (a -> b) -> a -> b
$ Server m s a b -> Event m s
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Event m s
serverState Server m s a b
server) (Server m s a b -> Signal m ()
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m ()
serverStateChanged_ Server m s a b
server)
  
-- | Signal when the 'serverState' property value has changed.
serverStateChanged_ :: MonadDES m => Server m s a b -> Signal m ()
{-# INLINABLE serverStateChanged_ #-}
serverStateChanged_ :: Server m s a b -> Signal m ()
serverStateChanged_ Server m s a b
server =
  ((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m (a, b)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m (a, b)
serverTaskProcessed Server m s a b
server)

-- | Return the counted total time when the server was locked while awaiting the input.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'serverTotalInputWaitTimeChanged' and 'serverTotalInputWaitTimeChanged_'.
serverTotalInputWaitTime :: MonadDES m => Server m s a b -> Event m Double
{-# INLINABLE serverTotalInputWaitTime #-}
serverTotalInputWaitTime :: Server m s a b -> Event m Double
serverTotalInputWaitTime Server m s a b
server =
  (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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalInputWaitTimeRef Server m s a b
server)
  
-- | Signal when the 'serverTotalInputWaitTime' property value has changed.
serverTotalInputWaitTimeChanged :: MonadDES m => Server m s a b -> Signal m Double
{-# INLINABLE serverTotalInputWaitTimeChanged #-}
serverTotalInputWaitTimeChanged :: Server m s a b -> Signal m Double
serverTotalInputWaitTimeChanged Server m s a b
server =
  (() -> Event m Double) -> Signal m () -> Signal m Double
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Double -> () -> Event m Double
forall a b. a -> b -> a
const (Event m Double -> () -> Event m Double)
-> Event m Double -> () -> Event m Double
forall a b. (a -> b) -> a -> b
$ Server m s a b -> Event m Double
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Event m Double
serverTotalInputWaitTime Server m s a b
server) (Server m s a b -> Signal m ()
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m ()
serverTotalInputWaitTimeChanged_ Server m s a b
server)
  
-- | Signal when the 'serverTotalInputWaitTime' property value has changed.
serverTotalInputWaitTimeChanged_ :: MonadDES m => Server m s a b -> Signal m ()
{-# INLINABLE serverTotalInputWaitTimeChanged_ #-}
serverTotalInputWaitTimeChanged_ :: Server m s a b -> Signal m ()
serverTotalInputWaitTimeChanged_ Server m s a b
server =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m a
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m a
serverInputReceived Server m s a b
server)

-- | Return the counted total time spent by the server while processing the tasks.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'serverTotalProcessingTimeChanged' and 'serverTotalProcessingTimeChanged_'.
serverTotalProcessingTime :: MonadDES m => Server m s a b -> Event m Double
{-# INLINABLE serverTotalProcessingTime #-}
serverTotalProcessingTime :: Server m s a b -> Event m Double
serverTotalProcessingTime Server m s a b
server =
  (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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalProcessingTimeRef Server m s a b
server)
  
-- | Signal when the 'serverTotalProcessingTime' property value has changed.
serverTotalProcessingTimeChanged :: MonadDES m => Server m s a b -> Signal m Double
{-# INLINABLE serverTotalProcessingTimeChanged #-}
serverTotalProcessingTimeChanged :: Server m s a b -> Signal m Double
serverTotalProcessingTimeChanged Server m s a b
server =
  (() -> Event m Double) -> Signal m () -> Signal m Double
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Double -> () -> Event m Double
forall a b. a -> b -> a
const (Event m Double -> () -> Event m Double)
-> Event m Double -> () -> Event m Double
forall a b. (a -> b) -> a -> b
$ Server m s a b -> Event m Double
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Event m Double
serverTotalProcessingTime Server m s a b
server) (Server m s a b -> Signal m ()
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m ()
serverTotalProcessingTimeChanged_ Server m s a b
server)
  
-- | Signal when the 'serverTotalProcessingTime' property value has changed.
serverTotalProcessingTimeChanged_ :: MonadDES m => Server m s a b -> Signal m ()
{-# INLINABLE serverTotalProcessingTimeChanged_ #-}
serverTotalProcessingTimeChanged_ :: Server m s a b -> Signal m ()
serverTotalProcessingTimeChanged_ Server m s a b
server =
  ((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m (a, b)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m (a, b)
serverTaskProcessed Server m s a b
server)

-- | Return the counted total time when the server was locked while trying
-- to deliver the output.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'serverTotalOutputWaitTimeChanged' and 'serverTotalOutputWaitTimeChanged_'.
serverTotalOutputWaitTime :: MonadDES m => Server m s a b -> Event m Double
{-# INLINABLE serverTotalOutputWaitTime #-}
serverTotalOutputWaitTime :: Server m s a b -> Event m Double
serverTotalOutputWaitTime Server m s a b
server =
  (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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalOutputWaitTimeRef Server m s a b
server)
  
-- | Signal when the 'serverTotalOutputWaitTime' property value has changed.
serverTotalOutputWaitTimeChanged :: MonadDES m => Server m s a b -> Signal m Double
{-# INLINABLE serverTotalOutputWaitTimeChanged #-}
serverTotalOutputWaitTimeChanged :: Server m s a b -> Signal m Double
serverTotalOutputWaitTimeChanged Server m s a b
server =
  (() -> Event m Double) -> Signal m () -> Signal m Double
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Double -> () -> Event m Double
forall a b. a -> b -> a
const (Event m Double -> () -> Event m Double)
-> Event m Double -> () -> Event m Double
forall a b. (a -> b) -> a -> b
$ Server m s a b -> Event m Double
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Event m Double
serverTotalOutputWaitTime Server m s a b
server) (Server m s a b -> Signal m ()
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m ()
serverTotalOutputWaitTimeChanged_ Server m s a b
server)
  
-- | Signal when the 'serverTotalOutputWaitTime' property value has changed.
serverTotalOutputWaitTimeChanged_ :: MonadDES m => Server m s a b -> Signal m ()
{-# INLINABLE serverTotalOutputWaitTimeChanged_ #-}
serverTotalOutputWaitTimeChanged_ :: Server m s a b -> Signal m ()
serverTotalOutputWaitTimeChanged_ Server m s a b
server =
  ((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m (a, b)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m (a, b)
serverOutputProvided Server m s a b
server)

-- | Return the counted total time spent by the server while it was preempted
-- waiting for the further proceeding.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'serverTotalPreemptionTimeChanged' and 'serverTotalPreemptionTimeChanged_'.
serverTotalPreemptionTime :: MonadDES m => Server m s a b -> Event m Double
{-# INLINABLE serverTotalPreemptionTime #-}
serverTotalPreemptionTime :: Server m s a b -> Event m Double
serverTotalPreemptionTime Server m s a b
server =
  (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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalPreemptionTimeRef Server m s a b
server)
  
-- | Signal when the 'serverTotalPreemptionTime' property value has changed.
serverTotalPreemptionTimeChanged :: MonadDES m => Server m s a b -> Signal m Double
{-# INLINABLE serverTotalPreemptionTimeChanged #-}
serverTotalPreemptionTimeChanged :: Server m s a b -> Signal m Double
serverTotalPreemptionTimeChanged Server m s a b
server =
  (() -> Event m Double) -> Signal m () -> Signal m Double
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Double -> () -> Event m Double
forall a b. a -> b -> a
const (Event m Double -> () -> Event m Double)
-> Event m Double -> () -> Event m Double
forall a b. (a -> b) -> a -> b
$ Server m s a b -> Event m Double
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Event m Double
serverTotalPreemptionTime Server m s a b
server) (Server m s a b -> Signal m ()
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m ()
serverTotalPreemptionTimeChanged_ Server m s a b
server)
  
-- | Signal when the 'serverTotalPreemptionTime' property value has changed.
serverTotalPreemptionTimeChanged_ :: MonadDES m => Server m s a b -> Signal m ()
{-# INLINABLE serverTotalPreemptionTimeChanged_ #-}
serverTotalPreemptionTimeChanged_ :: Server m s a b -> Signal m ()
serverTotalPreemptionTimeChanged_ Server m s a b
server =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m a
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m a
serverTaskPreemptionEnding Server m s a b
server)

-- | Return the statistics of the time when the server was locked while awaiting the input.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'serverInputWaitTimeChanged' and 'serverInputWaitTimeChanged_'.
serverInputWaitTime :: MonadDES m => Server m s a b -> Event m (SamplingStats Double)
{-# INLINABLE serverInputWaitTime #-}
serverInputWaitTime :: Server m s a b -> Event m (SamplingStats Double)
serverInputWaitTime Server m s a b
server =
  (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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverInputWaitTimeRef Server m s a b
server)
  
-- | Signal when the 'serverInputWaitTime' property value has changed.
serverInputWaitTimeChanged :: MonadDES m => Server m s a b -> Signal m (SamplingStats Double)
{-# INLINABLE serverInputWaitTimeChanged #-}
serverInputWaitTimeChanged :: Server m s a b -> Signal m (SamplingStats Double)
serverInputWaitTimeChanged Server m s a b
server =
  (() -> 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 (Event m (SamplingStats Double)
-> () -> Event m (SamplingStats Double)
forall a b. a -> b -> a
const (Event m (SamplingStats Double)
 -> () -> Event m (SamplingStats Double))
-> Event m (SamplingStats Double)
-> ()
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Server m s a b -> Event m (SamplingStats Double)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Event m (SamplingStats Double)
serverInputWaitTime Server m s a b
server) (Server m s a b -> Signal m ()
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m ()
serverInputWaitTimeChanged_ Server m s a b
server)
  
-- | Signal when the 'serverInputWaitTime' property value has changed.
serverInputWaitTimeChanged_ :: MonadDES m => Server m s a b -> Signal m ()
{-# INLINABLE serverInputWaitTimeChanged_ #-}
serverInputWaitTimeChanged_ :: Server m s a b -> Signal m ()
serverInputWaitTimeChanged_ Server m s a b
server =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m a
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m a
serverInputReceived Server m s a b
server)

-- | Return the statistics of the time spent by the server while processing the tasks.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'serverProcessingTimeChanged' and 'serverProcessingTimeChanged_'.
serverProcessingTime :: MonadDES m => Server m s a b -> Event m (SamplingStats Double)
{-# INLINABLE serverProcessingTime #-}
serverProcessingTime :: Server m s a b -> Event m (SamplingStats Double)
serverProcessingTime Server m s a b
server =
  (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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverProcessingTimeRef Server m s a b
server)
  
-- | Signal when the 'serverProcessingTime' property value has changed.
serverProcessingTimeChanged :: MonadDES m => Server m s a b -> Signal m (SamplingStats Double)
{-# INLINABLE serverProcessingTimeChanged #-}
serverProcessingTimeChanged :: Server m s a b -> Signal m (SamplingStats Double)
serverProcessingTimeChanged Server m s a b
server =
  (() -> 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 (Event m (SamplingStats Double)
-> () -> Event m (SamplingStats Double)
forall a b. a -> b -> a
const (Event m (SamplingStats Double)
 -> () -> Event m (SamplingStats Double))
-> Event m (SamplingStats Double)
-> ()
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Server m s a b -> Event m (SamplingStats Double)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Event m (SamplingStats Double)
serverProcessingTime Server m s a b
server) (Server m s a b -> Signal m ()
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m ()
serverProcessingTimeChanged_ Server m s a b
server)
  
-- | Signal when the 'serverProcessingTime' property value has changed.
serverProcessingTimeChanged_ :: MonadDES m => Server m s a b -> Signal m ()
{-# INLINABLE serverProcessingTimeChanged_ #-}
serverProcessingTimeChanged_ :: Server m s a b -> Signal m ()
serverProcessingTimeChanged_ Server m s a b
server =
  ((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m (a, b)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m (a, b)
serverTaskProcessed Server m s a b
server)

-- | Return the statistics of the time when the server was locked while trying
-- to deliver the output. 
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'serverOutputWaitTimeChanged' and 'serverOutputWaitTimeChanged_'.
serverOutputWaitTime :: MonadDES m => Server m s a b -> Event m (SamplingStats Double)
{-# INLINABLE serverOutputWaitTime #-}
serverOutputWaitTime :: Server m s a b -> Event m (SamplingStats Double)
serverOutputWaitTime Server m s a b
server =
  (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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverOutputWaitTimeRef Server m s a b
server)
  
-- | Signal when the 'serverOutputWaitTime' property value has changed.
serverOutputWaitTimeChanged :: MonadDES m => Server m s a b -> Signal m (SamplingStats Double)
{-# INLINABLE serverOutputWaitTimeChanged #-}
serverOutputWaitTimeChanged :: Server m s a b -> Signal m (SamplingStats Double)
serverOutputWaitTimeChanged Server m s a b
server =
  (() -> 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 (Event m (SamplingStats Double)
-> () -> Event m (SamplingStats Double)
forall a b. a -> b -> a
const (Event m (SamplingStats Double)
 -> () -> Event m (SamplingStats Double))
-> Event m (SamplingStats Double)
-> ()
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Server m s a b -> Event m (SamplingStats Double)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Event m (SamplingStats Double)
serverOutputWaitTime Server m s a b
server) (Server m s a b -> Signal m ()
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m ()
serverOutputWaitTimeChanged_ Server m s a b
server)
  
-- | Signal when the 'serverOutputWaitTime' property value has changed.
serverOutputWaitTimeChanged_ :: MonadDES m => Server m s a b -> Signal m ()
{-# INLINABLE serverOutputWaitTimeChanged_ #-}
serverOutputWaitTimeChanged_ :: Server m s a b -> Signal m ()
serverOutputWaitTimeChanged_ Server m s a b
server =
  ((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m (a, b)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m (a, b)
serverOutputProvided Server m s a b
server)

-- | Return the statistics of the time spent by the server while it was preempted
-- waiting for the further proceeding.
--
-- The value returned changes discretely and it is usually delayed relative
-- to the current simulation time.
--
-- See also 'serverPreemptionTimeChanged' and 'serverPreemptionTimeChanged_'.
serverPreemptionTime :: MonadDES m => Server m s a b -> Event m (SamplingStats Double)
{-# INLINABLE serverPreemptionTime #-}
serverPreemptionTime :: Server m s a b -> Event m (SamplingStats Double)
serverPreemptionTime Server m s a b
server =
  (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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverPreemptionTimeRef Server m s a b
server)
  
-- | Signal when the 'serverPreemptionTime' property value has changed.
serverPreemptionTimeChanged :: MonadDES m => Server m s a b -> Signal m (SamplingStats Double)
{-# INLINABLE serverPreemptionTimeChanged #-}
serverPreemptionTimeChanged :: Server m s a b -> Signal m (SamplingStats Double)
serverPreemptionTimeChanged Server m s a b
server =
  (() -> 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 (Event m (SamplingStats Double)
-> () -> Event m (SamplingStats Double)
forall a b. a -> b -> a
const (Event m (SamplingStats Double)
 -> () -> Event m (SamplingStats Double))
-> Event m (SamplingStats Double)
-> ()
-> Event m (SamplingStats Double)
forall a b. (a -> b) -> a -> b
$ Server m s a b -> Event m (SamplingStats Double)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Event m (SamplingStats Double)
serverPreemptionTime Server m s a b
server) (Server m s a b -> Signal m ()
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m ()
serverPreemptionTimeChanged_ Server m s a b
server)
  
-- | Signal when the 'serverPreemptionTime' property value has changed.
serverPreemptionTimeChanged_ :: MonadDES m => Server m s a b -> Signal m ()
{-# INLINABLE serverPreemptionTimeChanged_ #-}
serverPreemptionTimeChanged_ :: Server m s a b -> Signal m ()
serverPreemptionTimeChanged_ Server m s a b
server =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m a
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m a
serverTaskPreemptionEnding Server m s a b
server)

-- | It returns the factor changing from 0 to 1, which estimates how often
-- the server was awaiting for the next input task.
--
-- This factor is calculated as
--
-- @
--   totalInputWaitTime \/ (totalInputWaitTime + totalProcessingTime + totalOutputWaitTime + totalPreemptionTime)
-- @
--
-- As before in this module, the value returned changes discretely and
-- it is usually delayed relative to the current simulation time.
--
-- See also 'serverInputWaitFactorChanged' and 'serverInputWaitFactorChanged_'.
serverInputWaitFactor :: MonadDES m => Server m s a b -> Event m Double
{-# INLINABLE serverInputWaitFactor #-}
serverInputWaitFactor :: Server m s a b -> Event m Double
serverInputWaitFactor Server m s a b
server =
  (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 Double
x1 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalInputWaitTimeRef Server m s a b
server)
     Double
x2 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalProcessingTimeRef Server m s a b
server)
     Double
x3 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalOutputWaitTimeRef Server m s a b
server)
     Double
x4 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalPreemptionTimeRef Server m s a b
server)
     Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x1 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
x1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x2 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x3 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x4))
  
-- | Signal when the 'serverInputWaitFactor' property value has changed.
serverInputWaitFactorChanged :: MonadDES m => Server m s a b -> Signal m Double
{-# INLINABLE serverInputWaitFactorChanged #-}
serverInputWaitFactorChanged :: Server m s a b -> Signal m Double
serverInputWaitFactorChanged Server m s a b
server =
  (() -> Event m Double) -> Signal m () -> Signal m Double
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Double -> () -> Event m Double
forall a b. a -> b -> a
const (Event m Double -> () -> Event m Double)
-> Event m Double -> () -> Event m Double
forall a b. (a -> b) -> a -> b
$ Server m s a b -> Event m Double
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Event m Double
serverInputWaitFactor Server m s a b
server) (Server m s a b -> Signal m ()
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m ()
serverInputWaitFactorChanged_ Server m s a b
server)
  
-- | Signal when the 'serverInputWaitFactor' property value has changed.
serverInputWaitFactorChanged_ :: MonadDES m => Server m s a b -> Signal m ()
{-# INLINABLE serverInputWaitFactorChanged_ #-}
serverInputWaitFactorChanged_ :: Server m s a b -> Signal m ()
serverInputWaitFactorChanged_ Server m s a b
server =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m a
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m a
serverInputReceived Server m s a b
server) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  ((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m (a, b)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m (a, b)
serverTaskProcessed Server m s a b
server) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  ((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m (a, b)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m (a, b)
serverOutputProvided Server m s a b
server) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m a
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m a
serverTaskPreemptionEnding Server m s a b
server)

-- | It returns the factor changing from 0 to 1, which estimates how often
-- the server was busy with direct processing its tasks.
--
-- This factor is calculated as
--
-- @
--   totalProcessingTime \/ (totalInputWaitTime + totalProcessingTime + totalOutputWaitTime + totalPreemptionTime)
-- @
--
-- As before in this module, the value returned changes discretely and
-- it is usually delayed relative to the current simulation time.
--
-- See also 'serverProcessingFactorChanged' and 'serverProcessingFactorChanged_'.
serverProcessingFactor :: MonadDES m => Server m s a b -> Event m Double
{-# INLINABLE serverProcessingFactor #-}
serverProcessingFactor :: Server m s a b -> Event m Double
serverProcessingFactor Server m s a b
server =
  (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 Double
x1 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalInputWaitTimeRef Server m s a b
server)
     Double
x2 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalProcessingTimeRef Server m s a b
server)
     Double
x3 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalOutputWaitTimeRef Server m s a b
server)
     Double
x4 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalPreemptionTimeRef Server m s a b
server)
     Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x2 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
x1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x2 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x3 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x4))
  
-- | Signal when the 'serverProcessingFactor' property value has changed.
serverProcessingFactorChanged :: MonadDES m => Server m s a b -> Signal m Double
{-# INLINABLE serverProcessingFactorChanged #-}
serverProcessingFactorChanged :: Server m s a b -> Signal m Double
serverProcessingFactorChanged Server m s a b
server =
  (() -> Event m Double) -> Signal m () -> Signal m Double
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Double -> () -> Event m Double
forall a b. a -> b -> a
const (Event m Double -> () -> Event m Double)
-> Event m Double -> () -> Event m Double
forall a b. (a -> b) -> a -> b
$ Server m s a b -> Event m Double
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Event m Double
serverProcessingFactor Server m s a b
server) (Server m s a b -> Signal m ()
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m ()
serverProcessingFactorChanged_ Server m s a b
server)
  
-- | Signal when the 'serverProcessingFactor' property value has changed.
serverProcessingFactorChanged_ :: MonadDES m => Server m s a b -> Signal m ()
{-# INLINABLE serverProcessingFactorChanged_ #-}
serverProcessingFactorChanged_ :: Server m s a b -> Signal m ()
serverProcessingFactorChanged_ Server m s a b
server =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m a
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m a
serverInputReceived Server m s a b
server) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  ((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m (a, b)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m (a, b)
serverTaskProcessed Server m s a b
server) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  ((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m (a, b)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m (a, b)
serverOutputProvided Server m s a b
server) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m a
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m a
serverTaskPreemptionEnding Server m s a b
server)

-- | It returns the factor changing from 0 to 1, which estimates how often
-- the server was locked trying to deliver the output after the task is finished.
--
-- This factor is calculated as
--
-- @
--   totalOutputWaitTime \/ (totalInputWaitTime + totalProcessingTime + totalOutputWaitTime + totalPreemptionTime)
-- @
--
-- As before in this module, the value returned changes discretely and
-- it is usually delayed relative to the current simulation time.
--
-- See also 'serverOutputWaitFactorChanged' and 'serverOutputWaitFactorChanged_'.
serverOutputWaitFactor :: MonadDES m => Server m s a b -> Event m Double
{-# INLINABLE serverOutputWaitFactor #-}
serverOutputWaitFactor :: Server m s a b -> Event m Double
serverOutputWaitFactor Server m s a b
server =
  (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 Double
x1 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalInputWaitTimeRef Server m s a b
server)
     Double
x2 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalProcessingTimeRef Server m s a b
server)
     Double
x3 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalOutputWaitTimeRef Server m s a b
server)
     Double
x4 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalPreemptionTimeRef Server m s a b
server)
     Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x3 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
x1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x2 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x3 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x4))
  
-- | Signal when the 'serverOutputWaitFactor' property value has changed.
serverOutputWaitFactorChanged :: MonadDES m => Server m s a b -> Signal m Double
{-# INLINABLE serverOutputWaitFactorChanged #-}
serverOutputWaitFactorChanged :: Server m s a b -> Signal m Double
serverOutputWaitFactorChanged Server m s a b
server =
  (() -> Event m Double) -> Signal m () -> Signal m Double
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Double -> () -> Event m Double
forall a b. a -> b -> a
const (Event m Double -> () -> Event m Double)
-> Event m Double -> () -> Event m Double
forall a b. (a -> b) -> a -> b
$ Server m s a b -> Event m Double
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Event m Double
serverOutputWaitFactor Server m s a b
server) (Server m s a b -> Signal m ()
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m ()
serverOutputWaitFactorChanged_ Server m s a b
server)
  
-- | Signal when the 'serverOutputWaitFactor' property value has changed.
serverOutputWaitFactorChanged_ :: MonadDES m => Server m s a b -> Signal m ()
{-# INLINABLE serverOutputWaitFactorChanged_ #-}
serverOutputWaitFactorChanged_ :: Server m s a b -> Signal m ()
serverOutputWaitFactorChanged_ Server m s a b
server =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m a
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m a
serverInputReceived Server m s a b
server) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  ((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m (a, b)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m (a, b)
serverTaskProcessed Server m s a b
server) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  ((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m (a, b)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m (a, b)
serverOutputProvided Server m s a b
server) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m a
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m a
serverTaskPreemptionEnding Server m s a b
server)
  
-- | It returns the factor changing from 0 to 1, which estimates how often
-- the server was preempted waiting for the further proceeding.
--
-- This factor is calculated as
--
-- @
--   totalPreemptionTime \/ (totalInputWaitTime + totalProcessingTime + totalOutputWaitTime + totalPreemptionTime)
-- @
--
-- As before in this module, the value returned changes discretely and
-- it is usually delayed relative to the current simulation time.
--
-- See also 'serverPreemptionFactorChanged' and 'serverPreemptionFactorChanged_'.
serverPreemptionFactor :: MonadDES m => Server m s a b -> Event m Double
{-# INLINABLE serverPreemptionFactor #-}
serverPreemptionFactor :: Server m s a b -> Event m Double
serverPreemptionFactor Server m s a b
server =
  (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 Double
x1 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalInputWaitTimeRef Server m s a b
server)
     Double
x2 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalProcessingTimeRef Server m s a b
server)
     Double
x3 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalOutputWaitTimeRef Server m s a b
server)
     Double
x4 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalPreemptionTimeRef Server m s a b
server)
     Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double
x4 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
x1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x2 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x3 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
x4))
  
-- | Signal when the 'serverPreemptionFactor' property value has changed.
serverPreemptionFactorChanged :: MonadDES m => Server m s a b -> Signal m Double
{-# INLINABLE serverPreemptionFactorChanged #-}
serverPreemptionFactorChanged :: Server m s a b -> Signal m Double
serverPreemptionFactorChanged Server m s a b
server =
  (() -> Event m Double) -> Signal m () -> Signal m Double
forall (m :: * -> *) a b.
MonadDES m =>
(a -> Event m b) -> Signal m a -> Signal m b
mapSignalM (Event m Double -> () -> Event m Double
forall a b. a -> b -> a
const (Event m Double -> () -> Event m Double)
-> Event m Double -> () -> Event m Double
forall a b. (a -> b) -> a -> b
$ Server m s a b -> Event m Double
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Event m Double
serverPreemptionFactor Server m s a b
server) (Server m s a b -> Signal m ()
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m ()
serverPreemptionFactorChanged_ Server m s a b
server)
  
-- | Signal when the 'serverPreemptionFactor' property value has changed.
serverPreemptionFactorChanged_ :: MonadDES m => Server m s a b -> Signal m ()
{-# INLINABLE serverPreemptionFactorChanged_ #-}
serverPreemptionFactorChanged_ :: Server m s a b -> Signal m ()
serverPreemptionFactorChanged_ Server m s a b
server =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m a
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m a
serverInputReceived Server m s a b
server) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  ((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m (a, b)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m (a, b)
serverTaskProcessed Server m s a b
server) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  ((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m (a, b)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m (a, b)
serverOutputProvided Server m s a b
server) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m a
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m a
serverTaskPreemptionEnding Server m s a b
server)

-- | Raised when the server receives a new input task.
serverInputReceived :: MonadDES m => Server m s a b -> Signal m a
{-# INLINABLE serverInputReceived #-}
serverInputReceived :: Server m s a b -> Signal m a
serverInputReceived = SignalSource m a -> Signal m a
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (SignalSource m a -> Signal m a)
-> (Server m s a b -> SignalSource m a)
-> Server m s a b
-> Signal m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Server m s a b -> SignalSource m a
forall (m :: * -> *) s a b. Server m s a b -> SignalSource m a
serverInputReceivedSource

-- | Raised when the task processing was preempted.
serverTaskPreemptionBeginning :: MonadDES m => Server m s a b -> Signal m a
{-# INLINABLE serverTaskPreemptionBeginning #-}
serverTaskPreemptionBeginning :: Server m s a b -> Signal m a
serverTaskPreemptionBeginning = SignalSource m a -> Signal m a
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (SignalSource m a -> Signal m a)
-> (Server m s a b -> SignalSource m a)
-> Server m s a b
-> Signal m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Server m s a b -> SignalSource m a
forall (m :: * -> *) s a b. Server m s a b -> SignalSource m a
serverTaskPreemptionBeginningSource

-- | Raised when the task processing was proceeded after it had been preempeted earlier.
serverTaskPreemptionEnding :: MonadDES m => Server m s a b -> Signal m a
{-# INLINABLE serverTaskPreemptionEnding #-}
serverTaskPreemptionEnding :: Server m s a b -> Signal m a
serverTaskPreemptionEnding = SignalSource m a -> Signal m a
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (SignalSource m a -> Signal m a)
-> (Server m s a b -> SignalSource m a)
-> Server m s a b
-> Signal m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Server m s a b -> SignalSource m a
forall (m :: * -> *) s a b. Server m s a b -> SignalSource m a
serverTaskPreemptionEndingSource

-- | Raised when the server has just processed the task.
serverTaskProcessed :: MonadDES m => Server m s a b -> Signal m (a, b)
{-# INLINABLE serverTaskProcessed #-}
serverTaskProcessed :: Server m s a b -> Signal m (a, b)
serverTaskProcessed = SignalSource m (a, b) -> Signal m (a, b)
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (SignalSource m (a, b) -> Signal m (a, b))
-> (Server m s a b -> SignalSource m (a, b))
-> Server m s a b
-> Signal m (a, b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Server m s a b -> SignalSource m (a, b)
forall (m :: * -> *) s a b. Server m s a b -> SignalSource m (a, b)
serverTaskProcessedSource

-- | Raised when the server has just delivered the output.
serverOutputProvided :: MonadDES m => Server m s a b -> Signal m (a, b)
{-# INLINABLE serverOutputProvided #-}
serverOutputProvided :: Server m s a b -> Signal m (a, b)
serverOutputProvided = SignalSource m (a, b) -> Signal m (a, b)
forall (m :: * -> *) a. SignalSource m a -> Signal m a
publishSignal (SignalSource m (a, b) -> Signal m (a, b))
-> (Server m s a b -> SignalSource m (a, b))
-> Server m s a b
-> Signal m (a, b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Server m s a b -> SignalSource m (a, b)
forall (m :: * -> *) s a b. Server m s a b -> SignalSource m (a, b)
serverOutputProvidedSource

-- | Signal whenever any property of the server changes.
serverChanged_ :: MonadDES m => Server m s a b -> Signal m ()
{-# INLINABLE serverChanged_ #-}
serverChanged_ :: Server m s a b -> Signal m ()
serverChanged_ Server m s a b
server =
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m a
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m a
serverInputReceived Server m s a b
server) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  ((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m (a, b)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m (a, b)
serverTaskProcessed Server m s a b
server) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  ((a, b) -> ()) -> Signal m (a, b) -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> (a, b) -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m (a, b)
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m (a, b)
serverOutputProvided Server m s a b
server) Signal m () -> Signal m () -> Signal m ()
forall a. Semigroup a => a -> a -> a
<>
  (a -> ()) -> Signal m a -> Signal m ()
forall (m :: * -> *) a b.
MonadDES m =>
(a -> b) -> Signal m a -> Signal m b
mapSignal (() -> a -> ()
forall a b. a -> b -> a
const ()) (Server m s a b -> Signal m a
forall (m :: * -> *) s a b.
MonadDES m =>
Server m s a b -> Signal m a
serverTaskPreemptionEnding Server m s a b
server)

-- | Return the summary for the server with desciption of its
-- properties and activities using the specified indent.
serverSummary :: MonadDES m => Server m s a b -> Int -> Event m ShowS
{-# INLINABLE serverSummary #-}
serverSummary :: Server m s a b -> Int -> Event m ShowS
serverSummary Server m s a b
server Int
indent =
  (Point m -> m ShowS) -> Event m ShowS
forall (m :: * -> *) a. (Point m -> m a) -> Event m a
Event ((Point m -> m ShowS) -> Event m ShowS)
-> (Point m -> m ShowS) -> Event m ShowS
forall a b. (a -> b) -> a -> b
$ \Point m
p ->
  do Double
tx1 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalInputWaitTimeRef Server m s a b
server)
     Double
tx2 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalProcessingTimeRef Server m s a b
server)
     Double
tx3 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalOutputWaitTimeRef Server m s a b
server)
     Double
tx4 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalPreemptionTimeRef Server m s a b
server)
     let xf1 :: Double
xf1 = Double
tx1 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
tx1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx2 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx3 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx4)
         xf2 :: Double
xf2 = Double
tx2 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
tx1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx2 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx3 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx4)
         xf3 :: Double
xf3 = Double
tx3 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
tx1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx2 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx3 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx4)
         xf4 :: Double
xf4 = Double
tx4 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
tx1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx2 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx3 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
tx4)
     SamplingStats Double
xs1 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverInputWaitTimeRef Server m s a b
server)
     SamplingStats Double
xs2 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverProcessingTimeRef Server m s a b
server)
     SamplingStats Double
xs3 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverOutputWaitTimeRef Server m s a b
server)
     SamplingStats Double
xs4 <- 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. MonadRef m => Ref m a -> Event m a
readRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverPreemptionTimeRef Server m s a b
server)
     let tab :: [Char]
tab = Int -> Char -> [Char]
forall a. Int -> a -> [a]
replicate Int
indent Char
' '
     ShowS -> m ShowS
forall (m :: * -> *) a. Monad m => a -> m a
return (ShowS -> m ShowS) -> ShowS -> m ShowS
forall a b. (a -> b) -> a -> b
$
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"total input wait time (locked while awaiting the input) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
tx1 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"total processing time = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
tx2 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"total output wait time (locked while delivering the output) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
tx3 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"total preemption time = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
tx4 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"input wait factor (from 0 to 1) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
xf1 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"processing factor (from 0 to 1) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
xf2 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"output wait factor (from 0 to 1) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
xf3 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"output preemption factor (from 0 to 1) = " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> ShowS
forall a. Show a => a -> ShowS
shows Double
xf4 ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"input wait time (locked while awaiting the input):\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       SamplingStats Double -> Int -> ShowS
forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
xs1 (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
indent) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"processing time:\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       SamplingStats Double -> Int -> ShowS
forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
xs2 (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
indent) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"output wait time (locked while delivering the output):\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       SamplingStats Double -> Int -> ShowS
forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
xs3 (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
indent) ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
tab ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       [Char] -> ShowS
showString [Char]
"preemption time (waiting for the proceeding after preemption):\n\n" ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       SamplingStats Double -> Int -> ShowS
forall a. Show a => SamplingStats a -> Int -> ShowS
samplingStatsSummary SamplingStats Double
xs4 (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
indent)

-- | Reset the statistics.
resetServer :: MonadDES m => Server m s a b -> Event m ()
{-# INLINABLE resetServer #-}
resetServer :: Server m s a b -> Event m ()
resetServer Server m s a b
server =
  do Ref m Double -> Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalInputWaitTimeRef Server m s a b
server) Double
0
     Ref m Double -> Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalProcessingTimeRef Server m s a b
server) Double
0
     Ref m Double -> Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalOutputWaitTimeRef Server m s a b
server) Double
0
     Ref m Double -> Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Server m s a b -> Ref m Double
forall (m :: * -> *) s a b. Server m s a b -> Ref m Double
serverTotalPreemptionTimeRef Server m s a b
server) Double
0
     Ref m (SamplingStats Double) -> SamplingStats Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverInputWaitTimeRef Server m s a b
server) SamplingStats Double
forall a. Monoid a => a
mempty
     Ref m (SamplingStats Double) -> SamplingStats Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverProcessingTimeRef Server m s a b
server) SamplingStats Double
forall a. Monoid a => a
mempty
     Ref m (SamplingStats Double) -> SamplingStats Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverOutputWaitTimeRef Server m s a b
server) SamplingStats Double
forall a. Monoid a => a
mempty
     Ref m (SamplingStats Double) -> SamplingStats Double -> Event m ()
forall (m :: * -> *) a. MonadRef m => Ref m a -> a -> Event m ()
writeRef (Server m s a b -> Ref m (SamplingStats Double)
forall (m :: * -> *) s a b.
Server m s a b -> Ref m (SamplingStats Double)
serverPreemptionTimeRef Server m s a b
server) SamplingStats Double
forall a. Monoid a => a
mempty