std.concurrent.pool

*current*

dynamic

*defaults*

dynamic

*dispose*

dynamic

*stop-fn*

dynamic

+opts+

dispose-fn

added in 3.0

(dispose-fn m id)(dispose-fn m id stop-fn)

helper function for dispose and cleanup

pool

added in 3.0

(pool {:keys [size max keep-alive poll resource], :as m})

creates and starts the pool

(def -p- (pool {:size 2 :max 10 :keep-alive 10000 :poll 20000 :resource {:create (fn ) :initial 0.3 :thread-local true}}))

pool-handler

added in 3.0

(pool-handler {:keys [state], :as pool})

creates a handler loop for cleanup

pool-resource

added in 3.0

(pool-resource id {:keys [resource], :as pool})

creates a pool resource

(pool-resource “hello” {:resource {:create (fn [] ’)}}) => (contains {:id “hello”, :object ’ :status :idle, :create-time number? :update-time number? :busy 0.0, :used 0})

pool:acquire

added in 3.0

(pool:acquire {:keys [state resource], :as pool})

acquires a resource from the pool

(pool:acquire |pool|) => (contains string? ’)

pool:cleanup

added in 3.0

(pool:cleanup {:keys [state], :as pool})

runs cleanup on the pool

pool:create

added in 3.0

(pool:create m)

creates an initial pool

(pool:create {:size 5 :max 8 :keep-alive 10000 :poll 20000 :resource {:create (fn [] ’) :initial 0.3 :thread-local true}})

pool:dispose

added in 3.0

(pool:dispose {:keys [state resource], :as pool} id)

disposes an idle object

(pool:dispose |pool| (first (keys (pool:resources:idle |pool|))))

pool:dispose-over

added in 3.0

(pool:dispose-over {:keys [state resource], :as pool} id)

disposes if idle and busy are over size limit

pool:dispose:mark

added in 3.0

(pool:dispose:mark)

marks the current resource for dispose

pool:dispose:unmark

added in 3.0

(pool:dispose:unmark)

unmarks the current resource for dispose

pool:health

added in 3.0

(pool:health pool)

returns health of the pool

(pool:health |pool|) => {:status :ok}

pool:info

added in 3.0

(pool:info pool)(pool:info {:keys [state], :as pool} _)

returns information about the pool

(pool:info |pool|) => (contains-in {:running true, :idle 2, :busy 0, :resource {:count 0, :total number? :busy 0.0, :utilization 0.0, :duration 0}})

pool:kill

added in 3.0

(pool:kill pool)

kills the pool

(pool:kill |pool|) => pool:stopped?

pool:props

added in 3.0

(pool:props pool)

gets props for the pool

(keys (pool:props |pool|)) => (contains :size :max :keep-alive :poll)

pool:props:keep-alive

pool:props:max

pool:props:poll

pool:props:size

pool:release

added in 3.0

(pool:release pool id)(pool:release {:keys [state], :as pool} id dispose?)

releases a resource back to the pool

(let [id _(pool:acquire |pool|)] (pool:release |pool| id)) => string?

pool:resources:busy

added in 3.0

(pool:resources:busy {:keys [state], :as pool})

returns all the busy resources

pool:resources:idle

added in 3.0

(pool:resources:idle {:keys [state], :as pool})

returns all the idle resources

pool:resources:thread

added in 3.0

(pool:resources:thread pool)(pool:resources:thread {:keys [state], :as pool} thread)

returns acquired resources for a given thread

pool:start

added in 3.0

(pool:start {:keys [state resource poll], :as pool})

starts the pool

pool:started?

added in 3.0

(pool:started? {:keys [state], :as pool})

checks if pool has started

pool:stop

added in 3.0

(pool:stop {:keys [state], :as pool})

stops the pool

(pool:stop |pool|) => pool:stopped?

pool:stopped?

added in 3.0

(pool:stopped? pool)

checks if pool has stopped

pool:track-path

added in 3.0

(pool:track-path pool)

gets props for the pool

(pool:track-path |pool|) => :raw :pool

pool:with-resource

macro

added in 3.0

(pool:with-resource [obj pool] & body)

takes an object from the pool, performs operation then returns it

pool?

added in 3.0

(pool? obj)

checks that object is a pool

(pool? |pool|) => true

resource-info

added in 3.0

(resource-info res)(resource-info {:keys [create-time update-time busy used status]} mode)

returns info about the pool resource

(-> (pool-resource “hello” |pool|) (resource-info :full)) => (contains {:total number?, :busy 0.0, :count 0, :utilization 0.0, :duration 0})

resource-string

added in 3.0

(resource-string res)

returns a string describing the resource

wrap-pool-resource

added in 3.0

(wrap-pool-resource f pool)

wraps a function to operate on a pool resource