@@ -380,29 +380,7 @@ private void receive(Message msg) {
380380 String command = msg .getCommand ();
381381 if (Commands .CONNECTED .equals (command )) {
382382 String hbHeader = msg .headerValue (Header .HEART_BEAT );
383- int pingSecs = task .pingSeconds ();
384- int pongSecs = task .pongSeconds ();
385- if (hbHeader != null && (pingSecs > 0 || pongSecs > 0 )) {
386- String [] heartbeats = hbHeader .split ("," );
387- int pingSeconds = Integer .parseInt (heartbeats [1 ]) / 1000 ;
388- int pongSeconds = Integer .parseInt (heartbeats [0 ]) / 1000 ;
389- if (pingSeconds > 0 || pongSeconds > 0 ) {
390- if (task .pingSupplier () == null ) {
391- task .pingSupplier (() -> ByteString .of ((byte ) 0x0A ));
392- }
393- task .heatbeat (Math .max (pingSeconds , pingSecs ), Math .max (pongSeconds , pongSecs ));
394- }
395- }
396- synchronized (this ) {
397- for (Subscriber s : subscribers ) {
398- s .subscribe ();
399- }
400- connected = true ;
401- connecting = false ;
402- }
403- if (onConnected != null ) {
404- onConnected .on (this );
405- }
383+ onConnectedFrameReceived (hbHeader );
406384 } else if (Commands .MESSAGE .equals (command )) {
407385 String id = msg .headerValue (Header .SUBSCRIPTION );
408386 if (id != null ) {
@@ -424,6 +402,32 @@ private void receive(Message msg) {
424402 }
425403 }
426404
405+ private void onConnectedFrameReceived (String hbHeader ) {
406+ int pingSecs = task .pingSeconds ();
407+ int pongSecs = task .pongSeconds ();
408+ if (hbHeader != null && (pingSecs > 0 || pongSecs > 0 )) {
409+ String [] heartbeats = hbHeader .split ("," );
410+ int pingSeconds = Integer .parseInt (heartbeats [1 ]) / 1000 ;
411+ int pongSeconds = Integer .parseInt (heartbeats [0 ]) / 1000 ;
412+ if (pingSeconds > 0 || pongSeconds > 0 ) {
413+ if (task .pingSupplier () == null ) {
414+ task .pingSupplier (() -> ByteString .of ((byte ) 0x0A ));
415+ }
416+ task .heatbeat (Math .max (pingSeconds , pingSecs ), Math .max (pongSeconds , pongSecs ));
417+ }
418+ }
419+ synchronized (this ) {
420+ for (Subscriber s : subscribers ) {
421+ s .subscribe ();
422+ }
423+ connected = true ;
424+ connecting = false ;
425+ }
426+ if (onConnected != null ) {
427+ onConnected .on (this );
428+ }
429+ }
430+
427431 public MsgCodec getMsgCodec () {
428432 return msgCodec ;
429433 }
0 commit comments