Copyright | Copyright (c) 2009-2016 David Sorokin <david.sorokin@gmail.com> |
---|---|
License | BSD3 |
Maintainer | David Sorokin <david.sorokin@gmail.com> |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Tested with: GHC 8.0.1
This module defines the resource which can be acquired and
then released by the discontinuous process Process
.
The resource can be either limited by the upper bound
(run-time check), or it can have no upper bound. The latter
is useful for modeling the infinite queue, for example.
- type FCFSResource = Resource FCFS
- type LCFSResource = Resource LCFS
- type SIROResource = Resource SIRO
- type PriorityResource = Resource StaticPriorities
- data Resource s
- newFCFSResource :: Int -> Event FCFSResource
- newFCFSResourceWithMaxCount :: Int -> Maybe Int -> Event FCFSResource
- newLCFSResource :: Int -> Event LCFSResource
- newLCFSResourceWithMaxCount :: Int -> Maybe Int -> Event LCFSResource
- newSIROResource :: Int -> Event SIROResource
- newSIROResourceWithMaxCount :: Int -> Maybe Int -> Event SIROResource
- newPriorityResource :: Int -> Event PriorityResource
- newPriorityResourceWithMaxCount :: Int -> Maybe Int -> Event PriorityResource
- newResource :: QueueStrategy s => s -> Int -> Event (Resource s)
- newResourceWithMaxCount :: QueueStrategy s => s -> Int -> Maybe Int -> Event (Resource s)
- resourceStrategy :: Resource s -> s
- resourceMaxCount :: Resource s -> Maybe Int
- resourceCount :: Resource s -> Event Int
- resourceCountStats :: Resource s -> Event (TimingStats Int)
- resourceUtilisationCount :: Resource s -> Event Int
- resourceUtilisationCountStats :: Resource s -> Event (TimingStats Int)
- resourceQueueCount :: Resource s -> Event Int
- resourceQueueCountStats :: Resource s -> Event (TimingStats Int)
- resourceTotalWaitTime :: Resource s -> Event Double
- resourceWaitTime :: Resource s -> Event (SamplingStats Double)
- requestResource :: EnqueueStrategy s => Resource s -> Process ()
- requestResourceWithPriority :: PriorityQueueStrategy s p => Resource s -> p -> Process ()
- tryRequestResourceWithinEvent :: Resource s -> Event Bool
- releaseResource :: DequeueStrategy s => Resource s -> Process ()
- releaseResourceWithinEvent :: DequeueStrategy s => Resource s -> Event ()
- usingResource :: EnqueueStrategy s => Resource s -> Process a -> Process a
- usingResourceWithPriority :: PriorityQueueStrategy s p => Resource s -> p -> Process a -> Process a
- incResourceCount :: DequeueStrategy s => Resource s -> Int -> Event ()
- decResourceCount :: EnqueueStrategy s => Resource s -> Int -> Process ()
- resourceCountChanged :: Resource s -> Signal Int
- resourceCountChanged_ :: Resource s -> Signal ()
- resourceUtilisationCountChanged :: Resource s -> Signal Int
- resourceUtilisationCountChanged_ :: Resource s -> Signal ()
- resourceQueueCountChanged :: Resource s -> Signal Int
- resourceQueueCountChanged_ :: Resource s -> Signal ()
- resourceWaitTimeChanged :: Resource s -> Signal (SamplingStats Double)
- resourceWaitTimeChanged_ :: Resource s -> Signal ()
- resourceChanged_ :: Resource s -> Signal ()
Resource Types
type FCFSResource = Resource FCFS Source #
The ordinary FCFS (First Come - First Serviced) resource.
type LCFSResource = Resource LCFS Source #
The ordinary LCFS (Last Come - First Serviced) resource.
type SIROResource = Resource SIRO Source #
The SIRO (Serviced in Random Order) resource.
type PriorityResource = Resource StaticPriorities Source #
The resource with static priorities.
Represents the resource with strategy s
applied for queuing the requests.
Eq (Resource s) Source # | |
(Show s, ResultItemable (ResultValue s)) => ResultProvider (Resource s) Source # | |
Creating Resource
:: Int | the initial count (and maximal count too) of the resource |
-> Event FCFSResource |
Create a new FCFS resource with the specified initial count which value becomes the upper bound as well.
newFCFSResourceWithMaxCount Source #
:: Int | the initial count of the resource |
-> Maybe Int | the maximum count of the resource, which can be indefinite |
-> Event FCFSResource |
Create a new FCFS resource with the specified initial and maximum counts,
where Nothing
means that the resource has no upper bound.
:: Int | the initial count (and maximal count too) of the resource |
-> Event LCFSResource |
Create a new LCFS resource with the specified initial count which value becomes the upper bound as well.
newLCFSResourceWithMaxCount Source #
:: Int | the initial count of the resource |
-> Maybe Int | the maximum count of the resource, which can be indefinite |
-> Event LCFSResource |
Create a new LCFS resource with the specified initial and maximum counts,
where Nothing
means that the resource has no upper bound.
:: Int | the initial count (and maximal count too) of the resource |
-> Event SIROResource |
Create a new SIRO resource with the specified initial count which value becomes the upper bound as well.
newSIROResourceWithMaxCount Source #
:: Int | the initial count of the resource |
-> Maybe Int | the maximum count of the resource, which can be indefinite |
-> Event SIROResource |
Create a new SIRO resource with the specified initial and maximum counts,
where Nothing
means that the resource has no upper bound.
:: Int | the initial count (and maximal count too) of the resource |
-> Event PriorityResource |
Create a new priority resource with the specified initial count which value becomes the upper bound as well.
newPriorityResourceWithMaxCount Source #
:: Int | the initial count of the resource |
-> Maybe Int | the maximum count of the resource, which can be indefinite |
-> Event PriorityResource |
Create a new priority resource with the specified initial and maximum counts,
where Nothing
means that the resource has no upper bound.
:: QueueStrategy s | |
=> s | the strategy for managing the queuing requests |
-> Int | the initial count (and maximal count too) of the resource |
-> Event (Resource s) |
Create a new resource with the specified queue strategy and initial count. The last value becomes the upper bound as well.
newResourceWithMaxCount Source #
:: QueueStrategy s | |
=> s | the strategy for managing the queuing requests |
-> Int | the initial count of the resource |
-> Maybe Int | the maximum count of the resource, which can be indefinite |
-> Event (Resource s) |
Create a new resource with the specified queue strategy, initial and maximum counts,
where Nothing
means that the resource has no upper bound.
Resource Properties
resourceStrategy :: Resource s -> s Source #
Return the strategy applied for queuing the requests.
resourceMaxCount :: Resource s -> Maybe Int Source #
Return the maximum count of the resource, where Nothing
means that the resource has no upper bound.
resourceCount :: Resource s -> Event Int Source #
Return the current available count of the resource.
resourceCountStats :: Resource s -> Event (TimingStats Int) Source #
Return the statistics for the available count of the resource.
resourceUtilisationCount :: Resource s -> Event Int Source #
Return the current utilisation count of the resource.
resourceUtilisationCountStats :: Resource s -> Event (TimingStats Int) Source #
Return the statistics for the utilisation count of the resource.
resourceQueueCount :: Resource s -> Event Int Source #
Return the current queue length of the resource.
resourceQueueCountStats :: Resource s -> Event (TimingStats Int) Source #
Return the statistics for the queue length of the resource.
resourceTotalWaitTime :: Resource s -> Event Double Source #
Return the total wait time of the resource.
resourceWaitTime :: Resource s -> Event (SamplingStats Double) Source #
Return the statistics for the wait time of the resource.
Requesting for and Releasing Resource
:: EnqueueStrategy s | |
=> Resource s | the requested resource |
-> Process () |
Request for the resource decreasing its count in case of success, otherwise suspending the discontinuous process until some other process releases the resource.
requestResourceWithPriority Source #
:: PriorityQueueStrategy s p | |
=> Resource s | the requested resource |
-> p | the priority |
-> Process () |
Request with the priority for the resource decreasing its count in case of success, otherwise suspending the discontinuous process until some other process releases the resource.
:: DequeueStrategy s | |
=> Resource s | the resource to release |
-> Process () |
Release the resource increasing its count and resuming one of the previously suspended processes as possible.
releaseResourceWithinEvent Source #
:: DequeueStrategy s | |
=> Resource s | the resource to release |
-> Event () |
Release the resource increasing its count and resuming one of the previously suspended processes as possible.
:: EnqueueStrategy s | |
=> Resource s | the resource we are going to request for and then release in the end |
-> Process a | the action we are going to apply having the resource |
-> Process a | the result of the action |
Acquire the resource, perform some action and safely release the resource
in the end, even if the IOException
was raised within the action.
usingResourceWithPriority Source #
:: PriorityQueueStrategy s p | |
=> Resource s | the resource we are going to request for and then release in the end |
-> p | the priority |
-> Process a | the action we are going to apply having the resource |
-> Process a | the result of the action |
Acquire the resource with the specified priority, perform some action and
safely release the resource in the end, even if the IOException
was raised
within the action.
Altering Resource
:: DequeueStrategy s | |
=> Resource s | the resource |
-> Int | the increment for the resource count |
-> Event () |
Increase the count of available resource by the specified number, invoking the awaiting processes as needed.
:: EnqueueStrategy s | |
=> Resource s | the resource |
-> Int | the decrement for the resource count |
-> Process () |
Decrease the count of available resource by the specified number, waiting for the processes capturing the resource as needed.
Signals
resourceCountChanged :: Resource s -> Signal Int Source #
Signal triggered when the resourceCount
property changes.
resourceCountChanged_ :: Resource s -> Signal () Source #
Signal triggered when the resourceCount
property changes.
resourceUtilisationCountChanged :: Resource s -> Signal Int Source #
Signal triggered when the resourceUtilisationCount
property changes.
resourceUtilisationCountChanged_ :: Resource s -> Signal () Source #
Signal triggered when the resourceUtilisationCount
property changes.
resourceQueueCountChanged :: Resource s -> Signal Int Source #
Signal triggered when the resourceQueueCount
property changes.
resourceQueueCountChanged_ :: Resource s -> Signal () Source #
Signal triggered when the resourceQueueCount
property changes.
resourceWaitTimeChanged :: Resource s -> Signal (SamplingStats Double) Source #
Signal triggered when the resourceTotalWaitTime
and resourceWaitTime
properties change.
resourceWaitTimeChanged_ :: Resource s -> Signal () Source #
Signal triggered when the resourceTotalWaitTime
and resourceWaitTime
properties change.
resourceChanged_ :: Resource s -> Signal () Source #
Signal triggered when one of the resource counters changes.