Generated on 2009-08-09 21:22:57 with etap 0.3.4.
| Name | Total lines | Lines of code | Total coverage | Code coverage | ||||
| couch_event_sup | ?? | ?? | ?? |
|
....1 % Licensed under the Apache License, Version 2.0 (the "License"); you may not ....2 % use this file except in compliance with the License. You may obtain a copy of ....3 % the License at ....4 % ....5 % http://www.apache.org/licenses/LICENSE-2.0 ....6 % ....7 % Unless required by applicable law or agreed to in writing, software ....8 % distributed under the License is distributed on an "AS IS" BASIS, WITHOUT ....9 % WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the ...10 % License for the specific language governing permissions and limitations under ...11 % the License. ...12 ...13 %% The purpose of this module is to allow event handlers to particpate in Erlang ...14 %% supervisor trees. It provide a monitorable process that crashes if the event ...15 %% handler fails. The process, when shutdown, deregisters the event handler. ...16 ...17 -module(couch_event_sup). ...18 -behaviour(gen_server). ...19 ...20 -include("couch_db.hrl"). ...21 ...22 -export([start_link/3,start_link/4, stop/1]). ...23 -export([init/1, terminate/2, handle_call/3, handle_cast/2, handle_info/2,code_change/3]). ...24 ...25 % ...26 % Instead calling the ...27 % ok = gen_event:add_sup_handler(error_logger, my_log, Args) ...28 % ...29 % do this: ...30 % {ok, LinkedPid} = couch_event_sup:start_link(error_logger, my_log, Args) ...31 % ...32 % The benefit is the event is now part of the process tree, and can be ...33 % started, restarted and shutdown consistently like the rest of the server ...34 % components. ...35 % ...36 % And now if the "event" crashes, the supervisor is notified and can restart ...37 % the event handler. ...38 % ...39 % Use this form to named process: ...40 % {ok, LinkedPid} = couch_event_sup:start_link({local, my_log}, error_logger, my_log, Args) ...41 % ...42 ...43 start_link(EventMgr, EventHandler, Args) -> ...44 gen_server:start_link(couch_event_sup, {EventMgr, EventHandler, Args}, []). ...45 ...46 start_link(ServerName, EventMgr, EventHandler, Args) -> ...47 gen_server:start_link(ServerName, couch_event_sup, {EventMgr, EventHandler, Args}, []). ...48 ...49 stop(Pid) -> ...50 gen_server:cast(Pid, stop). ...51 ...52 init({EventMgr, EventHandler, Args}) -> ...53 ok = gen_event:add_sup_handler(EventMgr, EventHandler, Args), ...54 {ok, {EventMgr, EventHandler}}. ...55 ...56 terminate(_Reason, _State) -> ...57 ok. ...58 ...59 handle_call(_Whatever, _From, State) -> ...60 {ok, State}. ...61 ...62 handle_cast(stop, State) -> ...63 {stop, normal, State}. ...64 ...65 handle_info({gen_event_EXIT, _Handler, Reason}, State) -> ...66 {stop, Reason, State}. ...67 ...68 code_change(_OldVsn, State, _Extra) -> ...69 {ok, State}.
Generated using etap 0.3.4.