<commit_before>%%%-------------------------------------------------------------------
%%% File    : prfHost.erl
%%% Author  : <NAME> <<EMAIL>>
%%% Description : 
%%%
%%% Created :  2 Dec 2003 by <NAME> <<EMAIL>>
%%%-------------------------------------------------------------------
-module(prfHost).

-export([start/3,start/4,stop/1,config/3]).
-export([loop/1]).				%internal

-record(ld, {node, server=[], collectors, config=[], 
             proxy, consumer, consumer_data, data=[]}).

-define(LOOP, ?MODULE:loop).

-include("log.hrl").

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% runs in the shell

start(Name,Node,Consumer) -> start(Name,Node,Consumer,no_proxy).
start(Name,Node,Consumer,Proxy)
  when is_atom(Name),is_atom(Node),is_atom(Consumer),is_atom(Proxy) -> 
  assert_proxy(Proxy),
  SpawnFun = fun()->init(Consumer,Node,Proxy) end,
  case whereis(Name) of
    undefined -> register(Name, spawner(SpawnFun));
    Pid -> Pid
  end.

spawner(F) ->
  case is_in_shell() of
    true -> spawn(F);
    false-> spawn_link(F)
  end.

stop(Name) -> 
  case whereis(Name) of
    Pid when is_pid(Pid) -> Name ! {self(),stop}, receive stopped -> ok end;
    _ -> ok
  end.

config(Name,Type,Data) ->
  case whereis(Name) of
    Pid when is_pid(Pid) -> Pid ! {config,{Type,Data}};
    _ -> {Name,not_running}
  end.

assert_proxy(no_proxy) -> ok;
assert_proxy(Node) ->
  erlang:set_cookie(Node,watchdog),
  case net_adm:ping(Node) of
    pong -> ok;
    _    -> exit({no_proxy,Node})
end.

is_in_shell() ->
  {_,{x,S}} = (catch erlang:error(x)),
  element(1,hd(lists:reverse(S))) == shell.<commit_msg>Consistently return a PID from prfHost:start<commit_after>%%%-------------------------------------------------------------------
%%% File    : prfHost.erl
%%% Author  : <NAME> <<EMAIL>>
%%% Description : 
%%%
%%% Created :  2 Dec 2003 by <NAME> <<EMAIL>>
%%%-------------------------------------------------------------------
-module(prfHost).

-export([start/3,start/4,stop/1,config/3]).
-export([loop/1]).				%internal

-record(ld, {node, server=[], collectors, config=[], 
             proxy, consumer, consumer_data, data=[]}).

-define(LOOP, ?MODULE:loop).

-include("log.hrl").

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% runs in the shell

start(Name,Node,Consumer) -> start(Name,Node,Consumer,no_proxy).
start(Name,Node,Consumer,Proxy)
  when is_atom(Name),is_atom(Node),is_atom(Consumer),is_atom(Proxy) -> 
  assert_proxy(Proxy),
  SpawnFun = fun()->init(Consumer,Node,Proxy) end,
  case whereis(Name) of
    undefined ->
          Pid = spawner(SpawnFun),
          true = register(Name, Pid),
          Pid;
    Pid ->
          Pid
  end.

spawner(F) ->
  case is_in_shell() of
    true -> spawn(F);
    false-> spawn_link(F)
  end.

stop(Name) -> 
  case whereis(Name) of
    Pid when is_pid(Pid) -> Name ! {self(),stop}, receive stopped -> ok end;
    _ -> ok
  end.

config(Name,Type,Data) ->
  case whereis(Name) of
    Pid when is_pid(Pid) -> Pid ! {config,{Type,Data}};
    _ -> {Name,not_running}
  end.

assert_proxy(no_proxy) -> ok;
assert_proxy(Node) ->
  erlang:set_cookie(Node,watchdog),
  case net_adm:ping(Node) of
    pong -> ok;
    _    -> exit({no_proxy,Node})
end.

is_in_shell() ->
  {_,{x,S}} = (catch erlang:error(x)),
  element(1,hd(lists:reverse(S))) == shell.
{'fraction_non_alphanumeric': 0.2937166567871962, 'fraction_numerical': 0.006520450503852994, 'mean_word_length': 2.700657894736842, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3691813', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1160, 'n_words': 216}