[jboss-cvs] JBossAS SVN: r58082 - branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 3 13:33:47 EST 2006


Author: weston.price at jboss.com
Date: 2006-11-03 13:33:42 -0500 (Fri, 03 Nov 2006)
New Revision: 58082

Modified:
   branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/ServerSessionPoolFactory.java
   branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/StdServerSession.java
   branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/StdServerSessionPool.java
   branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/StdServerSessionPoolFactory.java
Log:
[JBAS-3511] ASF improvements and patch.

Modified: branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/ServerSessionPoolFactory.java
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/ServerSessionPoolFactory.java	2006-11-03 18:33:29 UTC (rev 58081)
+++ branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/ServerSessionPoolFactory.java	2006-11-03 18:33:42 UTC (rev 58082)
@@ -92,7 +92,7 @@
     * @throws JMSException for any error
     */
    ServerSessionPool getServerSessionPool(Destination destination, Connection con, int minSession, int maxSession, long keepAlive, boolean isTransacted, int ack,
-         boolean useLocalTX, boolean lazy, boolean recycle, long idleTimeout, MessageListener listener) throws JMSException;
+         boolean useLocalTX, boolean lazy, boolean recycle, long idleTimeout, boolean destroyOnError, String sorterClassName, MessageListener listener) throws JMSException;
 
 
 }
\ No newline at end of file

Modified: branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/StdServerSession.java
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/StdServerSession.java	2006-11-03 18:33:29 UTC (rev 58081)
+++ branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/StdServerSession.java	2006-11-03 18:33:42 UTC (rev 58082)
@@ -80,7 +80,11 @@
    
    private boolean hasPermit;
    
+   private boolean hasError = false;
    
+   private JMSExceptionSorter sorter;
+   
+   
    /**
     * Create a <tt>StdServerSession</tt> .
     *
@@ -97,7 +101,8 @@
                     final XASession xaSession,
                     final MessageListener delegateListener,
                     boolean useLocalTX,
-                    final XidFactoryMBean xidFactory)
+                    final XidFactoryMBean xidFactory,
+                    final JMSExceptionSorter sorter)
       throws JMSException
    {
 
@@ -112,7 +117,8 @@
       
       this.useLocalTX = useLocalTX;
       this.xidFactory = xidFactory;
-
+      this.sorter = sorter;
+      
       if (log.isDebugEnabled())
          log.debug("initializing (pool, session, xaSession, useLocalTX): " +
             pool + ", " + session + ", " + xaSession + ", " + useLocalTX);
@@ -214,20 +220,23 @@
 
       }catch(Throwable t)
       {
-                  
+         
          if (td != null)
          {
             td.error();
             
          }
          
-      }finally
+         handleSessionFailure(t);
+         
+      }
+      finally
       {
          if(td != null)
          {
             td.end();
             
-         }                 
+         }                        
          recycle();
       }
    }
@@ -352,6 +361,16 @@
       serverSessionPool.recycle(this, false);
    }
    
+   boolean getHasError()
+   {
+      return hasError;
+      
+   }
+   void setHasError(boolean destroy)
+   {
+      this.hasError = destroy;
+   }
+   
    boolean isTimedOut(long timeout)
    {
       return this.lastUse < timeout;
@@ -377,6 +396,41 @@
       return new DemarcationStrategyFactory().getStrategy();      
    }
    
+   private void handleSessionFailure(final Throwable t)
+   {
+      if(t instanceof JMSException)
+      {
+         JMSException jmex = (JMSException)t;
+         
+         if(log.isTraceEnabled())
+         {
+            log.trace("JMSException thrown in: " + this + "  ", jmex);
+            log.trace("JMSException error code: " + jmex.getErrorCode());
+            
+            Exception linked = jmex.getLinkedException();
+            
+            if(linked != null)
+            {
+               log.trace("JMSLinkedException is ", jmex);
+            
+               if(linked instanceof JMSException)
+               {
+                  JMSException linkedex = (JMSException)linked;
+                  log.trace("Linked JMSException error code: " + linkedex.getErrorCode());
+               }
+            }
+                        
+         }
+         
+         if(sorter != null)
+         {
+            setHasError(sorter.isJMSExceptionFatal(jmex));               
+         }
+                     
+      }
+   }
+
+   
    private interface TransactionDemarcationStrategy
    {
       void error();
@@ -569,8 +623,8 @@
          }
          catch(Throwable t)
          {
-            log.error(StdServerSession.this + "failed to commit/rollback", t);
-            
+            log.error(StdServerSession.this + "failed to commit/rollback", t);            
+            handleSessionFailure(t);
          }
       }
    }

Modified: branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/StdServerSessionPool.java
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/StdServerSessionPool.java	2006-11-03 18:33:29 UTC (rev 58081)
+++ branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/StdServerSessionPool.java	2006-11-03 18:33:42 UTC (rev 58082)
@@ -142,12 +142,15 @@
     * closed.
     */
    private int numServerSessions = 0;
-    
+   
+   private boolean destroyOnError = false;
+   
+   private JMSExceptionSorter sorter;
+   
    private XidFactoryMBean xidFactory;
    
    private FIFOSemaphore permits;
-   
-   
+      
    private SessionPoolStatisticsCollector counter = new SessionPoolStatisticsCollector();
    
    public StdServerSessionPool(final Destination destination, 
@@ -162,6 +165,8 @@
                            final boolean lazy,
                            final boolean recycle,
                            final long idleTimeout,
+                           final boolean destroyOnError,
+                           final String exceptionSorter,
                            final XidFactoryMBean xidFactory) throws JMSException
    {
       
@@ -189,7 +194,7 @@
       this.lazyInitialization = lazy;
       this.recycleIdleSessions = recycle;
       this.idleTimeOut = idleTimeout;
-      
+      this.destroyOnError = destroyOnError;
       // finish initializing the session
       if(!lazyInitialization)
       {
@@ -209,6 +214,22 @@
          
       }
       
+      if(exceptionSorter != null)
+      {
+         try
+         {
+            Class clz = Class.forName(exceptionSorter);
+            sorter = (JMSExceptionSorter)clz.newInstance();
+            
+         }catch(Exception e)
+         {
+            log.trace("Could not intialize JMSExceptionSorter. Setting to DefaultJMSExceptionSorter.");
+            sorter = new DefaultJMSExceptionSorter();
+         }         
+         
+      }
+      
+      
       log.debug("Server Session pool set up");
       
       
@@ -405,6 +426,20 @@
    {
       return counter.getMaxSessionInUse();
    }
+   
+   public int getSessionErrorCount()
+   {
+      return counter.getSessionErrorCount();
+      
+   }
+   
+   public int getSessionCreatedCount()
+   {      
+      return counter.getTotalSessionCreated();
+   
+   }
+   
+
    // --- Protected messages for StdServerSession to use
 
    /**
@@ -461,7 +496,10 @@
          if(!isTimedOut)
             counter.decInUse();
          
-         if (closing || isTimedOut)
+         if(session.getHasError())
+            counter.incError();
+                  
+         if (closing || isTimedOut || (session.getHasError() && destroyOnError))
          {
             session.close();
             numServerSessions--;
@@ -529,9 +567,10 @@
       // create the server session and add it to the pool - it is up to the
       // server session to set the listener
       StdServerSession serverSession = new StdServerSession(this, ses, xaSes,
-         listener, useLocalTX, xidFactory);
+         listener, useLocalTX, xidFactory, sorter);
       numServerSessions++;
-      
+      counter.incTotalCreated();
+
       if (debug)
          log.debug("" + serverSession);
       
@@ -581,10 +620,12 @@
          // create the server session and add it to the pool - it is up to the
          // server session to set the listener
          StdServerSession serverSession = new StdServerSession(this, ses, xaSes,
-            listener, useLocalTX, xidFactory);
-
+            listener, useLocalTX, xidFactory, sorter);
+         
+         counter.incTotalCreated();
          sessionPool.add(serverSession);
          numServerSessions++;
+         
          if (debug)
             log.debug("added server session to the pool: " + serverSession);
       }
@@ -710,7 +751,15 @@
       private int timedOut;
       private int inUse;
       private int maxInUse;
+      private int error;
+      private int totalCreated;
       
+      synchronized void incTotalCreated()
+      {
+         ++totalCreated;
+         
+      }
+      
       synchronized void decInUse()
       {
          --inUse;
@@ -730,7 +779,11 @@
          ++timedOut;
          
       }      
-            
+      synchronized void incError()
+      {
+         ++error;
+         
+      }
       synchronized void maxSessionInUse(int count)
       {
          if(count > maxInUse)
@@ -751,8 +804,17 @@
       {
          return inUse;
       }
-
-   
+      
+      private int getSessionErrorCount()
+      {
+         return error;
+         
+      }
+      
+      private int getTotalSessionCreated()
+      {
+         return totalCreated;
+      }
    }
 
 }

Modified: branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/StdServerSessionPoolFactory.java
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/StdServerSessionPoolFactory.java	2006-11-03 18:33:29 UTC (rev 58081)
+++ branches/JBoss_4_0_3_SP1_JBAS_3511/server/src/main/org/jboss/jms/asf/StdServerSessionPoolFactory.java	2006-11-03 18:33:42 UTC (rev 58082)
@@ -63,10 +63,10 @@
    }
    
 
-   public javax.jms.ServerSessionPool getServerSessionPool(Destination destination, Connection con, int minSession, int maxSession, long keepAlive, boolean isTransacted, int ack, boolean useLocalTX, boolean lazyInit, boolean recycle, long idleTimeout, javax.jms.MessageListener listener) throws javax.jms.JMSException
+   public javax.jms.ServerSessionPool getServerSessionPool(Destination destination, Connection con, int minSession, int maxSession, long keepAlive, boolean isTransacted, int ack, boolean useLocalTX, boolean lazyInit, boolean recycle, long idleTimeout, boolean destroySessionOnError, String sorterClassName, javax.jms.MessageListener listener) throws javax.jms.JMSException
    {
      
-      ServerSessionPool pool = (ServerSessionPool)new StdServerSessionPool(destination, con, isTransacted, ack, useLocalTX, listener, minSession, maxSession, keepAlive, lazyInit, recycle, idleTimeout, xidFactory);
+      ServerSessionPool pool = (ServerSessionPool)new StdServerSessionPool(destination, con, isTransacted, ack, useLocalTX, listener, minSession, maxSession, keepAlive, lazyInit, recycle, idleTimeout, destroySessionOnError, sorterClassName, xidFactory);
       return pool;
    }
    




More information about the jboss-cvs-commits mailing list