Module espace_tspace_srv

This is the custodian gen_server for the tuple space ETS table.

Copyright © (C) 2018, Fred Youhanaie

Behaviours: gen_server.

Authors: Fred Youhanaie (fyrlang@anydata.co.uk).

Description

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 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.

The etsmgr application is used to add resiliency to the server data, should the server restart while it is holding tuple space data.

Function Index

add_tuple/2Add a new tuple to the tuple space ETS table.
get_tuple/3Lookup a tuple pattern in the tuple space ETS table.
start_link/1 Starts the server.

Function Details

add_tuple/2

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.

Once the tuple is added it will trigger the 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/3

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, Key, List, Tuple} is returned, where Key uniquely identifies the ETS record, 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 for rd and rdp we do not require write access to the table, we can skip calling the gen_server and read from the ETS table directly.

For rd and 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/1

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