|
| 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 | +-module(couch_changes_mon). |
| 14 | + |
| 15 | +-behaviour(gen_server). |
| 16 | + |
| 17 | +-export([decrement_clients_requesting_changes_on_exit/0]). |
| 18 | + |
| 19 | +-export([ |
| 20 | + start_link/0, |
| 21 | + init/1, |
| 22 | + handle_call/3, |
| 23 | + handle_cast/2, |
| 24 | + handle_info/2 |
| 25 | +]). |
| 26 | + |
| 27 | +decrement_clients_requesting_changes_on_exit() -> |
| 28 | + gen_server:cast(?MODULE, {monitor_me, self()}). |
| 29 | + |
| 30 | +start_link() -> |
| 31 | + gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). |
| 32 | + |
| 33 | +init(_) -> |
| 34 | + {ok, nil}. |
| 35 | + |
| 36 | +handle_call(_Msg, _From, State) -> |
| 37 | + {reply, error, State}. |
| 38 | + |
| 39 | +handle_cast({monitor_me, Pid}, State) -> |
| 40 | + monitor(process, Pid), |
| 41 | + {noreply, State}. |
| 42 | + |
| 43 | +handle_info({'DOWN', _MonitorRef, process, _Pid, _Info}, State) -> |
| 44 | + couch_stats:decrement_counter([couchdb, httpd, clients_requesting_changes]), |
| 45 | + {noreply, State}; |
| 46 | +handle_info(_Msg, State) -> |
| 47 | + {noreply, State}. |
0 commit comments