gen_server
for the tuple space ETS table.
Copyright © (C) 2018, Fred Youhanaie
Behaviours: gen_server
.
Authors: Fred Youhanaie (fyrlang@anydata.co.uk
).
This is the custodian gen_server
for the tuple space ETS table.
The table is created as an ordered_set
and in protected
mode. All access to the table is expected to come through this
server, although other proceses can inspect the contents of the
table for debugging purposes.
Each record has the form {Num, {Tuple}}
, where Num
is a unique
integer key that we initialize to 0 and increment before inserting
the next record, and Tuple
is the user supplied payload. For example
if the tuple {hello, 123}
is the first to be added, then the
inserted record will be {1, {hello, 123}}
.
The ETS table name used will reflect the espace
instance
name. This will be espace_tspace
for the default/unnamed
instance, and espace_tspace_abc
for an instance named abc
.
etsmgr
application provides resilience for the server data,
should the server restart while it is holding tuple space data.
add_tuple/2 | Add a new tuple to the tuple space ETS table. |
get_tuple/3 | Lookup a tuple pattern in the tuple space ETS table. |
start_link/1 | Starts the server. |
add_tuple(Inst_name::atom(), Tuple::tuple()) -> done
Add a new tuple to the tuple space ETS table.
The tuple is inserted with a unique integer
as the key, the key
is incremented with every insert.
espace_tspatt_srv
server to check for any waiting (blocking) clients whose in
/rd
pattern matches the newly inserted tuple. We do not wait for any
replies from espace_tspatt_srv
.
get_tuple(Inst_name::atom(), Espace_op::in | rd | inp | rdp, Pattern::tuple()) -> {nomatch} | {nomatch, reference()} | {match, {list(), tuple()}}
Lookup a tuple pattern in the tuple space ETS table.
If no match is found, {nomatch}
is returned.
If a match is found, {match, {List, Tuple}}
is returned, where
List
is the list of the $N
elements referenced in the pattern,
if any, and Tuple
is the second part of the ETS record.
This function runs within the client process. Since rdp
does not
require write access to the table, we can skip calling the
gen_server and read the data directly from the ETS table.
rdp
, although we are bypassing the gen_server, we still need
to provide some of the State
data to the handler. For now, this
is created manually, but it will be fixed more elegantly in future.
start_link(Inst_name::atom()) -> {ok, pid()} | ignore | {error, {already_started, pid()} | term()}
Starts the server.
We expect an instance name to be supplied, which will be used to uniquely identify the ETS table for the instance.Generated by EDoc