Uploaded image for project: 'QuickFIX/J'
  1. QuickFIX/J
  2. QFJ-109

Session management endDay calculation is bad (I would say wrong)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Default
    • Resolution: Fixed
    • Affects Version/s: 1.0.4
    • Fix Version/s: 1.1.0
    • Component/s: Engine
    • Labels:
      None
    • Environment:
      linux, netbeans

      Description

      Since session management is important for a good engine (and QFJ is my favourite) I spent the afternoon a little in testing and debugging.
      I hope Steve as the maintainer is not too mad on me, that I have decided to create a new bug report.
      First the result, I´d like to suggest to change the code in:
      SessionSchedule.java: private TimeInterval theMostRecentIntervalBefore(Calendar t)
      There are the 2 if constructions adding a day to the end day:
      if (endTime.getDay() == -1 && startTime.getHour() >= endTime.getHour())

      { endCal.add(Calendar.DATE, 1); }

      if (endTime.getDay() != -1
      && (startTime.getDay() > endTime.getDay() || (startTime.getDay() == endTime
      .getDay() && startTime.getHour() >= endTime.getHour())))

      { endCal.add(Calendar.WEEK_OF_YEAR, 1); }

      My suggestion is, to make it more precise with:
      instead: startTime.getHour() >= endTime.getHour()
      startTime.getHour()*3600 +startTime.getMinute()*60+startTime.getSecond() >
      endTime.getHour()*3600 +endTime.getMinute()*60+endTime.getSecond()

      The important change is the little change ">=" to ">" in both if's

      If you are in hurry you can finish reading here .

      For most applications this works practically, but there are some problems with the original construction:

      1. for testing I have tried to test with small sessions (less than one hour) these sessions were able to start, but did not stop, even if I have put the same startDay and endDay in the config, the endDay was set to the next week.
      In case of no startDay and no endDay the endDay is set to tomorrow.
      Before I got the reason this was very frustrating.

      2. I can not see any good reason for adding on day to the end day only because start and end are in the same hour, but there is a good reason for doing so, when startTime > endTime (thatswhy my suggestion)

      3. If you take a look at the code (I mean the whole class SessionSchedule.java, the code is not very nice, no documentation, no clean structure, not effective. To understand what I mean, just take a look at the if-constructions in the method: MostRecentIntervalBefore
      3 times the:
      if (endTime.getDay() != -1)
      and many similiar constructions
      Maybe its not time critical at this point, but its also not good readable.

      Now the good news:
      The methode: public boolean isSessionTime() from Session.java works properly.
      So we could program a nice and slim session management like this (and this is my recommendation to do the session management):
      After receiving the logout message from the FIX-Engine, we simply check: if (!isSessionTime)
      If the session is really over (and not only a logout because of connection problems) we finish the FIX-Engine (according to Steves recommendation), then we clean up our system in a separat thread (archiving and so on) and then we start the FIX-Engine again.

      Well this is a recommendation but in some cases for example if you run multiple different sessions with the same engine you can not restart the engine but the session management should work properly like described.

      Well, slowly QFJ looks more and more friendly.

      Good night from germany, Welf

        Attachments

          Activity

            People

            • Assignee:
              admin Steve Bate
              Reporter:
              welf Welf Wustlich
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: