User: user57 Date: 01/07/20 21:18:28 Modified: src/main/org/jboss/jms/asf ServerSessionPoolFactory.java ServerSessionPoolLoader.java ServerSessionPoolLoaderMBean.java StdServerSession.java StdServerSessionPool.java StdServerSessionPoolFactory.java Log: o reformated and documented (mostly) o changed logging to Log4j o added a few more debug statements Revision Changes Path 1.2 +38 -12 jboss/src/main/org/jboss/jms/asf/ServerSessionPoolFactory.java Index: ServerSessionPoolFactory.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/jms/asf/ServerSessionPoolFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ServerSessionPoolFactory.java 2000/12/06 12:52:34 1.1 +++ ServerSessionPoolFactory.java 2001/07/21 04:18:28 1.2 @@ -21,21 +21,47 @@ import javax.jms.MessageListener; import javax.jms.ServerSessionPool; import javax.jms.JMSException; + /** - * ServerSessionPoolFactory.java - * + * Defines the model for creating <tt>ServerSessionPoolFactory</tt> objects. * - * Created: Wed Nov 29 15:55:21 2000 + * <p>Created: Wed Nov 29 15:55:21 2000 * - * @author - * @version + * @author <a href="mailto:[EMAIL PROTECTED]">Peter Antman</a>. + * @version $Revision: 1.2 $ */ +public interface ServerSessionPoolFactory +{ + /** + * Set the name of the factory. + * + * @param name The name of the factory. + */ + void setName(String name); -public interface ServerSessionPoolFactory { - - public void setName(String name); - public String getName(); - public ServerSessionPool getServerSessionPool(Connection con, int maxSession, boolean isTransacted, int ack, MessageListener listener)throws JMSException; + /** + * Get the name of the factory. + * + * @return The name of the factory. + */ + String getName(); - -} // ServerSessionPoolFactory + /** + * Create a new <tt>ServerSessionPool</tt>. + * + * @param con + * @param maxSession + * @param isTransacted + * @param ack + * @param listener + * @return A new pool. + * + * @throws JMSException + */ + ServerSessionPool getServerSessionPool(Connection con, + int maxSession, + boolean isTransacted, + int ack, + MessageListener listener) + throws JMSException; +} 1.3 +115 -70 jboss/src/main/org/jboss/jms/asf/ServerSessionPoolLoader.java Index: ServerSessionPoolLoader.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/jms/asf/ServerSessionPoolLoader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ServerSessionPoolLoader.java 2000/12/07 16:19:29 1.2 +++ ServerSessionPoolLoader.java 2001/07/21 04:18:28 1.3 @@ -19,6 +19,7 @@ import javax.management.ObjectName; import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; import javax.naming.Context; import javax.naming.Name; @@ -26,119 +27,163 @@ import javax.naming.NamingException; import javax.naming.NameNotFoundException; +import org.apache.log4j.Category; + import org.jboss.util.ServiceMBeanSupport; -import org.jboss.logging.Logger; /** - * ServerSessionPoolLoader.java - * + * A loader for <tt>ServerSessionPools</tt>. * - * Created: Wed Nov 29 16:14:46 2000 + * <p>Created: Wed Nov 29 16:14:46 2000 * - * @author - * @version + * @author <a href="mailto:[EMAIL PROTECTED]">Peter Antman</a>. + * @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a> + * @version $Revision: 1.3 $ */ - public class ServerSessionPoolLoader extends ServiceMBeanSupport implements ServerSessionPoolLoaderMBean { + /** Instance logger. */ + private final Category log = Category.getInstance(this.getClass()); + + /** 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; - - public void setPoolName(String name) + + /** + * Set the pool name. + * + * @param name The pool name. + */ + public void setPoolName(final String name) { this.name = name; } + /** + * Get the pool name. + * + * @return The pool name. + */ public String getPoolName() { return name; } - - public void setPoolFactoryClass(String clazz) - { - this.poolFactoryClass = clazz; + + /** + * Set the classname of pool factory to use. + * + * @param classname The name of the pool factory class. + */ + public void setPoolFactoryClass(final String classname) + { + this.poolFactoryClass = classname; } - + + /** + * Get the classname of pool factory to use. + * + * @return The name of the pool factory class. + */ public String getPoolFactoryClass() { return poolFactoryClass; } - - public ObjectName getObjectName(MBeanServer parm1, ObjectName parm2) - throws javax.management.MalformedObjectNameException - { - return (parm2 == null) ? new ObjectName(OBJECT_NAME) : parm2; - } + /** + * Get the JMX object name for this MBean. + * + * @param server The server which this bean is loaded. + * @param name The user specified name. + * + * @throws MalformedObjectNameException + */ + public ObjectName getObjectName(final MBeanServer server, + final ObjectName name) + throws MalformedObjectNameException + { + return (name == null) ? new ObjectName(OBJECT_NAME) : name; + } + + /** + * Get the name of this service. + * + * @return The pool name. + */ public String getName() { return name; } - - public void initService() - throws Exception + + /** + * Initialize the service. + * + * <p>Setup the pool factory. + * + * @throws ClassNotFoundException Could not find pool factory class. + * @throws Exception Failed to create pool factory instance. + */ + protected void initService() throws Exception { Class cls = Class.forName(poolFactoryClass); poolFactory = (ServerSessionPoolFactory)cls.newInstance(); poolFactory.setName(name); - } - - public void startService() - throws Exception - { - Context ctx = null; - Object mgr = null; - // Bind in JNDI - bind(new InitialContext(), "java:/"+poolFactory.getName(),poolFactory); + log.debug("initalized with pool factory: " + poolFactory); + } - log.log("JMS provider Adapter "+poolFactory.getName()+" bound to java:/"+poolFactory.getName()); + /** + * Start the service. + * + * <p>Bind the pool factory into JNDI. + * + * @throws Exception + */ + protected void startService() throws Exception + { + InitialContext ctx = new InitialContext(); + String name = poolFactory.getName(); + String jndiname = "java:/" + name; + try { + org.jboss.naming.Util.bind(ctx, jndiname, poolFactory); + log.info("pool factory " + name + " bound to " + jndiname); + } + finally { + ctx.close(); + } } - public void stopService() + /** + * Stop the service. + * + * <p>Unbind from JNDI. + */ + protected void stopService() { // Unbind from JNDI - try - { + InitialContext ctx = null; + try { + ctx = new InitialContext(); String name = poolFactory.getName(); - new InitialContext().unbind("java:/"+name); - log.log("JMA Provider Adapter "+name+" removed from JNDI"); - //source.close(); - //log.log("XA Connection pool "+name+" shut down"); - } catch (NamingException e) - { - // Ignore + String jndiname = "java:/" + name; + + ctx.unbind(jndiname); + log.info("pool factory " + name + " unbound from " + jndiname); } - } - - // Private ------------------------------------------------------- - - private void bind(Context ctx, String name, Object val) throws NamingException - { - // Bind val to name in ctx, and make sure that all intermediate contexts exist - Name n = ctx.getNameParser("").parse(name); - while (n.size() > 1) - { - String ctxName = n.get(0); - try - { - ctx = (Context)ctx.lookup(ctxName); - } catch (NameNotFoundException e) - { - ctx = ctx.createSubcontext(ctxName); + catch (NamingException ignore) {} + finally { + if (ctx != null) { + try { + ctx.close(); + } + catch (NamingException ignore) {} } - n = n.getSuffix(1); } - - ctx.bind(n.get(0), val); - } - - public static void main(String[] args) - { - } - -} // ServerSessionPoolLoader +} 1.3 +34 -14 jboss/src/main/org/jboss/jms/asf/ServerSessionPoolLoaderMBean.java Index: ServerSessionPoolLoaderMBean.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/jms/asf/ServerSessionPoolLoaderMBean.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ServerSessionPoolLoaderMBean.java 2000/12/07 16:19:29 1.2 +++ ServerSessionPoolLoaderMBean.java 2001/07/21 04:18:28 1.3 @@ -18,26 +18,46 @@ package org.jboss.jms.asf; import org.jboss.util.ServiceMBean; + /** - * ServerSessionPoolLoaderMBean.java - * + * The management interface for the <tt>ServerSessionPoolLoader</tt>. * - * Created: Wed Nov 29 16:20:17 2000 + * <p>Created: Wed Nov 29 16:20:17 2000 * - * @author - * @version + * @author <a href="mailto:[EMAIL PROTECTED]">Peter Antman</a>. + * @version $Revision: 1.3 $ */ - public interface ServerSessionPoolLoaderMBean extends ServiceMBean { - public static final String OBJECT_NAME = ":service=ServerSessionPoolMBean"; + /** The default MBean object name. */ + String OBJECT_NAME = ":service=ServerSessionPoolMBean"; + + /** + * Set the pool name. + * + * @param name The pool name. + */ + void setPoolName(String name); + + /** + * Get the pool name. + * + * @return The pool name. + */ + String getPoolName(); + + /** + * Set the classname of pool factory to use. + * + * @param classname The name of the pool factory class. + */ + void setPoolFactoryClass(String classname); - public void setPoolName(String name); - - public String getPoolName(); - - public void setPoolFactoryClass(String clazz); - - public String getPoolFactoryClass(); + /** + * Get the classname of pool factory to use. + * + * @return The name of the pool factory class. + */ + String getPoolFactoryClass(); } 1.6 +214 -174 jboss/src/main/org/jboss/jms/asf/StdServerSession.java Index: StdServerSession.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/jms/asf/StdServerSession.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- StdServerSession.java 2001/06/24 04:10:41 1.5 +++ StdServerSession.java 2001/07/21 04:18:28 1.6 @@ -17,12 +17,11 @@ */ package org.jboss.jms.asf; -import java.lang.Runnable; - import javax.jms.JMSException; import javax.jms.ServerSession; import javax.jms.Session; import javax.jms.XASession; + import javax.naming.InitialContext; import javax.transaction.Status; @@ -30,186 +29,227 @@ import javax.transaction.TransactionManager; import javax.transaction.xa.XAResource; -import org.jboss.logging.Logger; +import org.apache.log4j.Category; +import org.jboss.tm.TransactionManagerService; + /** - * StdServerSession.java - * + * An implementation of ServerSession. * - * Created: Thu Dec 7 18:25:40 2000 + * <p>Created: Thu Dec 7 18:25:40 2000 * - * @author - * @version + * @author <a href="mailto:[EMAIL PROTECTED]">Peter Antman</a>. + * @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a> + * @version $Revision: 1.6 $ */ - -public class StdServerSession implements Runnable, ServerSession { - private StdServerSessionPool serverSessionPool = null; - private Session session = null; - private XASession xaSession = null; - private TransactionManager tm; - - - StdServerSession(StdServerSessionPool pool, Session session, XASession xaSession) throws JMSException{ - - serverSessionPool = pool; - this.session = session; - this.xaSession = xaSession; +public class StdServerSession + implements Runnable, ServerSession +{ + /** Instance logger. */ + private final Category log = Category.getInstance(this.getClass()); + + /** The server session pool which we belong to. */ + private StdServerSessionPool serverSessionPool; // = null; + + /** Our session resource. */ + private Session session; // = null; + + /** Our XA session resource. */ + private XASession xaSession; // = null; + + /** The transaction manager that we will use for transactions. */ + private TransactionManager tm; + + /** + * 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. + * + * @throws JMSException Transation manager was not found. + */ + StdServerSession(final StdServerSessionPool pool, + final Session session, + final XASession xaSession) + throws JMSException + { + this.serverSessionPool = pool; + this.session = session; + this.xaSession = xaSession; + + if (log.isDebugEnabled()) { + log.debug("initializing (pool, session, xaSession): " + + pool + ", " + session + ", " + xaSession); + } + + InitialContext ctx = null; + try { + ctx = new InitialContext(); + 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) {} + } + } + } - try { - tm = (TransactionManager)new InitialContext().lookup("java:/TransactionManager"); - } catch ( Exception e ) { - throw new JMSException("Transation Manager was not found"); - } - - } - - // --- Impl of JMS standard API + // --- Impl of JMS standard API - /** - * Implementation of ServerSession.getSession - * - * 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. - */ - public Session getSession() - throws JMSException - { - return session; - } + /** + * Returns the session. + * + * <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. + */ + public Session getSession() throws JMSException + { + return session; + } + + /** + * Start the session and begin consuming messages. + * + * @throws JMSException No listener has been specified. + */ + public void start() throws JMSException { + log.debug("starting invokes on server session"); + + if (session != null) { + try { + serverSessionPool.getExecutor().execute(this); + } + catch (InterruptedException ignore) {} + } + else { + throw new JMSException("No listener has been specified"); + } + } - // implementation of ServerSession.start - public void start() throws JMSException { - //Logger.debug("Start invokes on server session"); - if (session != null) { - try { - serverSessionPool.getExecutor().execute(this); - } catch ( InterruptedException e ) { - } - } else { - throw new JMSException("No listener has been specified"); - } - } - - //--- Protected parts, used by other in the package + //--- Protected parts, used by other in the package - /** - * 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. - * - * HC: run() also starts a transaction with the TransactionManager and - * enlists the XAResource of the JMS XASession if a XASession was abvailable. - * 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 run() { - - Transaction trans=null; - - try { - - //Logger.debug("Invoking run on session"); - - //Logger.debug("Starting the Message Driven Bean transaction"); - tm.begin(); - trans = tm.getTransaction(); + /** + * 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. + * + * HC: run() also 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 run() { + log.debug("running..."); + + Transaction trans = null; + try { + tm.begin(); + trans = tm.getTransaction(); + + if (xaSession != null) { + XAResource res = xaSession.getXAResource(); + trans.enlistResource(res); + if (log.isDebugEnabled()) { + log.debug("XAResource '"+res+"' enlisted."); + } + } + + // run the session + session.run(); + } + catch (Exception e) { + log.error("session failed to run; setting rollback only", e); + + try { + // The transaction will be rolledback in the finally + trans.setRollbackOnly(); + } + catch (Exception x) { + log.error("failed to set rollback only", x); + } + } + finally { + try { + // Marked rollback + if (trans.getStatus() == Status.STATUS_MARKED_ROLLBACK) { + log.info("Rolling back JMS transaction"); + // actually roll it back + trans.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 + trans.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 (Exception e) { + log.error("failed to commit/rollback", e); + } - if( xaSession != null ) { - - XAResource res = xaSession.getXAResource(); - trans.enlistResource(res); - //Logger.debug("XAResource '"+res+"' enlisted."); - - } - - session.run(); - - }catch (Exception ex) { - - Logger.exception( ex ); - - try { - // The transaction will be rolledback in the finally - trans.setRollbackOnly(); - } catch( Exception e ) { - Logger.exception( e ); - } - - } finally { - - - try { - - //Logger.debug("Ending the Message Driven Bean transaction"); - - // Marked rollback - if ( trans.getStatus() == Status.STATUS_MARKED_ROLLBACK) { - Logger.log("Rolling back JMS transaction"); - // actually roll it back - trans.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 - - trans.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(Exception e) { - // There was a problem doing the commit/rollback. - Logger.exception(e); - } - - StdServerSession.this.recycle(); - } - } + StdServerSession.this.recycle(); + } + + log.debug("done"); + } - /** - * This method is called by the ServerSessionPool when it is ready to - * be recycled intot the pool - */ - void recycle() - { - serverSessionPool.recycle(this); - } - - /** - * Called by the ServerSessionPool when the sessions should be closed. - */ - void close() { - if (session != null) { - try { - session.close(); - }catch(Exception ex) {} - session = null; - } - if (xaSession != null) { - try { - xaSession.close(); - }catch(Exception ex) {} - xaSession = null; - } - } -} \ No newline at end of file + /** + * This method is called by the ServerSessionPool when it is ready to + * be recycled intot the pool + */ + void recycle() + { + serverSessionPool.recycle(this); + } + + /** + * Called by the ServerSessionPool when the sessions should be closed. + */ + void close() { + 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"); + } +} 1.9 +2 -3 jboss/src/main/org/jboss/jms/asf/StdServerSessionPool.java Index: StdServerSessionPool.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/jms/asf/StdServerSessionPool.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- StdServerSessionPool.java 2001/07/20 05:10:53 1.8 +++ StdServerSessionPool.java 2001/07/21 04:18:28 1.9 @@ -44,11 +44,10 @@ /** * Implementation of ServerSessionPool. * + * <p>Created: Thu Dec 7 17:02:03 2000 * - * Created: Thu Dec 7 17:02:03 2000 - * * @author <a href="mailto:[EMAIL PROTECTED]">Peter Antman</a>. - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ */ public class StdServerSessionPool implements ServerSessionPool 1.5 +7 -7 jboss/src/main/org/jboss/jms/asf/StdServerSessionPoolFactory.java Index: StdServerSessionPoolFactory.java =================================================================== RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/jms/asf/StdServerSessionPoolFactory.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- StdServerSessionPoolFactory.java 2001/07/21 02:04:57 1.4 +++ StdServerSessionPoolFactory.java 2001/07/21 04:18:28 1.5 @@ -25,12 +25,12 @@ import javax.jms.JMSException; /** - * StdServerSessionPoolFactory.java + * An implementation of ServerSessionPoolFactory. * - * Created: Fri Dec 22 09:47:41 2000 + * <p>Created: Fri Dec 22 09:47:41 2000 * * @author <a href="mailto:[EMAIL PROTECTED]">Peter Antman</a>. - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ */ public class StdServerSessionPoolFactory implements ServerSessionPoolFactory, Serializable @@ -75,11 +75,11 @@ * * @throws JMSException */ - public ServerSessionPool getServerSessionPool(Connection con, - int maxSession, - boolean isTransacted, - int ack, - MessageListener listener) + public ServerSessionPool getServerSessionPool(final Connection con, + final int maxSession, + final boolean isTransacted, + final int ack, + final MessageListener listener) throws JMSException { ServerSessionPool pool = (ServerSessionPool) _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-development