@@ -114,6 +114,8 @@ class Framer implements Agent, EngineEndPointHandler, ProtocolHandler
114
114
"Received Heartbeat (msg=%s) from library %s at %sms, sent at %sns" );
115
115
private final CharFormatter acquiringSessionFormatter = new CharFormatter (
116
116
"Acquiring session %s from library %s" );
117
+ private final CharFormatter disconnectingSessionFormatter = new CharFormatter (
118
+ "Disconnecting session %s from library %s" );
117
119
private final CharFormatter releasingSessionFormatter = new CharFormatter (
118
120
"Releasing session %s with connectionId %s from library %s" );
119
121
private final CharFormatter connectingFormatter = new CharFormatter (
@@ -493,7 +495,7 @@ private void onLibraryDisconnect(final LiveLibraryInfo library)
493
495
DebugLogger .log (LIBRARY_MANAGEMENT , timingOutFormatter .clear ().with (library .libraryId ()));
494
496
}
495
497
496
- tryAcquireLibrarySessions (library );
498
+ tryAcquireOrDisconnectLibrarySessions (library );
497
499
saveLibraryTimeout (library );
498
500
disconnectILinkConnections (library );
499
501
}
@@ -519,7 +521,7 @@ private void soleLibraryModeUnbind()
519
521
}
520
522
}
521
523
522
- private void tryAcquireLibrarySessions (final LiveLibraryInfo library )
524
+ private void tryAcquireOrDisconnectLibrarySessions (final LiveLibraryInfo library )
523
525
{
524
526
final int librarySessionId = library .aeronSessionId ();
525
527
final Image image = librarySubscription .imageBySessionId (librarySessionId );
@@ -533,7 +535,7 @@ private void tryAcquireLibrarySessions(final LiveLibraryInfo library)
533
535
// just acquire
534
536
if (!configuration .logOutboundMessages () || sentIndexedPosition (librarySessionId , libraryPosition ))
535
537
{
536
- acquireLibrarySessions (library );
538
+ acquireOrDisconnectLibrarySessions (library );
537
539
}
538
540
else
539
541
{
@@ -547,7 +549,7 @@ private boolean retryAcquireLibrarySessions(final LiveLibraryInfo library)
547
549
if (!configuration .logOutboundMessages () ||
548
550
sentIndexedPosition (library .aeronSessionId (), library .acquireAtPosition ()))
549
551
{
550
- acquireLibrarySessions (library );
552
+ acquireOrDisconnectLibrarySessions (library );
551
553
return true ;
552
554
}
553
555
@@ -572,7 +574,7 @@ private void saveLibraryTimeout(final LibraryInfo library)
572
574
schedule (() -> outboundPublication .saveLibraryTimeout (library , 0 ));
573
575
}
574
576
575
- private void acquireLibrarySessions (final LiveLibraryInfo library )
577
+ private void acquireOrDisconnectLibrarySessions (final LiveLibraryInfo library )
576
578
{
577
579
final List <GatewaySession > sessions = library .gatewaySessions ();
578
580
for (int i = 0 , size = sessions .size (); i < size ; i ++)
@@ -585,31 +587,46 @@ private void acquireLibrarySessions(final LiveLibraryInfo library)
585
587
continue ;
586
588
}
587
589
588
- final long sessionId = session .sessionId ();
589
- final int sentSequenceNumber = sentSequenceNumberIndex .lastKnownSequenceNumber (sessionId );
590
- final int receivedSequenceNumber = receivedSequenceNumberIndex .lastKnownSequenceNumber (sessionId );
591
- final boolean hasLoggedIn = receivedSequenceNumber != UNK_SESSION ;
592
- final SessionState state = hasLoggedIn ? ACTIVE : CONNECTED ;
593
-
594
- DebugLogger .log (
595
- LIBRARY_MANAGEMENT ,
596
- acquiringSessionFormatter , session .sessionId (), library .libraryId ());
597
-
598
- ((FixGatewaySessions )gatewaySessions ).acquire (
599
- session ,
600
- state ,
601
- false ,
602
- session .heartbeatIntervalInS (),
603
- sentSequenceNumber ,
604
- receivedSequenceNumber ,
605
- session .username (),
606
- session .password ());
607
-
608
- schedule (saveManageSession (ENGINE_LIBRARY_ID , session ));
590
+ if (soleLibraryMode )
591
+ {
592
+ DebugLogger .log (
593
+ LIBRARY_MANAGEMENT ,
594
+ disconnectingSessionFormatter , session .sessionId (), library .libraryId ());
595
+
596
+ final long connectionId = session .connectionId ();
597
+ receiverEndPoints .removeConnection (connectionId , DisconnectReason .LIBRARY_DISCONNECT );
598
+ fixSenderEndPoints .removeConnection (connectionId );
599
+ gatewaySessions .releaseByConnectionId (connectionId );
600
+ }
609
601
610
- if ( performingDisconnectOperation )
602
+ else
611
603
{
612
- session .session ().logoutAndDisconnect ();
604
+ final long sessionId = session .sessionId ();
605
+ final int sentSequenceNumber = sentSequenceNumberIndex .lastKnownSequenceNumber (sessionId );
606
+ final int receivedSequenceNumber = receivedSequenceNumberIndex .lastKnownSequenceNumber (sessionId );
607
+ final boolean hasLoggedIn = receivedSequenceNumber != UNK_SESSION ;
608
+ final SessionState state = hasLoggedIn ? ACTIVE : CONNECTED ;
609
+
610
+ DebugLogger .log (
611
+ LIBRARY_MANAGEMENT ,
612
+ acquiringSessionFormatter , session .sessionId (), library .libraryId ());
613
+
614
+ ((FixGatewaySessions )gatewaySessions ).acquire (
615
+ session ,
616
+ state ,
617
+ false ,
618
+ session .heartbeatIntervalInS (),
619
+ sentSequenceNumber ,
620
+ receivedSequenceNumber ,
621
+ session .username (),
622
+ session .password ());
623
+
624
+ schedule (saveManageSession (ENGINE_LIBRARY_ID , session ));
625
+
626
+ if (performingDisconnectOperation )
627
+ {
628
+ session .session ().logoutAndDisconnect ();
629
+ }
613
630
}
614
631
}
615
632
}
0 commit comments