[jboss-cvs] JBossAS SVN: r58910 - branches/JBoss_4_0_5_GA_JBAS_3657/server/src/main/org/jboss/ejb/plugins/jms

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Dec 7 16:59:29 EST 2006


Author: weston.price at jboss.com
Date: 2006-12-07 16:59:27 -0500 (Thu, 07 Dec 2006)
New Revision: 58910

Modified:
   branches/JBoss_4_0_5_GA_JBAS_3657/server/src/main/org/jboss/ejb/plugins/jms/JMSContainerInvoker.java
   branches/JBoss_4_0_5_GA_JBAS_3657/server/src/main/org/jboss/ejb/plugins/jms/JMSContainerInvokerMBean.java
Log:
[JBAS-3657][JBAS-3511] Port of patch made for client in integrating with WebSphereMQ

Modified: branches/JBoss_4_0_5_GA_JBAS_3657/server/src/main/org/jboss/ejb/plugins/jms/JMSContainerInvoker.java
===================================================================
--- branches/JBoss_4_0_5_GA_JBAS_3657/server/src/main/org/jboss/ejb/plugins/jms/JMSContainerInvoker.java	2006-12-07 21:58:03 UTC (rev 58909)
+++ branches/JBoss_4_0_5_GA_JBAS_3657/server/src/main/org/jboss/ejb/plugins/jms/JMSContainerInvoker.java	2006-12-07 21:59:27 UTC (rev 58910)
@@ -1,24 +1,12 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+/***************************************
+ *                                     *
+ *  JBoss: The OpenSource J2EE WebOS   *
+ *                                     *
+ *  Distributable under LGPL license.  *
+ *  See terms of license at gnu.org.   *
+ *                                     *
+ ***************************************/
+
 package org.jboss.ejb.plugins.jms;
 
 import java.lang.reflect.Method;
@@ -26,8 +14,6 @@
 import java.security.Principal;
 import java.security.PrivilegedAction;
 import java.util.Collection;
-
-import javax.ejb.EJBMetaData;
 import javax.jms.Connection;
 import javax.jms.ConnectionConsumer;
 import javax.jms.Destination;
@@ -69,21 +55,31 @@
 
 /**
  * EJBProxyFactory for JMS MessageDrivenBeans
- * 
  * @author <a href="mailto:peter.antman at tim.se">Peter Antman</a> .
- * @author <a href="mailto:rickard.oberg at telkel.com">Rickard Oberg</a>
+ * @author <a href="mailto:rickard.oberg at telkel.com">Rickard Öberg</a>
  * @author <a href="mailto:sebastien.alborini at m4x.org">Sebastien Alborini</a>
  * @author <a href="mailto:marc.fleury at telkel.com">Marc Fleury</a>
  * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
- * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="mailto:weston.price at jboss.com>Weston Price</a>
+ * 
  * @version <tt>$Revision$</tt>
+ * @jmx:mbean extends="org.jboss.system.ServiceMBean"
  */
-public class JMSContainerInvoker extends ServiceMBeanSupport
+/**
+ * A JMSContainerInvoker.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision$
+ */
+public class JMSContainerInvoker
+   extends ServiceMBeanSupport
    implements EJBProxyFactory, JMSContainerInvokerMBean
 {
+   // Constants -----------------------------------------------------
+   
    /** The logger */
    private static final Logger log = Logger.getLogger(JMSContainerInvoker.class);
-   
+
    /** Notification sent before connectioning */
    private static final String CONNECTING_NOTIFICATION = "org.jboss.ejb.plugins.jms.CONNECTING";
 
@@ -99,7 +95,9 @@
    /** Notification sent at connection failure */
    private static final String FAILURE_NOTIFICATION = "org.jboss.ejb.plugins.jms.FAILURE";
    
-   /** {@link MessageListener#onMessage} reference. */
+   /**
+    * {@link MessageListener#onMessage} reference.
+    */
    protected static Method ON_MESSAGE;
 
    /**
@@ -108,7 +106,7 @@
     * successfull. Default value: javax.jms.Topic.
     */
    protected final static String DEFAULT_DESTINATION_TYPE = "javax.jms.Topic";
-   
+
    /**
     * Initialize the ON_MESSAGE reference.
     */
@@ -122,67 +120,113 @@
       }
       catch (Exception e)
       {
+         e.printStackTrace();
          throw new ExceptionInInitializerError(e);
       }
    }
    
+   // Attributes ----------------------------------------------------
+   
    protected boolean optimize;
 
-   /** Maximum number provider is allowed to stuff into a session. */
+   /**
+    * Maximum number provider is allowed to stuff into a session.
+    */
    protected int maxMessagesNr = 1;
 
-   /** Minimun pool size of server sessions. */
+   /**
+    * Minimun pool size of server sessions.
+    */
    protected int minPoolSize = 1;
 
-   /** Keep alive server sessions. */
+   /**
+    * Keep alive server sessions.
+    */
    protected long keepAlive = 30 * 1000;
 
-   /** Maximun pool size of server sessions. */
+   /**
+    * Maximun pool size of server sessions.
+    */
    protected int maxPoolSize = 15;
-
-   /** Time to wait before retrying to reconnect a lost connection. */
+   
+   /** The lazyInitialization */
+   protected boolean lazyInitialization = false;
+   
+   /** The recycleIdleSessions */
+   protected boolean recycleIdleSessions = false;
+   
+   /** The idleTimeoutMinutes */
+   //Thirty minutes by default
+   protected long idleTimeoutMinutes = 1000 * 60 * 30; 
+   
+   /** The alwaysReconnect */
+   protected boolean alwaysReconnect;
+   
+   protected boolean destroySessionOnError = false;
+   
+   protected String supportCodeUrl = "NoUrl";
+   
+   protected boolean validateLinkedException = false;
+   
+   protected String exceptionSorterClassName = "NoSorter";
+   
+   /**
+    * Time to wait before retrying to reconnect a lost connection.
+    */
    protected long reconnectInterval = 10000;
 
-   /** If Dead letter queue should be used or not. */
+   /**
+    * If Dead letter queue should be used or not.
+    */
    protected boolean useDLQ = false;
 
    /**
     * JNDI name of the provider adapter.
-    * 
     * @see org.jboss.jms.jndi.JMSProviderAdapter
     */
    protected String providerAdapterJNDI;
 
    /**
     * JNDI name of the server session factory.
-    * 
     * @see org.jboss.jms.asf.ServerSessionPoolFactory
     */
    protected String serverSessionPoolFactoryJNDI;
 
-   /** JMS acknowledge mode, used when session is not XA. */
+   /**
+    * JMS acknowledge mode, used when session is not XA.
+    */
    protected int acknowledgeMode;
 
    protected boolean isContainerManagedTx;
    protected boolean isNotSupportedTx;
 
-   /** The container. */
+   /**
+    * The container.
+    */
    protected Container container;
 
-   /** The JMS connection. */
+   /**
+    * The JMS connection.
+    */
    protected Connection connection;
 
-   /** The JMS connection consumer. */
+   /**
+    * The JMS connection consumer.
+    */
    protected ConnectionConsumer connectionConsumer;
 
    protected TransactionManager tm;
    protected ServerSessionPool pool;
    protected ExceptionListenerImpl exListener;
 
-   /** Dead letter queue handler. */
+   /**
+    * Dead letter queue handler.
+    */
    protected DLQHandler dlqHandler;
 
-   /** DLQConfig element from MDBConfig element from jboss.xml. */
+   /**
+    * DLQConfig element from MDBConfig element from jboss.xml.
+    */
    protected Element dlqConfig;
 
    protected InvokerProxyBindingMetaData invokerMetaData;
@@ -208,57 +252,271 @@
    {
       invokerBinding = binding;
    }
+
+   // ContainerService implementation -------------------------------
    
    /**
     * Set the container for which this is an invoker to.
-    * 
     * @param container The container for which this is an invoker to.
     */
    public void setContainer(final Container container)
    {
       this.container = container;
    }
+   
+   // Static --------------------------------------------------------
+   
+   // Constructors --------------------------------------------------
+   
+   // Public --------------------------------------------------------
 
+   /**
+    * @jmx:managed-attribute
+    */
    public int getMinPoolSize()
    {
       return minPoolSize;
    }
 
+   /**
+    * @jmx:managed-attribute
+    */
    public void setMinPoolSize(int minPoolSize)
    {
       this.minPoolSize = minPoolSize;
    }
 
+   /**
+    * @jmx:managed-attribute
+    */
    public int getMaxPoolSize()
    {
       return maxPoolSize;
    }
 
+   /**
+    * @jmx:managed-attribute
+    */
    public void setMaxPoolSize(int maxPoolSize)
    {
       this.maxPoolSize = maxPoolSize;
    }
 
+   /**
+    * @jmx:managed-attribute
+    */
    public long getKeepAliveMillis()
    {
       return keepAlive;
    }
 
+   /**
+    * @jmx:managed-attribute
+    */
    public void setKeepAliveMillis(long keepAlive)
    {
       this.keepAlive = keepAlive;
    }
 
+   /**
+    * @jmx:managed-attribute
+    */
    public int getMaxMessages()
    {
       return maxMessagesNr;
    }
 
+   /**
+    * @jmx:managed-attribute
+    */
    public void setMaxMessages(int maxMessages)
    {
       this.maxMessagesNr = maxMessages;
    }
+   
+   public long getIdleTimeOutMinutes()
+   {
+      return this.idleTimeoutMinutes / (1000 * 60);
+      
+   }
+   
+   public boolean getLazyInitialization()
+   {
+      return this.lazyInitialization;
+   }
+   
+   public void setLazyInitialization(boolean lazy)
+   {
+      this.lazyInitialization = lazy;
+      
+   }
+   
+   public boolean getRecycleIdleSessions()
+   {
+      return this.recycleIdleSessions;
+   }
+   
+   public void setRecycleIdleSessions(boolean recycle)
+   {
+      this.recycleIdleSessions = recycle;
+      
+   }
+   
+   public void setIdleTimeOutMinutes(long idleTimeout)
+   {
+      this.idleTimeoutMinutes = (idleTimeout * 1000 * 60);
+   }
+   
+   public boolean getAlwaysReconnect()
+   {
+      return this.alwaysReconnect;
+      
+   }
+   
+   public void setAlwaysReconnect(boolean alwaysReconnect)
+   {
+      this.alwaysReconnect = alwaysReconnect;
+   }
+   
+   public int getSessionTimedOutCount()
+   {
+      int timedOut = 0;
+      if(pool != null)
+      {
+         StdServerSessionPool sp = (StdServerSessionPool)pool;
+         timedOut = sp.getTimedOut();
+      }
+      
+      return timedOut;
+   }
+   
+   public int getCurrentSessionCount() 
+   {
+      int currentCount = 0;
+      if(pool != null)
+      {
+         StdServerSessionPool sp = (StdServerSessionPool)pool;
+         currentCount = sp.getCurrentSessionCount();
+      }
+      
+      return currentCount;
 
+   }
+   
+   public int getMaxSessionInUseCount()
+   {
+      int maxInUseCount = 0;
+     
+      if(pool != null)
+      {
+         StdServerSessionPool sp = (StdServerSessionPool)pool;
+         maxInUseCount = sp.getSessionMaxInUseCount();
+      }
+      
+      return maxInUseCount;
+
+   }
+   
+   public int getCurrentSessionInUseCount()
+   {
+      int inUse = 0;
+      
+      if(pool != null)
+      {
+         StdServerSessionPool sp = (StdServerSessionPool)pool;
+         inUse = sp.getCurrentSessionInUseCount();
+         
+      }
+      return inUse;
+      
+   }
+   
+   public int getSessionErrorCount()
+   {
+      int error = 0;
+      
+      if(pool != null)
+      {
+         StdServerSessionPool sp = (StdServerSessionPool)pool;
+         error = sp.getSessionErrorCount();
+         
+      }
+      return error;
+   }
+   
+   public int getSessionCreatedCount()
+   {
+      int total = 0;
+      
+      if(pool != null)
+      {
+         StdServerSessionPool sp = (StdServerSessionPool)pool;
+         total = sp.getSessionCreatedCount();
+         
+      }      
+      return total;
+   }
+   
+   public int getSessionDestroyedCount()
+   {
+      int destroyed = 0;
+      
+      if(pool != null)
+      {
+         StdServerSessionPool sp = (StdServerSessionPool)pool;
+         destroyed = sp.getSessionDestroyedCount();
+         
+      }      
+      return destroyed;
+   }
+      
+   
+   public boolean getDestroySessionOnError()
+   {
+      return destroySessionOnError;
+      
+   }
+   
+   public void setDestroySessionOnError(boolean destroy)
+   {
+      this.destroySessionOnError = destroy;
+      
+   }
+   
+   public String getExceptionSorterClassName()
+   {
+      return this.exceptionSorterClassName;
+      
+   }
+   
+   public void setExceptionSorterClassName(String name)
+   {
+      this.exceptionSorterClassName = name;
+   }
+   
+   public void setSupportCodeUrl(String supportCodeUrl)
+   {
+      this.supportCodeUrl = supportCodeUrl;
+   }
+   
+   public String getSupportCodeUrl()
+   {
+      return this.supportCodeUrl;
+      
+   }
+
+   public void setValidateLinkedException(boolean vle)
+   {
+      this.validateLinkedException = vle;
+   }
+   
+   public boolean getValidateLinkedException()
+   {
+      return this.validateLinkedException;
+   }
+   /**
+    * @jmx:managed-attribute
+    */
    public MessageDrivenMetaData getMetaData()
    {
       MessageDrivenMetaData config =
@@ -266,16 +524,27 @@
       return config;
    }
 
+   /**
+    * @return whether delivery is active
+    * @jmx:managed-attribute
+    */
    public boolean getDeliveryActive()
    {
       return deliveryActive;
    }
 
+   /**
+    * @return whether we are creating jbossmq destinations
+    * @jmx:managed-attribute
+    */
    public boolean getCreateJBossMQDestination()
    {
       return createJBossMQDestination;
    }
 
+   /**
+    * @jmx:managed-operation
+    */
    public void startDelivery()
       throws Exception
    {
@@ -286,7 +555,106 @@
       deliveryActive = true;
       startService();
    }
+   
+   /**
+    * @jmx:managed-operation
+    */
+   public void refreshSupportCodes()
+   {
+      if(pool instanceof StdServerSessionPool)
+      {
+         StdServerSessionPool stdPool = (StdServerSessionPool)pool;
+         stdPool.refreshSupportCodeFile();
+         
+      }
+   }
+   /**
+    * @jmx:managed-operation
+    */  
+   public void clearCurrentSupportCodes()
+   {
+      if(pool instanceof StdServerSessionPool)
+      {
+         StdServerSessionPool stdPool = (StdServerSessionPool)pool;
+         stdPool.clearCurrentSupportCodes();         
+         
+      }
+      
+   }
+   
+   /**
+    * @jmx:managed-operation
+    */
+   public void loadSupportCodeFile(String fileName)
+   {
+      if(pool instanceof StdServerSessionPool)
+      {
+         StdServerSessionPool stdPool = (StdServerSessionPool)pool;
+         stdPool.loadSupportCodeFile(fileName);
+                  
+      }
+      
+   }
+   
+   public void addSupportCodes(String fileName)
+   {
+      if(pool instanceof StdServerSessionPool)
+      {
+         StdServerSessionPool stdPool = (StdServerSessionPool)pool;
+         stdPool.addSupportCodes(fileName);         
+                  
+      }
+      
+   }
+   
+   public String isCodeInUse(int code)
+   {
+ 
+      if(pool instanceof StdServerSessionPool)
+      {
+         StdServerSessionPool stdPool = (StdServerSessionPool)pool;
+         boolean inUse = stdPool.isCodeInUse(code);         
+         return (inUse) ? "Support code " + code + " is in use" : "Support code " + code + " is not in use";         
+      }
+      
+      return "";
+      
+   }
+   public String listCurrentSupportCodes()
+   {      
+      Integer[] codes = null;
+      StringBuffer codeBuff = new StringBuffer();
+      codeBuff.append("JMS Fatal Exception Codes: \n");
+      
+      if(pool instanceof StdServerSessionPool)
+      {
+         StdServerSessionPool stdPool = (StdServerSessionPool)pool;
+         codes = stdPool.listCurrentSupportCodes();         
+                  
+      }
 
+      if(codes != null && codes.length != 0)
+      {
+         for (int i = 0; i < codes.length; i++)
+         {
+            Integer code = codes[i];
+            codeBuff.append("Fatal Code: " + code + "\n");
+            
+         }
+      
+      }else
+      {
+         codeBuff.append("No codes found.\n");
+         
+      }
+      
+      return codeBuff.toString();
+      
+   }
+   
+   /**
+    * @jmx:managed-operation
+    */
    public void stopDelivery()
       throws Exception
    {
@@ -297,63 +665,97 @@
       deliveryActive = false;
       stopService();
    }
-
+   
    /**
     * Sets the Optimized attribute of the JMSContainerInvoker object
-    * 
     * @param optimize The new Optimized value
     */
    public void setOptimized(final boolean optimize)
    {
+      if (log.isDebugEnabled())
+         log.debug("Container Invoker optimize set to " + optimize);
+
       this.optimize = optimize;
    }
+   
+   // EJBProxyFactory implementation
 
    public boolean isIdentical(Container container, Invocation mi)
    {
       throw new Error("Not valid for MessageDriven beans");
    }
 
+   /**
+    * Always throws an Error
+    * @throws Error Not valid for MDB
+    */
    public Object getEJBHome()
    {
       throw new Error("Not valid for MessageDriven beans");
    }
 
-   public EJBMetaData getEJBMetaData()
+   /**
+    * Always throws an Error
+    * @throws Error Not valid for MDB
+    */
+   public javax.ejb.EJBMetaData getEJBMetaData()
    {
       throw new Error("Not valid for MessageDriven beans");
    }
 
+   /**
+    * Always throws an Error
+    * @throws Error Not valid for MDB
+    */
    public Collection getEntityCollection(Collection ids)
    {
       throw new Error("Not valid for MessageDriven beans");
    }
 
+   /**
+    * Always throws an Error
+    * @throws Error Not valid for MDB
+    */
    public Object getEntityEJBObject(Object id)
    {
       throw new Error("Not valid for MessageDriven beans");
    }
 
+   /**
+    * Always throws an Error
+    * @throws Error Not valid for MDB
+    */
    public Object getStatefulSessionEJBObject(Object id)
    {
       throw new Error("Not valid for MessageDriven beans");
    }
 
+   /**
+    * Always throws an Error
+    * @throws Error Not valid for MDB
+    */
    public Object getStatelessSessionEJBObject()
    {
       throw new Error("Not valid for MessageDriven beans");
    }
 
+   /**
+    * Gets the Optimized attribute of the JMSContainerInvoker object
+    * @return The Optimized value
+    */
    public boolean isOptimized()
    {
+      if (log.isDebugEnabled())
+         log.debug("Optimize in action: " + optimize);
+
       return optimize;
    }
 
    /**
     * XmlLoadable implementation.
     *
-    * @todo FIXME - we ought to move all config into MDBConfig, but I do not do that
+    * FIXME - we ought to move all config into MDBConfig, but I do not do that
     * now due to backward compatibility.
-    * 
     * @param element Description of Parameter
     * @throws DeploymentException Description of Exception
     */
@@ -409,7 +811,107 @@
       catch (Exception ignore)
       {
       }
+      
+      try
+      {
+         String lazy =  MetaData.getElementContent
+            (MetaData.getUniqueChild(element, "LazyInitialization"));
+         lazyInitialization = Boolean.valueOf(lazy).booleanValue(); 
+         
+      }catch(Exception ignore)
+      {
+         
+      }
+      
+      try
+      {
+         String ris =  MetaData.getElementContent
+            (MetaData.getUniqueChild(element, "RecycleIdleSessions"));
+         recycleIdleSessions = Boolean.valueOf(ris).booleanValue(); 
+         
+      }catch(Exception ignore)
+      {
+         
+      }
 
+      try
+      {
+         String rc =  MetaData.getElementContent
+            (MetaData.getUniqueChild(element, "AlwaysReconnect"));
+         alwaysReconnect = Boolean.valueOf(rc).booleanValue(); 
+         
+      }catch(Exception ignore)
+      {
+         
+      }
+
+            
+      try
+      {
+         String it =  MetaData.getElementContent
+            (MetaData.getUniqueChild(element, "IdleTimeOutMinutes"));
+         idleTimeoutMinutes = (Integer.valueOf(it).longValue() * 1000 * 60); 
+         
+      }catch(Exception ignore)
+      {
+         
+      }
+
+      try
+      {
+         String destroy =  MetaData.getElementContent
+            (MetaData.getUniqueChild(element, "DestroySessionOnError"));
+         destroySessionOnError = Boolean.valueOf(destroy).booleanValue(); ; 
+         
+      }catch(Exception ignore)
+      {
+         
+      }
+
+      try
+      {
+         String url =  MetaData.getElementContent
+         (MetaData.getUniqueChild(element, "SupportCodeUrl"));
+         
+         if(url != null && !url.equalsIgnoreCase(""))
+         {
+            this.supportCodeUrl = url; 
+            
+         }
+         
+      }catch(Exception ignore)
+      {
+         
+      }
+      
+      try
+      {
+         String linked = MetaData.getElementContent
+         (MetaData.getUniqueChild(element, "ValidateLinkedException"));
+         validateLinkedException = Boolean.valueOf(linked).booleanValue();
+         
+      }catch(Exception ignore)
+      {
+         
+      }
+      
+      try
+      {
+         
+         String sorter = MetaData.getElementContent
+         (MetaData.getUniqueChild(element, "ExceptionSorterClassName"));
+         
+         if(sorter != null && !sorter.equalsIgnoreCase(""))
+         {
+            this.exceptionSorterClassName = sorter;
+         }
+         
+      }catch(Exception ignore)
+      {
+         
+      }
+            
+      
       Element mdbConfig = MetaData.getUniqueChild(element, "MDBConfig");
 
       try
@@ -468,22 +970,20 @@
     * Initialize the container invoker. Sets up a connection, a server session
     * pool and a connection consumer for the configured destination.
     *
-    * <p>Any JMSExceptions produced while initializing will be assumed to be caused
+    * Any JMSExceptions produced while initializing will be assumed to be caused
     * due to JMS Provider failure.
-    * 
     * @throws Exception Failed to initalize.
     */
    protected void createService() throws Exception
    {
       importXml(invokerMetaData.getProxyFactoryConfig());
 
-      exListener = new ExceptionListenerImpl(this);
+      exListener = new ExceptionListenerImpl(this, alwaysReconnect);
    }
 
    /**
     * Initialize the container invoker. Sets up a connection, a server session
     * pool and a connection consumer for the configured destination.
-    * 
     * @throws Exception Failed to initalize.
     */
    protected void innerStartDelivery() throws Exception
@@ -494,10 +994,12 @@
          return;
       }
       
+      
       sendNotification(CONNECTING_NOTIFICATION, null);
 
+      
       log.debug("Initializing");
-
+      
       // Get the JMS provider
       JMSProviderAdapter adapter = getJMSProviderAdapter();
       log.debug("Provider adapter: " + adapter);
@@ -670,6 +1172,9 @@
                keepAlive,
                true, // tx
                acknowledgeMode,
+               lazyInitialization,
+               recycleIdleSessions,
+               idleTimeoutMinutes,
                new MessageListenerImpl(this));
 
             int subscriptionDurablity = config.getSubscriptionDurability();
@@ -788,6 +1293,9 @@
                keepAlive,
                true, // tx
                acknowledgeMode,
+               lazyInitialization,
+               recycleIdleSessions,
+               idleTimeoutMinutes,
                new MessageListenerImpl(this));
             log.debug("Server session pool: " + pool);
             
@@ -817,23 +1325,27 @@
       log.debug("Initialized with config " + toString());
 
       context.close();
-      
+
       if (dlqHandler != null)
-      {
          dlqHandler.start();
-      }
 
       if (connection != null)
       {
          connection.setExceptionListener(exListener);
          connection.start();
       }
-
+      
       sendNotification(CONNECTED_NOTIFICATION, null);
    }
 
    protected void startService() throws Exception
    {
+      
+      if(exListener != null)
+      {
+         exListener.setAlwaysReconnect(alwaysReconnect);
+      }
+      
       try
       {
          innerStartDelivery();
@@ -883,7 +1395,7 @@
       }
       catch (Throwable t)
       {
-         log.trace("Could not set ExceptionListener to null", t);
+         log.error("Could not set ExceptionListener to null", t);
       }
       
       // Stop the connection
@@ -897,28 +1409,25 @@
       }
       catch (Throwable t)
       {
-         log.trace("Could not stop JMS connection", t);
+         log.error("Could not stop JMS connection", t);
       }
 
-      try
+      if (dlqHandler != null)
       {
-         if (dlqHandler != null)
-            dlqHandler.stop();
+         dlqHandler.stop();
       }
-      catch (Throwable t)
-      {
-         log.trace("Failed to stop the dlq handler", t);
-      }
 
       // close the connection consumer
       try
       {
          if (connectionConsumer != null)
+         {
             connectionConsumer.close();
+         }
       }
       catch (Throwable t)
       {
-         log.trace("Failed to close connection consumer", t);
+         log.error("Failed to close connection consumer", t);
       }
       connectionConsumer = null;
       
@@ -933,7 +1442,7 @@
       }
       catch (Throwable t)
       {
-         log.trace("Failed to clear session pool", t);
+         log.error("Failed to clear session pool", t);
       }
       
       // close the connection
@@ -945,7 +1454,7 @@
          }
          catch (Throwable t)
          {
-            log.trace("Failed to close connection", t);
+            log.error("Failed to close connection", t);
          }
       }
       connection = null;
@@ -960,7 +1469,7 @@
       }
       catch (Throwable t)
       {
-         log.trace("Failed to close the dlq handler", t);
+         log.error("Failed to close the dlq handler", t);
       }
       dlqHandler = null;
       
@@ -996,7 +1505,6 @@
     * Try to get a destination type by looking up the destination JNDI, or
     * provide a default if there is not destinationJNDI or if it is not possible
     * to lookup.
-    * 
     * @param ctx The naming context to lookup destinations from.
     * @param destinationJNDI The name to use when looking up destinations.
     * @return The destination type, either derived from destinationJDNI or
@@ -1039,10 +1547,10 @@
 
    /**
     * Return the JMSProviderAdapter that should be used.
-    * 
     * @return The JMSProviderAdapter to use.
     */
-   protected JMSProviderAdapter getJMSProviderAdapter() throws NamingException
+   protected JMSProviderAdapter getJMSProviderAdapter()
+      throws NamingException
    {
       Context context = new InitialContext();
       try
@@ -1058,7 +1566,6 @@
 
    /**
     * Create and or lookup a JMS destination.
-    * 
     * @param type Either javax.jms.Queue or javax.jms.Topic.
     * @param ctx The naming context to lookup destinations from.
     * @param jndiName The name to use when looking up destinations.
@@ -1153,6 +1660,9 @@
       final long keepAlive,
       final boolean isTransacted,
       final int ack,
+      final boolean lazyInit,
+      final boolean recycleIdle,
+      final long idleTimeout,
       final MessageListener listener)
       throws NamingException, JMSException
    {
@@ -1168,7 +1678,7 @@
             context.lookup(serverSessionPoolFactoryJNDI);
          
          // the create the pool
-         pool = factory.getServerSessionPool(destination, connection, minSession, maxSession, keepAlive, isTransacted, ack, !isContainerManagedTx || isNotSupportedTx, listener);
+         pool = factory.getServerSessionPool(destination, connection, minSession, maxSession, keepAlive, isTransacted, ack, !isContainerManagedTx || isNotSupportedTx, lazyInit, recycleIdle, idleTimeout, destroySessionOnError, supportCodeUrl, exceptionSorterClassName, validateLinkedException, listener);
       }
       finally
       {
@@ -1193,7 +1703,6 @@
    
    /**
     * Parse the JNDI suffix from the given JNDI name.
-    * 
     * @param jndiname The JNDI name used to lookup the destination.
     * @param defautSuffix Description of Parameter
     * @return The parsed suffix or the defaultSuffix
@@ -1231,28 +1740,33 @@
     * An implementation of MessageListener that passes messages on to the
     * container invoker.
     */
-   class MessageListenerImpl implements MessageListener
+   class MessageListenerImpl
+      implements MessageListener
    {
-      /** The container invoker. */
+      /**
+       * The container invoker.
+       */
       JMSContainerInvoker invoker;
+      // = null;
       
       /**
        * Construct a <tt>MessageListenerImpl</tt> .
-       * 
        * @param invoker The container invoker. Must not be null.
        */
       MessageListenerImpl(final JMSContainerInvoker invoker)
       {
+         // assert invoker != null;
+         
          this.invoker = invoker;
       }
 
       /**
        * Process a message.
-       * 
        * @param message The message to process.
        */
       public void onMessage(final Message message)
       {
+         // assert message != null;
          if (log.isTraceEnabled())
          {
             log.trace("processing message: " + message);
@@ -1306,7 +1820,8 @@
       JMSContainerInvoker invoker;
       Thread currentThread;
       boolean notStopped = true;
-
+      boolean alwaysReconnect;
+      
       /**
        * Create a new ExceptionListenerImpl.
        * 
@@ -1316,6 +1831,12 @@
       {
          this.invoker = invoker;
       }
+      
+      ExceptionListenerImpl(final JMSContainerInvoker invoker, boolean alwaysReconnect)
+      {
+         this.invoker = invoker;
+         this.alwaysReconnect = alwaysReconnect;
+      }
 
       /**
        * Called on jms connection failure events
@@ -1326,7 +1847,7 @@
       {
          handleFailure(ex);
       }
-
+      
       /**
        * Handle a failure
        * 
@@ -1337,12 +1858,19 @@
          MessageDrivenMetaData metaData = invoker.getMetaData();
          log.warn("JMS provider failure detected for " + metaData.getEjbName(), t);
          
-         // JBAS-3750 - Help debug integration with foreign JMS providers
-         if (t instanceof JMSException)
+         if(t instanceof JMSException)
          {
-            Exception le = ((JMSException)t).getLinkedException();
-            if (le != null)
-               log.debug("Linked exception: " + le + ", cause: " + le.getCause());
+            JMSException jmex = (JMSException)t;            
+            Exception linked = jmex.getLinkedException();
+            
+            if(linked != null)
+            {
+               log.trace("JMSException error code " + jmex.getErrorCode());
+               log.trace("JMSException linked exception", linked);
+               log.trace("JMSException cause", linked.getCause());
+               
+            }
+            
          }
          
          // Run the reconnection in the background
@@ -1373,7 +1901,10 @@
             }
          }
       }
-
+      void setAlwaysReconnect(boolean alwaysReconnect)
+      {
+         this.alwaysReconnect = alwaysReconnect;
+      }
       class ExceptionListenerRunnable implements Runnable
       {
          Throwable failure;
@@ -1397,7 +1928,7 @@
             try
             {
                boolean tryIt = true;
-               while (tryIt && notStopped)
+               while (tryIt && notStopped || tryIt && alwaysReconnect)
                {
                   try
                   {
@@ -1445,7 +1976,21 @@
             }
          }
       }
-
+      
+//      void restart()
+//      {
+//         synchronized (lock)
+//         {
+//            log.debug("Start requested for recovery thread: " + currentThread);
+//            notStopped = true;
+//            if (currentThread != null)
+//            {
+//               currentThread.interrupt();
+//               log.debug("Recovery thread interrupted: " + currentThread);
+//            }
+//            
+//         }
+//      }
       void stop()
       {
          synchronized (lock)

Modified: branches/JBoss_4_0_5_GA_JBAS_3657/server/src/main/org/jboss/ejb/plugins/jms/JMSContainerInvokerMBean.java
===================================================================
--- branches/JBoss_4_0_5_GA_JBAS_3657/server/src/main/org/jboss/ejb/plugins/jms/JMSContainerInvokerMBean.java	2006-12-07 21:58:03 UTC (rev 58909)
+++ branches/JBoss_4_0_5_GA_JBAS_3657/server/src/main/org/jboss/ejb/plugins/jms/JMSContainerInvokerMBean.java	2006-12-07 21:59:27 UTC (rev 58910)
@@ -1,125 +1,101 @@
 /*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
+ * JBoss, the OpenSource J2EE webOS
  *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
  */
 package org.jboss.ejb.plugins.jms;
 
-import org.jboss.metadata.MessageDrivenMetaData;
-
 /**
  * MBean interface.
- * 
- * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
- * @version <tt>$Revision$</tt>
+ * @author <a href="mailto:weston.price at jboss.com>Weston Price</a>
  */
 public interface JMSContainerInvokerMBean extends org.jboss.system.ServiceMBean
 {
-   /**
-    * Get the minimum pool size
-    * 
-    * @return the minimum pool size
-    */
+
    int getMinPoolSize();
 
-   /**
-    * Set the minimum pool size
-    * 
-    * @param minPoolSize the size
-    */
    void setMinPoolSize(int minPoolSize);
 
-   /**
-    * Get the maximum pool size
-    * 
-    * @return the maximum pool size
-    */
    int getMaxPoolSize();
 
-   /**
-    * Set the maximum pool size
-    * 
-    * @param maxPoolSize the size
-    */
    void setMaxPoolSize(int maxPoolSize);
 
-   /**
-    * Get the keep alive millis
-    * 
-    * @return the milliseconds
-    */
    long getKeepAliveMillis();
 
-   /**
-    * Set the keep alive millis
-    * 
-    * @param keepAlive the milliseconds
-    */
    void setKeepAliveMillis(long keepAlive);
 
-   /**
-    * Get the maximum number of messages
-    * 
-    * @return the number of messages
-    */
    int getMaxMessages();
 
-   /**
-    * Set the maximum number of messages
-    * 
-    * @param maxMessages the number of messages
-    */
    void setMaxMessages(int maxMessages);
 
-   /**
-    * Get the message driven metadata
-    * 
-    * @return the metadata
-    */
-   MessageDrivenMetaData getMetaData();
+   org.jboss.metadata.MessageDrivenMetaData getMetaData();
 
-   /**
-    * Get whether delivery is active
-    * 
-    * @return true when active
-    */
    boolean getDeliveryActive();
 
-   /**
-    * Get whether JBossMQ destinations should be constructed
-    * when the destination is not in JNDI
-    * 
-    * @return true to create
-    */
    boolean getCreateJBossMQDestination();
 
-   /**
-    * Start delivery
-    * 
-    * @throws Exception for any error
-    */
-   void startDelivery() throws Exception;
+   void startDelivery() throws java.lang.Exception;
 
-   /**
-    * Stop delivery
-    * 
-    * @throws Exception for any error
-    */
-   void stopDelivery() throws Exception;
+   void stopDelivery() throws java.lang.Exception;
+   
+   boolean getLazyInitialization();
+   
+   void setLazyInitialization(boolean lazy);
+      
+   void setRecycleIdleSessions(boolean recycle);
+   
+   boolean getRecycleIdleSessions();
+   
+   long getIdleTimeOutMinutes();
+   
+   void setIdleTimeOutMinutes(long idleTimeout);
+   
+   int getSessionTimedOutCount();
+
+   int getCurrentSessionCount();
+  
+   int getCurrentSessionInUseCount();
+   
+   int getMaxSessionInUseCount();
+   
+   int getSessionErrorCount();
+   
+   int getSessionCreatedCount();
+   
+   int getSessionDestroyedCount();
+   
+   void setAlwaysReconnect(boolean alwaysReconnect);
+   
+   boolean getAlwaysReconnect();
+  
+   boolean getDestroySessionOnError();
+   
+   void setDestroySessionOnError(boolean destroy);
+   
+   String getExceptionSorterClassName();
+   
+   void setExceptionSorterClassName(String name);
+   
+   String getSupportCodeUrl();
+   
+   void setSupportCodeUrl(String supportCodeUrl);
+   
+   boolean getValidateLinkedException();
+   
+   void setValidateLinkedException(boolean vle);
+   
+   public void loadSupportCodeFile(String fileName);
+   
+   public void refreshSupportCodes();
+   
+   public String listCurrentSupportCodes();
+   
+   public void clearCurrentSupportCodes();
+   
+   public void addSupportCodes(String fileName);
+   
+   public String isCodeInUse(int code);
+   
+   
 }




More information about the jboss-cvs-commits mailing list