[jboss-cvs] JBossAS SVN: r65809 - trunk/server/src/main/org/jboss/jms/asf.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 3 17:20:57 EDT 2007


Author: reverbel
Date: 2007-10-03 17:20:57 -0400 (Wed, 03 Oct 2007)
New Revision: 65809

Removed:
   trunk/server/src/main/org/jboss/jms/asf/ServerSessionPoolFactory.java
   trunk/server/src/main/org/jboss/jms/asf/ServerSessionPoolLoader.java
   trunk/server/src/main/org/jboss/jms/asf/StdServerSession.java
   trunk/server/src/main/org/jboss/jms/asf/StdServerSessionPool.java
   trunk/server/src/main/org/jboss/jms/asf/StdServerSessionPoolFactory.java
Log:
JBAS-4517: Remove obsolete files that depend on the XidFactory, which will be soon removed from trunk.


Deleted: trunk/server/src/main/org/jboss/jms/asf/ServerSessionPoolFactory.java
===================================================================
--- trunk/server/src/main/org/jboss/jms/asf/ServerSessionPoolFactory.java	2007-10-03 21:13:36 UTC (rev 65808)
+++ trunk/server/src/main/org/jboss/jms/asf/ServerSessionPoolFactory.java	2007-10-03 21:20:57 UTC (rev 65809)
@@ -1,90 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.
- */
-package org.jboss.jms.asf;
-
-import javax.jms.Connection;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.MessageListener;
-import javax.jms.ServerSessionPool;
-import org.jboss.tm.XidFactoryMBean;
-
-/**
- * Defines the model for creating <tt>ServerSessionPoolFactory</tt> objects. <p>
- *
- * @author    <a href="mailto:peter.antman at tim.se">Peter Antman</a> .
- * @author    <a href="mailto:hiram.chirino at jboss.org">Hiram Chirino</a> .
- * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
- * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
- * @version   $Revision$
- */
-public interface ServerSessionPoolFactory
-{
-   /**
-    * Set the name of the factory.
-    *
-    * @param name  The name of the factory.
-    */
-   void setName(String name);
-
-   /**
-    * Get the name of the factory.
-    *
-    * @return   The name of the factory.
-    */
-   String getName();
-
-   /**
-    * The <code>setXidFactory</code> method supplies the XidFactory that 
-    * server sessions will use to get Xids to control local transactions.
-    *
-    * @param xidFactory a <code>XidFactoryMBean</code> value
-    */
-   void setXidFactory(XidFactoryMBean xidFactory);
-
-   /**
-    * The <code>getXidFactory</code> method returns the XidFactory that 
-    * server sessions will use to get xids..
-    *
-    * @return a <code>XidFactoryMBean</code> value
-    */
-   XidFactoryMBean getXidFactory();
-
-   /**
-    * Create a new <tt>ServerSessionPool</tt>.
-    * 
-    * @param destination the destination
-    * @param con the jms connection
-    * @param minSession the minimum number of sessions
-    * @param maxSession the maximum number of sessions
-    * @param keepAlive the time to keep sessions alive
-    * @param isTransacted whether the pool is transacted
-    * @param ack the acknowledegement method
-    * @param listener the listener
-    * @param useLocalTX whether to use local transactions
-    * @return A new pool.
-    * @throws JMSException for any error
-    */
-   ServerSessionPool getServerSessionPool(Destination destination, Connection con, int minSession, int maxSession,
-         long keepAlive, boolean isTransacted, int ack, boolean useLocalTX, MessageListener listener)
-         throws JMSException;
-}
\ No newline at end of file

Deleted: trunk/server/src/main/org/jboss/jms/asf/ServerSessionPoolLoader.java
===================================================================
--- trunk/server/src/main/org/jboss/jms/asf/ServerSessionPoolLoader.java	2007-10-03 21:13:36 UTC (rev 65808)
+++ trunk/server/src/main/org/jboss/jms/asf/ServerSessionPoolLoader.java	2007-10-03 21:20:57 UTC (rev 65809)
@@ -1,138 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.
- */
-package org.jboss.jms.asf;
-
-import javax.management.ObjectName;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-
-import org.jboss.util.naming.NonSerializableFactory;
-import org.jboss.system.ServiceMBeanSupport;
-import org.jboss.tm.XidFactoryMBean;
-
-/**
- * A loader for <tt>ServerSessionPools</tt>.
- *
- * @author <a href="mailto:peter.antman at tim.se">Peter Antman</a>.
- * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
- * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
- * @version $Revision$
- */
-public class ServerSessionPoolLoader extends ServiceMBeanSupport implements ServerSessionPoolLoaderMBean
-{
-   /** The factory used to create server session pools. */
-   private ServerSessionPoolFactory poolFactory;
-
-   /** The name of the pool. */
-   private String name;
-
-   /** The type of pool factory to use. */
-   private String poolFactoryClass;
-
-   private ObjectName xidFactory;
-
-   public void setPoolName(final String name)
-   {
-      this.name = name;
-   }
-
-   public String getPoolName()
-   {
-      return name;
-   }
-
-   public void setPoolFactoryClass(final String classname)
-   {
-      this.poolFactoryClass = classname;
-   }
-
-   public String getPoolFactoryClass()
-   {
-      return poolFactoryClass;
-   }
-
-   public ObjectName getXidFactory()
-   {
-      return xidFactory;
-   }
-
-   public void setXidFactory(final ObjectName xidFactory)
-   {
-      this.xidFactory = xidFactory;
-   }
-
-   protected void startService() throws Exception
-   {
-      XidFactoryMBean xidFactoryObj = (XidFactoryMBean) getServer().getAttribute(xidFactory, "Instance");
-
-      Class cls = Class.forName(poolFactoryClass);
-      poolFactory = (ServerSessionPoolFactory) cls.newInstance();
-      poolFactory.setName(name);
-      poolFactory.setXidFactory(xidFactoryObj);
-      log.debug("initialized with pool factory: " + poolFactory);
-
-      InitialContext ctx = new InitialContext();
-      String name = poolFactory.getName();
-      String jndiname = "java:/" + name;
-      try
-      {
-         NonSerializableFactory.rebind(ctx, jndiname, poolFactory);
-         log.debug("pool factory " + name + " bound to " + jndiname);
-      }
-      finally
-      {
-         ctx.close();
-      }
-   }
-
-   protected void stopService()
-   {
-      // Unbind from JNDI
-      InitialContext ctx = null;
-      try
-      {
-         ctx = new InitialContext();
-         String name = poolFactory.getName();
-         String jndiname = "java:/" + name;
-
-         ctx.unbind(jndiname);
-         NonSerializableFactory.unbind(jndiname);
-         log.debug("pool factory " + name + " unbound from " + jndiname);
-      }
-      catch (NamingException ignore)
-      {
-      }
-      finally
-      {
-         if (ctx != null)
-         {
-            try
-            {
-               ctx.close();
-            }
-            catch (NamingException ignore)
-            {
-            }
-         }
-      }
-   }
-}

Deleted: trunk/server/src/main/org/jboss/jms/asf/StdServerSession.java
===================================================================
--- trunk/server/src/main/org/jboss/jms/asf/StdServerSession.java	2007-10-03 21:13:36 UTC (rev 65808)
+++ trunk/server/src/main/org/jboss/jms/asf/StdServerSession.java	2007-10-03 21:20:57 UTC (rev 65809)
@@ -1,520 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.
-*/
-package org.jboss.jms.asf;
-
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.ServerSession;
-import javax.jms.Session;
-import javax.jms.XASession;
-import javax.naming.InitialContext;
-import javax.transaction.Status;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-import javax.transaction.xa.XAResource;
-import javax.transaction.xa.Xid;
-import org.jboss.logging.Logger;
-import org.jboss.tm.TransactionManagerService;
-import org.jboss.tm.XidFactoryMBean;
-
-/**
- * An implementation of ServerSession. <p>
- *
- * @author <a href="mailto:peter.antman at tim.se">Peter Antman</a> .
- * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
- * @author <a href="mailto:hiram.chirino at jboss.org">Hiram Chirino</a> .
- * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
- * @version $Revision$
- */
-public class StdServerSession implements Runnable, ServerSession, MessageListener
-{
-   /** Instance logger. */
-   static Logger log = Logger.getLogger(StdServerSession.class);
-
-   /** The server session pool which we belong to. */
-   private StdServerSessionPool serverSessionPool;
-
-   /** Our session resource. */
-   private Session session;
-
-   /** Our XA session resource. */
-   private XASession xaSession;
-
-   /** The transaction manager that we will use for transactions. */
-   private TransactionManager tm;
-
-   /**
-    * Use the session's XAResource directly if we have an JBossMQ XASession.
-    * this allows us to get around the TX timeout problem when you have
-    * extensive message processing.
-    */
-   private boolean useLocalTX;
-
-   /** The listener to delegate calls, to. In our case the container invoker. */
-   private MessageListener delegateListener;
-
-   private XidFactoryMBean xidFactory;
-
-   /**
-    * @deprecated 
-    * @todo these appeared in jboss-head where are they used?
-    */
-   public TransactionManager getTransactionManager()
-   {
-      return tm;
-   }
-
-   /**
-    * @deprecated 
-    * @todo these appeared in jboss-head where are they used?
-    */
-   public void setTransactionManager(TransactionManager transactionManager)
-   {
-      this.tm = transactionManager;
-   }
-
-   /**
-    * Create a <tt>StdServerSession</tt> .
-    *
-    * @param pool             The server session pool which we belong to.
-    * @param session          Our session resource.
-    * @param xaSession        Our XA session resource.
-    * @param delegateListener Listener to call when messages arrives.
-    * @param useLocalTX       Will this session be used in a global TX (we can optimize with 1 phase commit)
-    * @throws JMSException Transation manager was not found.
-    */
-   StdServerSession(final StdServerSessionPool pool,
-                    final Session session,
-                    final XASession xaSession,
-                    final MessageListener delegateListener,
-                    boolean useLocalTX,
-                    final XidFactoryMBean xidFactory,
-                    final TransactionManager tm)
-           throws JMSException
-   {
-      this.serverSessionPool = pool;
-      this.session = session;
-      this.xaSession = xaSession;
-      this.delegateListener = delegateListener;
-      if (xaSession == null)
-         useLocalTX = false;
-      this.useLocalTX = useLocalTX;
-      this.xidFactory = xidFactory;
-      this.tm = tm;
-
-      log.trace(this + " initializing (pool, session, xaSession, useLocalTX): " +
-                pool + ", " + session + ", " + xaSession + ", " + useLocalTX);
-
-      // Set out self as message listener
-      if (StdServerSessionPoolFactory.USE_OLD && xaSession != null)
-         xaSession.setMessageListener(this);
-      else
-         session.setMessageListener(this);
-
-      if (tm == null)
-      {
-         InitialContext ctx = null;
-         try
-         {
-            ctx = new InitialContext();
-            this.tm = (TransactionManager) ctx.lookup(TransactionManagerService.JNDI_NAME);
-         }
-         catch (Exception e)
-         {
-            throw new JMSException("Transation manager was not found");
-         }
-         finally
-         {
-            if (ctx != null)
-            {
-               try
-               {
-                  ctx.close();
-               }
-               catch (Exception ignore)
-               {
-               }
-            }
-         }
-      }
-   }
-
-   /**
-    * Returns the session. <p>
-    * <p/>
-    * This simply returns what it has fetched from the connection. It is up to
-    * the jms provider to typecast it and have a private API to stuff messages
-    * into it.
-    *
-    * @return The session.
-    * @throws JMSException Description of Exception
-    */
-   public Session getSession() throws JMSException
-   {
-      if (StdServerSessionPoolFactory.USE_OLD && xaSession != null)
-         return xaSession;
-      else
-         return session;
-   }
-
-   /**
-    * Runs in an own thread, basically calls the session.run(), it is up to the
-    * session to have been filled with messages and it will run against the
-    * listener set in StdServerSessionPool. When it has send all its messages it
-    * returns.
-    */
-   public void run()
-   {
-      boolean trace = log.isTraceEnabled();
-
-      TransactionDemarcation td = null;
-      if (StdServerSessionPoolFactory.USE_OLD == false)
-      {
-         td = createTransactionDemarcation();
-         if (td == null)
-            return;
-      }
-      try
-      {
-         if (trace)
-            log.trace(this + " running...");
-
-         if (StdServerSessionPoolFactory.USE_OLD && xaSession != null)
-            xaSession.run();
-         else
-            session.run();
-
-         if (trace)
-            log.trace(this + " run.");
-      }
-      catch (Throwable t)
-      {
-         log.error(this + " onMessage failed to run; setting rollback only", t);
-         if (td != null)
-            td.error();
-      }
-      finally
-      {
-         if (td != null)
-            td.end();
-
-         recycle();
-      }
-   }
-
-   /**
-    * Will get called from session for each message stuffed into it.
-    * <p/>
-    * Starts a transaction with the TransactionManager
-    * and enlists the XAResource of the JMS XASession if a XASession was
-    * available. A good JMS implementation should provide the XASession for use
-    * in the ASF. So we optimize for the case where we have an XASession. So,
-    * for the case where we do not have an XASession and the bean is not
-    * transacted, we have the unneeded overhead of creating a Transaction. I'm
-    * leaving it this way since it keeps the code simpler and that case should
-    * not be too common (JBossMQ provides XASessions).
-    */
-   public void onMessage(Message msg)
-   {
-      boolean trace = log.isTraceEnabled();
-
-      TransactionDemarcation td = null;
-      if (StdServerSessionPoolFactory.USE_OLD)
-      {
-         td = createTransactionDemarcation();
-         if (td == null)
-            return;
-      }
-      try
-      {
-         if (trace)
-            log.trace(this + " onMessage running (pool, session, xaSession, useLocalTX): " +
-                      ", " + session + ", " + xaSession + ", " + useLocalTX);
-
-         // Call delegate listener
-         delegateListener.onMessage(msg);
-
-         if (trace)
-            log.trace(this + " onMessage finished");
-      }
-      catch (Throwable t)
-      {
-         log.error(this + " onMessage failed to run; setting rollback only", t);
-         if (td != null)
-            td.error();
-      }
-      finally
-      {
-         if (td != null)
-            td.end();
-      }
-      if (trace)
-         log.trace(this + " onMessage done");
-   }
-
-   /**
-    * Start the session and begin consuming messages.
-    *
-    * @throws JMSException No listener has been specified.
-    */
-   public void start() throws JMSException
-   {
-      log.trace(this + " starting invokes on server session");
-
-      if (session != null)
-      {
-         try
-         {
-            serverSessionPool.getExecutor().execute(this);
-         }
-         catch (InterruptedException ignore)
-         {
-         }
-      }
-      else
-      {
-         throw new JMSException(this + " no listener has been specified");
-      }
-   }
-
-   /**
-    * Called by the ServerSessionPool when the sessions should be closed.
-    */
-   void close()
-   {
-      log.trace(this + " closing.");
-      
-      if (session != null)
-      {
-         try
-         {
-            session.close();
-         }
-         catch (Exception ignore)
-         {
-         }
-
-         session = null;
-      }
-
-      if (xaSession != null)
-      {
-         try
-         {
-            xaSession.close();
-         }
-         catch (Exception ignore)
-         {
-         }
-         xaSession = null;
-      }
-
-      log.debug("closed");
-   }
-
-   /**
-    * This method is called by the ServerSessionPool when it is ready to be
-    * recycled intot the pool
-    */
-   void recycle()
-   {
-      boolean trace = log.isTraceEnabled();
-      if (trace)
-         log.trace(this + " recycling");
-      serverSessionPool.recycle(this);
-      if (trace)
-         log.trace(this + " recycled");
-   }
-   
-   TransactionDemarcation createTransactionDemarcation()
-   {
-      try
-      {
-         return new TransactionDemarcation();
-      }
-      catch (Throwable t)
-      {
-         log.error(this + " error creating transaction demarcation ", t);
-         return null;
-      }
-   }
-   
-   private class TransactionDemarcation
-   {
-      boolean trace = log.isTraceEnabled();
-      
-      // Used if run with useLocalTX if true
-      Xid localXid = null;
-      boolean localRollbackFlag = false;
-      // Used if run with useLocalTX if false
-      Transaction trans = null;
-
-      public TransactionDemarcation() throws Throwable
-      {
-         if (useLocalTX)
-         {
-            // Use JBossMQ One Phase Commit to commit the TX
-            localXid = xidFactory.newXid();//new XidImpl();
-            XAResource res = xaSession.getXAResource();
-            res.start(localXid, XAResource.TMNOFLAGS);
-
-            if (trace)
-               log.trace(StdServerSession.this + " using optimized 1p commit to control TX. xid=" + localXid);
-         }
-         else
-         {
-
-            // Use the TM to control the TX
-            tm.begin();
-            try
-            {
-               trans = tm.getTransaction();
-
-               if (trace)
-                  log.trace(StdServerSession.this +  " using tx=" + trans);
-
-               if (xaSession != null)
-               {
-                  XAResource res = xaSession.getXAResource();
-                  if (!trans.enlistResource(res))
-                  {
-                     throw new JMSException("could not enlist resource");
-                  }
-                  if (trace)
-                     log.trace(StdServerSession.this + " XAResource '" + res + "' enlisted.");
-               }
-            }
-            catch (Throwable t)
-            {
-               try
-               {
-                  tm.rollback();
-               }
-               catch (Throwable ignored)
-               {
-                  log.trace(StdServerSession.this + " ignored error rolling back after failed enlist", ignored);
-               }
-               throw t;
-            }
-         }
-      }
-      
-      public void error()
-      {
-         if (useLocalTX)
-         {
-            // Use JBossMQ One Phase Commit to commit the TX
-            localRollbackFlag = true;
-         }
-         else
-         {
-            // Mark for tollback TX via TM
-            try
-            {
-               // The transaction will be rolledback in the finally
-               if (trace)
-                  log.trace(StdServerSession.this + " using TM to mark TX for rollback tx=" + trans);
-               trans.setRollbackOnly();
-            }
-            catch (Throwable t)
-            {
-               log.error(StdServerSession.this + " failed to set rollback only", t);
-            }
-         }
-      }
-      
-      public void end()
-      {
-         try
-         {
-            if (useLocalTX)
-            {
-               if (localRollbackFlag == true)
-               {
-                  if (trace)
-                     log.trace(StdServerSession.this + " using optimized 1p commit to rollback TX xid=" + localXid);
-
-                  XAResource res = xaSession.getXAResource();
-                  res.end(localXid, XAResource.TMSUCCESS);
-                  res.rollback(localXid);
-
-               }
-               else
-               {
-                  if (trace)
-                     log.trace(StdServerSession.this +  " using optimized 1p commit to commit TX xid=" + localXid);
-
-                  XAResource res = xaSession.getXAResource();
-                  res.end(localXid, XAResource.TMSUCCESS);
-                  res.commit(localXid, true);
-               }
-            }
-            else
-            {
-               // Use the TM to commit the Tx (assert the correct association) 
-               Transaction currentTx = tm.getTransaction();
-               if (trans.equals(currentTx) == false)
-                  throw new IllegalStateException("Wrong tx association: expected " + trans + " was " + currentTx);
-
-               // Marked rollback
-               if (trans.getStatus() == Status.STATUS_MARKED_ROLLBACK)
-               {
-                  if (trace)
-                     log.trace(StdServerSession.this + " rolling back JMS transaction tx=" + trans);
-                  // actually roll it back
-                  tm.rollback();
-
-                  // NO XASession? then manually rollback.
-                  // This is not so good but
-                  // it's the best we can do if we have no XASession.
-                  if (xaSession == null && serverSessionPool.isTransacted())
-                  {
-                     session.rollback();
-                  }
-               }
-               else if (trans.getStatus() == Status.STATUS_ACTIVE)
-               {
-                  // Commit tx
-                  // This will happen if
-                  // a) everything goes well
-                  // b) app. exception was thrown
-                  if (trace)
-                     log.trace(StdServerSession.this + " commiting the JMS transaction tx=" + trans);
-                  tm.commit();
-
-                  // NO XASession? then manually commit.  This is not so good but
-                  // it's the best we can do if we have no XASession.
-                  if (xaSession == null && serverSessionPool.isTransacted())
-                  {
-                     session.commit();
-                  }
-               }
-            }
-         }
-         catch (Throwable t)
-         {
-            log.error(StdServerSession.this + " failed to commit/rollback", t);
-         }
-      }
-   }
-}

Deleted: trunk/server/src/main/org/jboss/jms/asf/StdServerSessionPool.java
===================================================================
--- trunk/server/src/main/org/jboss/jms/asf/StdServerSessionPool.java	2007-10-03 21:13:36 UTC (rev 65808)
+++ trunk/server/src/main/org/jboss/jms/asf/StdServerSessionPool.java	2007-10-03 21:20:57 UTC (rev 65809)
@@ -1,413 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.
-*/
-package org.jboss.jms.asf;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.jms.Connection;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.MessageListener;
-import javax.jms.Queue;
-import javax.jms.QueueConnection;
-import javax.jms.ServerSession;
-import javax.jms.ServerSessionPool;
-import javax.jms.Session;
-import javax.jms.Topic;
-import javax.jms.TopicConnection;
-import javax.jms.XAQueueConnection;
-import javax.jms.XAQueueSession;
-import javax.jms.XASession;
-import javax.jms.XATopicConnection;
-import javax.jms.XATopicSession;
-import javax.transaction.TransactionManager;
-
-import org.jboss.logging.Logger;
-import org.jboss.tm.XidFactoryMBean;
-
-import EDU.oswego.cs.dl.util.concurrent.Executor;
-import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
-import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
-
-/**
- * Implementation of ServerSessionPool.
- *
- * @author    <a href="mailto:peter.antman at tim.se">Peter Antman</a> .
- * @author    <a href="mailto:hiram.chirino at jboss.org">Hiram Chirino</a> .
- * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
- * @version   $Revision$
- */
-public class StdServerSessionPool implements ServerSessionPool
-{
-   /** The thread group which session workers will run. */
-   private static ThreadGroup threadGroup = new ThreadGroup("ASF Session Pool Threads");
-
-   /** Instance logger. */
-   private final Logger log = Logger.getLogger(this.getClass());
-
-   /** The minimum size of the pool */
-   private int minSize;
-
-   /** The size of the pool. */
-   private int poolSize;
-
-   /** The message acknowledgment mode. */
-   private int ack;
-
-   /** Is the bean container managed? */
-   private boolean useLocalTX;
-
-   /** True if this is a transacted session. */
-   private boolean transacted;
-
-   /** The destination. */
-   private Destination destination;
-
-   /** The session connection. */
-   private Connection con;
-
-   /** The message listener for the session. */
-   private MessageListener listener;
-
-   /** The list of ServerSessions. */
-   private List sessionPool;
-
-   /** The executor for processing messages? */
-   private PooledExecutor executor;
-
-   /** Used to signal when the Pool is being closed down */
-   private boolean closing = false;
-
-   /** Used during close down to wait for all server sessions to be returned and closed. */
-   private int numServerSessions = 0;
-
-   private XidFactoryMBean xidFactory;
-
-   private TransactionManager tm;
-
-   /**
-    * Construct a <tt>StdServerSessionPool</tt> using the default pool size.
-    *
-    * @param destination the destination
-    * @param con connection to get sessions from
-    * @param transacted transaction mode when not XA (
-    * @param ack ackmode when not XA
-    * @param listener the listener the sessions will call
-    * @param minSession minumum number of sessions in the pool
-    * @param maxSession maximum number of sessions in the pool
-    * @param keepAlive the time to keep sessions alive
-    * @param xidFactory  the xid factory
-    * @param tm the transaction manager
-    * @exception JMSException    Description of Exception
-    */
-   public StdServerSessionPool(final Destination destination,
-                               final Connection con,
-                               final boolean transacted,
-                               final int ack,
-                               final boolean useLocalTX,
-                               final MessageListener listener,
-                               final int minSession,
-                               final int maxSession,
-                               final long keepAlive,
-                               final XidFactoryMBean xidFactory,
-                               final TransactionManager tm)
-      throws JMSException
-   {
-      this.destination = destination;
-      this.con = con;
-      this.ack = ack;
-      this.listener = listener;
-      this.transacted = transacted;
-      this.minSize = minSession;
-      this.poolSize = maxSession;
-      this.sessionPool = new ArrayList(maxSession);
-      this.useLocalTX = useLocalTX;
-      this.xidFactory = xidFactory;
-      this.tm = tm;
-      // setup the worker pool
-      executor = new MyPooledExecutor(poolSize);
-      executor.setMinimumPoolSize(minSize);
-      executor.setKeepAliveTime(keepAlive);
-      executor.waitWhenBlocked();
-      executor.setThreadFactory(new DefaultThreadFactory());
-
-      // finish initializing the session
-      create();
-      log.debug("Server Session pool set up");
-   }
-
-   /**
-    * Get a server session.
-    *
-    * @return               A server session.
-    * @throws JMSException  Failed to get a server session.
-    */
-   public ServerSession getServerSession() throws JMSException
-   {
-      if( log.isTraceEnabled() )
-         log.trace("getting a server session");
-      ServerSession session = null;
-
-      try
-      {
-         while (true)
-         {
-            synchronized (sessionPool)
-            {
-               if (closing)
-               {
-                  throw new JMSException("Cannot get session after pool has been closed down.");
-               }
-               else if (sessionPool.size() > 0)
-               {
-                  session = (ServerSession)sessionPool.remove(0);
-                  break;
-               }
-               else
-               {
-                  try
-                  {
-                     sessionPool.wait();
-                  }
-                  catch (InterruptedException ignore)
-                  {
-                  }
-               }
-            }
-         }
-      }
-      catch (Exception e)
-      {
-         throw new JMSException("Failed to get a server session: " + e);
-      }
-
-      if( log.isTraceEnabled() )
-         log.trace("using server session: " + session);
-      return session;
-   }
-
-   /**
-    * Clear the pool, clear out both threads and ServerSessions,
-    * connection.stop() should be run before this method.
-    */
-   public void clear()
-   {
-      synchronized (sessionPool)
-      {
-         // FIXME - is there a runaway condition here. What if a
-         // ServerSession are taken by a ConnecionConsumer? Should we set
-         // a flag somehow so that no ServerSessions are recycled and the
-         // ThreadPool won't leave any more threads out.
-         closing = true;
-
-         log.debug("Clearing " + sessionPool.size() + " from ServerSessionPool");
-
-         Iterator iter = sessionPool.iterator();
-         while (iter.hasNext())
-         {
-            StdServerSession ses = (StdServerSession)iter.next();
-            // Should we do anything to the server session?
-            ses.close();
-            numServerSessions--;
-         }
-
-         sessionPool.clear();
-         sessionPool.notifyAll();
-      }
-
-      //Must be outside synchronized block because of recycle method.
-      executor.shutdownAfterProcessingCurrentlyQueuedTasks();
-
-      //wait for all server sessions to be returned.
-      synchronized (sessionPool)
-      {
-         while (numServerSessions > 0)
-         {
-            try
-            {
-               sessionPool.wait();
-            }
-            catch (InterruptedException ignore)
-            {
-            }
-         }
-      }
-   }
-
-   /**
-    * Get the executor we are using.
-    *
-    * @return   The Executor value
-    */
-   Executor getExecutor()
-   {
-      return executor;
-   }
-
-   // --- Protected messages for StdServerSession to use
-
-   /**
-    * Returns true if this server session is transacted.
-    *
-    * @return   The Transacted value
-    */
-   boolean isTransacted()
-   {
-      return transacted;
-   }
-
-   /**
-    * Recycle a server session.
-    *
-    * @param session  Description of Parameter
-    */
-   void recycle(StdServerSession session)
-   {
-      synchronized (sessionPool)
-      {
-         if (closing)
-         {
-            session.close();
-            numServerSessions--;
-            if (numServerSessions == 0)
-            {
-               //notify clear thread.
-               sessionPool.notifyAll();
-            }
-         }
-         else
-         {
-            sessionPool.add(session);
-            sessionPool.notifyAll();
-            if( log.isTraceEnabled() )
-               log.trace("recycled server session: " + session);
-         }
-      }
-   }
-
-   private void create() throws JMSException
-   {
-      for (int index = 0; index < poolSize; index++)
-      {
-         // Here is the meat, that MUST follow the spec
-         Session ses = null;
-         XASession xaSes = null;
-
-         log.debug("initializing with connection: " + con);
-
-         if (destination instanceof Topic && con instanceof XATopicConnection)
-         {
-            xaSes = ((XATopicConnection)con).createXATopicSession();
-            ses = ((XATopicSession)xaSes).getTopicSession();
-         }
-         else if (destination instanceof Queue && con instanceof XAQueueConnection)
-         {
-            xaSes = ((XAQueueConnection)con).createXAQueueSession();
-            ses = ((XAQueueSession)xaSes).getQueueSession();
-         }
-         else if (destination instanceof Topic && con instanceof TopicConnection)
-         {
-            ses = ((TopicConnection)con).createTopicSession(transacted, ack);
-            log.warn("Using a non-XA TopicConnection.  " +
-                  "It will not be able to participate in a Global UOW");
-         }
-         else if (destination instanceof Queue && con instanceof QueueConnection)
-         {
-            ses = ((QueueConnection)con).createQueueSession(transacted, ack);
-            log.warn("Using a non-XA QueueConnection.  " +
-                  "It will not be able to participate in a Global UOW");
-         }
-         else
-         {
-            throw new JMSException("Connection was not reconizable: " + con + " for destination " + destination);
-         }
-
-         // 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, tm);
-
-         sessionPool.add(serverSession);
-         numServerSessions++;
-
-         log.debug("added server session to the pool: " + serverSession);
-      }
-   }
-
-   /**
-    * A pooled executor where the minimum pool size
-    * threads are kept alive
-    */
-   private static class MyPooledExecutor extends PooledExecutor
-   {
-      public MyPooledExecutor(int poolSize)
-      {
-         super(poolSize);
-      }
-      
-      protected Runnable getTask() throws InterruptedException
-      {
-         Runnable task = null;
-         while ((task = super.getTask()) == null && keepRunning());
-         return task;
-      }
-      
-      /**
-       * We keep running unless we are told to shutdown
-       * or there are more than minimumPoolSize_ threads in the pool
-       * 
-       * @return whether to keep running
-       */
-      protected synchronized boolean keepRunning()
-      {
-         if (shutdown_)
-            return false;
-         
-         return poolSize_ <= minimumPoolSize_;
-      }
-   }
-
-   private static class DefaultThreadFactory implements ThreadFactory
-   {
-      private static int count = 0;
-      private static synchronized int nextCount()
-      {
-         return count ++;
-      }
-
-      /**
-       * Create a new Thread for the given Runnable
-       *
-       * @param command The Runnable to pass to Thread
-       * @return The newly created Thread
-       */
-      public Thread newThread(final Runnable command)
-      {
-         String name = "JMS SessionPool Worker-" + nextCount();
-         Thread thread = new Thread(threadGroup, command, name);
-         thread.setDaemon(true);
-         return thread;
-      }
-   }
-}

Deleted: trunk/server/src/main/org/jboss/jms/asf/StdServerSessionPoolFactory.java
===================================================================
--- trunk/server/src/main/org/jboss/jms/asf/StdServerSessionPoolFactory.java	2007-10-03 21:13:36 UTC (rev 65808)
+++ trunk/server/src/main/org/jboss/jms/asf/StdServerSessionPoolFactory.java	2007-10-03 21:20:57 UTC (rev 65809)
@@ -1,109 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.
-*/
-package org.jboss.jms.asf;
-
-import java.io.Serializable;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-import javax.jms.Connection;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.MessageListener;
-import javax.jms.ServerSessionPool;
-import javax.transaction.TransactionManager;
-
-import org.jboss.tm.XidFactoryMBean;
-
-/**
- * An implementation of ServerSessionPoolFactory. 
- *
- * @author    <a href="mailto:peter.antman at tim.se">Peter Antman</a> .
- * @author    <a href="mailto:hiram.chirino at jboss.org">Hiram Chirino</a> .
- * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
- * @version   $Revision$
- */
-public class StdServerSessionPoolFactory implements ServerSessionPoolFactory, Serializable
-{
-   private static final long serialVersionUID = 4969432475779524576L;
-
-   public static final boolean USE_OLD;
-   
-   static
-   {
-      USE_OLD = ((Boolean) AccessController.doPrivileged(new PrivilegedAction()
-      {
-         public Object run()
-         {
-            return new Boolean(System.getProperty("org.jboss.jms.asf.useold", "false"));
-         }
-      })).booleanValue();
-   }
-   
-   /** The name of this factory. */
-   private String name;
-
-   private XidFactoryMBean xidFactory;
-
-   private TransactionManager transactionManager;
-
-   public StdServerSessionPoolFactory()
-   {
-      super();
-   }
-
-   public void setName(final String name)
-   {
-      this.name = name;
-   }
-
-   public String getName()
-   {
-      return name;
-   }
-
-   public void setXidFactory(final XidFactoryMBean xidFactory)
-   {
-      this.xidFactory = xidFactory;
-   }
-
-   public XidFactoryMBean getXidFactory()
-   {
-      return xidFactory;
-   }
-
-   public void setTransactionManager(TransactionManager transactionManager)
-   {
-      this.transactionManager = transactionManager;
-   }
-
-   public TransactionManager getTransactionManager()
-   {
-      return transactionManager;
-   }
-
-   public ServerSessionPool getServerSessionPool(Destination destination, Connection con, int minSession, int maxSession, long keepAlive, boolean isTransacted, int ack, boolean useLocalTX, MessageListener listener) throws JMSException
-   {
-      ServerSessionPool pool = new StdServerSessionPool(destination, con, isTransacted, ack, useLocalTX, listener, minSession, maxSession, keepAlive, xidFactory, transactionManager);
-      return pool;
-   }
-}




More information about the jboss-cvs-commits mailing list