Module wpool_pool

A pool of workers.

Behaviours: supervisor.

Authors: Fernando Benavides (elbrujohalcon@inaka.net).

Description

A pool of workers. If you want to put it in your supervisor tree, remember it's a supervisor.

Data Types

wpool()

abstract datatype: wpool()

Function Index

add_callback_module/2
all/0
best_worker/1Picks the worker with the smaller queue of messages.
broadcast/2Casts a message to all the workers within the given pool.
call_available_worker/3Picks the first available worker and sends the call to it.
cast_to_available_worker/2Casts a message to the first available worker.
create_table/0Creates the ets table that will hold the information about active pools.
find_wpool/1Use this function to get the Worker pool record in a custom worker.
hash_worker/2Picks a worker base on a hash result.
next/2Set next within the worker pool record.
next_available_worker/1Picks the first available worker, if any.
next_worker/1Picks the next worker in a round robin fashion.
random_worker/1Picks a random worker.
remove_callback_module/2
start_link/2Starts a supervisor with several wpool_processes as its children.
stats/0Retrieves the pool stats for all pools.
stats/1Retrieves a snapshot of the pool stats.
time_checker_name/1
wpool_get/2Get values from the worker pool record.

Function Details

add_callback_module/2

add_callback_module(Pool::wpool:name(), Module::module()) -> ok | {error, term()}

all/0

all() -> [wpool:name()]

best_worker/1

best_worker(Sup::wpool:name()) -> atom()

throws no_workers

Picks the worker with the smaller queue of messages.

broadcast/2

broadcast(Sup::wpool:name(), Cast::term()) -> ok

Casts a message to all the workers within the given pool.

call_available_worker/3

call_available_worker(Sup::wpool:name(), Call::any(), Timeout::timeout()) -> atom()

throws no_workers | timeout

Picks the first available worker and sends the call to it. The timeout provided includes the time it takes to get a worker and for it to process the call.

cast_to_available_worker/2

cast_to_available_worker(Sup::wpool:name(), Cast::term()) -> ok

Casts a message to the first available worker. Since we can wait forever for a wpool:cast to be delivered but we don't want the caller to be blocked, this function just forwards the cast when it gets the worker

create_table/0

create_table() -> ok

Creates the ets table that will hold the information about active pools

find_wpool/1

find_wpool(Name::atom()) -> undefined | wpool()

Use this function to get the Worker pool record in a custom worker.

hash_worker/2

hash_worker(Sup::wpool:name(), HashKey::term()) -> atom()

throws no_workers

Picks a worker base on a hash result.

phash2(Term, Range)
returns hash = integer, 0 <= hash < Range so
1
must be added

next/2

next(Next::pos_integer(), WPool::wpool()) -> wpool()

Set next within the worker pool record. Useful when using a custom strategy function.

next_available_worker/1

next_available_worker(Sup::wpool:name()) -> atom()

throws no_workers | no_available_workers

Picks the first available worker, if any

next_worker/1

next_worker(Sup::wpool:name()) -> atom()

throws no_workers

Picks the next worker in a round robin fashion

random_worker/1

random_worker(Sup::wpool:name()) -> atom()

throws no_workers

Picks a random worker

remove_callback_module/2

remove_callback_module(Pool::wpool:name(), Module::module()) -> ok | {error, term()}

start_link/2

start_link(Name::wpool:name(), Options::[wpool:option()]) -> {ok, pid()} | {error, {already_started, pid()} | term()}

Starts a supervisor with several wpool_processes as its children

stats/0

stats() -> [wpool:stats()]

Retrieves the pool stats for all pools

stats/1

stats(Sup::wpool:name()) -> wpool:stats()

throws no_workers

Retrieves a snapshot of the pool stats

time_checker_name/1

time_checker_name(Sup::wpool:name()) -> atom()

wpool_get/2

wpool_get(List::atom(), WPool::wpool()) -> any()

wpool_get(List::[atom()], WPool::wpool()) -> any()

Get values from the worker pool record. Useful when using a custom strategy function.


Generated by EDoc