User: starksm 
  Date: 01/07/08 18:06:04

  Modified:    src/main/org/jboss/test/jmsra/bean Tag: Branch_2_4
                        PublisherBean.java PublisherCMPBean.java
  Log:
  Merge latest changes from main to the 2.4 branch
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.1   +140 -79   jbosstest/src/main/org/jboss/test/jmsra/bean/PublisherBean.java
  
  Index: PublisherBean.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/jmsra/bean/PublisherBean.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- PublisherBean.java        2001/05/19 23:13:11     1.2
  +++ PublisherBean.java        2001/07/09 01:06:03     1.2.2.1
  @@ -1,3 +1,9 @@
  +/*
  + * JBoss, the OpenSource EJB server
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   package org.jboss.test.jmsra.bean;
   
   import java.rmi.RemoteException;
  @@ -8,105 +14,155 @@
   import javax.naming.*;
   import javax.jms.*;
   
  +import org.apache.log4j.Category;
   
  -public class PublisherBean implements SessionBean {
  -
  -    private static final String CONNECTION_JNDI = 
"java:comp/env/jms/MyQueueConnection";
  -    private static final String QUEUE_JNDI = "java:comp/env/jms/QueueName";
  -
  -    private static final String BEAN_JNDI = "java:comp/env/ejb/PublisherCMP";
  -
  -    private SessionContext ctx = null;
  -    private Queue queue = null;
  -    private QueueConnection queueConnection = null;
  +/**
  + * Bean to help JMS RA test publish/send JMS messages and test transactional
  + * behavior.
  + *
  + * <p>Created: Mon Apr 23 21:35:25 2001
  + *
  + * @author  Unknown
  + * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
  + * @version $Revision: 1.2.2.1 $
  + */
  +public class PublisherBean
  +    implements SessionBean
  +{
  +    private static final String CONNECTION_JNDI =
  +        "java:comp/env/jms/MyQueueConnection";
  +    
  +    private static final String QUEUE_JNDI =
  +        "java:comp/env/jms/QueueName";
  +
  +    private static final String BEAN_JNDI =
  +        "java:comp/env/ejb/PublisherCMP";
  +
  +    private final Category log = Category.getInstance(this.getClass());
  +   
  +    private SessionContext ctx; // = null;
  +    private Queue queue; // = null;
  +    private QueueConnection queueConnection; // = null;
  +    
       public PublisherBean() {
  +        // empty
       }
   
  -    public void setSessionContext(SessionContext ctx) {
  +    public void setSessionContext(final SessionContext ctx) {
           this.ctx = ctx;
       }
   
  -    public void ejbCreate()  {
  +    public void ejbCreate() {
           try {
               Context context = new InitialContext();
               queue = (Queue)context.lookup(QUEUE_JNDI);
   
  -        QueueConnectionFactory factory = 
(QueueConnectionFactory)context.lookup(CONNECTION_JNDI);
  -        queueConnection = factory.createQueueConnection();
  -    
  -        } catch (Exception ex) {
  +            QueueConnectionFactory factory =
  +                (QueueConnectionFactory)context.lookup(CONNECTION_JNDI);
  +            queueConnection = factory.createQueueConnection();
  +        }
  +        catch (Exception e) {
               // JMSException or NamingException could be thrown
  -            ex.printStackTrace();
  -        throw new EJBException(ex.toString());
  +            log.error("failed to create bean", e);
  +            throw new EJBException(e);
           }
       }
   
       /**
        * Send a message with a message nr in property MESSAGE_NR
        */
  -    public void simple(int messageNr)  {
  -    sendMessage(messageNr);
  +    public void simple(int messageNr) {
  +        log.info("sending message");
  +        sendMessage(messageNr);
  +        log.info("sent");
       }
  +    
       /**
        * Try send a message with a message nr in property MESSAGE_NR,
        * but set rollback only
        */
  -    public void simpleFail(int messageNr)  {
  -    sendMessage(messageNr);
  -    // Roll it back, no message should be sent if transactins work
  -    System.err.println("DEBUG: Setting rollbackOnly");
  -    ctx.setRollbackOnly();
  -    System.err.println("DEBUG rollback set: " + ctx.getRollbackOnly());
  -    
  +    public void simpleFail(int messageNr) {
  +        log.info("sending message");
  +        sendMessage(messageNr);
  +        log.info("sent");
  +        
  +        // Roll it back, no message should be sent if transactins work
  +        log.info("Setting rollbackOnly");
  +        ctx.setRollbackOnly();
  +        log.info("rollback set: " + ctx.getRollbackOnly());
       }
   
       public void beanOk(int messageNr) {
  -    // DO JMS - First transaction
  -    sendMessage(messageNr);
  -    PublisherCMPHome h = null;
  -    try {
  -        // DO entity bean - Second transaction
  -        h = (PublisherCMPHome) new InitialContext().lookup(BEAN_JNDI);
  -        PublisherCMP b = h.create(new Integer(messageNr));
  -        b.ok(messageNr);
  -    }catch(Exception ex) {
  -        throw new EJBException("OPS exception in ok: " + ex);
  -    } finally {
  +        log.info("sending message");        
  +        // DO JMS - First transaction
  +        sendMessage(messageNr);
  +        log.info("sent");
  +        
  +        PublisherCMPHome h = null;
           try {
  -        h.remove(new Integer(messageNr));
  -        }catch(Exception e) {
  -        e.printStackTrace();
  +            // DO entity bean - Second transaction
  +            h = (PublisherCMPHome) new InitialContext().lookup(BEAN_JNDI);
  +            PublisherCMP b = h.create(new Integer(messageNr));
  +            log.info("calling bean");                        
  +            b.ok(messageNr);
  +            log.info("called bean");
           }
  -    }
  -    
  +        catch (Exception e) {
  +            log.error("failed to contact 3rdparty bean", e);
  +            throw new EJBException(e);
  +        }
  +        finally {
  +            try {
  +                h.remove(new Integer(messageNr));
  +            }
  +            catch (Exception e) {
  +                log.error("failed to remove 3rdparty bean", e);
  +            }
  +            finally {
  +                log.info("done");
  +            }
  +        }
       }
   
       public void beanError(int messageNr) {
  -    // DO JMS - First transaction
  -    sendMessage(messageNr);
  -    PublisherCMPHome h = null;
  -    try {
  -        // DO entity bean - Second transaction
  -        h = (PublisherCMPHome) new InitialContext().lookup(BEAN_JNDI);
  -        PublisherCMP b = h.create(new Integer(messageNr));
  -        b.error(messageNr);
  -    } catch(Exception ex) {
  -        throw new EJBException("Exception in erro: " + ex);
  -    }finally {
  +        log.info("sending message");                
  +        // DO JMS - First transaction
  +        sendMessage(messageNr);
  +        log.info("sent");
  +        
  +        PublisherCMPHome h = null;
           try {
  -        h.remove(new Integer(messageNr));
  -        }catch(Exception ex) {
  -        ex.printStackTrace();
  +            // DO entity bean - Second transaction
  +            h = (PublisherCMPHome) new InitialContext().lookup(BEAN_JNDI);
  +            PublisherCMP b = h.create(new Integer(messageNr));
  +            log.info("calling bean");            
  +            b.error(messageNr);
  +            log.info("bean called (should never get here)");
           }
  -    }
  +        catch (Exception e) {
  +            log.info("caught exception (as expected)");
  +            throw new EJBException("Exception in erro: " + e);
  +        }
  +        finally {
  +            try {
  +                h.remove(new Integer(messageNr));
  +            }
  +            catch (Exception e) {
  +                log.error("failed to remove 3rdparty bean", e);
  +            }
  +            finally {
  +                log.info("done");
  +            }
  +        }
       }
   
       public void ejbRemove() throws RemoteException {
  -        if(queueConnection != null) {
  +        if (queueConnection != null) {
               try {
                   queueConnection.close();
  -            } catch (Exception e) {
  -                e.printStackTrace();
  +            }
  +            catch (Exception e) {
  +                log.error("failed to close connection", e);
               }
           }
       }
  @@ -115,32 +171,37 @@
       public void ejbPassivate() {}
   
       private void sendMessage(int messageNr) {
  -    QueueSession   queueSession = null;
  -    try {
  -        QueueSender queueSender = null;
  -        TextMessage    message = null;
  -    
  +        log.info("sending message wtih nr: " + messageNr);
  +        QueueSession queueSession = null;
  +        try {
  +            QueueSender queueSender = null;
  +            TextMessage message = null;
               queueSession =
  -                queueConnection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
  +                queueConnection.createQueueSession(true,
  +                                                   Session.AUTO_ACKNOWLEDGE);
               queueSender = queueSession.createSender(queue);
       
               message = queueSession.createTextMessage();
  -        message.setText(String.valueOf(messageNr));
  -        message.setIntProperty(Publisher.JMS_MESSAGE_NR, messageNr);
  -        queueSender.send(message);
  -    
  -    
  -        } catch (JMSException ex) {
  -    
  -            ex.printStackTrace();
  +            message.setText(String.valueOf(messageNr));
  +            message.setIntProperty(Publisher.JMS_MESSAGE_NR, messageNr);
  +            queueSender.send(message);
  +            log.info("sent message with nr = " + messageNr);
  +        }
  +        catch (JMSException e) {
  +            log.debug("failed to send", e);
               ctx.setRollbackOnly();
  -        throw new EJBException(ex.toString());
  -        } finally {
  +            throw new EJBException(e);
  +        }
  +        finally {
               if (queueSession != null) {
                   try {
                       queueSession.close();
  -                } catch (Exception e) {
  -                    e.printStackTrace();
  +                }
  +                catch (Exception e) {
  +                    log.error("failed to close session", e);
  +                }
  +                finally {
  +                    log.info("done sending message");
                   }
               }
           }
  
  
  
  1.2.2.1   +37 -33    
jbosstest/src/main/org/jboss/test/jmsra/bean/PublisherCMPBean.java
  
  Index: PublisherCMPBean.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/jmsra/bean/PublisherCMPBean.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- PublisherCMPBean.java     2001/05/19 23:13:11     1.2
  +++ PublisherCMPBean.java     2001/07/09 01:06:03     1.2.2.1
  @@ -17,59 +17,63 @@
    */
   package org.jboss.test.jmsra.bean;
   
  -
   import java.rmi.RemoteException;
   import javax.ejb.CreateException;
   import javax.ejb.EJBException;
   
   import org.jboss.test.util.ejb.EntitySupport;
  +
   /**
  - * PublisherCMPBean.java
  - *
  + * 3rdparty bean to help test JMS RA transactions.
    *
  - * Created: Tue Apr 24 22:32:41 2001
  + * <p>Created: Tue Apr 24 22:32:41 2001
    *
  - * @author
  - * @version
  + * @author  <a href="mailto:[EMAIL PROTECTED]";>Peter Antman</a>
  + * @author  <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
  + * @version $Revision: 1.2.2.1 $
    */
  -
  -public class PublisherCMPBean  extends EntitySupport {
  +public class PublisherCMPBean
  +    extends EntitySupport
  +{
       public Integer nr;
  +    
       public PublisherCMPBean() {
  +        // empty
  +    }
       
  +    public Integer getNr() {
  +        return nr;
       }
  -    public Integer getNr()
  -   {
  -      return nr;
  -   }
   
  -    public void setNr(Integer nr)
  -    {
  -    this.nr = nr;
  +    public void setNr(Integer nr) {
  +        this.nr = nr;
       }
   
       public void ok(int nr) {
  -    // Do nothing
  +        // Do nothing
       }
   
       public void error(int nr) {
  -    // Roll back throug an exception
  -    throw new EJBException("Roll back!");
  +        // Roll back throug an exception
  +        throw new EJBException("Roll back!");
       }
  +    
       // EntityBean implementation -------------------------------------
  -   public Integer ejbCreate(Integer nr)
  -      throws CreateException
  -   {
  -       this.nr = nr;
  -      return null;
  -   }
  -
  -   public void ejbPostCreate(Integer nr)
  -      throws CreateException
  -   {
  -   }
  -
  -   public void ejbLoad()
  -   {
  -   }
  +    
  +    public Integer ejbCreate(Integer nr)
  +        throws CreateException
  +    {
  +        this.nr = nr;
  +        return null;
  +    }
  +
  +    public void ejbPostCreate(Integer nr)
  +        throws CreateException
  +    {
  +    }
  +
  +    public void ejbLoad()
  +    {
  +    }
  +    
   } // PublisherCMPBean
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to