11 Replies Latest reply on Mar 9, 2010 5:12 PM by asookazian

    ConversationScoped state can be destroyed at any time?

    matthijs

      Hi there all,


      I am currently thinking if the CDI ConversationScope would be a good replacement of the JSF 2 ViewScope.


      However, in the CDI spec and in the Weld documenation I read something that might give me the idea that state in that has ConversationScope can be destroyed at any time, if the container whishes so. Is that correct?


      I am referring to paragraph 5.3.3 of the Weld documentation that can be found here where it says: The container is permitted to destroy a conversation and all state held in its context at any time in order to conserve resources. A CDI implementation will normally do this on the basis of some kind of timeout—though this is not required by the specification.


      Then in the JSR 299 spec I see in chapter 6.7.4: “The container is permitted to arbitrarily destroy any long-running conversation that is associated with no current JSF request, in order to conserve resources.”


      So does that mean that when a JSF request is over and some state is still preserved in a long running conversation, waiting for the next JSF request, the container can just destroy that conversation?


      Hope anyone can make that clear to me.
      Great spec and Weld documentation by the way!


      Matthijs

        • 1. Re: ConversationScoped state can be destroyed at any time?
          nickarls

          Actually, I asked Gavin about this and he replied


          But yes, the server is permitted to destroy a conversation between clicks.
          



          Not that I think it would be implemented quite that aggressively...

          • 2. Re: ConversationScoped state can be destroyed at any time?
            matthijs

            Ok, thanks for the quick reply Nicklas. Though I was afraid of an answer like that :-).


            Any idea's why the spec says it like that?


             

            • 3. Re: ConversationScoped state can be destroyed at any time?
              matthijs

              Ow, I forgot, does anyone know how the Weld implementation implements this spec?

              • 4. Re: ConversationScoped state can be destroyed at any time?
                nickarls

                Don't know why, perhaps Gavin will drop by at some point and shed some light on the issue.


                Currently Weld goes down with its boot on in a OutOfMemoryException in the spirit of equal treatment ;-)

                • 5. Re: ConversationScoped state can be destroyed at any time?
                  matthijs

                  Thanks, that clears things up for me!

                  • 6. Re: ConversationScoped state can be destroyed at any time?
                    jpleed3.john.leediii.minitmarkets.com

                    In section 6.7.4 of the CDI spec:



                    If the propagated conversation cannot be restored, the container must associate the request with a new transient conversation and throw an exception of type  javax.enterprise.context.NonexistentConversationException from the restore view phase of the JSF lifecycle. The application may handle this exception using the JSF  ExceptionHandler.

                    So if a conversation gets destroyed by the container to conserve resources, it can't be restored, yes? If so, at that point a NonexistentConversationException should be thrown, but how would one distinguish those circumstances from any other that would cause the conversation not to be restored?


                    In other words, should there be a javax.enterprise.context.ConversationSacrificedForTheGoodOfTheContainerException to be thrown in this type of situation?


                    • 7. Re: ConversationScoped state can be destroyed at any time?
                      nickarls

                      "Don't test for error conditions you can't handle" ;-) In other words, since the conversation is already gone and the user can't tell if it just died or crashed or was sacrificed (or if it is likely to happen again), there is little good in distinguishing them...

                      • 8. Re: ConversationScoped state can be destroyed at any time?
                        gavin.king

                        The only reason the container should destroy the conversation is to conserve resources (memory). Most containers will do this by destroying conversations that have been inactive for a certain length of time, or by limiting the total number of conversations and destroying the most inactive ones. But the spec definitely shouldn't be defining exactly what the container is allowed to do here. That's a quality of implementation concern. So the spec lets the container do pretty much anything. Which is not the same as saying that a good implementation should do anything.

                        • 9. Re: ConversationScoped state can be destroyed at any time?
                          asookazian

                          John Leed wrote on Mar 05, 2010 18:51:


                          In section 6.7.4 of the CDI spec:

                          If the propagated conversation cannot be restored, the container must associate the request with a new transient conversation and throw an exception of type  javax.enterprise.context.NonexistentConversationException from the restore view phase of the JSF lifecycle. The application may handle this exception using the JSF  ExceptionHandler.

                          So if a conversation gets destroyed by the container to conserve resources, it can't be restored, yes? If so, at that point a NonexistentConversationException should be thrown, but how would one distinguish those circumstances from any other that would cause the conversation not to be restored?

                          In other words, should there be a javax.enterprise.context.ConversationSacrificedForTheGoodOfTheContainerException to be thrown in this type of situation?




                          This is a good question.  If the backing (or managed) bean is a SFSB or JavaBean implementing java.io.Serializable, then it should be possible for the CDI container to passivate the object to disk prior to destruction, correct?  So will this happen, is it impl dependent, and is the conversation recoverable?  The user loses the contents of the shopping cart/wizard??

                          • 10. Re: ConversationScoped state can be destroyed at any time?
                            nickarls

                            Well the conversation scope is passivation capable per definition. I assume the dropping would only occur when there is too much active load. But the problem is who wants their conversation dropped. Of course, there could be some sort of QOS level added...

                            • 11. Re: ConversationScoped state can be destroyed at any time?
                              asookazian

                              Hypothetical scenario: 2-node horz JBoss cluster.  There should be seamless failover if state replication (sync or async) is turned on.  Since the conversation lives in the HttpSession (at least in Seam it does), then the LRC should be available if the node fails...