Package javax.jms

Examples of javax.jms.XAConnection


      userName = ((ConnectionRequest) cxRequest).getUserName();
      password = ((ConnectionRequest) cxRequest).getPassword();
      identityClass = ((ConnectionRequest) cxRequest).getIdentityClass();
    }

    XAConnection cnx = null;

    if (collocated) {
        hostName = "localhost";
        serverPort = -1;
    }
View Full Code Here


      userName = ((ConnectionRequest) cxRequest).getUserName();
      password = ((ConnectionRequest) cxRequest).getPassword();
      identityClass = ((ConnectionRequest) cxRequest).getIdentityClass();
    }

    XAConnection cnx = null;

    if (collocated) {
        hostName = "localhost";
        serverPort = -1;
    }
View Full Code Here

      password = ((ConnectionRequest) cxRequest).getPassword();
      identityClass = ((ConnectionRequest) cxRequest).getIdentityClass();
    }

    XAConnectionFactory factory;
    XAConnection cnx = null;

    if (collocated) {
      hostName = "localhost";
      serverPort = -1;
    }
View Full Code Here

      }

      // set identity class for this connectionFactory.
      cf.setIdentityClassName(identityClass);

      XAConnection cnx = cf.createXAConnection(userName, password);
     
      // set Exception listener
      cnx.setExceptionListener(this);
     
      if (logger.isLoggable(BasicLevel.DEBUG))
        logger.log(BasicLevel.DEBUG, this + " endpointActivation cnx = " + cnx);

      // Creating and registering a consumer instance for this endpoint.
View Full Code Here

      throw new IllegalStateException("Stopped resource adapter.");

    ActivationSpecImpl specImpl;
    String userName;
    ConnectionFactory cf = null;
    XAConnection connection;
    Vector resources = new Vector();

    if (connections == null)
      connections = new Hashtable();

    try {
      for (int i = 0; i < specs.length; i++) {
        if (! (specs[i] instanceof ActivationSpecImpl))
          throw new ResourceException("Provided ActivationSpec instance is not a JORAM activation spec.");

        specImpl = (ActivationSpecImpl) specs[i];

        if (! specImpl.getResourceAdapter().equals(this))
          throw new ResourceException("Supplied ActivationSpec instance associated to an other ResourceAdapter.");

        userName = specImpl.getUserName();

        // The connection does not already exist: creating it.
        if (! connections.containsKey(userName)) {
          String password = specImpl.getPassword();
          String identityClass = specImpl.getIdentityClass();

          if (isHa) {
            if (collocated) {
              if (logger.isLoggable(BasicLevel.DEBUG))
                logger.log(BasicLevel.DEBUG, "haURL = " + haURL);
              if (haURL != null) {
                cf = HATcpConnectionFactory.create(haURL);
              } else {
                cf = HALocalConnectionFactory.create();
              }
            } else {
              String urlHa = "hajoram://" + hostName + ":" + serverPort;
              cf = HATcpConnectionFactory.create(urlHa);
            }
          }  else {
            if (collocated)
              cf = LocalConnectionFactory.create();
            else
              cf = TcpConnectionFactory.create(hostName, serverPort);
          }

          cf.getParameters().connectingTimer = connectingTimer;
          cf.getParameters().cnxPendingTimer = cnxPendingTimer;
          cf.getParameters().txPendingTimer = txPendingTimer;

          // set identity class for this connectionFactory.
          cf.setIdentityClassName(identityClass);

          connection = cf.createXAConnection(userName, password);

          connections.put(userName, connection);

          resources.add(connection.createXASession().getXAResource());
        }
        if (logger.isLoggable(BasicLevel.DEBUG))
          logger.log(BasicLevel.DEBUG,
                     this + " getXAResources resources = " + resources);
      }
View Full Code Here

    */
   public void testComplexTransactionalRecoveryWithoutRestart() throws Exception
   {
      Connection conn1 = null;
     
      XAConnection conn2 = null;
     
      XAConnection conn3 = null;
     
      try
      {
         conn1 = cf.createConnection();
        
         Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         MessageProducer prod1 = sess1.createProducer(queueA);
        
         MessageProducer prod2 = sess1.createProducer(queueB);
        
         TextMessage tm1 = sess1.createTextMessage("tm1");
         TextMessage tm2 = sess1.createTextMessage("tm2");
         TextMessage tm3 = sess1.createTextMessage("tm3");
         TextMessage tm4 = sess1.createTextMessage("tm4");
         TextMessage tm5 = sess1.createTextMessage("tm5");
         TextMessage tm6 = sess1.createTextMessage("tm6");
         TextMessage tm7 = sess1.createTextMessage("tm7");
         TextMessage tm8 = sess1.createTextMessage("tm8");
        
         prod1.send(tm1);
         prod1.send(tm2);
         prod1.send(tm3);        
         prod1.send(tm4);
        
         prod2.send(tm5);
         prod2.send(tm6);
         prod2.send(tm7);
         prod2.send(tm8);
        
         conn1.close();
        
         conn2 = cf.createXAConnection();
        
         conn2.start();
        
         XASession sess2 = conn2.createXASession();
        
         XAResource res = sess2.getXAResource();
        
         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
        
         res.start(xid1, XAResource.TMNOFLAGS);
        
         MessageProducer prod3 = sess2.createProducer(queueA);
        
         TextMessage tm9 = sess2.createTextMessage("tm9");
         TextMessage tm10 = sess2.createTextMessage("tm10");
         TextMessage tm11 = sess2.createTextMessage("tm11");
         TextMessage tm12 = sess2.createTextMessage("tm12");
        
         prod3.send(tm9);
         prod3.send(tm10);
         prod3.send(tm11);
         prod3.send(tm12);
        
         MessageProducer prod4 = sess2.createProducer(queueB);
        
         TextMessage tm13 = sess2.createTextMessage("tm13");
         TextMessage tm14 = sess2.createTextMessage("tm14");
         TextMessage tm15 = sess2.createTextMessage("tm15");
         TextMessage tm16 = sess2.createTextMessage("tm16");
        
         prod4.send(tm13);
         prod4.send(tm14);
         prod4.send(tm15);
         prod4.send(tm16);
        
         MessageConsumer cons1 = sess2.createConsumer(queueA);
        
         TextMessage rm1 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm1);
         assertEquals(tm1.getText(), rm1.getText());
        
         TextMessage rm2 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm2);
         assertEquals(tm2.getText(), rm2.getText());
        
         TextMessage rm3 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm3);
         assertEquals(tm3.getText(), rm3.getText());
        
         TextMessage rm4 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm4);
         assertEquals(tm4.getText(), rm4.getText());
        
         Message m = cons1.receive(1000);
        
         assertNull(m);
                 
         MessageConsumer cons2 = sess2.createConsumer(queueB);
        
         TextMessage rm5 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm5);
         assertEquals(tm5.getText(), rm5.getText());
        
         TextMessage rm6 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm6);
         assertEquals(tm6.getText(), rm6.getText());
        
         TextMessage rm7 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm7);
         assertEquals(tm7.getText(), rm7.getText());
        
         TextMessage rm8 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm8);
         assertEquals(tm8.getText(), rm8.getText());
        
         m = cons2.receive(1000);
        
         assertNull(m);
        
         res.end(xid1, XAResource.TMSUCCESS);
        
         //prepare it
        
         log.trace("Preparing xid " + xid1);
         res.prepare(xid1);
         log.trace("Prepared xid " + xid1);
           
         conn3 = cf.createXAConnection();
        
         XASession sess3 = conn3.createXASession();
        
         XAResource res3 = sess3.getXAResource();
        
         Xid[] xids = res3.recover(XAResource.TMSTARTRSCAN);
         assertEquals(1, xids.length);
        
         Xid[] xids2 = res3.recover(XAResource.TMENDRSCAN);
         assertEquals(0, xids2.length);

         assertEquals(xid1, xids[0]);
        
         log.trace("Committing the tx");
        
         //Commit
         res3.commit(xids[0], false);
        
         log.trace("committed the tx");
        
         conn1.close();
        
         conn2.close();
        
         conn1 = cf.createConnection();
        
         conn1.start();
        
         sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         log.trace("creating a consumer");
        
         cons1 = sess1.createConsumer(queueA);
        
         log.trace("created a consumer");
        
         TextMessage rm9 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm9);
         assertEquals(tm9.getText(), rm9.getText());
        
         TextMessage rm10 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm10);
         assertEquals(tm10.getText(), rm10.getText());
        
         TextMessage rm11 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm11);
         assertEquals(tm11.getText(), rm11.getText());
        
         TextMessage rm12 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm12);
         assertEquals(tm12.getText(), rm12.getText());
        
         m = cons1.receive(1000);
        
         assertNull(m);
                 
         cons2 = sess1.createConsumer(queueB);
        
         TextMessage rm13 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm13);
         assertEquals(tm13.getText(), rm13.getText());
        
         TextMessage rm14 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm14);
         assertEquals(tm14.getText(), rm14.getText());
        
         TextMessage rm15 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm15);
         assertEquals(tm15.getText(), rm15.getText());
        
         TextMessage rm16 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm16);
         assertEquals(tm16.getText(), rm16.getText());
        
         m = cons2.receive(1000);
        
         assertNull(m);
        
         if (checkNoMessageData())
         {
            fail("Data remains in database");
         }
        
      }
      finally
      {
         if (conn1 != null)
         {
            conn1.close();
         }
        
         if (conn2 != null)
         {
            conn2.close();
         }
        
         if (conn3 != null)
         {
            conn3.close();
         }              
      }
   }
View Full Code Here

    */
   public void testComplexTransactionalRecoveryWithoutRestartRollback() throws Exception
   {
      Connection conn1 = null;
     
      XAConnection conn2 = null;
     
      XAConnection conn3 = null;
     
      try
      {
         conn1 = cf.createConnection();
        
         Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         MessageProducer prod1 = sess1.createProducer(queueA);
        
         MessageProducer prod2 = sess1.createProducer(queueB);
        
         TextMessage tm1 = sess1.createTextMessage("tm1");
         TextMessage tm2 = sess1.createTextMessage("tm2");
         TextMessage tm3 = sess1.createTextMessage("tm3");
         TextMessage tm4 = sess1.createTextMessage("tm4");
         TextMessage tm5 = sess1.createTextMessage("tm5");
         TextMessage tm6 = sess1.createTextMessage("tm6");
         TextMessage tm7 = sess1.createTextMessage("tm7");
         TextMessage tm8 = sess1.createTextMessage("tm8");
        
         prod1.send(tm1);
         prod1.send(tm2);
         prod1.send(tm3);        
         prod1.send(tm4);
        
         prod2.send(tm5);
         prod2.send(tm6);
         prod2.send(tm7);
         prod2.send(tm8);
        
         conn2 = cf.createXAConnection();
        
         conn2.start();
        
         XASession sess2 = conn2.createXASession();
        
         XAResource res = sess2.getXAResource();
        
         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
        
         res.start(xid1, XAResource.TMNOFLAGS);
        
         MessageProducer prod3 = sess2.createProducer(queueA);
        
         TextMessage tm9 = sess2.createTextMessage("tm9");
         TextMessage tm10 = sess2.createTextMessage("tm10");
         TextMessage tm11 = sess2.createTextMessage("tm11");
         TextMessage tm12 = sess2.createTextMessage("tm12");
        
         prod3.send(tm9);
         prod3.send(tm10);
         prod3.send(tm11);
         prod3.send(tm12);
        
         MessageProducer prod4 = sess2.createProducer(queueB);
        
         TextMessage tm13 = sess2.createTextMessage("tm13");
         TextMessage tm14 = sess2.createTextMessage("tm14");
         TextMessage tm15 = sess2.createTextMessage("tm15");
         TextMessage tm16 = sess2.createTextMessage("tm16");
        
         prod4.send(tm13);
         prod4.send(tm14);
         prod4.send(tm15);
         prod4.send(tm16);
        
         MessageConsumer cons1 = sess2.createConsumer(queueA);
        
         TextMessage rm1 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm1);
         assertEquals(tm1.getText(), rm1.getText());
        
         TextMessage rm2 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm2);
         assertEquals(tm2.getText(), rm2.getText());
        
         TextMessage rm3 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm3);
         assertEquals(tm3.getText(), rm3.getText());
        
         TextMessage rm4 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm4);
         assertEquals(tm4.getText(), rm4.getText());
        
         Message m = cons1.receive(1000);
        
         assertNull(m);
                 
         MessageConsumer cons2 = sess2.createConsumer(queueB);
        
         TextMessage rm5 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm5);
         assertEquals(tm5.getText(), rm5.getText());
        
         TextMessage rm6 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm6);
         assertEquals(tm6.getText(), rm6.getText());
        
         TextMessage rm7 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm7);
         assertEquals(tm7.getText(), rm7.getText());
        
         TextMessage rm8 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm8);
         assertEquals(tm8.getText(), rm8.getText());
        
         m = cons2.receive(1000);
        
         assertNull(m);
        
         res.end(xid1, XAResource.TMSUCCESS);
        
         //prepare it
        
         res.prepare(xid1);
                 
         conn3 = cf.createXAConnection();
        
         XASession sess3 = conn3.createXASession();
        
         XAResource res3 = sess3.getXAResource();
        
         Xid[] xids = res3.recover(XAResource.TMSTARTRSCAN);
         assertEquals(1, xids.length);
        
         Xid[] xids2 = res3.recover(XAResource.TMENDRSCAN);
         assertEquals(0, xids2.length);

         assertEquals(xid1, xids[0]);
        
         log.trace("rolling back the tx");
        
         //rollback
         res3.rollback(xids[0]);
        
         log.trace("rolledb back the tx");
        
         Thread.sleep(1000);
        
         conn1.close();
        
         conn2.close();
        
        
         conn1 = cf.createConnection();
        
         conn1.start();
        
         sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         log.trace("creating a consumer");
        
         cons1 = sess1.createConsumer(queueA);
        
         log.trace("created a consumer");
        
         TextMessage rm9 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm9);
         assertEquals(tm1.getText(), rm9.getText());
        
         TextMessage rm10 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm10);
         assertEquals(tm2.getText(), rm10.getText());
        
         TextMessage rm11 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm11);
         assertEquals(tm3.getText(), rm11.getText());
        
         TextMessage rm12 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm12);
         assertEquals(tm4.getText(), rm12.getText());
        
         m = cons1.receive(1000);
        
         assertNull(m);
                 
         cons2 = sess1.createConsumer(queueB);
        
         TextMessage rm13 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm13);
         assertEquals(tm5.getText(), rm13.getText());
        
         TextMessage rm14 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm14);
         assertEquals(tm6.getText(), rm14.getText());
        
         TextMessage rm15 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm15);
         assertEquals(tm7.getText(), rm15.getText());
        
         TextMessage rm16 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm16);
         assertEquals(tm8.getText(), rm16.getText());
        
         m = cons2.receive(1000);
        
         assertNull(m);
        
         if (checkNoMessageData())
         {
            fail("Data remains in database");
         }
        
      }
      finally
      {
         if (conn1 != null)
         {
            try
            {
               conn1.close();
            }
            catch (Exception e)
            {
               //Ignore
            }
         }
        
         if (conn2 != null)
         {
            try
            {
               conn2.close();
            }
            catch (Exception e)
            {
               //Ignore
            }
         }
        
         if (conn3 != null)
         {
            try
            {
               conn3.close();
            }
            catch (Exception e)
            {
               //Ignore
            }
View Full Code Here

    */
   public void testComplexTransactionalRecoveryWithRestart() throws Exception
   {
      Connection conn1 = null;
     
      XAConnection conn2 = null;
     
      XAConnection conn3 = null;
     
      try
      {
         conn1 = cf.createConnection();
        
         Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         MessageProducer prod1 = sess1.createProducer(queueA);
        
         MessageProducer prod2 = sess1.createProducer(queueB);
        
         TextMessage tm1 = sess1.createTextMessage("tm1");
         TextMessage tm2 = sess1.createTextMessage("tm2");
         TextMessage tm3 = sess1.createTextMessage("tm3");
         TextMessage tm4 = sess1.createTextMessage("tm4");
         TextMessage tm5 = sess1.createTextMessage("tm5");
         TextMessage tm6 = sess1.createTextMessage("tm6");
         TextMessage tm7 = sess1.createTextMessage("tm7");
         TextMessage tm8 = sess1.createTextMessage("tm8");
        
         prod1.send(tm1);
         prod1.send(tm2);
         prod1.send(tm3);        
         prod1.send(tm4);
        
         prod2.send(tm5);
         prod2.send(tm6);
         prod2.send(tm7);
         prod2.send(tm8);
        
         conn2 = cf.createXAConnection();
        
         conn2.start();
        
         XASession sess2 = conn2.createXASession();
        
         XAResource res = sess2.getXAResource();
        
         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
        
         res.start(xid1, XAResource.TMNOFLAGS);
        
         MessageProducer prod3 = sess2.createProducer(queueA);
        
         TextMessage tm9 = sess2.createTextMessage("tm9");
         TextMessage tm10 = sess2.createTextMessage("tm10");
         TextMessage tm11 = sess2.createTextMessage("tm11");
         TextMessage tm12 = sess2.createTextMessage("tm12");
        
         prod3.send(tm9);
         prod3.send(tm10);
         prod3.send(tm11);
         prod3.send(tm12);
        
         MessageProducer prod4 = sess2.createProducer(queueB);
        
         TextMessage tm13 = sess2.createTextMessage("tm13");
         TextMessage tm14 = sess2.createTextMessage("tm14");
         TextMessage tm15 = sess2.createTextMessage("tm15");
         TextMessage tm16 = sess2.createTextMessage("tm16");
        
         prod4.send(tm13);
         prod4.send(tm14);
         prod4.send(tm15);
         prod4.send(tm16);
        
         MessageConsumer cons1 = sess2.createConsumer(queueA);
        
         TextMessage rm1 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm1);
         assertEquals(tm1.getText(), rm1.getText());
        
         TextMessage rm2 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm2);
         assertEquals(tm2.getText(), rm2.getText());
        
         TextMessage rm3 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm3);
         assertEquals(tm3.getText(), rm3.getText());
        
         TextMessage rm4 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm4);
         assertEquals(tm4.getText(), rm4.getText());
        
         Message m = cons1.receive(1000);
        
         assertNull(m);
                 
         MessageConsumer cons2 = sess2.createConsumer(queueB);
        
         TextMessage rm5 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm5);
         assertEquals(tm5.getText(), rm5.getText());
        
         TextMessage rm6 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm6);
         assertEquals(tm6.getText(), rm6.getText());
        
         TextMessage rm7 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm7);
         assertEquals(tm7.getText(), rm7.getText());
        
         TextMessage rm8 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm8);
         assertEquals(tm8.getText(), rm8.getText());
        
         m = cons2.receive(1000);
        
         assertNull(m);
        
         res.end(xid1, XAResource.TMSUCCESS);
        
         //prepare it
        
         res.prepare(xid1);
        
         conn1 = null;
        
         conn2 = null;
        
         // Now "crash" the server

         ServerManagement.stopServerPeer();

         ServerManagement.startServerPeer();
        
         ServerManagement.deployQueue("QA");
        
         ServerManagement.deployQueue("QB");
                          
         conn3 = cf.createXAConnection();
        
         XASession sess3 = conn3.createXASession();
        
         XAResource res3 = sess3.getXAResource();
        
         Xid[] xids = res3.recover(XAResource.TMSTARTRSCAN);
         assertEquals(1, xids.length);
        
         Xid[] xids2 = res3.recover(XAResource.TMENDRSCAN);
         assertEquals(0, xids2.length);

         assertEquals(xid1, xids[0]);
        
         log.trace("Committing the tx");
        
         //Commit
         res3.commit(xids[0], false);
        
         log.trace("committed the tx");

         conn1 = cf.createConnection();
        
         conn1.start();
        
         sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         log.trace("creating a consumer");
        
         cons1 = sess1.createConsumer(queueA);
        
         log.trace("created a consumer");
        
         TextMessage rm9 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm9);
         assertEquals(tm9.getText(), rm9.getText());
        
         TextMessage rm10 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm10);
         assertEquals(tm10.getText(), rm10.getText());
        
         TextMessage rm11 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm11);
         assertEquals(tm11.getText(), rm11.getText());
        
         TextMessage rm12 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm12);
         assertEquals(tm12.getText(), rm12.getText());
        
         m = cons1.receive(1000);
        
         assertNull(m);
                 
         cons2 = sess1.createConsumer(queueB);
        
         TextMessage rm13 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm13);
         assertEquals(tm13.getText(), rm13.getText());
        
         TextMessage rm14 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm14);
         assertEquals(tm14.getText(), rm14.getText());
        
         TextMessage rm15 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm15);
         assertEquals(tm15.getText(), rm15.getText());
        
         TextMessage rm16 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm16);
         assertEquals(tm16.getText(), rm16.getText());
        
         m = cons2.receive(1000);
        
         assertNull(m);
        
         if (checkNoMessageData())
         {
            fail("Data remains in database");
         }
        
      }
      finally
      {
         if (conn1 != null)
         {
            try
            {
               conn1.close();
            }
            catch (Exception e)
            {
               //Ignore
            }
         }
        
         if (conn2 != null)
         {
            try
            {
               conn2.close();
            }
            catch (Exception e)
            {
               //Ignore
            }
         }
        
         if (conn3 != null)
         {
            try
            {
               conn3.close();
            }
            catch (Exception e)
            {
               //Ignore
            }
View Full Code Here

    */
   public void testComplexTransactionalRecoveryWithRestartRollback() throws Exception
   {
      Connection conn1 = null;
     
      XAConnection conn2 = null;
     
      XAConnection conn3 = null;
     
      try
      {
         conn1 = cf.createConnection();
        
         Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         MessageProducer prod1 = sess1.createProducer(queueA);
        
         MessageProducer prod2 = sess1.createProducer(queueB);
        
         TextMessage tm1 = sess1.createTextMessage("tm1");
         TextMessage tm2 = sess1.createTextMessage("tm2");
         TextMessage tm3 = sess1.createTextMessage("tm3");
         TextMessage tm4 = sess1.createTextMessage("tm4");
         TextMessage tm5 = sess1.createTextMessage("tm5");
         TextMessage tm6 = sess1.createTextMessage("tm6");
         TextMessage tm7 = sess1.createTextMessage("tm7");
         TextMessage tm8 = sess1.createTextMessage("tm8");
        
         prod1.send(tm1);
         prod1.send(tm2);
         prod1.send(tm3);        
         prod1.send(tm4);
        
         prod2.send(tm5);
         prod2.send(tm6);
         prod2.send(tm7);
         prod2.send(tm8);
        
         conn2 = cf.createXAConnection();
        
         conn2.start();
        
         XASession sess2 = conn2.createXASession();
        
         XAResource res = sess2.getXAResource();
        
         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
        
         res.start(xid1, XAResource.TMNOFLAGS);
        
         MessageProducer prod3 = sess2.createProducer(queueA);
        
         TextMessage tm9 = sess2.createTextMessage("tm9");
         TextMessage tm10 = sess2.createTextMessage("tm10");
         TextMessage tm11 = sess2.createTextMessage("tm11");
         TextMessage tm12 = sess2.createTextMessage("tm12");
        
         prod3.send(tm9);
         prod3.send(tm10);
         prod3.send(tm11);
         prod3.send(tm12);
        
         MessageProducer prod4 = sess2.createProducer(queueB);
        
         TextMessage tm13 = sess2.createTextMessage("tm13");
         TextMessage tm14 = sess2.createTextMessage("tm14");
         TextMessage tm15 = sess2.createTextMessage("tm15");
         TextMessage tm16 = sess2.createTextMessage("tm16");
        
         prod4.send(tm13);
         prod4.send(tm14);
         prod4.send(tm15);
         prod4.send(tm16);
        
         MessageConsumer cons1 = sess2.createConsumer(queueA);
        
         TextMessage rm1 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm1);
         assertEquals(tm1.getText(), rm1.getText());
        
         TextMessage rm2 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm2);
         assertEquals(tm2.getText(), rm2.getText());
        
         TextMessage rm3 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm3);
         assertEquals(tm3.getText(), rm3.getText());
        
         TextMessage rm4 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm4);
         assertEquals(tm4.getText(), rm4.getText());
        
         Message m = cons1.receive(1000);
        
         assertNull(m);
                 
         MessageConsumer cons2 = sess2.createConsumer(queueB);
        
         TextMessage rm5 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm5);
         assertEquals(tm5.getText(), rm5.getText());
        
         TextMessage rm6 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm6);
         assertEquals(tm6.getText(), rm6.getText());
        
         TextMessage rm7 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm7);
         assertEquals(tm7.getText(), rm7.getText());
        
         TextMessage rm8 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm8);
         assertEquals(tm8.getText(), rm8.getText());
        
         m = cons2.receive(1000);
        
         assertNull(m);
        
         res.end(xid1, XAResource.TMSUCCESS);
        
         //prepare it
        
         res.prepare(xid1);
        
         conn1 = null;
        
         conn2 = null;
        
         // Now "crash" the server

         ServerManagement.stopServerPeer();

         ServerManagement.startServerPeer();
        
         ServerManagement.deployQueue("QA");
        
         ServerManagement.deployQueue("QB");
                          
         conn3 = cf.createXAConnection();
        
         XASession sess3 = conn3.createXASession();
        
         XAResource res3 = sess3.getXAResource();
        
         Xid[] xids = res3.recover(XAResource.TMSTARTRSCAN);
         assertEquals(1, xids.length);
        
         Xid[] xids2 = res3.recover(XAResource.TMENDRSCAN);
         assertEquals(0, xids2.length);

         assertEquals(xid1, xids[0]);
        
         log.trace("rolling back the tx");
        
         //rollback
         res3.rollback(xids[0]);
        
         log.trace("rolled back the tx");
        
         Thread.sleep(1000);

         conn1 = cf.createConnection();
        
         conn1.start();
        
         sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         log.trace("creating a consumer");
        
         cons1 = sess1.createConsumer(queueA);
        
         log.trace("created a consumer");
        
         TextMessage rm9 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm9);
         assertEquals(tm1.getText(), rm9.getText());
        
         TextMessage rm10 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm10);
         assertEquals(tm2.getText(), rm10.getText());
        
         TextMessage rm11 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm11);
         assertEquals(tm3.getText(), rm11.getText());
        
         TextMessage rm12 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm12);
         assertEquals(tm4.getText(), rm12.getText());
        
         m = cons1.receive(1000);
        
         assertNull(m);
                 
         cons2 = sess1.createConsumer(queueB);
        
         TextMessage rm13 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm13);
         assertEquals(tm5.getText(), rm13.getText());
        
         TextMessage rm14 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm14);
         assertEquals(tm6.getText(), rm14.getText());
        
         TextMessage rm15 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm15);
         assertEquals(tm7.getText(), rm15.getText());
        
         TextMessage rm16 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm16);
         assertEquals(tm8.getText(), rm16.getText());
        
         m = cons2.receive(1000);
        
         assertNull(m);
        
         cons1.close();
        
         if (checkNoMessageData())
         {
            fail("Data remains in database");
         }
        
      }
      finally
      {
         if (conn1 != null)
         {
            try
            {
               conn1.close();
            }
            catch (Exception e)
            {
               //Ignore
            }
         }
        
         if (conn2 != null)
         {
            try
            {
               conn2.close();
            }
            catch (Exception e)
            {
               //Ignore
            }
         }
        
         if (conn3 != null)
         {
            try
            {
               conn3.close();
            }
            catch (Exception e)
            {
               //Ignore
            }
View Full Code Here

   /* Not really necessary - but it does no harm */
   public void testComplexTransactional() throws Exception
   {
      Connection conn1 = null;
     
      XAConnection conn2 = null;
     
      XAConnection conn3 = null;
     
      try
      {
         conn1 = cf.createConnection();
        
         Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         MessageProducer prod1 = sess1.createProducer(queueA);
        
         MessageProducer prod2 = sess1.createProducer(queueB);
        
         TextMessage tm1 = sess1.createTextMessage("tm1");
         TextMessage tm2 = sess1.createTextMessage("tm2");
         TextMessage tm3 = sess1.createTextMessage("tm3");
         TextMessage tm4 = sess1.createTextMessage("tm4");
         TextMessage tm5 = sess1.createTextMessage("tm5");
         TextMessage tm6 = sess1.createTextMessage("tm6");
         TextMessage tm7 = sess1.createTextMessage("tm7");
         TextMessage tm8 = sess1.createTextMessage("tm8");
        
         prod1.send(tm1);
         prod1.send(tm2);
         prod1.send(tm3);        
         prod1.send(tm4);
        
         prod2.send(tm5);
         prod2.send(tm6);
         prod2.send(tm7);
         prod2.send(tm8);
        
         conn2 = cf.createXAConnection();
        
         conn2.start();
        
         XASession sess2 = conn2.createXASession();
        
         XAResource res = sess2.getXAResource();
        
         Xid xid1 = new MessagingXid("bq1".getBytes(), 42, "eemeli".getBytes());
        
         res.start(xid1, XAResource.TMNOFLAGS);
        
         MessageProducer prod3 = sess2.createProducer(queueA);
        
         TextMessage tm9 = sess2.createTextMessage("tm9");
         TextMessage tm10 = sess2.createTextMessage("tm10");
         TextMessage tm11 = sess2.createTextMessage("tm11");
         TextMessage tm12 = sess2.createTextMessage("tm12");
        
         prod3.send(tm9);
         prod3.send(tm10);
         prod3.send(tm11);
         prod3.send(tm12);
        
         MessageProducer prod4 = sess2.createProducer(queueB);
        
         TextMessage tm13 = sess2.createTextMessage("tm13");
         TextMessage tm14 = sess2.createTextMessage("tm14");
         TextMessage tm15 = sess2.createTextMessage("tm15");
         TextMessage tm16 = sess2.createTextMessage("tm16");
        
         prod4.send(tm13);
         prod4.send(tm14);
         prod4.send(tm15);
         prod4.send(tm16);
        
         MessageConsumer cons1 = sess2.createConsumer(queueA);
        
         TextMessage rm1 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm1);
         assertEquals(tm1.getText(), rm1.getText());
        
         TextMessage rm2 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm2);
         assertEquals(tm2.getText(), rm2.getText());
        
         TextMessage rm3 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm3);
         assertEquals(tm3.getText(), rm3.getText());
        
         TextMessage rm4 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm4);
         assertEquals(tm4.getText(), rm4.getText());
        
         Message m = cons1.receive(1000);
        
         assertNull(m);
                 
         MessageConsumer cons2 = sess2.createConsumer(queueB);
        
         TextMessage rm5 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm5);
         assertEquals(tm5.getText(), rm5.getText());
        
         TextMessage rm6 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm6);
         assertEquals(tm6.getText(), rm6.getText());
        
         TextMessage rm7 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm7);
         assertEquals(tm7.getText(), rm7.getText());
        
         TextMessage rm8 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm8);
         assertEquals(tm8.getText(), rm8.getText());
        
         m = cons2.receive(1000);
        
         assertNull(m);
        
         res.end(xid1, XAResource.TMSUCCESS);
        
         //prepare it
        
         res.prepare(xid1);
        
         res.commit(xid1, false);
        
         conn1.close();
        
         conn2.close();
                 
        
        
         conn1 = cf.createConnection();
        
         conn1.start();
        
         sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         cons1 = sess1.createConsumer(queueA);
        
         TextMessage rm9 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm9);
         assertEquals(tm9.getText(), rm9.getText());
        
         TextMessage rm10 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm10);
         assertEquals(tm10.getText(), rm10.getText());
        
         TextMessage rm11 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm11);
         assertEquals(tm11.getText(), rm11.getText());
        
         TextMessage rm12 = (TextMessage)cons1.receive(1000);
         assertNotNull(rm12);
         assertEquals(tm12.getText(), rm12.getText());
        
         m = cons1.receive(1000);
        
         assertNull(m);
                 
         cons2 = sess1.createConsumer(queueB);
        
         TextMessage rm13 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm13);
         assertEquals(tm13.getText(), rm13.getText());
        
         TextMessage rm14 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm14);
         assertEquals(tm14.getText(), rm14.getText());
        
         TextMessage rm15 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm15);
         assertEquals(tm15.getText(), rm15.getText());
        
         TextMessage rm16 = (TextMessage)cons2.receive(1000);
         assertNotNull(rm16);
         assertEquals(tm16.getText(), rm16.getText());
        
         m = cons2.receive(1000);
        
         assertNull(m);
        
         if (checkNoMessageData())
         {
            fail("Data remains in database");
         }
        
      }
      finally
      {
         if (conn1 != null)
         {
            try
            {
               conn1.close();
            }
            catch (Exception e)
            {
               //Ignore
            }
         }
        
         if (conn2 != null)
         {
            try
            {
               conn2.close();
            }
            catch (Exception e)
            {
               //Ignore
            }
         }
        
         if (conn3 != null)
         {
            try
            {
               conn3.close();
            }
            catch (Exception e)
            {
               //Ignore
            }
View Full Code Here

TOP

Related Classes of javax.jms.XAConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.