%% ------------------------------------------------------------------- %% %% Copyright (c) 2012 Basho Technologies, Inc. %% %% 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. %% %% ------------------------------------------------------------------- -module(verify_bdp_event_handler). -behaviour(gen_event). %% API -export([add_handler/1]). %% gen_event callbacks -export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2, code_change/3]). -record(state, { test_pid :: pid() }). %%%=================================================================== %%% gen_event callbacks %%%=================================================================== add_handler(Pid) -> gen_event:add_handler(riak_sysmon_handler, ?MODULE, Pid). %%%=================================================================== %%% gen_event callbacks %%%=================================================================== %%-------------------------------------------------------------------- %% @private %% @doc %% Whenever a new event handler is added to an event manager, %% this function is called to initialize the event handler. %% %% @spec init(Args) -> {ok, State} %% @end %%-------------------------------------------------------------------- init(Pid) -> {ok, #state{test_pid=Pid}}. %%-------------------------------------------------------------------- %% @private %% @doc %% Whenever an event manager receives an event sent using %% gen_event:notify/2 or gen_event:sync_notify/2, this function is %% called for each installed event handler to handle the event. %% %% @spec handle_event(Event, State) -> %% {ok, State} | %% {swap_handler, Args1, State1, Mod2, Args2} | %% remove_handler %% @end %%-------------------------------------------------------------------- handle_event({monitor, _, busy_dist_port, {_Port, _}}, State) -> %% notify test busy_dist_port event fired State#state.test_pid ! go, {ok, State}; handle_event(_Event, State) -> {ok, State}. %%-------------------------------------------------------------------- %% @private %% @doc %% Whenever an event manager receives a request sent using %% gen_event:call/3,4, this function is called for the specified %% event handler to handle the request. %% %% @spec handle_call(Request, State) -> %% {ok, Reply, State} | %% {swap_handler, Reply, Args1, State1, Mod2, Args2} | %% {remove_handler, Reply} %% @end %%-------------------------------------------------------------------- handle_call(_, State) -> {ok, ok, State}. %%-------------------------------------------------------------------- %% @private %% @doc %% This function is called for each installed event handler when %% an event manager receives any other message than an event or a %% synchronous request (or a system message). %% %% @spec handle_info(Info, State) -> %% {ok, State} | %% {swap_handler, Args1, State1, Mod2, Args2} | %% remove_handler %% @end %%-------------------------------------------------------------------- handle_info(_Info, State) -> {ok, State}. %%-------------------------------------------------------------------- %% @private %% @doc %% Whenever an event handler is deleted from an event manager, this %% function is called. It should be the opposite of Module:init/1 and %% do any necessary cleaning up. %% %% @spec terminate(Reason, State) -> void() %% @end %%-------------------------------------------------------------------- terminate(_Reason, _State) -> ok. %%-------------------------------------------------------------------- %% @private %% @doc %% Convert process state when code is changed %% %% @spec code_change(OldVsn, State, Extra) -> {ok, NewState} %% @end %%-------------------------------------------------------------------- code_change(_OldVsn, State, _Extra) -> {ok, State}.