Module espace_tspatt_srv

Custodian for the espace_tspatt, waiting patterns, ETS table.

Copyright © (C) 2018, Fred Youhanaie

Behaviours: gen_server.

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

Description

Custodian for the espace_tspatt, waiting patterns, ETS table.

The table is created as a set and in protected mode. All access to the table is expected to come through this server. However, other proceses can inspect the contents of the table for debugging purposes.

The table keeps track of client processes that are blocked on in or rd waiting for a tuple matching their pattern to be added to the tuple space. In effect the ETS table is a pattern waiting list.

Our sole client is espace_tspace_srv. Whenever an in or rd operation does not find a match the client is given a unique key to wait on, and that key along with the pattern and client's pid is passed to us, via add_pattern/4, to add to the waiting list.

Whenever a new tuple is added to the tuple space, we will receive a copy of the tuple, via check_waitlist/2, to check against waiting patterns. If we find a match, the correponding client(s) will be notified of the new arrival.

Communication from espace_tspace_srv is unidirectional. Once it sends us a request, it will continue with its own work. We never reply to espace_tspace_srv.

The ETS table name used will reflect the espace instance name. This will be espace_tspatt for the default/unnamed instance, and espace_tspatt_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 patterns.

Function Index

add_pattern/4Add a new pattern to the waiting list.
check_waitlist/2Check a tuple against waiting patterns.
start_link/1 Starts the server.

Function Details

add_pattern/4

add_pattern(Inst_name::atom(), Cli_ref::reference(), Pattern::tuple(), Cli_pid::pid()) -> ok

Add a new pattern to the waiting list.

We insert the Pattern along with the client's pid and unique ref in the ETS table.

check_waitlist/2

check_waitlist(Inst_name::atom(), Tuple::tuple()) -> ok

Check a tuple against waiting patterns.

We check the newly added tuple against the existing client patterns using ets:test_ms/2. If a pattern is found, the waiting client(s) will be informed, via their Pid and Cli_Ref, to retry the in or rd operation.

Once a client is notified, the pattern will be removed from the waiting list.

start_link/1

start_link(Inst_name::atom()) -> ignore | {error, {already_started, pid()} | term()} | {ok, pid()}

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