12 Replies Latest reply on Sep 19, 2007 6:37 AM by aBill

    FlexContext.getFlexClient() returns an invalid object

    Robert_Csiki
      I have this Flex client application I'm trying to implement the Logout function for. This client has both HTTP and RTMP connections to the server. So when the user presses the Logout button in client, I'm trying to invalidate both HTTP and RTMP sessions on the FDS so the FlexClient would get invalidated.
      The behavior on the client is the Login screen pops up so the user can login again if they want. The problem is, if they do so, the following happens on the FDS side:

      - connecting via the HTTP channel will result in FlexContext.getFlexClient() call returning a new FlexClient object (that is correct), with the newly created Http flex session

      - aftarwards, trying to connect via the RTMP channel, will result in FlexContext.getFlexClient() call returning the old FlexClient object (that is, the one used on the previous session, before the user pressed the Logout), wich is in an invalid state and has no sessions associated. Everything would fail using this FlexClient. More over, here FlexContext.getFlexSession() returns the new RTMPFlexSession object (which is correct), but this session has no FlexClient objects associated (the getFlexClients() call returns an empty list)!

      My question is why would FDS do that?? Why is FlexContext.getFlexClient() returning an old, invalidated FlexClient object? It looks odd to me. I'm using LiveCycle Data Services ES 2.5.1 on the backend, deployed on Tomcat 5.5

      Thanks.
      Robert
        • 1. Re: FlexContext.getFlexClient() returns an invalid object
          Mete Atamel Level 1
          Hi Robert,

          Are you sure that the RTMPFlexSession for the old FlexClient has been invalidated? The easiest way to figure out which sessions are created/destroyed during your test is to turn LCDS debug logging on with "Endpoint.FlexSession" filter. I'm curious to see the debug log with your test case.

          Secondly, there's a FlexClient timeout configuration value that is set in services-config.xml as follows:

          <flex-client>
          <!--
          Each Flex application that connects to the server triggers the creation of a
          FlexClient instance that represents the remote client application.
          If timeout-minutes is left undefined or set to 0, FlexClient instances on the server
          are shutdown once all associated FlexSessions (corresponding to connections between
          the client and server) are shutdown.
          If this value is defined, FlexClient instances will be kept alive for this amount of
          idle time.
          FlexClient instances that have an associated RTMP connection/session that is open are
          kept alive even if they are idle because the open connection indicates that the remote
          client application is still running.
          For Http connections/sessions, if the remote client application is polling this keeps
          the FlexClient alive.
          If the remote client is not polling and a FlexClient instance is idle for this amount of time
          it is shut down even if an associated HttpSession is still valid. This is because multiple
          Flex client applications may share a single HttpSession so a valid HttpSession does not indicate
          that a specific client application instance is still running.
          -->
          <timeout-minutes>45</timeout-minutes>
          </flex-client>

          I'm not sure if this is related to your test case but something to keep in mind.
          • 2. FlexContext.getFlexClient() returns an invalid object
            Ansire
            >>This is because multiple Flex client applications may share a single HttpSession so a valid HttpSession does not indicate

            That is an interesting part. Is there a way to avoid sharing sessions between multiple client apps? May be some config settings?
            • 3. FlexContext.getFlexClient() returns an invalid object
              Robert_Csiki Level 1
              Hello Mete,

              Yes, the RTMP session gets invalidated. Here is my Logout method:

              public void doLogout()
              {
              // get the FlexClient associated to this request
              FlexClient thisFlexClient = FlexContext.getFlexClient();

              // get all the sessions associated to this client
              List sessions = thisFlexClient.getFlexSessions();

              // contains all the FlexClient associated to this session
              List sharedClients = null;

              // invalidate all the Flex Sessions for this client
              for (Iterator iter = sessions.iterator() ; iter.hasNext();)
              {
              // get the next Flex Session
              FlexSession fs = (FlexSession)iter.next();

              // check if it is the Http Flex Session
              if (fs instanceof flex.messaging.HttpFlexSession)
              {
              // get the shared Flex clients for this Http Flex session
              sharedClients = fs.getFlexClients();
              }

              // invalidate this Flex Session
              fs.invalidate();
              }

              // now search for other non-Http Flex sessions (e.g. RMPT ones) associated
              // to Flex clients that shared the same Http Flex session (e.g. multiple browser instances)
              // and invalidate them all, to force the correspondent Flex clients to get invalidated
              if (sharedClients.size() > 1)
              {
              for (Iterator iter2 = sharedClients.iterator() ; iter2.hasNext();)
              {
              FlexClient sharedClient = (FlexClient)iter2.next();
              if (sharedClient.isValid() && !sharedClient.equals(thisFlexClient))
              {
              List sharedClientFlexSessions = sharedClient.getFlexSessions();
              for (Iterator iter3 = sharedClientFlexSessions.iterator() ; iter3.hasNext();)
              {
              FlexSession sharedClientFlexSession = (FlexSession)iter3.next();
              if (sharedClientFlexSession.isValid())
              {
              sharedClientFlexSession.invalidate();
              }
              }
              }
              }
              }
              }

              I will turn on that LCDS logging and will post the results soon. Thanks. By the way, where did you get that very descriptive message for the "<timeout-minutes>" node? The "services-config.xml" file that comes with LCDS 2.5.1 does not even contain a "<flex-client>" node..

              Also, offtopic: how to properly insert a code snippet on this forum? I noticed the above sample code got stripped from all its left white spaces, the formatting is now just ugly.
              • 4. Re: FlexContext.getFlexClient() returns an invalid object
                Robert_Csiki Level 1
                Here,s the log:

                [Flex] 10:39:47.328 [DEBUG] [Endpoint.FlexSession] FlexSession created with id '0DB83653B7561285669BB5DC0ABF18E7' for an Http-based client connection.
                [Flex] 10:40:03.484 [DEBUG] [Endpoint.FlexSession] FlexSession created with id '759CCC2F-DC0D-C199-21BD-7871C6175538' for a direct RTMP client connection.
                [Flex] 10:40:43.687 [DEBUG] [Endpoint.FlexSession] FlexSession with id '0DB83653B7561285669BB5DC0ABF18E7' for an Http-based client connection has been invalidated.
                [Flex] 10:40:43.687 [DEBUG] [Endpoint.FlexSession] FlexSession created with id 'C94FDAD845F6F89808AF7691C4E2F5BE' for an Http-based client connection.
                [Flex] 10:40:43.703 [DEBUG] [Endpoint.FlexSession] FlexSession created with id '759E4BBE-C70D-996F-A8A4-D96DCBD1799E' for a direct RTMP client connection.
                [Flex] 10:40:43.703 [DEBUG] [Endpoint.FlexSession] FlexSession with id '759CCC2F-DC0D-C199-21BD-7871C6175538' for a direct RTMP client connection has been invalidated.

                The test case steps:

                - login (HTTP session was created, RTMP session was created)
                - logout -> (both sessions are invalidated, a new HTTP one is created) the login page is now shown in browser
                - login again - here I got the error trying to work with the FlexClient object in a RTMP request. There is a new RTMP session created, but it has no FlexClient associated. FlexContext.getFlexClient() returns the old, invalidated Flexclient object, whicxh has 0 (zero) Flex sessions associated.

                Cheers,
                Robert
                • 5. Re: FlexContext.getFlexClient() returns an invalid object
                  aBill Level 1
                  Hi Robert,

                  Can you do a quick test for me? Can you also try disconnect rtmp channel after logout? I think it may help

                  Thanks!

                  William Chan
                  • 6. Re: FlexContext.getFlexClient() returns an invalid object
                    Robert_Csiki Level 1
                    William,

                    I tried this early in the morning (disconnecting the DataService from the Flex client, using the disconnect() ActionScript call), and it worked, as you predicted. Thanks for the tip. Still I don't know what the client-side implications are with the managed data, should I also do something specific with the ArrayCollection objects this DataService used to manage, or nothing needs to be done on this matter?
                    Should we consider what I described in previous posts on this topic a bug?

                    Cheers
                    Robert
                    • 7. Re: FlexContext.getFlexClient() returns an invalid object
                      aBill Level 1
                      Not sure this is a bug or not. I'll discuss it with dev, but I agree with you invalidate the flexclient should also destroy it.

                      William Chan
                      • 8. Re: FlexContext.getFlexClient() returns an invalid object
                        aBill Level 1
                        "should I also do something specific with the ArrayCollection objects this DataService used to manage, or nothing needs to be done on this matter?"

                        I am not quite sure what the situation is. When user logs out, should the application close all services and release all the collections?

                        William Chan
                        • 9. Re: FlexContext.getFlexClient() returns an invalid object
                          Robert_Csiki Level 1
                          Yes, on Logout all the server resources (including the managed data) need to be released/cleared. So for instance, the ArrayCollection object used to be filled with managed data needs to be emptied. I noticed explicitly calling removeAll() for this collection after disconnecting the data service won't work, an error is being thrown.

                          Thanks,
                          Robert
                          • 10. Re: FlexContext.getFlexClient() returns an invalid object
                            aBill Level 1
                            I think you should use the dataservice.release() or dataservice.releaseCollection(collection, true) before ds.logout

                            William Chan
                            • 11. Re: FlexContext.getFlexClient() returns an invalid object
                              Robert_Csiki Level 1
                              Thanks, so as a recap, the following calls need to be done in this case, in this order:

                              ds.release(); // to release everything that's managed by this service
                              ds.disconnect(); // to disconnect the RTMP link to the server
                              ds.logout(); // to logout the destination for all the ds instances used by this client

                              Correct? Thank you..
                              • 12. Re: FlexContext.getFlexClient() returns an invalid object
                                aBill Level 1
                                I think the logout should go before rtmp disconnect.

                                William