capataz-0.2.0.0: OTP-like supervision trees in Haskell

Safe HaskellNone
LanguageHaskell2010

Control.Concurrent.Capataz.Internal.Util

Description

This module contains:

  • Functions to manipulate the state of the Supervisor record
  • Utility functions used for communication between threads
  • Public API utility functions

Synopsis

Documentation

getTidNumber :: ThreadId -> Maybe Text Source #

Returns only the number of the ThreadId.

setProcessThreadName :: MonadIO m => WorkerId -> WorkerName -> m () Source #

Internal functions that overwrites the GHC thread name, for increasing traceability on GHC internals.

getProcessId :: Process m -> ProcessId Source #

Gets the ProcessId of both a Worker or Supervisor process.

fetchProcess :: MonadIO m => SupervisorEnv m -> ProcessId -> m (Maybe (Process m)) Source #

Gets a supervised Process from a Supervisor instance.

appendProcessToMap :: MonadIO m => SupervisorEnv m -> Process m -> m () Source #

Appends a new Process to the Supervisor existing process map.

removeProcessFromMap :: MonadIO m => SupervisorEnv m -> ProcessId -> m () Source #

Removes a Process from a Supervisor existing process map.

resetProcessMap :: MonadIO m => SupervisorEnv m -> (ProcessMap m -> ProcessMap m) -> m () Source #

Function to modify a Supervisor process map using a pure function.

readProcessMap :: MonadIO m => SupervisorEnv m -> m (ProcessMap m) Source #

Function to get a snapshot of a Supervisor process map.

sortProcessesByTerminationOrder :: ProcessTerminationOrder -> ProcessMap m -> [Process m] Source #

Returns all processes of a Supervisor by ProcessTerminationOrder. This is used on AllForOne restarts and shutdown operations.

readSupervisorStatusSTM :: TVar SupervisorStatus -> STM SupervisorStatus Source #

Returns the SupervisorStatus, this sub-routine will retry transaction until its associated Supervisor has a status different from Initializing.

readSupervisorStatus :: MonadIO m => SupervisorEnv m -> m SupervisorStatus Source #

Executes transaction that returns the SupervisorStatus.

writeSupervisorStatus :: MonadIO m => SupervisorEnv m -> SupervisorStatus -> m () Source #

Modifes the Supervisor 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 $sel:notifyEvent:ParentSupervisorEnv sub-routine, orginally given in the CapatazOption record.

sendControlMsg :: SupervisorEnv m -> ControlAction m -> m () Source #

Used from public API functions to send ControlAction messages to a Supervisor thread loop.

sendSyncControlMsg Source #

Arguments

:: MonadIO m 
=> SupervisorEnv m 
-> (m () -> ControlAction m)

Blocking sub-routine used from the caller

-> m () 

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.

toParentSupervisorEnv :: SupervisorEnv m -> ParentSupervisorEnv m Source #

Utility function to transform a SupervisorEnv record to a ParentSupervisorEnv record; used on functions where supervision of supervisors is managed.