aivika-2.1: A multi-paradigm simulation library

Stabilityexperimental
MaintainerDavid Sorokin <david.sorokin@gmail.com>
Safe HaskellSafe-Inferred

Simulation.Aivika.Resource

Contents

Description

Tested with: GHC 7.8.3

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.

Synopsis

Resource Types

type FCFSResource = Resource FCFSSource

The ordinary FCFS (First Come - First Serviced) resource.

type LCFSResource = Resource LCFSSource

The ordinary LCFS (Last Come - First Serviced) resource.

type SIROResource = Resource SIROSource

The SIRO (Serviced in Random Order) resource.

type PriorityResource = Resource StaticPrioritiesSource

The resource with static priorities.

data Resource s Source

Represents the resource with strategy s applied for queuing the requests.

Instances

Eq (Resource s) 

Creating Resource

newFCFSResourceSource

Arguments

:: Int

the initial count (and maximal count too) of the resource

-> Simulation FCFSResource 

Create a new FCFS resource with the specified initial count which value becomes the upper bound as well.

newFCFSResourceWithMaxCountSource

Arguments

:: Int

the initial count of the resource

-> Maybe Int

the maximum count of the resource, which can be indefinite

-> Simulation FCFSResource 

Create a new FCFS resource with the specified initial and maximum counts, where Nothing means that the resource has no upper bound.

newLCFSResourceSource

Arguments

:: Int

the initial count (and maximal count too) of the resource

-> Simulation LCFSResource 

Create a new LCFS resource with the specified initial count which value becomes the upper bound as well.

newLCFSResourceWithMaxCountSource

Arguments

:: Int

the initial count of the resource

-> Maybe Int

the maximum count of the resource, which can be indefinite

-> Simulation LCFSResource 

Create a new LCFS resource with the specified initial and maximum counts, where Nothing means that the resource has no upper bound.

newSIROResourceSource

Arguments

:: Int

the initial count (and maximal count too) of the resource

-> Simulation SIROResource 

Create a new SIRO resource with the specified initial count which value becomes the upper bound as well.

newSIROResourceWithMaxCountSource

Arguments

:: Int

the initial count of the resource

-> Maybe Int

the maximum count of the resource, which can be indefinite

-> Simulation SIROResource 

Create a new SIRO resource with the specified initial and maximum counts, where Nothing means that the resource has no upper bound.

newPriorityResourceSource

Arguments

:: Int

the initial count (and maximal count too) of the resource

-> Simulation PriorityResource 

Create a new priority resource with the specified initial count which value becomes the upper bound as well.

newPriorityResourceWithMaxCountSource

Arguments

:: Int

the initial count of the resource

-> Maybe Int

the maximum count of the resource, which can be indefinite

-> Simulation PriorityResource 

Create a new priority resource with the specified initial and maximum counts, where Nothing means that the resource has no upper bound.

newResourceSource

Arguments

:: QueueStrategy s 
=> s

the strategy for managing the queuing requests

-> Int

the initial count (and maximal count too) of the resource

-> Simulation (Resource s) 

Create a new resource with the specified queue strategy and initial count. The last value becomes the upper bound as well.

newResourceWithMaxCountSource

Arguments

:: 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

-> Simulation (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 -> sSource

Return the strategy applied for queuing the requests.

resourceMaxCount :: Resource s -> Maybe IntSource

Return the maximum count of the resource, where Nothing means that the resource has no upper bound.

resourceCount :: Resource s -> Event IntSource

Return the current count of the resource.

Requesting for and Releasing Resource

requestResourceSource

Arguments

:: 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.

requestResourceWithPrioritySource

Arguments

:: 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.

tryRequestResourceWithinEventSource

Arguments

:: Resource s

the resource which we try to request for

-> Event Bool 

Try to request for the resource decreasing its count in case of success and returning True in the Event monad; otherwise, returning False.

releaseResourceSource

Arguments

:: 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.

releaseResourceWithinEventSource

Arguments

:: 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.

usingResourceSource

Arguments

:: 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.

usingResourceWithPrioritySource

Arguments

:: 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.