<commit_before>%% This file is provided to you 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.    

%% @doc A wrapper server for connecting riak_eventer handlers to the gen_event.

-module(riak_event_guard).

-export([start_link/0]).
-export([add_handler/3]).
-export([init/1, handle_info/2]).
-export([handle_call/3,handle_cast/2,code_change/3,terminate/2]).

-behavior(gen_server).

%% @spec start_link() -> {ok, pid()}
%% @doc The usual gen_server start_link mechanism.
start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

% @private
init([]) ->
    case gen_event:start_link({local,riak_event}) of
        {ok, Pid} -> {ok, Pid};
        {error,{already_started,Pid}} -> {ok, Pid};
        X -> {stop, {error_in_init, X}}
    end.

%% @spec add_handler(HandlerMod :: atom(), Arg :: term()) ->
%%       ok | {error, Error :: term()}
%% @doc Attach a new HandlerMod to riak events, started with Arg.
add_handler(HandlerMod, Arg, MatchSpec) ->
    gen_server:call(?MODULE, {add_handler, HandlerMod, Arg, MatchSpec}).

%% @private
handle_call({add_handler, HandlerMod, Arg, MatchSpec},_From,State) -> 
    {ok, MyRing} = riak_ring_manager:get_my_ring(),
    Eventers0 = case riak_ring:get_meta(eventers, MyRing) of
        undefined -> [];
        {ok, X} -> sets:to_list(X)<commit_msg>@spec fix<commit_after>%% This file is provided to you 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.    

%% @doc A wrapper server for connecting riak_eventer handlers to the gen_event.

-module(riak_event_guard).

-export([start_link/0]).
-export([add_handler/3]).
-export([init/1, handle_info/2]).
-export([handle_call/3,handle_cast/2,code_change/3,terminate/2]).

-behavior(gen_server).

%% @spec start_link() -> {ok, pid()}
%% @doc The usual gen_server start_link mechanism.
start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

% @private
init([]) ->
    case gen_event:start_link({local,riak_event}) of
        {ok, Pid} -> {ok, Pid};
        {error,{already_started,Pid}} -> {ok, Pid};
        X -> {stop, {error_in_init, X}}
    end.

%% @spec add_handler(HandlerMod :: atom(), Arg :: term(), 
%%                   MatchSpec :: string()) ->
%%       ok | {error, Error :: term()}
%% @doc Attach a new HandlerMod to riak events, started with Arg.
add_handler(HandlerMod, Arg, MatchSpec) ->
    gen_server:call(?MODULE, {add_handler, HandlerMod, Arg, MatchSpec}).

%% @private
handle_call({add_handler, HandlerMod, Arg, MatchSpec},_From,State) -> 
    {ok, MyRing} = riak_ring_manager:get_my_ring(),
    Eventers0 = case riak_ring:get_meta(eventers, MyRing) of
        undefined -> [];
        {ok, X} -> sets:to_list(X)
{'fraction_non_alphanumeric': 0.14735688852369214, 'fraction_numerical': 0.007121336620104081, 'mean_word_length': 4.051175656984785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '2726544', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1152, 'n_words': 358}