0 Replies Latest reply on Jan 26, 2009 9:53 PM by Tomas Cerny

    Synchronized data among conversations

    Tomas Cerny Novice

      Hi guys,


      I have found many questions about synchronization of data among conversation, but no answers.
      So I investigated some solutions and will provide you with one solution.


      I have long-running, natural conversations identified by id of selected entity. (e.g. Person.id or Car.id)


      So I am in one conversation and I modify name of a person. But the person name is also shown in conversation holding person's car.
      So I want after the modification of person name to refresh the info about person at cars conversation.


      You might have some inheritance at you manager that inherits method save(). In this method append a code for refreshing the other conversations. Something like this:



      public String updateOtherConversations() {
          
               String thisConversationId = Conversation.instance().getId();
               
               ConversationEntries ces = ConversationEntries.getInstance();
               try {
                    for (ConversationEntry ce : ces.getConversationEntries()) {
                                        
                          if ((ce.getId().startsWith("personHome")
                                    || ce.getId().startsWith("carHome"))
                                    && !ce.getId().equals(thisConversationId)
                                    && !ce.isEnded() && ce.isDisplayable()) {
                               
           
                               Manager.instance().switchConversation(ce.getId());
                               Contexts.getConversationContext().flush();
                               Context conversationContext = Contexts.getConversationContext();
                               Contexts.getConversationContext().flush();
                               
                               String manager = getManagerByConversation(ce.getId());
                               
                               IGeneralManager g = (IGeneralManager)Component.getInstance(manager);
                               g.setNeedToRefresh(true);
                               
                               Manager.instance().switchConversation(thisConversationId);
                               Contexts.getConversationContext().flush();
                          }
                          flush();
                     }
                         } catch (Exception e) {
                     addFatal(e);
                }                  
                return null;
           }
      



      So this fragment switches to other conversations and calls method GeneralManager#setNeedToRefresh(true); this sets a flag in the manager that says that the data in the conversation are stale.


      Then whenever you access the other conversation the flag will trigger some logic like getEm().refresh(getActiveInstance());
      You want this to happen whenever you access the page containing info from the manager. So you may define a dummy property that is rendered on the page and not returning anything but refreshing the instance if necessary.


      To use the boolean flag is better then to refresh the other conversations immediately. Because user may not access them any more. So it is like to compare eager and lazy fetch..


      Hope it will help..


      Tomas