-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | OTP-like supervision trees in Haskell
--   
--   <a>capataz</a> enhances the reliability of your concurrent
--   applications by offering supervision of green threads that run in your
--   application.
--   
--   Advantages over standard library:
--   
--   <ul>
--   <li>Links related long-living processes together under a common
--   capataz supervisor, with restart/shutdown order</li>
--   <li>Set restart strategies (Permanent, Transient, Temporary) on
--   <a>IO</a> sub-routines on a granular level</li>
--   <li>Set restart strategies on a pool of long-living worker threads
--   (AllForOne, OneForOne)</li>
--   <li>Complete telemetry on the sub-routine lifecycle of your
--   application (start, error, restarts, shutdown)</li>
--   </ul>
@package capataz
@version 0.1.0.1


-- | This module contains all the types used across all the other modules
module Control.Concurrent.Capataz.Internal.Types
type CapatazId = UUID
type WorkerId = UUID
type SupervisorId = UUID
type ProcessId = UUID
type WorkerAction = IO ()
type ProcessThreadId = ThreadId
type ProcessName = Text
type CapatazName = Text
type SupervisorName = Text
type WorkerName = Text
type RestartCount = Int
type ProcessMap = HashMap ProcessId Process
type ParentSupervisor = Supervisor

-- | Event delivered to the "notifyEvent" callback sub-routine; these
--   events can be used to monitor the capataz system and track what is
--   doing, providing high levels of telemetry for all supervisors and
--   workers of a capataz system, ergo, should be used for logging,
--   monitoring and testing purposes.
data CapatazEvent
InvalidSupervisorStatusReached :: !SupervisorId -> !SupervisorName -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
SupervisorStatusChanged :: !SupervisorId -> !SupervisorName -> !SupervisorStatus -> !SupervisorStatus -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:prevSupervisorStatus:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorStatus
[$sel:newSupervisorStatus:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorStatus
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessTerminated :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !Text -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:terminationReason:InvalidSupervisorStatusReached] :: CapatazEvent -> !Text
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessStarted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessRestarted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !Int -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:processRestartCount:InvalidSupervisorStatusReached] :: CapatazEvent -> !Int
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessCompleted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessFailed :: !SupervisorName -> !SupervisorId -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !SomeException -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:processError:InvalidSupervisorStatusReached] :: CapatazEvent -> !SomeException
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessCallbackExecuted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !(Maybe SomeException) -> !CallbackType -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:processCallbackError:InvalidSupervisorStatusReached] :: CapatazEvent -> !(Maybe SomeException)
[$sel:processCallbackType:InvalidSupervisorStatusReached] :: CapatazEvent -> !CallbackType
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessTerminationStarted :: !SupervisorName -> !SupervisorId -> !Text -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:terminationReason:InvalidSupervisorStatusReached] :: CapatazEvent -> !Text
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessTerminationFinished :: !SupervisorName -> !SupervisorId -> !Text -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:terminationReason:InvalidSupervisorStatusReached] :: CapatazEvent -> !Text
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
CapatazFailed :: !SupervisorId -> !SupervisorName -> !SomeException -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorError:InvalidSupervisorStatusReached] :: CapatazEvent -> !SomeException
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
CapatazTerminated :: !SupervisorName -> !SupervisorId -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime

-- | Defines how a <a>Worker</a> process termination should be handled by
--   its supervisor.
data WorkerTerminationPolicy

-- | Supervisor waits until infinity for the worker termination callback to
--   finish execution.
Infinity :: WorkerTerminationPolicy

-- | Supervisor terminates worker process without a chance to call its
--   termination callback.
BrutalTermination :: WorkerTerminationPolicy

-- | Supervisor allows a number of milliseconds for worker termination
--   callback complete, if not completed by specified milliseconds the
--   termination is cancelled via a <a>BrutalTermination</a> signal.
TimeoutMillis :: !Int -> WorkerTerminationPolicy

-- | Internal helper record that assesses if a Supervisor error intensity
--   has been breached.
data ProcessRestartAction

-- | Indicates a Supervisor to restart a failed process _and_ reset the
--   restart count given this Supervisor's intensity period timeout has
--   passed.
ResetRestartCount :: ProcessRestartAction

-- | Indicates a Supervisor to restart the failed process _and_ increase
--   the restart count (normal operation) of the supervised process.
IncreaseRestartCount :: ProcessRestartAction

-- | Indicates a Supervisor stop executing given the error intensity has
--   been breached.
HaltSupervisor :: ProcessRestartAction

-- | Specifies the order in which supervised process should be terminated
--   by a Supervisor in case of a restart or shutdown.
data ProcessTerminationOrder

-- | Supervisor terminates supervised process from most recent to oldest.
NewestFirst :: ProcessTerminationOrder

-- | Supervisor terminates supervised process from oldest to most recent.
OldestFirst :: ProcessTerminationOrder

-- | Specifies how a Supervisor restarts a failing process.
data SupervisorRestartStrategy

-- | Supervisor terminates all sibling supervised processes that didn't
--   fail, and then restarts all of them together. This strategy serves
--   best when all processes depend upon each other.
AllForOne :: SupervisorRestartStrategy

-- | Supervisor only restarts the supervised process that failed.
OneForOne :: SupervisorRestartStrategy

-- | Allows to:
--   
--   <ul>
--   <li>Specify options for The root supervisor of a capataz system.</li>
--   <li>Provie a "notifyEvent" callback to monitor or log a capataz
--   system.</li>
--   </ul>
data CapatazOptions
CapatazOptions :: !SupervisorName -> !Int -> !NominalDiffTime -> !SupervisorRestartStrategy -> ![ProcessSpec] -> !ProcessTerminationOrder -> !(IO ()) -> !(SomeException -> IO ()) -> !(CapatazEvent -> IO ()) -> CapatazOptions
[$sel:supervisorName:CapatazOptions] :: CapatazOptions -> !SupervisorName
[$sel:supervisorIntensity:CapatazOptions] :: CapatazOptions -> !Int
[$sel:supervisorPeriodSeconds:CapatazOptions] :: CapatazOptions -> !NominalDiffTime
[$sel:supervisorRestartStrategy:CapatazOptions] :: CapatazOptions -> !SupervisorRestartStrategy
[$sel:supervisorProcessSpecList:CapatazOptions] :: CapatazOptions -> ![ProcessSpec]
[$sel:supervisorProcessTerminationOrder:CapatazOptions] :: CapatazOptions -> !ProcessTerminationOrder
[$sel:supervisorOnIntensityReached:CapatazOptions] :: CapatazOptions -> !(IO ())

-- | Callback sub-routine that gets executed when the root supervisor
--   fails.
[$sel:supervisorOnFailure:CapatazOptions] :: CapatazOptions -> !(SomeException -> IO ())

-- | Callback used for telemetry purposes.
[$sel:notifyEvent:CapatazOptions] :: CapatazOptions -> !(CapatazEvent -> IO ())

-- | Specifies how a Supervisor deals with the lifecycle of worker process
--   in case of completion without errors and failure.
data WorkerRestartStrategy

-- | Supervisor will <b>always</b> restart a worker process, in both
--   completion and failure scenarios.
Permanent :: WorkerRestartStrategy

-- | Supervisor will <b>only</b> restart worker process if it has a failure
--   in execution.
Transient :: WorkerRestartStrategy

-- | Supervisor will <b>never</b> restart a worker, even on failure.
Temporary :: WorkerRestartStrategy

-- | Specifies all options that can be used to create a Worker Process. You
--   may create a record of this type via the smart constructor
--   "buildWorkerOptions".
data WorkerOptions
WorkerOptions :: WorkerAction -> !WorkerName -> !(SomeException -> IO ()) -> !(IO ()) -> !(IO ()) -> !WorkerTerminationPolicy -> !WorkerRestartStrategy -> WorkerOptions

-- | An <tt>IO ()</tt> sub-routine that will be executed when the worker
--   thread is created, this attribute is lazy given we want to this value
--   on a worker thread environment.
[$sel:workerAction:WorkerOptions] :: WorkerOptions -> WorkerAction

-- | Name of the Worker (present on <a>CapatazEvent</a> records)
[$sel:workerName:WorkerOptions] :: WorkerOptions -> !WorkerName

-- | Callback used when the worker fails with an error
[$sel:workerOnFailure:WorkerOptions] :: WorkerOptions -> !(SomeException -> IO ())

-- | Callback used when the worker completes execution without error
[$sel:workerOnCompletion:WorkerOptions] :: WorkerOptions -> !(IO ())

-- | Callback used when the worker is terminated
[$sel:workerOnTermination:WorkerOptions] :: WorkerOptions -> !(IO ())

-- | Indicates how a worker should be terminated
[$sel:workerTerminationPolicy:WorkerOptions] :: WorkerOptions -> !WorkerTerminationPolicy

-- | Indicates how a worker should be restarted
[$sel:workerRestartStrategy:WorkerOptions] :: WorkerOptions -> !WorkerRestartStrategy

-- | Record that contains the <a>Async</a> record (thread reference) of a
--   worker
data Worker
Worker :: !WorkerId -> !(Async ()) -> !UTCTime -> !WorkerName -> !WorkerOptions -> Worker

-- | Unique identifier for a worker that is executing
[$sel:workerId:Worker] :: Worker -> !WorkerId

-- | <a>Async</a> thread of a worker, this Async executes the <tt>IO
--   ()</tt> sub-routine
[$sel:workerAsync:Worker] :: Worker -> !(Async ())

-- | Time where this worker was created (used for error intensity checks)
[$sel:workerCreationTime:Worker] :: Worker -> !UTCTime

-- | Name of the Worker (present on <a>CapatazEvent</a> records)
[$sel:workerName:Worker] :: Worker -> !WorkerName

-- | <a>WorkerOptions</a> contains all the options around restart and
--   termination policies
[$sel:workerOptions:Worker] :: Worker -> !WorkerOptions
data ProcessEnv
ProcessEnv :: !ProcessId -> !ProcessName -> !(Async ()) -> !UTCTime -> !WorkerRestartStrategy -> ProcessEnv
[$sel:processId:ProcessEnv] :: ProcessEnv -> !ProcessId
[$sel:processName:ProcessEnv] :: ProcessEnv -> !ProcessName
[$sel:processAsync:ProcessEnv] :: ProcessEnv -> !(Async ())
[$sel:processCreationTime:ProcessEnv] :: ProcessEnv -> !UTCTime
[$sel:processRestartStrategy:ProcessEnv] :: ProcessEnv -> !WorkerRestartStrategy
data SupervisorOptions
SupervisorOptions :: Text -> !Int -> !NominalDiffTime -> !SupervisorRestartStrategy -> ![ProcessSpec] -> !ProcessTerminationOrder -> !(IO ()) -> !(SomeException -> IO ()) -> SupervisorOptions

-- | Name of the Supervisor (present on <a>CapatazEvent</a> records)
[$sel:supervisorName:SupervisorOptions] :: SupervisorOptions -> Text

-- | How many errors is the Supervisor be able to handle; check:
--   <a>http://erlang.org/doc/design_principles/sup_princ.html#max_intensity</a>
[$sel:supervisorIntensity:SupervisorOptions] :: SupervisorOptions -> !Int

-- | Period of time where the Supervisor can receive "supervisorIntensity"
--   amount of errors
[$sel:supervisorPeriodSeconds:SupervisorOptions] :: SupervisorOptions -> !NominalDiffTime

-- | What is the <a>SupervisorRestartStrategy</a> for this Capataz
[$sel:supervisorRestartStrategy:SupervisorOptions] :: SupervisorOptions -> !SupervisorRestartStrategy

-- | Static set of workers that start as soon as the <a>Capataz</a> is
--   created
[$sel:supervisorProcessSpecList:SupervisorOptions] :: SupervisorOptions -> ![ProcessSpec]

-- | In which order the <a>Supervisor</a> record is going to terminate it's
--   workers
[$sel:supervisorProcessTerminationOrder:SupervisorOptions] :: SupervisorOptions -> !ProcessTerminationOrder

-- | Callback used when the error intensity is reached
[$sel:supervisorOnIntensityReached:SupervisorOptions] :: SupervisorOptions -> !(IO ())
[$sel:supervisorOnFailure:SupervisorOptions] :: SupervisorOptions -> !(SomeException -> IO ())
data Supervisor
Supervisor :: !SupervisorId -> !SupervisorName -> !SupervisorOptions -> !UTCTime -> !(Async ()) -> (SupervisorMessage -> IO ()) -> !SupervisorEnv -> Supervisor
[$sel:supervisorId:Supervisor] :: Supervisor -> !SupervisorId
[$sel:supervisorName:Supervisor] :: Supervisor -> !SupervisorName
[$sel:supervisorOptions:Supervisor] :: Supervisor -> !SupervisorOptions
[$sel:supervisorCreationTime:Supervisor] :: Supervisor -> !UTCTime
[$sel:supervisorAsync:Supervisor] :: Supervisor -> !(Async ())
[$sel:supervisorNotify:Supervisor] :: Supervisor -> SupervisorMessage -> IO ()
[$sel:supervisorEnv:Supervisor] :: Supervisor -> !SupervisorEnv

-- | Internal record that represents an action being sent from threads
--   using the Capataz public API.
data ControlAction
ForkWorker :: !WorkerOptions -> !(WorkerId -> IO ()) -> ControlAction
[$sel:workerOptions:ForkWorker] :: ControlAction -> !WorkerOptions
[$sel:returnWorkerId:ForkWorker] :: ControlAction -> !(WorkerId -> IO ())
ForkSupervisor :: !SupervisorOptions -> !(Supervisor -> IO ()) -> ControlAction
[$sel:supervisorOptions:ForkWorker] :: ControlAction -> !SupervisorOptions
[$sel:returnSupervisor:ForkWorker] :: ControlAction -> !(Supervisor -> IO ())
TerminateProcess :: !ProcessId -> !Text -> !(Bool -> IO ()) -> ControlAction
[$sel:processId:ForkWorker] :: ControlAction -> !ProcessId
[$sel:processTerminationReason:ForkWorker] :: ControlAction -> !Text
[$sel:notifyProcessTermination:ForkWorker] :: ControlAction -> !(Bool -> IO ())

-- | Internal exception thrown to the Capataz loop to indicate termination
--   of execution
data CapatazSignal
CapatazFailure :: CapatazSignal
RestartProcessException :: CapatazSignal
TerminateProcessException :: !ProcessId -> !Text -> CapatazSignal
[$sel:processId:CapatazFailure] :: CapatazSignal -> !ProcessId
[$sel:processTerminationReason:CapatazFailure] :: CapatazSignal -> !Text
BrutallyTerminateProcessException :: !ProcessId -> !Text -> CapatazSignal
[$sel:processId:CapatazFailure] :: CapatazSignal -> !ProcessId
[$sel:processTerminationReason:CapatazFailure] :: CapatazSignal -> !Text

-- | Internal exception triggered when a Worker violates error intensity
--   specification
data CapatazError
SupervisorIntensityReached :: !ProcessId -> !ProcessName -> !Int -> CapatazError
[$sel:processId:SupervisorIntensityReached] :: CapatazError -> !ProcessId
[$sel:processName:SupervisorIntensityReached] :: CapatazError -> !ProcessName
[$sel:processRestartCount:SupervisorIntensityReached] :: CapatazError -> !Int

-- | Internal record that indicates what type of callback function is being
--   invoked; this is used for telemetry purposes
data CallbackType
OnCompletion :: CallbackType
OnFailure :: CallbackType
OnTermination :: CallbackType
data ProcessType
SupervisorType :: ProcessType
WorkerType :: ProcessType

-- | Internal exception triggered when a callback of a Worker fails
data ProcessError
ProcessCallbackFailed :: !WorkerId -> !(Maybe SomeException) -> !SomeException -> !CallbackType -> ProcessError
[$sel:processId:ProcessCallbackFailed] :: ProcessError -> !WorkerId
[$sel:processError:ProcessCallbackFailed] :: ProcessError -> !(Maybe SomeException)
[$sel:processCallbackError:ProcessCallbackFailed] :: ProcessError -> !SomeException
[$sel:processCallbackType:ProcessCallbackFailed] :: ProcessError -> !CallbackType

-- | Internal event delivered from Worker threads to the Capataz thread to
--   indicate completion, failure or termination
data MonitorEvent
ProcessTerminated' :: !ProcessId -> !ProcessName -> !RestartCount -> !Text -> !UTCTime -> MonitorEvent
[$sel:processId:ProcessTerminated'] :: MonitorEvent -> !ProcessId
[$sel:processName:ProcessTerminated'] :: MonitorEvent -> !ProcessName
[$sel:processRestartCount:ProcessTerminated'] :: MonitorEvent -> !RestartCount
[$sel:processTerminationReason:ProcessTerminated'] :: MonitorEvent -> !Text
[$sel:monitorEventTime:ProcessTerminated'] :: MonitorEvent -> !UTCTime
ProcessFailed' :: !WorkerId -> !WorkerName -> !RestartCount -> !SomeException -> !UTCTime -> MonitorEvent
[$sel:processId:ProcessTerminated'] :: MonitorEvent -> !WorkerId
[$sel:processName:ProcessTerminated'] :: MonitorEvent -> !WorkerName
[$sel:processRestartCount:ProcessTerminated'] :: MonitorEvent -> !RestartCount
[$sel:processError:ProcessTerminated'] :: MonitorEvent -> !SomeException
[$sel:monitorEventTime:ProcessTerminated'] :: MonitorEvent -> !UTCTime
ProcessCompleted' :: !ProcessId -> !ProcessName -> !UTCTime -> MonitorEvent
[$sel:processId:ProcessTerminated'] :: MonitorEvent -> !ProcessId
[$sel:processName:ProcessTerminated'] :: MonitorEvent -> !ProcessName
[$sel:monitorEventTime:ProcessTerminated'] :: MonitorEvent -> !UTCTime
ProcessForcedRestart :: !ProcessId -> !ProcessName -> !UTCTime -> MonitorEvent
[$sel:processId:ProcessTerminated'] :: MonitorEvent -> !ProcessId
[$sel:processName:ProcessTerminated'] :: MonitorEvent -> !ProcessName
[$sel:monitorEventTime:ProcessTerminated'] :: MonitorEvent -> !UTCTime

-- | Internal record used as a state machine, indicating the state of a
--   supervisor process
data SupervisorStatus

-- | This state is set when the process is created and it starts spawning
--   its static process list.
Initializing :: SupervisorStatus

-- | This state is set when the supervisor process starts listenting to
--   both <a>ControlAction</a> and <a>MonitorEvent</a> messages.
Running :: SupervisorStatus

-- | This state is set when the supervisor process is terminating it's
--   assigned worker
Halting :: SupervisorStatus

-- | This state is set when the supervisor process is finished
Halted :: SupervisorStatus

-- | Internal message delivered to a supervisor process that can either be
--   a call from public API or an event from its monitored worker process.
data SupervisorMessage

-- | Represents a request from done to the supervisor thread from another
--   thread using the public API
ControlAction :: !ControlAction -> SupervisorMessage

-- | Represents an event (failure, completion, etc) from a monitored worker
--   process to the supervisor
MonitorEvent :: !MonitorEvent -> SupervisorMessage

-- | Internal Type to manage both Worker and Supervisor processes
data Process
WorkerProcess :: Worker -> Process
SupervisorProcess :: Supervisor -> Process

-- | Record used to specify how to <b>build</b> a runtime <a>Process</a> in
--   a static supervision tree; to create values of this type, you must
--   use:
--   
--   <ul>
--   <li>"workerSpec" or "workerSpecWithDefaults" to build a worker
--   process</li>
--   <li>"supervisorSpec" or "supervisorSpecWithDefaults" to build a
--   supervisor process</li>
--   </ul>
data ProcessSpec
WorkerSpec :: WorkerOptions -> ProcessSpec
SupervisorSpec :: SupervisorOptions -> ProcessSpec

-- | Record that contains the environment of a capataz monitor, this is
--   used as the main record to create workers and to stop the supervisor
--   thread.
data Capataz
Capataz :: !Supervisor -> !Teardown -> Capataz
[$sel:capatazSupervisor:Capataz] :: Capataz -> !Supervisor
[$sel:capatazTeardown:Capataz] :: Capataz -> !Teardown

-- | Internal utility record used to hold part of the runtime information
--   of a supervisor that acts as a parent of another supervisor.
data ParentSupervisorEnv
ParentSupervisorEnv :: !SupervisorId -> !SupervisorName -> !(SupervisorMessage -> IO ()) -> !(CapatazEvent -> IO ()) -> ParentSupervisorEnv
[$sel:supervisorId:ParentSupervisorEnv] :: ParentSupervisorEnv -> !SupervisorId
[$sel:supervisorName:ParentSupervisorEnv] :: ParentSupervisorEnv -> !SupervisorName
[$sel:supervisorNotify:ParentSupervisorEnv] :: ParentSupervisorEnv -> !(SupervisorMessage -> IO ())
[$sel:notifyEvent:ParentSupervisorEnv] :: ParentSupervisorEnv -> !(CapatazEvent -> IO ())

-- | Convenience internal utility record that contains all values related
--   to a supervisor process.
data SupervisorEnv
SupervisorEnv :: !SupervisorId -> !SupervisorName -> !(SupervisorMessage -> IO ()) -> !(STM SupervisorMessage) -> !(IORef ProcessMap) -> !(TVar SupervisorStatus) -> !SupervisorOptions -> !Int -> !NominalDiffTime -> !SupervisorRestartStrategy -> !ProcessTerminationOrder -> !(IO ()) -> !(SomeException -> IO ()) -> !(CapatazEvent -> IO ()) -> SupervisorEnv
[$sel:supervisorId:SupervisorEnv] :: SupervisorEnv -> !SupervisorId
[$sel:supervisorName:SupervisorEnv] :: SupervisorEnv -> !SupervisorName
[$sel:supervisorNotify:SupervisorEnv] :: SupervisorEnv -> !(SupervisorMessage -> IO ())
[$sel:supervisorGetNotification:SupervisorEnv] :: SupervisorEnv -> !(STM SupervisorMessage)
[$sel:supervisorProcessMap:SupervisorEnv] :: SupervisorEnv -> !(IORef ProcessMap)
[$sel:supervisorStatusVar:SupervisorEnv] :: SupervisorEnv -> !(TVar SupervisorStatus)
[$sel:supervisorOptions:SupervisorEnv] :: SupervisorEnv -> !SupervisorOptions

-- | 
--   <a>http://erlang.org/doc/design_principles/sup_princ.html#max_intensity</a>
[$sel:supervisorIntensity:SupervisorEnv] :: SupervisorEnv -> !Int
[$sel:supervisorPeriodSeconds:SupervisorEnv] :: SupervisorEnv -> !NominalDiffTime
[$sel:supervisorRestartStrategy:SupervisorEnv] :: SupervisorEnv -> !SupervisorRestartStrategy
[$sel:supervisorProcessTerminationOrder:SupervisorEnv] :: SupervisorEnv -> !ProcessTerminationOrder
[$sel:supervisorOnIntensityReached:SupervisorEnv] :: SupervisorEnv -> !(IO ())
[$sel:supervisorOnIntensityReached:SupervisorEnv] :: SupervisorEnv -> !(SomeException -> IO ())
[$sel:notifyEvent:SupervisorEnv] :: SupervisorEnv -> !(CapatazEvent -> IO ())

-- | Builds a <a>CapatazOptions</a> record with defaults on how to create a
--   capataz root supervisor, these defaults are:
--   
--   <ul>
--   <li>Intensity error tolerance is set to 1 error every 5 seconds</li>
--   <li>A <a>SupervisorRestartStrategy</a> of <a>OneForOne</a></li>
--   <li>A <a>ProcessTerminationOrder</a> of <a>OldestFirst</a></li>
--   </ul>
--   
--   This function is intended to be used in combination with
--   "forkCapataz".
defCapatazOptions :: Text -> (CapatazOptions -> CapatazOptions) -> CapatazOptions

-- | Builds a <a>ProcessSpec</a> record for a supervisor process with
--   defaults from "supervisorSpecWithDefaults". This function allows
--   overrides of these defaults using lenses.
--   
--   This function is used when building a supervisor branch in a static
--   supervision trees.
supervisorSpec :: SupervisorName -> (SupervisorOptions -> SupervisorOptions) -> ProcessSpec

-- | Builds a <a>ProcessSpec</a> record for a supervisor process with
--   defaults from "buildSupervisorOptionsWithDefaults".
--   
--   This function is used when building a supervisor branch in a static
--   supervision trees.
supervisorSpecWithDefaults :: SupervisorName -> ProcessSpec

-- | Builds a <a>ProcessSpec</a> record for a worker process with defaults
--   from "workerSpecWithDefaults". This function allows overrides of these
--   defaults using lenses.
--   
--   This function is used when building a worker in a static supervision
--   tree.
workerSpec :: WorkerName -> IO () -> (WorkerOptions -> WorkerOptions) -> ProcessSpec

-- | Builds a <a>ProcessSpec</a> record for a worker process with defaults
--   from "buildSupervisorOptionsWithDefaults".
--   
--   This function is used when building a worker in a static supervision
--   tree.
workerSpecWithDefaults :: WorkerName -> IO () -> ProcessSpec

-- | Builds a <a>SupervisorOptions</a> record with defaults from
--   "buildSupervisorOptionsWithDefaults". This function allows overrides
--   of these defaults using lenses.
--   
--   This function is intended to be used in combination with
--   "forkSupervisor".
buildSupervisorOptions :: SupervisorName -> (SupervisorOptions -> SupervisorOptions) -> SupervisorOptions

-- | Builds a <a>SupervisorOptions</a> record with defaults to create a
--   supervisor process, these defaults are:
--   
--   <ul>
--   <li>Intensity error tolerance is set to 1 error every 5 seconds</li>
--   <li>A <a>SupervisorRestartStrategy</a> of <a>OneForOne</a></li>
--   <li>A <a>ProcessTerminationOrder</a> of <a>OldestFirst</a></li>
--   </ul>
--   
--   This function is intended to be used in combination with
--   "forkSupervisor".
buildSupervisorOptionsWithDefaults :: SupervisorName -> SupervisorOptions

-- | Builds a <a>WorkerOptions</a> record, keeps the defaults from
--   "buildWorkerOptionsWithDefaults" but allows overrides using lenses.
--   
--   This function is intended to be used in combination with "forkWorker".
--   See the ... example in the examples directory for a demonstration.
buildWorkerOptions :: WorkerName -> IO () -> (WorkerOptions -> WorkerOptions) -> WorkerOptions

-- | Builds a <a>WorkerOptions</a> record with defaults to create a worker
--   process, the defaults are:
--   
--   <ul>
--   <li>A <a>Transient</a> <a>WorkerRestartStrategy</a></li>
--   <li>A <a>WorkerTerminationPolicy</a> of a 3 seconds timeout</li>
--   <li>A _completion_ callback that just returns unit</li>
--   <li>A _termination_ callback that just returns unit</li>
--   <li>A _failure_ callback that just returns unit</li>
--   </ul>
--   
--   This function is intended to be used in combination with "forkWorker",
--   for creating a worker in an static supervision tree, use
--   "workerSpecWithDefaults" instead. See the ... example for a
--   demonstration.
buildWorkerOptionsWithDefaults :: WorkerName -> IO () -> WorkerOptions
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.ControlAction
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.SupervisorMessage
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.CapatazEvent
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.CapatazEvent
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.SupervisorStatus
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.SupervisorStatus
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.SupervisorStatus
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.MonitorEvent
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.ProcessError
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.ProcessError
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.ProcessType
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.ProcessType
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.CallbackType
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.CallbackType
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.CallbackType
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.CapatazError
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.CapatazError
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.CapatazSignal
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.CapatazSignal
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.WorkerOptions
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.WorkerRestartStrategy
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.WorkerRestartStrategy
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.WorkerRestartStrategy
instance GHC.Classes.Ord Control.Concurrent.Capataz.Internal.Types.SupervisorRestartStrategy
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.SupervisorRestartStrategy
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.SupervisorRestartStrategy
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.SupervisorRestartStrategy
instance GHC.Classes.Ord Control.Concurrent.Capataz.Internal.Types.ProcessTerminationOrder
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.ProcessTerminationOrder
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.ProcessTerminationOrder
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.ProcessTerminationOrder
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.ProcessRestartAction
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.ProcessRestartAction
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.ProcessRestartAction
instance GHC.Classes.Ord Control.Concurrent.Capataz.Internal.Types.WorkerTerminationPolicy
instance GHC.Classes.Eq Control.Concurrent.Capataz.Internal.Types.WorkerTerminationPolicy
instance GHC.Show.Show Control.Concurrent.Capataz.Internal.Types.WorkerTerminationPolicy
instance GHC.Generics.Generic Control.Concurrent.Capataz.Internal.Types.WorkerTerminationPolicy
instance Control.Teardown.Internal.Types.ITeardown Control.Concurrent.Capataz.Internal.Types.Capataz
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.SupervisorStatus
instance GHC.Exception.Exception Control.Concurrent.Capataz.Internal.Types.ProcessError
instance GHC.Exception.Exception Control.Concurrent.Capataz.Internal.Types.CapatazError
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.CapatazError
instance GHC.Exception.Exception Control.Concurrent.Capataz.Internal.Types.CapatazSignal
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.CapatazSignal
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.WorkerRestartStrategy
instance Data.Default.Class.Default Control.Concurrent.Capataz.Internal.Types.WorkerRestartStrategy
instance Data.Default.Class.Default Control.Concurrent.Capataz.Internal.Types.SupervisorRestartStrategy
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.SupervisorRestartStrategy
instance Data.Default.Class.Default Control.Concurrent.Capataz.Internal.Types.ProcessTerminationOrder
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.ProcessTerminationOrder
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.ProcessRestartAction
instance Data.Default.Class.Default Control.Concurrent.Capataz.Internal.Types.WorkerTerminationPolicy
instance Control.DeepSeq.NFData Control.Concurrent.Capataz.Internal.Types.WorkerTerminationPolicy

module Control.Concurrent.Capataz.Event

-- | Event delivered to the "notifyEvent" callback sub-routine; these
--   events can be used to monitor the capataz system and track what is
--   doing, providing high levels of telemetry for all supervisors and
--   workers of a capataz system, ergo, should be used for logging,
--   monitoring and testing purposes.
data CapatazEvent
InvalidSupervisorStatusReached :: !SupervisorId -> !SupervisorName -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
SupervisorStatusChanged :: !SupervisorId -> !SupervisorName -> !SupervisorStatus -> !SupervisorStatus -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:prevSupervisorStatus:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorStatus
[$sel:newSupervisorStatus:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorStatus
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessTerminated :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !Text -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:terminationReason:InvalidSupervisorStatusReached] :: CapatazEvent -> !Text
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessStarted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessRestarted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !Int -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:processRestartCount:InvalidSupervisorStatusReached] :: CapatazEvent -> !Int
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessCompleted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessFailed :: !SupervisorName -> !SupervisorId -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !SomeException -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:processError:InvalidSupervisorStatusReached] :: CapatazEvent -> !SomeException
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessCallbackExecuted :: !SupervisorId -> !SupervisorName -> !ProcessThreadId -> !ProcessId -> !ProcessName -> !ProcessType -> !(Maybe SomeException) -> !CallbackType -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:processThreadId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessThreadId
[$sel:processId:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessId
[$sel:processName:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessName
[$sel:processType:InvalidSupervisorStatusReached] :: CapatazEvent -> !ProcessType
[$sel:processCallbackError:InvalidSupervisorStatusReached] :: CapatazEvent -> !(Maybe SomeException)
[$sel:processCallbackType:InvalidSupervisorStatusReached] :: CapatazEvent -> !CallbackType
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessTerminationStarted :: !SupervisorName -> !SupervisorId -> !Text -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:terminationReason:InvalidSupervisorStatusReached] :: CapatazEvent -> !Text
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
ProcessTerminationFinished :: !SupervisorName -> !SupervisorId -> !Text -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:terminationReason:InvalidSupervisorStatusReached] :: CapatazEvent -> !Text
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
CapatazFailed :: !SupervisorId -> !SupervisorName -> !SomeException -> !UTCTime -> CapatazEvent
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorError:InvalidSupervisorStatusReached] :: CapatazEvent -> !SomeException
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime
CapatazTerminated :: !SupervisorName -> !SupervisorId -> !UTCTime -> CapatazEvent
[$sel:supervisorName:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorName
[$sel:supervisorId:InvalidSupervisorStatusReached] :: CapatazEvent -> !SupervisorId
[$sel:eventTime:InvalidSupervisorStatusReached] :: CapatazEvent -> !UTCTime

module Control.Concurrent.Capataz.Internal.Types.Lens
class HasSupervisorIntensity s

-- | Specifies how many errors is a supervisor able to handle; check:
--   <a>http://erlang.org/doc/design_principles/sup_princ.html#max_intensity</a>.
supervisorIntensityL :: (HasSupervisorIntensity s, Functor f) => (Int -> f Int) -> s -> f s
class HasSupervisorPeriodSeconds s

-- | Specifies period of time in which a supervisor can receive a number of
--   errors specified in "supervisorIntensityL".
supervisorPeriodSecondsL :: (HasSupervisorPeriodSeconds s, Functor f) => (NominalDiffTime -> f NominalDiffTime) -> s -> f s
class HasSupervisorRestartStrategy s

-- | Specifies the <a>SupervisorRestartStrategy</a> for a root supervisor.
supervisorRestartStrategyL :: (HasSupervisorRestartStrategy s, Functor f) => (SupervisorRestartStrategy -> f SupervisorRestartStrategy) -> s -> f s
class HasSupervisorProcessSpecList s

-- | Specifies a static list of processes that start automatically with a
--   supervisor.
supervisorProcessSpecListL :: (HasSupervisorProcessSpecList s, Functor f) => ([ProcessSpec] -> f [ProcessSpec]) -> s -> f s
class HasSupervisorProcessTerminationOrder s

-- | Specifies order in which a supervisor is going to terminate its
--   supervised processes.
supervisorProcessTerminationOrderL :: (HasSupervisorProcessTerminationOrder s, Functor f) => (ProcessTerminationOrder -> f ProcessTerminationOrder) -> s -> f s
class HasSupervisorIntensityReachedCallback s

-- | Specifies a callback sub-routine that gets executed when there is a
--   breach in a supervisor's error intensity.
supervisorOnIntensityReachedL :: (HasSupervisorIntensityReachedCallback s, Functor f) => (IO () -> f (IO ())) -> s -> f s
class HasSupervisorFailureCallback s

-- | Specifies callback sub-routine that gets executed when a supervisor
--   fails.
supervisorOnFailureL :: (HasSupervisorFailureCallback s, Functor f) => ((SomeException -> IO ()) -> f (SomeException -> IO ())) -> s -> f s
onSystemEventL :: Functor f => ((CapatazEvent -> IO ()) -> f (CapatazEvent -> IO ())) -> CapatazOptions -> f CapatazOptions

-- | Specifies callback that gets executed when worker sub-routine has
--   runtime error.
--   
--   NOTE: the given sub-routine execution may be interrupted depending on
--   the worker <a>WorkerTerminationPolicy</a>.
workerOnFailureL :: Functor f => ((SomeException -> IO ()) -> f (SomeException -> IO ())) -> WorkerOptions -> f WorkerOptions

-- | Specifies callback that gets executed when worker sub-routine
--   completes with no errors.
--   
--   NOTE: the given sub-routine execution may be interrupted depending on
--   the worker <a>WorkerTerminationPolicy</a>.
workerOnCompletionL :: Functor f => (IO () -> f (IO ())) -> WorkerOptions -> f WorkerOptions

-- | Specifies callback that gets executed when worker sub-routine is
--   terminated by its supervisor; this may happen in case of a capataz
--   system shutdown or when there is an <a>AllForOne</a> restart policy in
--   place.
--   
--   NOTE: the given sub-routine execution may be interrupted depending on
--   the worker <a>WorkerTerminationPolicy</a>.
workerOnTerminationL :: Functor f => (IO () -> f (IO ())) -> WorkerOptions -> f WorkerOptions

-- | Specifies how to handle a worker termination. See
--   <a>WorkerTerminationPolicy</a> documentation for more details.
workerTerminationPolicyL :: Functor f => (WorkerTerminationPolicy -> f WorkerTerminationPolicy) -> WorkerOptions -> f WorkerOptions

-- | Specifies how supervisor should deal with an error when worker fails
--   or completes. See <a>WorkerRestartStrategy</a> documentation for more
--   details.
workerRestartStrategyL :: Functor f => (WorkerRestartStrategy -> f WorkerRestartStrategy) -> WorkerOptions -> f WorkerOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorFailureCallback Control.Concurrent.Capataz.Internal.Types.SupervisorOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorFailureCallback Control.Concurrent.Capataz.Internal.Types.CapatazOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorIntensityReachedCallback Control.Concurrent.Capataz.Internal.Types.SupervisorOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorIntensityReachedCallback Control.Concurrent.Capataz.Internal.Types.CapatazOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorProcessTerminationOrder Control.Concurrent.Capataz.Internal.Types.SupervisorOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorProcessTerminationOrder Control.Concurrent.Capataz.Internal.Types.CapatazOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorProcessSpecList Control.Concurrent.Capataz.Internal.Types.SupervisorOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorProcessSpecList Control.Concurrent.Capataz.Internal.Types.CapatazOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorRestartStrategy Control.Concurrent.Capataz.Internal.Types.SupervisorOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorRestartStrategy Control.Concurrent.Capataz.Internal.Types.CapatazOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorPeriodSeconds Control.Concurrent.Capataz.Internal.Types.SupervisorOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorPeriodSeconds Control.Concurrent.Capataz.Internal.Types.CapatazOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorIntensity Control.Concurrent.Capataz.Internal.Types.SupervisorOptions
instance Control.Concurrent.Capataz.Internal.Types.Lens.HasSupervisorIntensity Control.Concurrent.Capataz.Internal.Types.CapatazOptions


-- | This module contains:
--   
--   <ul>
--   <li>Functions to manipulate the state of the Supervisor record</li>
--   <li>Utility functions used for communication between threads</li>
--   <li>Public API utility functions</li>
--   </ul>
module Control.Concurrent.Capataz.Internal.Util

-- | Returns only the number of the ThreadId.
getTidNumber :: ThreadId -> Maybe Text

-- | Internal functions that overwrites the GHC thread name, for increasing
--   traceability on GHC internals.
setProcessThreadName :: WorkerId -> WorkerName -> IO ()

-- | Gets the <a>ProcessId</a> of both a Worker or Supervisor process.
getProcessId :: Process -> ProcessId

-- | Gets a supervised <a>Process</a> from a <a>Supervisor</a> instance.
fetchProcess :: SupervisorEnv -> ProcessId -> IO (Maybe Process)

-- | Appends a new <a>Process</a> to the <a>Supervisor</a> existing process
--   map.
appendProcessToMap :: SupervisorEnv -> Process -> IO ()

-- | Removes a <a>Process</a> from a <a>Supervisor</a> existing process
--   map.
removeProcessFromMap :: SupervisorEnv -> ProcessId -> IO ()

-- | Function to modify a <a>Supervisor</a> process map using a pure
--   function.
resetProcessMap :: SupervisorEnv -> (ProcessMap -> ProcessMap) -> IO ()

-- | Function to get a snapshot of a <a>Supervisor</a> process map.
readProcessMap :: SupervisorEnv -> IO ProcessMap

-- | Returns all processes of a <a>Supervisor</a> by
--   <a>ProcessTerminationOrder</a>. This is used on <a>AllForOne</a>
--   restarts and shutdown operations.
sortProcessesByTerminationOrder :: ProcessTerminationOrder -> ProcessMap -> [Process]

-- | Returns the <a>SupervisorStatus</a>, this sub-routine will retry
--   transaction until its associated <a>Supervisor</a> has a status
--   different from <a>Initializing</a>.
readSupervisorStatusSTM :: TVar SupervisorStatus -> STM SupervisorStatus

-- | Executes transaction that returns the <a>SupervisorStatus</a>.
readSupervisorStatus :: SupervisorEnv -> IO SupervisorStatus

-- | Modifes the <a>Supervisor</a> status.
--   
--   IMPORTANT: this is the only function that should be used for this
--   purpose given it has the side-effect of notifying a status change via
--   the "notifyEvent" sub-routine, orginally given in the
--   <a>CapatazOption</a> record.
writeSupervisorStatus :: SupervisorEnv -> SupervisorStatus -> IO ()

-- | Used from public API functions to send <a>ControlAction</a> messages
--   to a Supervisor thread loop.
sendControlMsg :: SupervisorEnv -> ControlAction -> IO ()

-- | Used from public API functions to send ControlAction messages to the a
--   Supervisor thread loop, it receives an IO sub-routine that expects an
--   IO operation that blocks a thread until the message is done.
sendSyncControlMsg :: SupervisorEnv -> (IO () -> ControlAction) -> IO ()

-- | Utility function to transform a <a>CapatazOptions</a> record to a
--   <a>SupervisorOptions</a> record.
capatazOptionsToSupervisorOptions :: CapatazOptions -> SupervisorOptions

-- | Utility function to transform a <a>SupervisorEnv</a> record to a
--   <a>ParentSupervisorEnv</a> record; used on functions where supervision
--   of supervisors is managed.
toParentSupervisorEnv :: SupervisorEnv -> ParentSupervisorEnv


-- | This module contains all logic related to error handling when spawning
--   threads to execute Worker sub-routines
module Control.Concurrent.Capataz.Internal.Worker

-- | Decorates the given <tt>IO ()</tt> sub-routine with failure handling
workerMain :: ParentSupervisorEnv -> WorkerOptions -> WorkerId -> RestartCount -> IO Worker

-- | Internal function that forks a worker thread on the Capataz thread;
--   note this is different from the public <tt>forkWorker</tt> function
--   which sends a message to the capataz loop
forkWorker :: ParentSupervisorEnv -> WorkerOptions -> Maybe (WorkerId, RestartCount) -> IO Worker

module Control.Concurrent.Capataz.Internal.Supervisor

-- | Internal function that forks a supervisor thread; note this is
--   different from the public <tt>forkSupervisor</tt> function which sends
--   a message to the supervisor loop.
forkSupervisor :: ParentSupervisorEnv -> SupervisorOptions -> Maybe (ProcessId, RestartCount) -> IO Supervisor

-- | Utility function that builds an utility record which is used on all
--   internal APIs of the supervision logic.
buildSupervisorEnv :: (CapatazEvent -> IO ()) -> (SupervisorMessage -> IO ()) -> STM SupervisorMessage -> SupervisorId -> SupervisorOptions -> IO SupervisorEnv

-- | Handles an event produced by one of the processes this supervisor
--   monitors.
handleMonitorEvent :: SupervisorEnv -> MonitorEvent -> IO Bool

-- | Handles an action triggered by the public Capataz API.
handleControlAction :: SupervisorEnv -> ControlAction -> IO Bool

-- | Executes the shutdown operation of a Supervisor, including the
--   termination of its supervised processes.
haltSupervisor :: Text -> SupervisorEnv -> IO ()

-- | Handles all messages that a Supervisor can receive from its monitored
--   processes or from the public API.
handleSupervisorMessage :: SupervisorEnv -> SupervisorMessage -> IO Bool

-- | This sub-routine executes the main thread loop of a <a>Supervisor</a>
--   instance.
supervisorLoop :: (forall b. IO b -> IO b) -> ParentSupervisorEnv -> SupervisorEnv -> RestartCount -> IO ()

-- | This sub-routine starts a Supervisor thread and initializes its
--   processList.
supervisorMain :: ParentSupervisorEnv -> SupervisorOptions -> SupervisorId -> RestartCount -> IO Supervisor

-- | Tracks difference between two timestamps so that we keep track of a
--   Supervisor error intensity.
calcDiffSeconds :: UTCTime -> IO NominalDiffTime

-- | Checks restart counts and worker start times to assess if the
--   Supervisor error intensity has been breached, see
--   <a>ProcessRestartAction</a> for possible outcomes.
calcRestartAction :: SupervisorEnv -> Int -> NominalDiffTime -> ProcessRestartAction

-- | Sub-routine responsible of executing a
--   <a>SupervisorRestartStrategy</a>.
execCapatazRestartStrategy :: SupervisorEnv -> ProcessId -> ProcessSpec -> Int -> IO ()

-- | Executes a restart action returned from the invokation of
--   "calcRestartAction".
execRestartAction :: SupervisorEnv -> ProcessId -> ProcessSpec -> Text -> UTCTime -> Int -> IO ()

-- | Restarts _all_ processes that are supervised by Supervisor, invoked
--   when one worker green thread fails and causes sibling process threads
--   to get restarted as well (e.g. <a>AllForOne</a> supervisor restart
--   strategy).
restartProcessList :: SupervisorEnv -> WorkerId -> RestartCount -> IO [Process]

-- | Sub-routine that is used when there is a restart request sent to a
--   Process caused by an <a>AllForOne</a> restart from a failing sibling
--   process.
forceRestartProcess :: SupervisorEnv -> Process -> IO ()

-- | Starts a new worker thread taking into account an existing
--   <a>WorkerId</a> and keeping a <a>RestartCount</a> to manage the
--   Supervisor error intensity.
restartWorker :: SupervisorEnv -> WorkerOptions -> WorkerId -> RestartCount -> IO Process

-- | Starts a new Supervisor thread taking into account an existing
--   <a>SupervisorId</a> and keeping a <a>RestartCount</a> to manage the
--   parent Supervisor error intensity.
restartSupervisor :: ParentSupervisorEnv -> SupervisorOptions -> ProcessId -> RestartCount -> IO Process

-- | Executes restart strategy for when a worker finishes it execution
--   because of a completion (e.g. worker sub-routine finished without any
--   errors).
handleWorkerCompleted :: SupervisorEnv -> Worker -> IO ()

-- | Executes restart strategy for when a process finishes it execution
--   because of a completion (e.g. worker sub-routine finished without any
--   errors).
handleProcessCompleted :: SupervisorEnv -> ProcessId -> UTCTime -> IO ()

-- | Executes restart strategy for when a worker finishes it execution
--   because of a failure.
handleWorkerFailed :: SupervisorEnv -> Worker -> Int -> IO ()

-- | Executes restart strategy for when a supervisor finishes it execution
--   because of a failure.
handleSupervisorFailed :: SupervisorEnv -> Supervisor -> Int -> IO ()

-- | Executes restart strategy for when a process finishes it execution
--   because of a failure.
handleProcessFailed :: SupervisorEnv -> WorkerId -> SomeException -> Int -> IO ()

-- | Executes restart strategy for when a worker finishes it execution
--   because of a termination from its supervisor.
handleWorkerTerminated :: SupervisorEnv -> Worker -> Int -> IO ()

-- | Executes restart strategy for when a supervisor finishes it execution
--   because of a termination from its parent supervisor.
handleSupervisorTerminated :: SupervisorEnv -> Supervisor -> Int -> IO ()

-- | Executes restart strategy for when a process finishes it execution
--   because of a termination from its supervisor.
handleProcessTerminated :: SupervisorEnv -> ProcessId -> Text -> Int -> IO ()


-- | This module contains:
--   
--   <ul>
--   <li>Functions exported on the public API</li>
--   <li>High level message handlers of the supervisor thread loop</li>
--   </ul>
module Control.Concurrent.Capataz.Internal.Core

-- | Utility typeclass to call public supervision API with types that
--   contain a supervisor (e.g. Capataz record).
class HasSupervisor a

-- | Fetches a supervisor from a record internals.
getSupervisor :: HasSupervisor a => a -> Supervisor

-- | Creates a green thread from an "IO ()" sub-routine. Depending in
--   options defined in the <a>WorkerOptions</a> record, it will
--   automatically restart this sub-routine in case of failures.
--   
--   See documentation of related functions:
--   
--   <ul>
--   <li>"buildWorkerOptionsWithDefault"</li>
--   <li>"buildWorkerOptions"</li>
--   </ul>
forkWorker :: HasSupervisor supervisor => WorkerOptions -> supervisor -> IO WorkerId

-- | Creates a green thread which monitors other green threads for failures
--   and restarts them using settings defined on <a>SupervisorOptions</a>.
--   
--   See documentation of related functions:
--   
--   <ul>
--   <li>"buildSupervisorOptionsWithDefault"</li>
--   <li>"buildSupervisorOptions"</li>
--   </ul>
forkSupervisor :: HasSupervisor parentSupervisor => SupervisorOptions -> parentSupervisor -> IO Supervisor

-- | Creates a Capataz record, which holds both a root supervisor and a
--   <a>Teardown</a> to shut down the system. The root supervisor monitors
--   failures on process threads defined with "supervisorProcessSpecList"
--   or created dynamically using "forkWorker" or "forkSupervisor".
forkCapataz :: Text -> (CapatazOptions -> CapatazOptions) -> IO Capataz

-- | Stops the execution of a green thread being supervised by the given
--   supervisor.
--   
--   NOTE: If <a>ProcessId</a> maps to a worker that is configured with a
--   <a>Permanent</a> worker restart strategy, the worker green thread
--   <b>will be restarted again</b>.
terminateProcess :: HasSupervisor supervisor => Text -> ProcessId -> supervisor -> IO Bool

-- | Joins the thread of the root supervisor of the given capataz system to
--   the current thread.
joinCapatazThread :: Capataz -> IO ()

-- | Gets the process identifier of a Supervisor; normally used for
--   termination.
getSupervisorProcessId :: Supervisor -> ProcessId

-- | Gets the <a>Async</a> of a Supervisor thread.
--   
--   NOTE: There is no way to get the <a>Async</a> value of the root
--   supervisor; this is to avoid error scenarios.
getSupervisorAsync :: Supervisor -> Async ()

-- | Gets <a>Teardown</a> record of this capataz system.
getCapatazTeardown :: Capataz -> Teardown
instance Control.Concurrent.Capataz.Internal.Core.HasSupervisor Control.Concurrent.Capataz.Internal.Types.Capataz
instance Control.Concurrent.Capataz.Internal.Core.HasSupervisor Control.Concurrent.Capataz.Internal.Types.Supervisor

module Control.Concurrent.Capataz.Lens


-- | Public API for the capataz library
--   
--   Capataz is a library that brings an OTP-like supervisor API to the
--   Haskell concurrency toolset.
module Control.Concurrent.Capataz

-- | Utility typeclass to call public supervision API with types that
--   contain a supervisor (e.g. Capataz record).
class HasSupervisor a

-- | Fetches a supervisor from a record internals.
getSupervisor :: HasSupervisor a => a -> Supervisor

-- | Internal record that indicates what type of callback function is being
--   invoked; this is used for telemetry purposes
data CallbackType
OnCompletion :: CallbackType
OnFailure :: CallbackType
OnTermination :: CallbackType
type WorkerId = UUID

-- | Specifies how a Supervisor deals with the lifecycle of worker process
--   in case of completion without errors and failure.
data WorkerRestartStrategy

-- | Supervisor will <b>always</b> restart a worker process, in both
--   completion and failure scenarios.
Permanent :: WorkerRestartStrategy

-- | Supervisor will <b>only</b> restart worker process if it has a failure
--   in execution.
Transient :: WorkerRestartStrategy

-- | Supervisor will <b>never</b> restart a worker, even on failure.
Temporary :: WorkerRestartStrategy

-- | Defines how a <a>Worker</a> process termination should be handled by
--   its supervisor.
data WorkerTerminationPolicy

-- | Supervisor waits until infinity for the worker termination callback to
--   finish execution.
Infinity :: WorkerTerminationPolicy

-- | Supervisor terminates worker process without a chance to call its
--   termination callback.
BrutalTermination :: WorkerTerminationPolicy

-- | Supervisor allows a number of milliseconds for worker termination
--   callback complete, if not completed by specified milliseconds the
--   termination is cancelled via a <a>BrutalTermination</a> signal.
TimeoutMillis :: !Int -> WorkerTerminationPolicy

-- | Specifies all options that can be used to create a Worker Process. You
--   may create a record of this type via the smart constructor
--   "buildWorkerOptions".
data WorkerOptions
type ProcessId = UUID

-- | Record used to specify how to <b>build</b> a runtime <a>Process</a> in
--   a static supervision tree; to create values of this type, you must
--   use:
--   
--   <ul>
--   <li>"workerSpec" or "workerSpecWithDefaults" to build a worker
--   process</li>
--   <li>"supervisorSpec" or "supervisorSpecWithDefaults" to build a
--   supervisor process</li>
--   </ul>
data ProcessSpec
WorkerSpec :: WorkerOptions -> ProcessSpec
SupervisorSpec :: SupervisorOptions -> ProcessSpec
data ProcessType
SupervisorType :: ProcessType
WorkerType :: ProcessType

-- | Specifies the order in which supervised process should be terminated
--   by a Supervisor in case of a restart or shutdown.
data ProcessTerminationOrder

-- | Supervisor terminates supervised process from most recent to oldest.
NewestFirst :: ProcessTerminationOrder

-- | Supervisor terminates supervised process from oldest to most recent.
OldestFirst :: ProcessTerminationOrder

-- | Internal exception triggered when a callback of a Worker fails
data ProcessError
ProcessCallbackFailed :: !WorkerId -> !(Maybe SomeException) -> !SomeException -> !CallbackType -> ProcessError
[$sel:processId:ProcessCallbackFailed] :: ProcessError -> !WorkerId
[$sel:processError:ProcessCallbackFailed] :: ProcessError -> !(Maybe SomeException)
[$sel:processCallbackError:ProcessCallbackFailed] :: ProcessError -> !SomeException
[$sel:processCallbackType:ProcessCallbackFailed] :: ProcessError -> !CallbackType
type SupervisorId = UUID
data Supervisor

-- | Specifies how a Supervisor restarts a failing process.
data SupervisorRestartStrategy

-- | Supervisor terminates all sibling supervised processes that didn't
--   fail, and then restarts all of them together. This strategy serves
--   best when all processes depend upon each other.
AllForOne :: SupervisorRestartStrategy

-- | Supervisor only restarts the supervised process that failed.
OneForOne :: SupervisorRestartStrategy

-- | Internal record used as a state machine, indicating the state of a
--   supervisor process
data SupervisorStatus

-- | This state is set when the process is created and it starts spawning
--   its static process list.
Initializing :: SupervisorStatus

-- | This state is set when the supervisor process starts listenting to
--   both <a>ControlAction</a> and <a>MonitorEvent</a> messages.
Running :: SupervisorStatus

-- | This state is set when the supervisor process is terminating it's
--   assigned worker
Halting :: SupervisorStatus

-- | This state is set when the supervisor process is finished
Halted :: SupervisorStatus
data SupervisorOptions

-- | Allows to:
--   
--   <ul>
--   <li>Specify options for The root supervisor of a capataz system.</li>
--   <li>Provie a "notifyEvent" callback to monitor or log a capataz
--   system.</li>
--   </ul>
data CapatazOptions

-- | Record that contains the environment of a capataz monitor, this is
--   used as the main record to create workers and to stop the supervisor
--   thread.
data Capataz

-- | Builds a <a>SupervisorOptions</a> record with defaults from
--   "buildSupervisorOptionsWithDefaults". This function allows overrides
--   of these defaults using lenses.
--   
--   This function is intended to be used in combination with
--   "forkSupervisor".
buildSupervisorOptions :: SupervisorName -> (SupervisorOptions -> SupervisorOptions) -> SupervisorOptions

-- | Builds a <a>SupervisorOptions</a> record with defaults to create a
--   supervisor process, these defaults are:
--   
--   <ul>
--   <li>Intensity error tolerance is set to 1 error every 5 seconds</li>
--   <li>A <a>SupervisorRestartStrategy</a> of <a>OneForOne</a></li>
--   <li>A <a>ProcessTerminationOrder</a> of <a>OldestFirst</a></li>
--   </ul>
--   
--   This function is intended to be used in combination with
--   "forkSupervisor".
buildSupervisorOptionsWithDefaults :: SupervisorName -> SupervisorOptions

-- | Builds a <a>WorkerOptions</a> record, keeps the defaults from
--   "buildWorkerOptionsWithDefaults" but allows overrides using lenses.
--   
--   This function is intended to be used in combination with "forkWorker".
--   See the ... example in the examples directory for a demonstration.
buildWorkerOptions :: WorkerName -> IO () -> (WorkerOptions -> WorkerOptions) -> WorkerOptions

-- | Builds a <a>WorkerOptions</a> record with defaults to create a worker
--   process, the defaults are:
--   
--   <ul>
--   <li>A <a>Transient</a> <a>WorkerRestartStrategy</a></li>
--   <li>A <a>WorkerTerminationPolicy</a> of a 3 seconds timeout</li>
--   <li>A _completion_ callback that just returns unit</li>
--   <li>A _termination_ callback that just returns unit</li>
--   <li>A _failure_ callback that just returns unit</li>
--   </ul>
--   
--   This function is intended to be used in combination with "forkWorker",
--   for creating a worker in an static supervision tree, use
--   "workerSpecWithDefaults" instead. See the ... example for a
--   demonstration.
buildWorkerOptionsWithDefaults :: WorkerName -> IO () -> WorkerOptions

-- | Builds a <a>ProcessSpec</a> record for a supervisor process with
--   defaults from "supervisorSpecWithDefaults". This function allows
--   overrides of these defaults using lenses.
--   
--   This function is used when building a supervisor branch in a static
--   supervision trees.
supervisorSpec :: SupervisorName -> (SupervisorOptions -> SupervisorOptions) -> ProcessSpec

-- | Builds a <a>ProcessSpec</a> record for a supervisor process with
--   defaults from "buildSupervisorOptionsWithDefaults".
--   
--   This function is used when building a supervisor branch in a static
--   supervision trees.
supervisorSpecWithDefaults :: SupervisorName -> ProcessSpec

-- | Builds a <a>ProcessSpec</a> record for a worker process with defaults
--   from "workerSpecWithDefaults". This function allows overrides of these
--   defaults using lenses.
--   
--   This function is used when building a worker in a static supervision
--   tree.
workerSpec :: WorkerName -> IO () -> (WorkerOptions -> WorkerOptions) -> ProcessSpec

-- | Builds a <a>ProcessSpec</a> record for a worker process with defaults
--   from "buildSupervisorOptionsWithDefaults".
--   
--   This function is used when building a worker in a static supervision
--   tree.
workerSpecWithDefaults :: WorkerName -> IO () -> ProcessSpec
onSystemEventL :: Functor f => ((CapatazEvent -> IO ()) -> f (CapatazEvent -> IO ())) -> CapatazOptions -> f CapatazOptions

-- | Specifies how many errors is a supervisor able to handle; check:
--   <a>http://erlang.org/doc/design_principles/sup_princ.html#max_intensity</a>.
supervisorIntensityL :: (HasSupervisorIntensity s, Functor f) => (Int -> f Int) -> s -> f s

-- | Specifies period of time in which a supervisor can receive a number of
--   errors specified in "supervisorIntensityL".
supervisorPeriodSecondsL :: (HasSupervisorPeriodSeconds s, Functor f) => (NominalDiffTime -> f NominalDiffTime) -> s -> f s

-- | Specifies the <a>SupervisorRestartStrategy</a> for a root supervisor.
supervisorRestartStrategyL :: (HasSupervisorRestartStrategy s, Functor f) => (SupervisorRestartStrategy -> f SupervisorRestartStrategy) -> s -> f s

-- | Specifies a static list of processes that start automatically with a
--   supervisor.
supervisorProcessSpecListL :: (HasSupervisorProcessSpecList s, Functor f) => ([ProcessSpec] -> f [ProcessSpec]) -> s -> f s

-- | Specifies order in which a supervisor is going to terminate its
--   supervised processes.
supervisorProcessTerminationOrderL :: (HasSupervisorProcessTerminationOrder s, Functor f) => (ProcessTerminationOrder -> f ProcessTerminationOrder) -> s -> f s

-- | Specifies a callback sub-routine that gets executed when there is a
--   breach in a supervisor's error intensity.
supervisorOnIntensityReachedL :: (HasSupervisorIntensityReachedCallback s, Functor f) => (IO () -> f (IO ())) -> s -> f s

-- | Specifies callback sub-routine that gets executed when a supervisor
--   fails.
supervisorOnFailureL :: (HasSupervisorFailureCallback s, Functor f) => ((SomeException -> IO ()) -> f (SomeException -> IO ())) -> s -> f s

-- | Specifies callback that gets executed when worker sub-routine has
--   runtime error.
--   
--   NOTE: the given sub-routine execution may be interrupted depending on
--   the worker <a>WorkerTerminationPolicy</a>.
workerOnFailureL :: Functor f => ((SomeException -> IO ()) -> f (SomeException -> IO ())) -> WorkerOptions -> f WorkerOptions

-- | Specifies callback that gets executed when worker sub-routine
--   completes with no errors.
--   
--   NOTE: the given sub-routine execution may be interrupted depending on
--   the worker <a>WorkerTerminationPolicy</a>.
workerOnCompletionL :: Functor f => (IO () -> f (IO ())) -> WorkerOptions -> f WorkerOptions

-- | Specifies callback that gets executed when worker sub-routine is
--   terminated by its supervisor; this may happen in case of a capataz
--   system shutdown or when there is an <a>AllForOne</a> restart policy in
--   place.
--   
--   NOTE: the given sub-routine execution may be interrupted depending on
--   the worker <a>WorkerTerminationPolicy</a>.
workerOnTerminationL :: Functor f => (IO () -> f (IO ())) -> WorkerOptions -> f WorkerOptions

-- | Specifies how to handle a worker termination. See
--   <a>WorkerTerminationPolicy</a> documentation for more details.
workerTerminationPolicyL :: Functor f => (WorkerTerminationPolicy -> f WorkerTerminationPolicy) -> WorkerOptions -> f WorkerOptions

-- | Specifies how supervisor should deal with an error when worker fails
--   or completes. See <a>WorkerRestartStrategy</a> documentation for more
--   details.
workerRestartStrategyL :: Functor f => (WorkerRestartStrategy -> f WorkerRestartStrategy) -> WorkerOptions -> f WorkerOptions

-- | Creates a green thread from an "IO ()" sub-routine. Depending in
--   options defined in the <a>WorkerOptions</a> record, it will
--   automatically restart this sub-routine in case of failures.
--   
--   See documentation of related functions:
--   
--   <ul>
--   <li>"buildWorkerOptionsWithDefault"</li>
--   <li>"buildWorkerOptions"</li>
--   </ul>
forkWorker :: HasSupervisor supervisor => WorkerOptions -> supervisor -> IO WorkerId

-- | Creates a green thread which monitors other green threads for failures
--   and restarts them using settings defined on <a>SupervisorOptions</a>.
--   
--   See documentation of related functions:
--   
--   <ul>
--   <li>"buildSupervisorOptionsWithDefault"</li>
--   <li>"buildSupervisorOptions"</li>
--   </ul>
forkSupervisor :: HasSupervisor parentSupervisor => SupervisorOptions -> parentSupervisor -> IO Supervisor

-- | Creates a Capataz record, which holds both a root supervisor and a
--   <a>Teardown</a> to shut down the system. The root supervisor monitors
--   failures on process threads defined with "supervisorProcessSpecList"
--   or created dynamically using "forkWorker" or "forkSupervisor".
forkCapataz :: Text -> (CapatazOptions -> CapatazOptions) -> IO Capataz

-- | Stops the execution of a green thread being supervised by the given
--   supervisor.
--   
--   NOTE: If <a>ProcessId</a> maps to a worker that is configured with a
--   <a>Permanent</a> worker restart strategy, the worker green thread
--   <b>will be restarted again</b>.
terminateProcess :: HasSupervisor supervisor => Text -> ProcessId -> supervisor -> IO Bool

-- | Joins the thread of the root supervisor of the given capataz system to
--   the current thread.
joinCapatazThread :: Capataz -> IO ()

-- | Gets the process identifier of a Supervisor; normally used for
--   termination.
getSupervisorProcessId :: Supervisor -> ProcessId

-- | Gets the <a>Async</a> of a Supervisor thread.
--   
--   NOTE: There is no way to get the <a>Async</a> value of the root
--   supervisor; this is to avoid error scenarios.
getSupervisorAsync :: Supervisor -> Async ()

-- | Gets <a>Teardown</a> record of this capataz system.
getCapatazTeardown :: Capataz -> Teardown

-- | Executes teardown sub-routine returning a <a>TeardownResult</a>
teardown :: ITeardown teardown => teardown -> IO TeardownResult

-- | (<a>.~</a>) assigns a value to the target. It's the same thing as
--   using (<a>%~</a>) with <a>const</a>:
--   
--   <pre>
--   l <a>.~</a> x = l <a>%~</a> <a>const</a> x
--   </pre>
--   
--   See <a>set</a> if you want a non-operator synonym.
--   
--   Here it is used to change 2 fields of a 3-tuple:
--   
--   <pre>
--   &gt;&gt;&gt; (0,0,0) &amp; _1 .~ 1 &amp; _3 .~ 3
--   (1,0,3)
--   </pre>
(.~) :: () => ASetter s t a b -> b -> s -> t
infixr 4 .~

-- | <a>&amp;</a> is a reverse application operator. This provides
--   notational convenience. Its precedence is one higher than that of the
--   forward application operator <a>$</a>, which allows <a>&amp;</a> to be
--   nested in <a>$</a>.
(&) :: () => a -> (a -> b) -> b
infixl 1 &

-- | <a>set</a> is a synonym for (<a>.~</a>).
--   
--   Setting the 1st component of a pair:
--   
--   <pre>
--   <a>set</a> <a>_1</a> :: x -&gt; (a, b) -&gt; (x, b)
--   <a>set</a> <a>_1</a> = \x t -&gt; (x, snd t)
--   </pre>
--   
--   Using it to rewrite (<a>&lt;$</a>):
--   
--   <pre>
--   <a>set</a> <a>mapped</a> :: <a>Functor</a> f =&gt; a -&gt; f b -&gt; f a
--   <a>set</a> <a>mapped</a> = (<a>&lt;$</a>)
--   </pre>
set :: () => ASetter s t a b -> b -> s -> t
