mongoDB-0.9: A driver for MongoDB



Cycle through a set of resources (randomly), recreating them when they expire



data Factory e r Source

Creator, destroyer, and checker of resources of type r. Creator may throw error or type e.




newResource :: ErrorT e IO r
killResource :: r -> IO ()
isExpired :: r -> IO Bool

newPool :: Factory e r -> Int -> IO (Pool e r)Source

Create new pool of initial max size, which must be >= 1

data Pool e r Source

Pool of maximum N resources. Resources may expire on their own or be killed. Resources will initially be created on demand up N resources then recycled in random fashion. N may be changed by resizing the pool. Random is preferred to round-robin to distribute effect of pathological use cases that use every Xth resource the most and N is a multiple of X. Resources *must* close/kill themselves when garbage collected (resize relies on this).




factory :: Factory e r
resources :: MVar (IOArray Int (Maybe r))

aResource :: Error e => Pool e r -> ErrorT e IO rSource

Return a random live resource in pool or create new one if expired or not yet created

poolSize :: Pool e r -> IO IntSource

current max size of pool

resize :: Pool e r -> Int -> IO ()Source

resize max size of pool. When shrinking some resource will be dropped without closing since they may still be in use. They are expected to close themselves when garbage collected.

killAll :: Pool e r -> IO ()Source

Kill all resources in pool so subsequent access creates new ones