Skip to content

Conversation

andyflury
Copy link
Contributor

QFJ supports dynamic acceptor sessions, however the same does not exist for initiator sessions. This pull request would allow applications to createDynamic initiator sessions through AbstractSocketInitiator.createDynamicSession

Also, I added a new session level boolean setting "Inactive", that can be added to settings that should not start automatically when starting QuickFix. So this session can be started on demand with above new method. The constant SETTING_INACTIVE_SESSION would probably have to be moved somewhere else.

This might not be the proper way to do this, but it seems to be working.

Any comments are welcome

@chrjohn
Copy link
Member

chrjohn commented Nov 27, 2017

Hi @andyflury , thanks for the PR. Could you please document the intended usage of the new setting in https://github.com/quickfix-j/quickfixj/blob/master/quickfixj-core/src/main/doc/usermanual/usage/configuration.html ?

Thanks,
Chris.

@chrjohn
Copy link
Member

chrjohn commented Nov 27, 2017

Just found this old JIRA issue... :)
https://www.quickfixj.org/jira/browse/QFJ-247

@chrjohn chrjohn changed the title dynamic initiator session dynamic initiator session (QFJ-247) Nov 27, 2017
@chrjohn chrjohn added this to the QFJ 2.0.1 milestone Nov 27, 2017
@andyflury
Copy link
Contributor Author

Hi Chris, thanks! I updated the documentation according to your suggestion

protected final Logger log = LoggerFactory.getLogger(getClass());
private final Set<IoSessionInitiator> initiators = new HashSet<>();

private static final String SETTING_INACTIVE_SESSION = "Inactive";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Belongs in Initiator class.

Copy link
Contributor

@philipwhiuk philipwhiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest this belongs in 2.1.0 given it's a feature not a bugfix.

Regarding the 'Inactive' flag - seems strange to have that for Dynamic Initiator and not the Dynamic Acceptor. Shouldn't they work similarly (SocketConnectHost vs SocketAcceptHost is already an annoyance to me)?

try {
final Session quickfixSession = createSession(sessionID);
initiatorSessions.put(sessionID, quickfixSession);
if (!settings.isSetting(sessionID, SETTING_INACTIVE_SESSION) || !settings.getBool(sessionID, SETTING_INACTIVE_SESSION)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests on this would be nice.

setSessions(initiatorSessions);
}

public void createDynamicSession(SessionID sessionID) throws ConfigError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again for a new feature it would be nice to see tests. For a considerable feature like a dynamic session some of the end-to-end / regression tests seem appropriate.

@andyflury
Copy link
Contributor Author

@philipwhiuk I'll be happy to provide a test case. Could you point me to an existing test case I could use as a basis for the new test case?

@andyflury
Copy link
Contributor Author

I also moved the setting to the Initiator class, thanks for pointing this out

@chrjohn chrjohn modified the milestones: QFJ 2.0.1, QFJ 2.1.0 Jan 25, 2018
@chrjohn chrjohn added the TODO label Jan 25, 2018
@chrjohn
Copy link
Member

chrjohn commented Jan 25, 2018

Hi @andyflury ,
there is a test in SessionConnectorTest and DynamicAcceptorSessionProviderTest. Maybe they can be used as a template?
If you need help, just ask.
Thanks,
Chris.

@baboono
Copy link

baboono commented May 23, 2018

@philipwhiuk
I hope we are not too stuck here. I agree AbstractSocketInitiator.createDynamicSession would be very usefull. Is it possible if I provide end-to-end / regression test ? Can we refresh that issue a bit to keep it alive?

@chrjohn
Copy link
Member

chrjohn commented May 24, 2018

Hi,
I think any help is appreciated. :) Feel free to push some changes or open a separate PR.
Cheers,
Chris.

@baboono
Copy link

baboono commented Jun 1, 2018

I can see test ready here. If this is sufficient enough for pull request it will be great.

@chrjohn
Copy link
Member

chrjohn commented Jun 3, 2018

Hi @andyflury ,
the test is failing:

[ERROR] Failures: 
[ERROR]   SessionConnectorTest.testDynamicInitiatorSession:237 expected:<2> but was:<4>

I think the initiators are only removed from the set if the connector is stopped. Otherwise you will end up with double the initiators.

@andyflury
Copy link
Contributor Author

andyflury commented Jun 4, 2018

Hi @chrjohn Glad to get Your comment up here. From what I understand in this this part in AbstractSocketInitiator.class:
protected void createSessionInitiators()
throws ConfigError {
try {
// QFJ698: clear() is needed on restart, otherwise the set gets filled up with
// more and more initiators which are not equal because the local port differs
initiators.clear();
...
clear() should be removed from here and instead its should be placed in stopInitiators()?

@chrjohn
Copy link
Member

chrjohn commented Jun 4, 2018

Hi @andyflury ,

I think you have an outdated version of the code. ;)
That clear() statement has been removed here: #175 (beginning of March). And indeed now the initiators are cleaned up in stopInitiators().

Calling createSessionInitiators() does not check if the old initiators have been stopped. This is only done when calling from SocketInitiator.stop().

So I guess in your test you could just stop the connector and then re-create the sessions.

Corrected the assertion and added one more to check , if initiators are removed.
@andyflury
Copy link
Contributor Author

No magic here I guess. Would that be sufficient?
//This should remove initiators
connector.stopInitiators();
assertEquals(0,connector.getInitiators().size());
//Tear down
for(Session s:sessions){
s.close();
}

@chrjohn
Copy link
Member

chrjohn commented Jun 4, 2018

That should do the trick, thanks.
I restarted the build, there was another (unrelated) error.

@baboono
Copy link

baboono commented Jun 5, 2018

Hi @chrjohn
Is it possible to know , when are You going to do release with this feature?

@andyflury
Copy link
Contributor Author

Thank You @chrjohn . Is there an option to merge the changes?

@chrjohn
Copy link
Member

chrjohn commented Jun 6, 2018

Hi guys,
I corrected the name of the setting in the documentation (changed from Inactive to DynamicSession).
Apart from that everything is looking fine to me and I am going to merge the changes.
I'll probably open a PR to unify the setting with dynamic acceptors (there it is called AcceptorTemplate at the moment, but DynamicSession could be used for both now).
Regarding the release: there are some minor things I want to incorporate into the release, but I'll try to be finished with that by the end of the month.

Cheers,
Chris.

@chrjohn chrjohn removed the TODO label Jun 6, 2018
@chrjohn chrjohn merged commit c9b51d9 into quickfix-j:master Jun 6, 2018
@andyflury
Copy link
Contributor Author

Great @chrjohn . Thanks for all Your support. I hope we ll get a change to talk again :)

@chrjohn
Copy link
Member

chrjohn commented Jun 6, 2018

You're welcome. Thanks for the pull request!
Yes, I guess there will be a chance. :)
Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants