[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...

Gavin King gavin.king at jboss.com
Tue Oct 31 17:29:40 EST 2006


  User: gavin   
  Date: 06/10/31 17:29:40

  Modified:    src/main/org/jboss/seam/core    ConversationEntry.java
                        Manager.java Switcher.java
  Log:
  fix a bug where conversation lists did not get updated
  share the same lock b/w all nested conversations of the same root conversation
  improve display of conversation list
  
  Revision  Changes    Path
  1.26      +36 -15    jboss-seam/src/main/org/jboss/seam/core/ConversationEntry.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ConversationEntry.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/ConversationEntry.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -b -r1.25 -r1.26
  --- ConversationEntry.java	31 Oct 2006 20:09:21 -0000	1.25
  +++ ConversationEntry.java	31 Oct 2006 22:29:40 -0000	1.26
  @@ -29,18 +29,31 @@
      private String initiatorComponentName;
      private Integer timeout;
      private boolean removeAfterRedirect;
  +   private boolean ended;
      
  -   private ConversationEntries parent;
  +   private ConversationEntries entries;
      
  -   private ReentrantLock lock = new ReentrantLock(true);
  +   private ReentrantLock lock;
   
  -   public ConversationEntry(String id, List<String> stack, ConversationEntries parent)
  +   public ConversationEntry(String id, List<String> stack, ConversationEntries entries)
      {
         this.id = id;
         this.conversationIdStack = stack==null ? 
               null : Collections.unmodifiableList(stack);
         this.startDatetime = new Date();
  -      this.parent = parent;
  +      this.entries = entries;
  +      
  +      if ( conversationIdStack.size()>1 )
  +      {
  +         // get the root conversation entry lock (we want to share the same lock  
  +         // among all nested conversations in the same conversation stack)
  +         lock = entries.getConversationEntry( conversationIdStack.get( conversationIdStack.size()-1 ) ).lock;
  +      }
  +      else
  +      {
  +         lock = new ReentrantLock(true);
  +      }
  +
         touch();
      }
   
  @@ -54,7 +67,7 @@
      }
   
      void setDescription(String description) {
  -      parent.setDirty(this.description, description);
  +      entries.setDirty(this.description, description);
         this.description = description;
      }
   
  @@ -63,7 +76,7 @@
      }
   
      synchronized void touch() {
  -      parent.setDirty();
  +      entries.setDirty();
         lastRequestTime = System.currentTimeMillis();
         lastDatetime = new Date();
      }
  @@ -76,10 +89,9 @@
         return startDatetime;
      }
   
  -   public String destroy() {
  +   public void destroy() {
         boolean success = Manager.instance().switchConversation( getId() );
         if (success) Manager.instance().endConversation(false);
  -      return null;
      }
   
      public void select() {
  @@ -109,7 +121,7 @@
      }
   
      void setViewId(String viewId) {
  -      parent.setDirty(this.viewId, viewId);
  +      entries.setDirty(this.viewId, viewId);
         this.viewId = viewId;
      }
   
  @@ -136,14 +148,12 @@
      }
   
      void setInitiatorComponentName(String ownerComponentName) {
  -      parent.setDirty(this.initiatorComponentName, ownerComponentName);
  +      entries.setDirty(this.initiatorComponentName, ownerComponentName);
         this.initiatorComponentName = ownerComponentName;
      }
   
      public boolean isDisplayable() {
  -      Manager manager = Manager.instance();
  -      return getDescription()!=null &&
  -         ( manager.isLongRunningConversation() || !id.equals( manager.getCurrentConversationId() ) );
  +      return !isEnded() && getDescription()!=null;
      }
   
      public boolean isCurrent()
  @@ -171,7 +181,7 @@
      }
   
      void setTimeout(int conversationTimeout) {
  -      parent.setDirty(this.timeout, timeout);
  +      entries.setDirty(this.timeout, timeout);
         this.timeout = conversationTimeout;
      }
   
  @@ -180,7 +190,7 @@
      }
   
      public void setRemoveAfterRedirect(boolean removeAfterRedirect) {
  -      parent.setDirty();
  +      entries.setDirty();
         this.removeAfterRedirect = removeAfterRedirect;
      }
      
  @@ -211,9 +221,20 @@
         lock.unlock();
      }
      
  +   public void end()
  +   {
  +      ended = true;
  +   }
  +   
  +   public boolean isEnded()
  +   {
  +      return ended;
  +   }
  +
      @Override
      public String toString()
      {
         return "ConversationEntry(" + id + ")";
      }
  +
   }
  \ No newline at end of file
  
  
  
  1.107     +37 -19    jboss-seam/src/main/org/jboss/seam/core/Manager.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Manager.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Manager.java,v
  retrieving revision 1.106
  retrieving revision 1.107
  diff -u -b -r1.106 -r1.107
  --- Manager.java	31 Oct 2006 20:09:21 -0000	1.106
  +++ Manager.java	31 Oct 2006 22:29:40 -0000	1.107
  @@ -12,6 +12,7 @@
   import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.List;
  +import java.util.ListIterator;
   import java.util.Map;
   import java.util.StringTokenizer;
   
  @@ -42,7 +43,7 @@
    *
    * @author Gavin King
    * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
  - * @version $Revision: 1.106 $
  + * @version $Revision: 1.107 $
    */
   @Scope(ScopeType.EVENT)
   @Name("org.jboss.seam.core.manager")
  @@ -109,13 +110,16 @@
         }
      }
   
  -   private void touchConversationStack()
  +   private static void touchConversationStack(List<String> stack)
      {
  -      List<String> stack = getCurrentConversationIdStack();
         if ( stack!=null )
         {
  -         for ( String conversationId: stack )
  +         //iterate in reverse order, so that current conversation 
  +         //sits at top of conversation lists
  +         ListIterator<String> iter = stack.listIterator( stack.size() );
  +         while ( iter.hasPrevious() )
            {
  +            String conversationId = iter.previous();
               ConversationEntry conversationEntry = ConversationEntries.instance().getConversationEntry(conversationId);
               if (conversationEntry!=null)
               {
  @@ -123,13 +127,17 @@
               }
            }
         }
  +   }
   
  -      //do this last, to bring it to the top of the conversation list
  -      if ( isLongRunningConversation() )
  +   private static void endNestedConversations(String id)
  +   {
  +      for ( ConversationEntry ce: ConversationEntries.instance().getConversationEntries() )
         {
  -         getCurrentConversationEntry().touch();
  +         if ( ce.getConversationIdStack().contains(id) )
  +         {
  +            ce.end();
  +         }
         }
  -
      }
   
      /**
  @@ -303,7 +311,7 @@
      {
         if ( isLongRunningConversation() )
         {
  -         touchConversationStack();
  +         touchConversationStack( getCurrentConversationIdStack() );
            if ( !Seam.isSessionInvalid() ) 
            {
               storeLongRunningConversation(response);
  @@ -389,10 +397,10 @@
      private void removeCurrentConversationAndDestroyNestedContexts(ContextAdaptor session) 
      {
         ConversationEntries.instance().removeConversationEntry( getCurrentConversationId() );
  -      destroyNestedContexts( session, getCurrentConversationId() );
  +      destroyNestedConversationContexts( session, getCurrentConversationId() );
      }
   
  -   private void destroyNestedContexts(ContextAdaptor session, String conversationId) 
  +   private void destroyNestedConversationContexts(ContextAdaptor session, String conversationId) 
      {
         List<ConversationEntry> entries = new ArrayList<ConversationEntry>( ConversationEntries.instance().getConversationEntries() );
         for  ( ConversationEntry ce: entries )
  @@ -534,8 +542,9 @@
               null : ConversationEntries.instance().getConversationEntry(storedConversationId);
         if ( ce!=null && ce.lock() )
         {
  -         
  -         touchConversationStack();
  +         // do this asap, since there is a window where conversationTimeout() might  
  +         // try to destroy the conversation, even if he cannot obtain the lock!
  +         touchConversationStack( ce.getConversationIdStack() );
   
            //we found an id and obtained the lock, so restore the long-running conversation
            log.debug("Restoring conversation with id: " + storedConversationId);
  @@ -644,6 +653,7 @@
         if ( Events.exists() ) Events.instance().raiseEvent("org.jboss.seam.endConversation");
         setLongRunningConversation(false);
         destroyBeforeRedirect = beforeRedirect;
  +      endNestedConversations( getCurrentConversationId() );
      }
      
      /**
  @@ -693,6 +703,9 @@
         ConversationEntry ce = ConversationEntries.instance().getConversationEntry(id);
         if (ce!=null)
         {
  +         if ( ce.lock() )
  +         {
  +            unlockConversation();
            setCurrentConversationId(id);
            setCurrentConversationIdStack( ce.getConversationIdStack() );
            setLongRunningConversation(true);
  @@ -703,6 +716,11 @@
            return false;
         }
      }
  +      else
  +      {
  +         return false;
  +      }
  +   }
   
      public int getConversationTimeout() {
         return conversationTimeout;
  
  
  
  1.13      +4 -5      jboss-seam/src/main/org/jboss/seam/core/Switcher.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Switcher.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Switcher.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -b -r1.12 -r1.13
  --- Switcher.java	31 Oct 2006 20:09:21 -0000	1.12
  +++ Switcher.java	31 Oct 2006 22:29:40 -0000	1.13
  @@ -23,7 +23,7 @@
    * Support for the conversation switcher drop-down menu.
    * 
    * @author Gavin King
  - * @version $Revision: 1.12 $
  + * @version $Revision: 1.13 $
    */
   @Scope(ScopeType.PAGE)
   @Name("switcher")
  @@ -31,6 +31,8 @@
   public class Switcher implements Serializable {
      
      private List<SelectItem> selectItems;
  +   private String conversationIdOrOutcome;
  +   private String resultingConversationIdOrOutcome;
      
      @Create
      public void createSelectItems()
  @@ -53,9 +55,6 @@
         return selectItems;
      }
         
  -   private String conversationIdOrOutcome;
  -   private String resultingConversationIdOrOutcome;
  -   
      private String getLongRunningConversationId()
      {
         if ( Manager.instance().isLongRunningConversation() )
  
  
  



More information about the jboss-cvs-commits mailing list