Blanket
This is the facade of the Blanket application. Handles starting/stopping the application and defines the client API.
Summary
abandon_table(tab) | Finds the heir associated with the table, and stops it |
claim_table(tref, opts) | Create an ETS table associated to a table reference, or claims the ownership of the table, after a restart |
recover_heir(tab) | Creates a new heir for the table |
Functions
Specs:
- abandon_table(:ets.tid) :: :ok | {:error, any}
Finds the heir associated with the table, and stops it.
The calling process must own the table.
Specs:
- claim_table(term, Keyword.t) :: {:ok, :ets.tid} | {:ok, :ets.tid, reference} | {:error, term}
Create an ETS table associated to a table reference, or claims the ownership of the table, after a restart.
The table reference is used in Blanket and is not the ETS table id. A table reference can actually be any term but must be unique.
This function must be called by the process that will own the table, best is
to put it in your c:GenServer.init/1
or c:Agent.start_link/2
function.
If your process crashes, it must be restarted with the same table reference in
order to retrieve its ETS table. The table reference argument should be in the
supervisor child spec or in the Supervisor.start_child/2
for instance.
Available Options
:create_table
, required. Determines how to create the ETS table
the first time the heir is created. One of the following :
- A
fn
returning{:ok, tab}
wheretab
is the identifier of the created ETS table. - A tuple
{table_name, table_opts}
which will be used to call:ets.new(table_name, table_opts)
. - A module name, e.g.
MyTableServer
or__MODULE__
. The module must export acreate_table/1
function which will be passed the wholeclaim_table
options list and must return{:ok, tab}
wheretab
is the identifier of the created ETS table.
Any {:heir, _, _}
set on the table will be overriden by the Blanket heir.
:monitor
, optional, defaults to false. If true, the calling process will
set a monitor the heir process and receive a :'DOWN'
message if the latter
crashes. Mostly useless because heir have an extremely rare chance to crash,
as they do basically nothing.
:monitor_ref
, optional, defaults to false. If true, the return of
claim_table/2
also includ a monitor reference as the third element.
Specs:
- recover_heir(:ets.tid) :: {:ok, reference} | {:error, any}
Creates a new heir for the table.
The calling process must be the table owner. Sets a monitor and return the new process monitor ref.
This function should not be called if the heir is not dead because the current heir will not be turned down while booting a new one.