<commit_before>%% @doc nodefinder+ec2nodefinder service.
%% @end

-module (combonodefinder).
-export ([ discover/0 ]).
-behaviour (application).
-export ([ start/0, start/2, stop/0, stop/1 ]).

%-=====================================================================-
%-                                Public                               -
%-=====================================================================-

%% @spec discover () -> ok
%% @doc Initiate a discovery request.  Nodes will respond 
%% synchronously (on EC2) or asynchronously (not on EC2) 
%% and therefore should not necessarily be considered added to the 
%% erlang node list subsequent to this call returning.
%% @end

discover () ->
  case is_ec2_host () of
    true -> ec2nodefindersrv:discover ();
    false -> nodefindersrv:discover ()
  end.

%-=====================================================================-
%-                        application callbacks                        -
%-=====================================================================-

%% @hidden

start () ->
  crypto:start (),
  application:start (inets),
  application:start (combonodefinder).

%% @hidden

start (Type, Args) ->
  case is_ec2_host () of
    true -> ec2nodefinder:start (Type, Args);
    false -> nodefinder:start (Type, Args)
  end.

%% @hidden

stop () ->
  application:stop (combonodefinder).

%% @hidden

stop (State) ->
  case is_ec2_host () of
    true -> ec2nodefinder:stop (State);
    false -> nodefinder:stop (State)
  end.

%-=====================================================================-
%-                               Private                               -
%-=====================================================================-

is_ec2_host () ->
  Host = lists:last (string:tokens (atom_to_list (node ()), "@")),

  case lists:reverse (string:tokens (Host, ".")) of
    [ "com", "amazonaws" | _ ] -> true;
    _ -> false
  end.<commit_msg>adding alternative ec2 mode<commit_after>%% @doc nodefinder+ec2nodefinder service.
%% @end

-module (combonodefinder).
-export ([ discover/0 ]).
-behaviour (application).
-export ([ start/0, start/2, stop/0, stop/1 ]).

%-=====================================================================-
%-                                Public                               -
%-=====================================================================-

%% @spec discover () -> ok
%% @doc Initiate a discovery request.  Nodes will respond 
%% synchronously (on EC2) or asynchronously (not on EC2) 
%% and therefore should not necessarily be considered added to the 
%% erlang node list subsequent to this call returning.
%% @end

discover () ->
  case is_ec2_host () of
    true -> ec2nodefindersrv:discover ();
    false -> nodefindersrv:discover ()
  end.

%-=====================================================================-
%-                        application callbacks                        -
%-=====================================================================-

%% @hidden

start () ->
  crypto:start (),
  application:start (inets),
  application:start (combonodefinder).

%% @hidden

start (Type, Args) ->
  case is_ec2_host () of
    true -> start_ec2_mode(Type, Args);
    false -> nodefinder:start (Type, Args)
  end.

%% @hidden

start_ec2_mode(Type, Args) ->
  case application:get_env (combonodefinder, use_erlcloud) of
    true -> 
		ec2nodefinder:start (Type, Args);
	false -> 
		application:start (erlcloud), 
		ec2erlcloudnodefinder:start (Type, Args)
  end.

%% @hidden

stop () ->
  application:stop (combonodefinder).

%% @hidden

stop (State) ->
  case is_ec2_host () of
    true -> stop_ec2_mode (State);
    false -> nodefinder:stop (State)
  end.

%% @hidden

stop_ec2_mode(Type, Args) ->
  case application:get_env (combonodefinder, use_erlcloud) of
    true -> ec2nodefinder:stop (State);
	false -> ec2erlcloudnodefinder:stop (State)
  end.

%-=====================================================================-
%-                               Private                               -
%-=====================================================================-

is_ec2_host () ->
  Host = lists:last (string:tokens (atom_to_list (node ()), "@")),

  case lists:reverse (string:tokens (Host, ".")) of
    [ "com", "amazonaws" | _ ] -> true;
    _ -> false
  end.
{'fraction_non_alphanumeric': 0.3090446449225075, 'fraction_numerical': 0.008558871154291001, 'mean_word_length': 3.1024667931688805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, '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': '1996433', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1172, 'n_words': 281}