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

Gavin King gavin.king at jboss.com
Tue Oct 10 18:09:05 EDT 2006


  User: gavin   
  Date: 06/10/10 18:09:05

  Modified:    src/main/org/jboss/seam/core   ConversationEntry.java
                        Manager.java
  Log:
  single concurrent request per conversation model JBSEAM-335, JBSEAM-183
  
  Revision  Changes    Path
  1.19      +22 -0     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.18
  retrieving revision 1.19
  diff -u -b -r1.18 -r1.19
  --- ConversationEntry.java	10 Oct 2006 21:00:53 -0000	1.18
  +++ ConversationEntry.java	10 Oct 2006 22:09:05 -0000	1.19
  @@ -27,8 +27,11 @@
      private String initiatorComponentName;
      private Integer timeout;
      private boolean removeAfterRedirect;
  +   
      private ConversationEntries parent;
   
  +   private transient Thread lock;
  +
      public ConversationEntry(String id, List<String> stack, ConversationEntries parent)
      {
         this.id = id;
  @@ -169,4 +172,23 @@
      {
         this.id = id;
      }
  +
  +   public synchronized boolean lock()
  +   {
  +      if ( lock!=null && !lock.equals( Thread.currentThread() ) ) 
  +      {
  +         return false;
  +      }
  +      this.lock = Thread.currentThread();
  +      return true;
  +   }
  +   
  +   public synchronized void unlock()
  +   {
  +      if ( lock!=null && lock.equals( Thread.currentThread() ) )
  +      {
  +         this.lock = null;
  +      }
  +   }
  +   
   }
  \ No newline at end of file
  
  
  
  1.91      +47 -32    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.90
  retrieving revision 1.91
  diff -u -b -r1.90 -r1.91
  --- Manager.java	10 Oct 2006 21:00:53 -0000	1.90
  +++ Manager.java	10 Oct 2006 22:09:05 -0000	1.91
  @@ -41,7 +41,7 @@
    *
    * @author Gavin King
    * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
  - * @version $Revision: 1.90 $
  + * @version $Revision: 1.91 $
    */
   @Scope(ScopeType.EVENT)
   @Name("org.jboss.seam.core.manager")
  @@ -57,12 +57,6 @@
      public static final String PAGEFLOW_NODE_NAME = NAME + ".pageflowNodeName";
      public static final String PAGEFLOW_NAME = NAME + ".pageflowName";
   
  -   //A map of all conversations for the session,
  -   //to the last activity time, which is flushed
  -   //stored in the session context at the end
  -   //of each request
  -   private Map<String, ConversationEntry> conversationIdEntryMap;
  -
      //The id of the current conversation
      private String currentConversationId;
      private List<String> currentConversationIdStack;
  @@ -95,6 +89,7 @@
      public void setCurrentConversationId(String id)
      {
         currentConversationId = id;
  +      currentConversationEntry = null;
      }
      
      public void updateCurrentConversationId(String id)
  @@ -108,9 +103,9 @@
         }
         Contexts.getConversationContext().flush();
         
  -      ConversationEntries.instance().updateConversationId(currentConversationId, id);
  +      ConversationEntries.instance().updateConversationId( getCurrentConversationId(), id );
         currentConversationIdStack.set(0, id);
  -      currentConversationId = id;
  +      setCurrentConversationId(id);
         //TODO: update nested conversations!!!!!
         
         for (int i=0; i<names.length; i++)
  @@ -178,16 +173,14 @@
   
      public String getCurrentConversationDescription()
      {
  -      if ( conversationIdEntryMap==null ) return null;
  -      ConversationEntry ce = conversationIdEntryMap.get(currentConversationId);
  +      ConversationEntry ce = getCurrentConversationEntry();
         if ( ce==null ) return null;
         return ce.getDescription();
      }
   
      public String getCurrentConversationViewId()
      {
  -      if ( conversationIdEntryMap==null ) return null;
  -      ConversationEntry ce = conversationIdEntryMap.get(currentConversationId);
  +      ConversationEntry ce = getCurrentConversationEntry();
         if ( ce==null ) return null;
         return ce.getViewId();
      }
  @@ -300,9 +293,18 @@
         conversationAlreadyStored = true;
      }
   
  +   public void unlockConversation()
  +   {
  +      ConversationEntry ce = getCurrentConversationEntry();
  +      if (ce!=null) ce.unlock();
  +   }
  +
      private void storeLongRunningConversation(Object response)
      {
  -      log.debug("Storing conversation state: " + currentConversationId);
  +      if ( log.isDebugEnabled() )
  +      {
  +         log.debug("Storing conversation state: " + getCurrentConversationId());
  +      }
         Conversation.instance().flush();
         //if the session is invalid, don't put the conversation id
         //in the view, 'cos we are expecting the conversation to
  @@ -313,11 +315,11 @@
            //      RENDER_RESPONSE phase, ie. not before redirects
            if ( isReallyLongRunningConversation() )
            {
  -            Contexts.getPageContext().set( CONVERSATION_ID, currentConversationId );
  +            Contexts.getPageContext().set( CONVERSATION_ID, getCurrentConversationId() );
               Contexts.getPageContext().set( CONVERSATION_IS_LONG_RUNNING, true );
            }
         }
  -      writeConversationIdToResponse(response, currentConversationId);
  +      writeConversationIdToResponse( response, getCurrentConversationId() );
         
         if ( Contexts.isPageContextActive() && Init.instance().isJbpmInstalled() )
         {
  @@ -333,7 +335,10 @@
   
      private void discardTemporaryConversation(ContextAdaptor session, Object response)
      {
  -      log.debug("Discarding conversation state: " + currentConversationId);
  +      if (log.isDebugEnabled())
  +      {
  +         log.debug("Discarding conversation state: " + getCurrentConversationId());
  +      }
   
         List<String> stack = getCurrentConversationIdStack();
         if ( stack.size()>1 )
  @@ -374,8 +379,8 @@
      }
   
      private void removeCurrentConversationAndDestroyNestedContexts(ContextAdaptor session) {
  -      ConversationEntries.instance().removeConversationEntry(currentConversationId);
  -      destroyNestedContexts(session, currentConversationId);
  +      ConversationEntries.instance().removeConversationEntry( getCurrentConversationId() );
  +      destroyNestedContexts( session, getCurrentConversationId() );
      }
   
      private void destroyNestedContexts(ContextAdaptor session, String conversationId) {
  @@ -454,7 +459,7 @@
            isLongRunningConversation = false;
         }
   
  -      return restoreConversation(storedConversationId, isLongRunningConversation);
  +      return restoreAndLockConversation(storedConversationId, isLongRunningConversation);
         
      }
      
  @@ -512,17 +517,16 @@
       * Initialize the request conversation context, given the 
       * conversation id.
       */
  -   public boolean restoreConversation(String storedConversationId, boolean isLongRunningConversation) {
  -      boolean isStoredConversation = storedConversationId!=null &&
  -            ConversationEntries.instance().getConversationIds().contains(storedConversationId);
  -      if ( isStoredConversation )
  +   public boolean restoreAndLockConversation(String storedConversationId, boolean isLongRunningConversation) {
  +      ConversationEntry ce = storedConversationId==null ? 
  +            null : ConversationEntries.instance().getConversationEntry(storedConversationId);
  +      if ( ce!=null && ce.lock() )
         {
   
  -         //we found an id, so restore the long-running conversation
  +         //we found an id and obtained the lock, so restore the long-running conversation
            log.debug("Restoring conversation with id: " + storedConversationId);
            setLongRunningConversation(true);
            setCurrentConversationId(storedConversationId);
  -         ConversationEntry ce = getCurrentConversationEntry();
            setCurrentConversationIdStack( ce.getConversationIdStack() );
   
            boolean removeAfterRedirect = ce.isRemoveAfterRedirect() && !(
  @@ -543,7 +547,7 @@
         {
            //there was no id in either place, so there is no
            //long-running conversation to restore
  -         log.debug("No stored conversation");
  +         log.debug("No stored conversation, or concurrent call to the stored conversation");
            initializeTemporaryConversation();
            return !isLongRunningConversation;
         }
  @@ -599,7 +603,10 @@
   
      private ConversationEntry createConversationEntry()
      {
  -      return ConversationEntries.instance().createConversationEntry( getCurrentConversationId(), getCurrentConversationIdStack() );
  +      ConversationEntry entry = ConversationEntries.instance()
  +            .createConversationEntry( getCurrentConversationId(), getCurrentConversationIdStack() );
  +      entry.lock();
  +      return entry;
      }
   
      /**
  @@ -640,8 +647,16 @@
         conversationEntry.setInitiatorComponentName(ownerName);
      }
   
  +   // two reasons for this: 
  +   // (1) a cache
  +   // (2) so we can unlock() it after destruction of the session context 
  +   private ConversationEntry currentConversationEntry; 
      public ConversationEntry getCurrentConversationEntry() {
  -      return ConversationEntries.instance().getConversationEntry(getCurrentConversationId());
  +      if (currentConversationEntry==null)
  +      {
  +         currentConversationEntry = ConversationEntries.instance().getConversationEntry( getCurrentConversationId() );
  +      }
  +      return currentConversationEntry;
      }
      
      /**
  @@ -694,7 +709,7 @@
      {
         if (!destroyBeforeRedirect)
         {
  -         ConversationEntry ce = ConversationEntries.instance().getConversationEntry(currentConversationId);
  +         ConversationEntry ce = getCurrentConversationEntry();
            if (ce==null)
            {
               ce = createConversationEntry();
  @@ -930,7 +945,7 @@
         FacesMessages.instance().addFromResourceBundle( 
               FacesMessage.SEVERITY_WARN, 
               "org.jboss.seam.NoConversation", 
  -            "No conversation" 
  +            "The conversation ended, timed out or was processing another request" 
            );
         
         //stuff from jPDL takes precedence
  
  
  



More information about the jboss-cvs-commits mailing list