storelisten_int( integer, integer, integer )

1.115. storelisten_int( integer, integer, integer )

Function Properties

Language: PLPGSQL

Return Type: integer

FUNCTION storeListen_int (li_origin, li_provider, li_receiver) Process STORE_LISTEN event, indicating that receiver node li_receiver listens to node li_provider in order to get messages coming from node li_origin.

declare
	p_li_origin		alias for $1;
	p_li_provider	alias for $2;
	p_li_receiver	alias for $3;
	v_exists		int4;
begin
	-- ----
	-- Grab the central configuration lock
	-- ----
	lock table sl_config_lock;

	select 1 into v_exists
			from sl_listen
			where li_origin = p_li_origin
			and li_provider = p_li_provider
			and li_receiver = p_li_receiver;
	if not found then
		-- ----
		-- In case we receive STORE_LISTEN events before we know
		-- about the nodes involved in this, we generate those nodes
		-- as pending.
		-- ----
		if not exists (select 1 from sl_node
						where no_id = p_li_origin) then
			perform storeNode_int (p_li_origin, '<event pending>', 'f');
		end if;
		if not exists (select 1 from sl_node
						where no_id = p_li_provider) then
			perform storeNode_int (p_li_provider, '<event pending>', 'f');
		end if;
		if not exists (select 1 from sl_node
						where no_id = p_li_receiver) then
			perform storeNode_int (p_li_receiver, '<event pending>', 'f');
		end if;

		insert into sl_listen
				(li_origin, li_provider, li_receiver) values
				(p_li_origin, p_li_provider, p_li_receiver);
	end if;

	return 0;
end;