Differences between revisions 4 and 5
Revision 4 as of 2008-08-14 15:24:19
Size: 4727
Editor: ocs
Comment: The constructor name was different from the class name
Revision 5 as of 2009-09-20 23:00:59
Size: 4727
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
Lets again look at the example from our ["BO/DAO Patterns in Orchestra"] page: Lets again look at the example from our [[BO/DAO_Patterns_in_Orchestra]] page:

Conversation Termination

Introduction

Ok we are done with it, we have done everything we want inside our conversation. When is the conversation closed, how can I force a close, is it possible to close all currently running conversations?

We are done with it

Lets again look at the example from our BO/DAO_Patterns_in_Orchestra page:

   public class BasicViewController {
      BasicBO basicbo;

      MyEntity workEntity;


      public void doAction() {
          basicbo.doSomething(workEntity);
          return "success";
      }

      public void doWearedonewithit() {
         Conversation.getCurrentInstance().invalidate();
         return "done";  
      }      

      public void valueBound(ConversationBindingEvent arg0) {
        workEntity = basicbo.loadEntity(); //we first init it with an empty query
      }



     //setters and getters
     public  BasicBO set....  
  }

As we already said, we are done with it, we are ready for the weekly recycling...

so what happens.

  1. We simply could forget about it and wait for the next timeout to close and dispose everything
  2. We could manually interfere by triggering an action
  3. We could terminate all Currently running conversations (which also means conversations which are tangling in the air for whatever reason waiting for their timeout.

in the example above we decided to go for number two, we try to terminate our conversation because we trigger an action which just said OK, i am done (endstate)

   public void doWearedonewithit() {
         Conversation.getCurrentInstance().invalidate();
         return "done";  
   }      

So what happens, if the user jumps out of our page without triggering the action. In this case 1. is triggered, the conversation will be hanging until recovered or terminated.

So it is advisable to locate central points in your application when you can terminate all conversations, or at least the current conversation which at that point probably still is referenced (usually a central navigation or a main page is a good place for it)

 ConversationManager.getInstance()
                        .clearCurrentConversationContext();

Would clear all conversations in our current conversation context (most of the times there is only one context, multiple contexts usually exist in multi window solutions.

A nav handler doing this could look like following:

public class ConvNavNavigationHandler extends NavigationHandler {

    private static final String CONVNAV_PREFIX = "convnav_";
    private NavigationHandler _handler;
  
    
    public ConvNavNavigationHandler(NavigationHandler handler) {
        super();
        _handler = handler;
    }

    public void handleNavigation(FacesContext context, String fromAction,
            String outcome) {
        if (outcome != null && outcome.startsWith(CONVNAV_PREFIX)) {
            try {
                //We drop the navigation just in case to add some cleanup
                ConversationManager.getInstance()
                        .clearCurrentConversationContext();
            } catch (RuntimeException e) {
                LogFactory.getLog(this.getClass()).error(e);
            }            
        }
        _handler.handleNavigation(context, fromAction, outcome);

    }

}

This is a nav handler which adds the implicit behaviour to the applications navigation, that every navigation case, starting with convnav_ triggers a conversation clear up automatically:

This could look like this in our faces-config.xml

        <navigation-rule>
                <from-view-id>/*</from-view-id>
                <navigation-case>
                        <from-outcome>convnav_template</from-outcome>
                        <to-view-id>/template/master.jsf</to-view-id>
                </navigation-case>
                <navigation-case>
                        <from-outcome>convnav_room</from-outcome>
                        <to-view-id>/room/master.jsf</to-view-id>
                </navigation-case>
                <navigation-case>
                        <from-outcome>convnav_user</from-outcome>
                        <to-view-id>/user/master.jsf</to-view-id>
                </navigation-case>
                <navigation-case>
                        <from-outcome>convnav_login</from-outcome>
                        <to-view-id>/login/login.jsf</to-view-id>
                </navigation-case>
        </navigation-rule>

This examples a central inter module navigation for an application linking the various modules in combination with our navigation handler, every time the application jumps from one module to the other the conversations are cleared up. So in our case we can be sure that from time to time a semi automatic garbage collection consuming tangling conversation happens without any code interference into our application logic.

Conversation_Termination (last edited 2009-09-20 23:00:59 by localhost)