44
44
45
45
-include (" amqqueue.hrl" ).
46
46
47
- -behaviour (gen_server2 ).
47
+ -behaviour (gen_server ).
48
48
49
49
-export ([start_link /11 , start_link /12 , do /2 , do /3 , do_flow /3 , flush /1 , shutdown /1 ]).
50
50
-export ([send_command /2 ]).
221
221
put ({Type , Key }, none )
222
222
end ).
223
223
224
+ -define (HIBERNATE_AFTER , 6_000 ).
225
+
224
226
% %----------------------------------------------------------------------------
225
227
226
228
-export_type ([channel_number / 0 ]).
@@ -258,9 +260,10 @@ start_link(Channel, ReaderPid, WriterPid, ConnPid, ConnName, Protocol, User,
258
260
259
261
start_link (Channel , ReaderPid , WriterPid , ConnPid , ConnName , Protocol , User ,
260
262
VHost , Capabilities , CollectorPid , Limiter , AmqpParams ) ->
261
- gen_server2 :start_link (
263
+ Opts = [{hibernate_after , ? HIBERNATE_AFTER }],
264
+ gen_server :start_link (
262
265
? MODULE , [Channel , ReaderPid , WriterPid , ConnPid , ConnName , Protocol ,
263
- User , VHost , Capabilities , CollectorPid , Limiter , AmqpParams ], [] ).
266
+ User , VHost , Capabilities , CollectorPid , Limiter , AmqpParams ], Opts ).
264
267
265
268
-spec do (pid (), rabbit_framing :amqp_method_record ()) -> 'ok' .
266
269
@@ -286,17 +289,17 @@ do_flow(Pid, Method, Content) ->
286
289
-spec flush (pid ()) -> 'ok' .
287
290
288
291
flush (Pid ) ->
289
- gen_server2 :call (Pid , flush , infinity ).
292
+ gen_server :call (Pid , flush , infinity ).
290
293
291
294
-spec shutdown (pid ()) -> 'ok' .
292
295
293
296
shutdown (Pid ) ->
294
- gen_server2 :cast (Pid , terminate ).
297
+ gen_server :cast (Pid , terminate ).
295
298
296
299
-spec send_command (pid (), rabbit_framing :amqp_method_record ()) -> 'ok' .
297
300
298
301
send_command (Pid , Msg ) ->
299
- gen_server2 :cast (Pid , {command , Msg }).
302
+ gen_server :cast (Pid , {command , Msg }).
300
303
301
304
302
305
-spec deliver_reply (binary (), mc :state ()) -> 'ok' .
@@ -317,7 +320,7 @@ deliver_reply(<<"amq.rabbitmq.reply-to.", EncodedBin/binary>>, Message) ->
317
320
318
321
deliver_reply_local (Pid , Key , Message ) ->
319
322
case pg_local :in_group (rabbit_channels , Pid ) of
320
- true -> gen_server2 :cast (Pid , {deliver_reply , Key , Message });
323
+ true -> gen_server :cast (Pid , {deliver_reply , Key , Message });
321
324
false -> ok
322
325
end .
323
326
@@ -330,13 +333,25 @@ declare_fast_reply_to(<<"amq.rabbitmq.reply-to.", EncodedBin/binary>>) ->
330
333
Msg = {declare_fast_reply_to , Key },
331
334
rabbit_misc :with_exit_handler (
332
335
rabbit_misc :const (not_found ),
333
- fun () -> gen_server2 :call (Pid , Msg , infinity ) end );
336
+ fun () -> gen_server :call (Pid , Msg , infinity ) end );
334
337
{error , _ } ->
335
338
not_found
336
339
end ;
337
340
declare_fast_reply_to (_ ) ->
338
341
not_found .
339
342
343
+ declare_fast_reply_to_v1 (EncodedBin ) ->
344
+ % % the the original encoding function
345
+ case rabbit_direct_reply_to :decode_reply_to_v1 (EncodedBin ) of
346
+ {ok , V1Pid , V1Key } ->
347
+ Msg = {declare_fast_reply_to , V1Key },
348
+ rabbit_misc :with_exit_handler (
349
+ rabbit_misc :const (not_found ),
350
+ fun () -> gen_server :call (V1Pid , Msg , infinity ) end );
351
+ {error , _ } ->
352
+ not_found
353
+ end .
354
+
340
355
-spec list () -> [pid ()].
341
356
342
357
list () ->
@@ -357,7 +372,7 @@ info_keys() -> ?INFO_KEYS.
357
372
info (Pid ) ->
358
373
{Timeout , Deadline } = get_operation_timeout_and_deadline (),
359
374
try
360
- case gen_server2 :call (Pid , {info , Deadline }, Timeout ) of
375
+ case gen_server :call (Pid , {info , Deadline }, Timeout ) of
361
376
{ok , Res } -> Res ;
362
377
{error , Error } -> throw (Error )
363
378
end
@@ -372,7 +387,7 @@ info(Pid) ->
372
387
info (Pid , Items ) ->
373
388
{Timeout , Deadline } = get_operation_timeout_and_deadline (),
374
389
try
375
- case gen_server2 :call (Pid , {{info , Items }, Deadline }, Timeout ) of
390
+ case gen_server :call (Pid , {{info , Items }, Deadline }, Timeout ) of
376
391
{ok , Res } -> Res ;
377
392
{error , Error } -> throw (Error )
378
393
end
@@ -412,7 +427,7 @@ refresh_config_local() ->
412
427
_ = rabbit_misc :upmap (
413
428
fun (C ) ->
414
429
try
415
- gen_server2 :call (C , refresh_config , infinity )
430
+ gen_server :call (C , refresh_config , infinity )
416
431
catch _ :Reason ->
417
432
rabbit_log :error (" Failed to refresh channel config "
418
433
" for channel ~tp . Reason ~tp " ,
@@ -426,7 +441,7 @@ refresh_interceptors() ->
426
441
_ = rabbit_misc :upmap (
427
442
fun (C ) ->
428
443
try
429
- gen_server2 :call (C , refresh_interceptors , ? REFRESH_TIMEOUT )
444
+ gen_server :call (C , refresh_interceptors , ? REFRESH_TIMEOUT )
430
445
catch _ :Reason ->
431
446
rabbit_log :error (" Failed to refresh channel interceptors "
432
447
" for channel ~tp . Reason ~tp " ,
@@ -447,11 +462,11 @@ ready_for_close(Pid) ->
447
462
% This event is necessary for the stats timer to be initialized with
448
463
% the correct values once the management agent has started
449
464
force_event_refresh (Ref ) ->
450
- [gen_server2 :cast (C , {force_event_refresh , Ref }) || C <- list ()],
465
+ [gen_server :cast (C , {force_event_refresh , Ref }) || C <- list ()],
451
466
ok .
452
467
453
468
list_queue_states (Pid ) ->
454
- gen_server2 :call (Pid , list_queue_states ).
469
+ gen_server :call (Pid , list_queue_states ).
455
470
456
471
-spec update_user_state (pid (), rabbit_types :user ()) -> 'ok' | {error , channel_terminated }.
457
472
@@ -467,8 +482,6 @@ update_user_state(Pid, UserState) when is_pid(Pid) ->
467
482
init ([Channel , ReaderPid , WriterPid , ConnPid , ConnName , Protocol , User , VHost ,
468
483
Capabilities , CollectorPid , LimiterPid , AmqpParams ]) ->
469
484
process_flag (trap_exit , true ),
470
- rabbit_process_flag :adjust_for_message_handling_proc (),
471
-
472
485
? LG_PROCESS_TYPE (channel ),
473
486
? store_proc_name ({ConnName , Channel }),
474
487
ok = pg_local :join (rabbit_channels , self ()),
@@ -542,8 +555,7 @@ init([Channel, ReaderPid, WriterPid, ConnPid, ConnName, Protocol, User, VHost,
542
555
fun () -> emit_stats (State2 ) end ),
543
556
put_operation_timeout (),
544
557
State3 = init_tick_timer (State2 ),
545
- {ok , State3 , hibernate ,
546
- {backoff , ? HIBERNATE_AFTER_MIN , ? HIBERNATE_AFTER_MIN , ? DESIRED_HIBERNATE }}.
558
+ {ok , State3 }.
547
559
548
560
prioritise_call (Msg , _From , _Len , _State ) ->
549
561
case Msg of
@@ -722,7 +734,7 @@ handle_info(emit_stats, State) ->
722
734
State1 = rabbit_event :reset_stats_timer (State , # ch .stats_timer ),
723
735
% % NB: don't call noreply/1 since we don't want to kick off the
724
736
% % stats timer.
725
- {noreply , send_confirms_and_nacks (State1 ), hibernate };
737
+ {noreply , send_confirms_and_nacks (State1 )};
726
738
727
739
handle_info ({{'DOWN' , QName }, _MRef , process , QPid , Reason },
728
740
# ch {queue_states = QStates0 } = State0 ) ->
@@ -822,14 +834,14 @@ get_consumer_timeout() ->
822
834
823
835
% %---------------------------------------------------------------------------
824
836
825
- reply (Reply , NewState ) -> {reply , Reply , next_state (NewState ), hibernate }.
837
+ reply (Reply , NewState ) -> {reply , Reply , next_state (NewState )}.
826
838
827
- noreply (NewState ) -> {noreply , next_state (NewState ), hibernate }.
839
+ noreply (NewState ) -> {noreply , next_state (NewState )}.
828
840
829
841
next_state (State ) -> ensure_stats_timer (send_confirms_and_nacks (State )).
830
842
831
843
noreply_coalesce (# ch {confirmed = [], rejected = []} = State ) ->
832
- {noreply , ensure_stats_timer (State ), hibernate };
844
+ {noreply , ensure_stats_timer (State )};
833
845
noreply_coalesce (# ch {} = State ) ->
834
846
% Immediately process 'timeout' info message
835
847
{noreply , ensure_stats_timer (State ), 0 }.
0 commit comments