moduleHappstack.State.TxControl(runTxSystem,runTxSystem',shutdownSystem)whereimportSystem.Log.LoggerimportSystem.IOimportControl.MonadimportControl.ExceptionimportControl.ConcurrentimportHappstack.State.CheckpointimportHappstack.State.SaverimportHappstack.State.TransactionimportHappstack.State.SpreadimportHappstack.State.ComponentSystemimportHappstack.Data.ProxylogMM::Priority->String->IO()logMM=logM"Happstack.State.TxControl"-- | Run the MACID system without multimaster support and with the given Saver.runTxSystem::(Methodsst,Componentst)=>Saver->Proxyst->IO(MVarTxControl)runTxSystem=runTxSystem'False-- | Run the MACID system with multimaster support turned on if the first-- argument is True.runTxSystem'::(Methodsst,Componentst)=>Bool->Saver->Proxyst->IO(MVarTxControl)runTxSystem'withMultimastersaverstateProxy=dologMMNOTICE"Initializing system control."ctl<-createTxControlsaverstateProxylogMMNOTICE"Creating event mapper."localEventMap<-createEventMapctlstateProxysetNewEventMaplocalEventMaplogMMNOTICE"Restoring state."enableLogging<-restoreStatectlwhen(withMultimaster)$dologMMNOTICE"Multimaster mode"cluster<-connectToClustereventMap<-changeEventMappingctllocalEventMapclustersetNewEventMapeventMapenableLoggingletioActions=componentIOstateProxylogMMNOTICE"Forking children."children<-forMioActions$\action->domv<-newEmptyMVartid<-forkIO(action`finally`putMVarmv())return(tid,mv)modifyMVar_ctl$\c->returnc{ctlChildren=children}returnctl-- | Shuts down a transaction systemshutdownSystem::MVarTxControl->IO()shutdownSystemctl=dologMMNOTICE"Shutting down."children<-liftMctlChildren$readMVarctllogMMNOTICE"Killing children."mapM_(killThread.fst)childrenmapM_(takeMVar.snd)children-- FIXME: Use a timeout.logMMNOTICE"Shutdown complete"closeTxControlctl