42
42
43
43
-include (" amqqueue.hrl" ).
44
44
45
- -behaviour (gen_server2 ).
45
+ -behaviour (gen_server ).
46
46
47
47
-export ([start_link /11 , start_link /12 , do /2 , do /3 , do_flow /3 , flush /1 , shutdown /1 ]).
48
48
-export ([send_command /2 ]).
217
217
put ({Type , Key }, none )
218
218
end ).
219
219
220
+ -define (HIBERNATE_AFTER , 6_000 ).
221
+
220
222
% %----------------------------------------------------------------------------
221
223
222
224
-export_type ([channel_number / 0 ]).
@@ -254,9 +256,10 @@ start_link(Channel, ReaderPid, WriterPid, ConnPid, ConnName, Protocol, User,
254
256
255
257
start_link (Channel , ReaderPid , WriterPid , ConnPid , ConnName , Protocol , User ,
256
258
VHost , Capabilities , CollectorPid , Limiter , AmqpParams ) ->
257
- gen_server2 :start_link (
259
+ Opts = [{hibernate_after , ? HIBERNATE_AFTER }],
260
+ gen_server :start_link (
258
261
? MODULE , [Channel , ReaderPid , WriterPid , ConnPid , ConnName , Protocol ,
259
- User , VHost , Capabilities , CollectorPid , Limiter , AmqpParams ], [] ).
262
+ User , VHost , Capabilities , CollectorPid , Limiter , AmqpParams ], Opts ).
260
263
261
264
-spec do (pid (), rabbit_framing :amqp_method_record ()) -> 'ok' .
262
265
@@ -282,17 +285,17 @@ do_flow(Pid, Method, Content) ->
282
285
-spec flush (pid ()) -> 'ok' .
283
286
284
287
flush (Pid ) ->
285
- gen_server2 :call (Pid , flush , infinity ).
288
+ gen_server :call (Pid , flush , infinity ).
286
289
287
290
-spec shutdown (pid ()) -> 'ok' .
288
291
289
292
shutdown (Pid ) ->
290
- gen_server2 :cast (Pid , terminate ).
293
+ gen_server :cast (Pid , terminate ).
291
294
292
295
-spec send_command (pid (), rabbit_framing :amqp_method_record ()) -> 'ok' .
293
296
294
297
send_command (Pid , Msg ) ->
295
- gen_server2 :cast (Pid , {command , Msg }).
298
+ gen_server :cast (Pid , {command , Msg }).
296
299
297
300
298
301
-spec deliver_reply (binary (), mc :state ()) -> 'ok' .
@@ -324,7 +327,7 @@ deliver_reply_v1(EncodedBin, Message) ->
324
327
325
328
deliver_reply_local (Pid , Key , Message ) ->
326
329
case pg_local :in_group (rabbit_channels , Pid ) of
327
- true -> gen_server2 :cast (Pid , {deliver_reply , Key , Message });
330
+ true -> gen_server :cast (Pid , {deliver_reply , Key , Message });
328
331
false -> ok
329
332
end .
330
333
@@ -338,7 +341,7 @@ declare_fast_reply_to(<<"amq.rabbitmq.reply-to.", EncodedBin/binary>>) ->
338
341
Msg = {declare_fast_reply_to , Key },
339
342
rabbit_misc :with_exit_handler (
340
343
rabbit_misc :const (not_found ),
341
- fun () -> gen_server2 :call (Pid , Msg , infinity ) end )
344
+ fun () -> gen_server :call (Pid , Msg , infinity ) end )
342
345
end ;
343
346
declare_fast_reply_to (_ ) ->
344
347
not_found .
@@ -350,7 +353,7 @@ declare_fast_reply_to_v1(EncodedBin) ->
350
353
Msg = {declare_fast_reply_to , V1Key },
351
354
rabbit_misc :with_exit_handler (
352
355
rabbit_misc :const (not_found ),
353
- fun () -> gen_server2 :call (V1Pid , Msg , infinity ) end );
356
+ fun () -> gen_server :call (V1Pid , Msg , infinity ) end );
354
357
{error , _ } ->
355
358
not_found
356
359
end .
@@ -375,7 +378,7 @@ info_keys() -> ?INFO_KEYS.
375
378
info (Pid ) ->
376
379
{Timeout , Deadline } = get_operation_timeout_and_deadline (),
377
380
try
378
- case gen_server2 :call (Pid , {info , Deadline }, Timeout ) of
381
+ case gen_server :call (Pid , {info , Deadline }, Timeout ) of
379
382
{ok , Res } -> Res ;
380
383
{error , Error } -> throw (Error )
381
384
end
@@ -390,7 +393,7 @@ info(Pid) ->
390
393
info (Pid , Items ) ->
391
394
{Timeout , Deadline } = get_operation_timeout_and_deadline (),
392
395
try
393
- case gen_server2 :call (Pid , {{info , Items }, Deadline }, Timeout ) of
396
+ case gen_server :call (Pid , {{info , Items }, Deadline }, Timeout ) of
394
397
{ok , Res } -> Res ;
395
398
{error , Error } -> throw (Error )
396
399
end
@@ -430,7 +433,7 @@ refresh_config_local() ->
430
433
_ = rabbit_misc :upmap (
431
434
fun (C ) ->
432
435
try
433
- gen_server2 :call (C , refresh_config , infinity )
436
+ gen_server :call (C , refresh_config , infinity )
434
437
catch _ :Reason ->
435
438
rabbit_log :error (" Failed to refresh channel config "
436
439
" for channel ~tp . Reason ~tp " ,
@@ -444,7 +447,7 @@ refresh_interceptors() ->
444
447
_ = rabbit_misc :upmap (
445
448
fun (C ) ->
446
449
try
447
- gen_server2 :call (C , refresh_interceptors , ? REFRESH_TIMEOUT )
450
+ gen_server :call (C , refresh_interceptors , ? REFRESH_TIMEOUT )
448
451
catch _ :Reason ->
449
452
rabbit_log :error (" Failed to refresh channel interceptors "
450
453
" for channel ~tp . Reason ~tp " ,
@@ -465,11 +468,11 @@ ready_for_close(Pid) ->
465
468
% This event is necessary for the stats timer to be initialized with
466
469
% the correct values once the management agent has started
467
470
force_event_refresh (Ref ) ->
468
- [gen_server2 :cast (C , {force_event_refresh , Ref }) || C <- list ()],
471
+ [gen_server :cast (C , {force_event_refresh , Ref }) || C <- list ()],
469
472
ok .
470
473
471
474
list_queue_states (Pid ) ->
472
- gen_server2 :call (Pid , list_queue_states ).
475
+ gen_server :call (Pid , list_queue_states ).
473
476
474
477
-spec update_user_state (pid (), rabbit_types :auth_user ()) -> 'ok' | {error , channel_terminated }.
475
478
@@ -485,6 +488,7 @@ update_user_state(Pid, UserState) when is_pid(Pid) ->
485
488
init ([Channel , ReaderPid , WriterPid , ConnPid , ConnName , Protocol , User , VHost ,
486
489
Capabilities , CollectorPid , LimiterPid , AmqpParams ]) ->
487
490
process_flag (trap_exit , true ),
491
+ process_flag (message_queue_data , off_heap ),
488
492
? LG_PROCESS_TYPE (channel ),
489
493
? store_proc_name ({ConnName , Channel }),
490
494
ok = pg_local :join (rabbit_channels , self ()),
@@ -549,8 +553,7 @@ init([Channel, ReaderPid, WriterPid, ConnPid, ConnName, Protocol, User, VHost,
549
553
fun () -> emit_stats (State2 ) end ),
550
554
put_operation_timeout (),
551
555
State3 = init_tick_timer (State2 ),
552
- {ok , State3 , hibernate ,
553
- {backoff , ? HIBERNATE_AFTER_MIN , ? HIBERNATE_AFTER_MIN , ? DESIRED_HIBERNATE }}.
556
+ {ok , State3 }.
554
557
555
558
prioritise_call (Msg , _From , _Len , _State ) ->
556
559
case Msg of
@@ -726,7 +729,7 @@ handle_info(emit_stats, State) ->
726
729
State1 = rabbit_event :reset_stats_timer (State , # ch .stats_timer ),
727
730
% % NB: don't call noreply/1 since we don't want to kick off the
728
731
% % stats timer.
729
- {noreply , send_confirms_and_nacks (State1 ), hibernate };
732
+ {noreply , send_confirms_and_nacks (State1 )};
730
733
731
734
handle_info ({{'DOWN' , QName }, _MRef , process , QPid , Reason },
732
735
# ch {queue_states = QStates0 } = State0 ) ->
@@ -821,14 +824,14 @@ get_consumer_timeout() ->
821
824
end .
822
825
% %---------------------------------------------------------------------------
823
826
824
- reply (Reply , NewState ) -> {reply , Reply , next_state (NewState ), hibernate }.
827
+ reply (Reply , NewState ) -> {reply , Reply , next_state (NewState )}.
825
828
826
- noreply (NewState ) -> {noreply , next_state (NewState ), hibernate }.
829
+ noreply (NewState ) -> {noreply , next_state (NewState )}.
827
830
828
831
next_state (State ) -> ensure_stats_timer (send_confirms_and_nacks (State )).
829
832
830
833
noreply_coalesce (# ch {confirmed = [], rejected = []} = State ) ->
831
- {noreply , ensure_stats_timer (State ), hibernate };
834
+ {noreply , ensure_stats_timer (State )};
832
835
noreply_coalesce (# ch {} = State ) ->
833
836
% Immediately process 'timeout' info message
834
837
{noreply , ensure_stats_timer (State ), 0 }.
0 commit comments