db_connection v0.2.2 DBConnection.Ownership
A DBConnection.Pool
that requires explicit checkout and checking
as a mechanism to coordinate between processes.
Options
:ownership_pool
- The actual pool to use to power the ownership mechanism. The pool is started when the ownership pool is started, although this option may also be given onownership_checkout/2
allowing developers to customize the pool checkout/checkin:ownership_mode
- When mode is:manual
, all connections must be explicitly checked out before by usingownership_checkout/2
. Otherwise, mode is:auto
and connections are checked out implicitly. In both cases, checkins are implicit viaownership_checkin/2
. Defaults to:auto
.
If the :ownership_pool
has an atom name given in the :name
option,
an ETS table will be created and automatically used for lookups whenever
the name is used on checkout.
Finally, if the :caller
option is given on checkout with a pid and no
pool is assigned to the current process, a connection will be allowed
from the given pid and used on checkout with :pool_timeout
of :infinity
.
This is useful when multiple tasks need to collaborate on the same
connection (hence the :infinity
timeout).
Summary
Functions
Allows the process given by allow
to use the connection checked out by owner
Checks a connection back in
Explicitly checks a connection out from the ownership manager
Changes the ownwership mode
Functions
Specs
ownership_allow(GenServer.server, owner :: pid, allow :: pid, Keyword.t) ::
:ok |
{:already, :owner | :allowed} |
:not_owner |
:not_found
Allows the process given by allow
to use the connection checked out by owner
.
It may return :ok
if the connection is checked out.
{:already, :owner | :allowed}
if the allow
process already
has a connection, :not_owner
if the owner process is not an
owner or :not_found
if the owner process does not have any
connection checked out.
Specs
ownership_checkin(GenServer.server, Keyword.t) ::
:ok |
:not_owner |
:not_found
Checks a connection back in.
A connection can only be checked back in by its owner.
Specs
ownership_checkout(GenServer.server, Keyword.t) ::
:ok |
{:already, :owner | :allowed} |
:error |
no_return
Explicitly checks a connection out from the ownership manager.
It may return :ok
if the connection is checked out.
{:already, :owner | :allowed}
if the caller process already
has a connection, :error
if it could be not checked out or
raise if there was an error.
Specs
ownership_mode(GenServer.server, :auto | :manual, Keyword.t) :: :ok
Changes the ownwership mode.
mode
may be :auto
or :manual
. Returns :ok
.