<commit_before>% @copyright 2010-2012 Zuse Institute Berlin

%   Licensed under the Apache License, Version 2.0 (the "License");
%   you may not use this file except in compliance with the License.
%   You may obtain a copy of the License at
%
%       http://www.apache.org/licenses/LICENSE-2.0
%
%   Unless required by applicable law or agreed to in writing, software
%   distributed under the License is distributed on an "AS IS" BASIS,
%   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%   See the License for the specific language governing permissions and
%   limitations under the License.

%% @author <NAME> <<EMAIL>>
%% @doc    Heartbeat server (HBS) for fd.erl.
%%         Instatiated per pair of Erlang nodes/VMs.
%%         Sends heartbeats (symmetrically), and is proxy for local /
%%         remote subscriptions on Pid granularity. Uses
%%         erlang:monitor/2 to watch local Pids and forwards crash
%%         notification, when a watched Pid finishes.
%% @end
%% @version $Id$
-module(fd_hbs).
-author('<EMAIL>').
-vsn('$Id$').

%-define(TRACE(X,Y), io:format(X,Y)).
-define(TRACE(_X,_Y), ok).
%-define(TRACEPONG(X,Y), io:format(X,Y)).
-define(TRACEPONG(_X,_Y), ok).
-behavior(gen_component).
-include("scalaris.hrl").

-export([init/1, on/2, start_link/2, check_config/0]).

-type(rempid() :: %% locally existing subscriptions for remote pids
        {
          comm:mypid(),  %% remote pid a local subscriber is subscribed to
                         %% the other end (fd_hbs) has a monitor
                         %% established for this
          non_neg_integer(), %% number of local subscribers for the remote pid
          util:time(),   %% delay remote demonitoring:
                         %%   time of ref count reached 0
                         %%   all other modifications change this to {0,0,0}
          boolean()      %% delayed demonitoring requested and still open?
        }).

-type(state() :: {
       comm:mypid(), %% remote hbs
       [rempid()],  %% subscribed rem. pids + ref counting
       util:time(),  %% local time of last pong arrival
       util:time(),  %% remote is crashed if no pong arrives until this
       atom(),       %% ets table name
       %% locally erlang:monitored() pids for a remote hbs:
       [{comm:mypid(), reference()}]
     }).

-define(SEND_OPTIONS, [{channel, prio}]).

%% Akronyms: HBS =:= (local) heartbeat server instance

%% @doc spawns a fd_hbs instance
-spec start_link(pid_groups:groupname(), comm:mypid()) -> {ok, pid()}.
start_link(ServiceGroup, RemotePid) ->
    RemoteFDPid = comm:get(fd, RemotePid),
    Name = list_to_atom(lists:flatten(io_lib:format("fd <-> ~p", [RemoteFDPid]))),<commit_msg>do not create a atom() name for each fd_hbs<commit_after>% @copyright 2010-2012 Zuse Institute Berlin

%   Licensed under the Apache License, Version 2.0 (the "License");
%   you may not use this file except in compliance with the License.
%   You may obtain a copy of the License at
%
%       http://www.apache.org/licenses/LICENSE-2.0
%
%   Unless required by applicable law or agreed to in writing, software
%   distributed under the License is distributed on an "AS IS" BASIS,
%   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%   See the License for the specific language governing permissions and
%   limitations under the License.

%% @author <NAME> <<EMAIL>>
%% @doc    Heartbeat server (HBS) for fd.erl.
%%         Instatiated per pair of Erlang nodes/VMs.
%%         Sends heartbeats (symmetrically), and is proxy for local /
%%         remote subscriptions on Pid granularity. Uses
%%         erlang:monitor/2 to watch local Pids and forwards crash
%%         notification, when a watched Pid finishes.
%% @end
%% @version $Id$
-module(fd_hbs).
-author('<EMAIL>').
-vsn('$Id$').

%-define(TRACE(X,Y), io:format(X,Y)).
-define(TRACE(_X,_Y), ok).
%-define(TRACEPONG(X,Y), io:format(X,Y)).
-define(TRACEPONG(_X,_Y), ok).
-behavior(gen_component).
-include("scalaris.hrl").

-export([init/1, on/2, start_link/2, check_config/0]).

-type(rempid() :: %% locally existing subscriptions for remote pids
        {
          comm:mypid(),  %% remote pid a local subscriber is subscribed to
                         %% the other end (fd_hbs) has a monitor
                         %% established for this
          non_neg_integer(), %% number of local subscribers for the remote pid
          util:time(),   %% delay remote demonitoring:
                         %%   time of ref count reached 0
                         %%   all other modifications change this to {0,0,0}
          boolean()      %% delayed demonitoring requested and still open?
        }).

-type(state() :: {
       comm:mypid(), %% remote hbs
       [rempid()],  %% subscribed rem. pids + ref counting
       util:time(),  %% local time of last pong arrival
       util:time(),  %% remote is crashed if no pong arrives until this
       atom(),       %% ets table name
       %% locally erlang:monitored() pids for a remote hbs:
       [{comm:mypid(), reference()}]
     }).

-define(SEND_OPTIONS, [{channel, prio}]).

%% Akronyms: HBS =:= (local) heartbeat server instance

%% @doc spawns a fd_hbs instance
-spec start_link(pid_groups:groupname(), comm:mypid()) -> {ok, pid()}.
start_link(ServiceGroup, RemotePid) ->
    RemoteFDPid = comm:get(fd, RemotePid),
    Name = lists:flatten(io_lib:format("fd <-> ~p", [RemoteFDPid])),
{'fraction_non_alphanumeric': 0.1278941565600882, 'fraction_numerical': 0.007717750826901874, 'mean_word_length': 2.890636168691923, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3774876', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1600, 'n_words': 555}