Package org.jboss.jms.tx

Examples of org.jboss.jms.tx.ResourceManager


         ClientConnectionDelegate del = (ClientConnectionDelegate)jbConn.getDelegate();

         ConnectionState state = (ConnectionState)del.getState();

         ResourceManager rm = state.getResourceManager();

         XASession xaSession = xaConn.createXASession();

         xaConn.start();

         XAResource res = xaSession.getXAResource();

         XAResource dummy = new DummyXAResource();

         for (int i = 0; i < 100; i++)
         {
            tm.begin();

            Transaction tx = tm.getTransaction();

            tx.enlistResource(res);

            tx.enlistResource(dummy);

            assertEquals(1, rm.size());

            tx.delistResource(res, XAResource.TMSUCCESS);

            tx.delistResource(dummy, XAResource.TMSUCCESS);

            tm.commit();
         }

         assertEquals(1, rm.size());

         xaConn.close();

         xaConn = null;

         assertEquals(0, rm.size());

      }
      finally
      {
         if (xaConn != null)
View Full Code Here


         ClientConnectionDelegate del = (ClientConnectionDelegate)jbConn.getDelegate();

         ConnectionState state = (ConnectionState)del.getState();

         ResourceManager rm = state.getResourceManager();

         XASession xaSession = xaConn.createXASession();

         xaConn.start();

         XAResource res = xaSession.getXAResource();

         XAResource dummy = new DummyXAResource();

         for (int i = 0; i < 100; i++)
         {
            tm.begin();

            Transaction tx = tm.getTransaction();

            tx.enlistResource(res);

            tx.enlistResource(dummy);

            assertEquals(1, rm.size());

            tx.delistResource(res, XAResource.TMSUCCESS);

            tx.delistResource(dummy, XAResource.TMSUCCESS);

            tm.rollback();
         }

         assertEquals(1, rm.size());

         xaConn.close();

         xaConn = null;

         assertEquals(0, rm.size());

      }
      finally
      {
         if (xaConn != null)
View Full Code Here

      {
         if (trace) { log.trace("Session is XA"); }
        
         ConnectionState connState = (ConnectionState)state.getParent();
        
         ResourceManager rm = connState.getResourceManager();
        
         // An XASession should never be closed if there is prepared ack work that has not yet been
         // committed or rolled back. Imagine if messages had been consumed in the session, and
         // prepared but not committed. Then the connection was explicitly closed causing the
         // session to close. Closing the session causes any outstanding delivered but unacked
         // messages to be cancelled to the server which means they would be available for other
         // consumers to consume. If another consumer then consumes them, then recover() is called
         // and the original transaction is committed, then this means the same message has been
         // delivered twice which breaks the once and only once delivery guarantee.
        
         if (rm.checkForAcksInSession(state.getSessionID()))
         {
            throw new IllegalStateException(
               "Attempt to close an XASession when there are still uncommitted acknowledgements!");
         }       
      }
           
      int ackMode = state.getAcknowledgeMode();
 
      //We need to either ack (for auto_ack) or cancel (for client_ack)
      //any deliveries - this is because the message listener might have closed
      //before on message had finished executing
     
      if (ackMode == Session.AUTO_ACKNOWLEDGE || isXAAndConsideredNonTransacted(state))
      {
         //Acknowledge or cancel any outstanding auto ack
       
         DeliveryInfo remainingAutoAck = state.getAutoAckInfo();
        
         if (remainingAutoAck != null)
         {
            if (trace) { log.trace(this + " handleClosing(). Found remaining auto ack. Will ack " + remainingAutoAck); }
           
            try
            {
               ackDelivery(del, remainingAutoAck);
              
               if (trace) { log.trace(this + " acked it"); }              
            }
            finally
            {                       
               state.setAutoAckInfo(null);
            }
         }
      }
      else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
      {
         //Ack any remaining deliveries
                         
         if (!state.getClientAckList().isEmpty())
         {              
            try
            {
               acknowledgeDeliveries(del, state.getClientAckList());
            }
            finally
            {           
               state.getClientAckList().clear();
              
               state.setAutoAckInfo(null);
            }
         }
      }
      else if (ackMode == Session.CLIENT_ACKNOWLEDGE)
      {
         // Cancel any oustanding deliveries
         // We cancel any client ack or transactional, we do this explicitly so we can pass the
         // updated delivery count information from client to server. We could just do this on the
         // server but we would lose delivery count info.
                 
         // CLIENT_ACKNOWLEDGE cannot be used with MDBs (i.e. no connection consumer)
         // so is always safe to cancel on this session                 
        
         cancelDeliveries(del, state.getClientAckList());
        
         state.getClientAckList().clear();
      }
      else if (state.isTransacted() && !state.isXA())
      {
         //We need to explicitly cancel any deliveries back to the server
         //from the resource manager, otherwise delivery count won't be updated
        
         ConnectionState connState = (ConnectionState)state.getParent();
        
         ResourceManager rm = connState.getResourceManager();
        
         List dels = rm.getDeliveriesForSession(state.getSessionID());
        
         cancelDeliveries(del, dels);       
      }

      return invocation.invokeNext();
View Full Code Here

         {
            throw new TransactionInProgressException("Cannot call rollback on an XA session");
         }
        
         ConnectionState connState = (ConnectionState)state.getParent();
         ResourceManager rm = connState.getResourceManager();
         try
         {
            rm.rollbackLocal((LocalTx)state.getCurrentTxId());
         }
         finally
         {
            // start new local tx
            Object xid = rm.createLocalTx();
            state.setCurrentTxId(xid);
         }
  
         return null;
      }
View Full Code Here

            log.trace(this + " synchronized failover browser " + browserDelegate);
         }
      }

      ConnectionState connState = (ConnectionState)getParent();
      ResourceManager rm = connState.getResourceManager();

      // We need to failover from one session ID to another in the resource manager
      rm.handleFailover(connState.getServerID(), oldSessionID, newState.sessionID);

      List ackInfos = Collections.EMPTY_LIST;

      if (!isTransacted() || (isXA() && getCurrentTxId() == null))
      {
         // TODO - the check "(isXA() && getCurrentTxId() == null)" shouldn't be necessary any more
         // since xa sessions no longer fall back to non transacted
        
         // Non transacted session or an XA session with no transaction set (it falls back
         // to AUTO_ACKNOWLEDGE)

         log.trace(this + " is not transacted (or XA with no transaction set), " +
                   "retrieving deliveries from session state");

         // We remove any unacked non-persistent messages - this is because we don't want to ack
         // them since the server won't know about them and will get confused

         if (acknowledgeMode == Session.CLIENT_ACKNOWLEDGE)
         {
            for(Iterator i = getClientAckList().iterator(); i.hasNext(); )
            {
               DeliveryInfo info = (DeliveryInfo)i.next();
               if (!info.getMessageProxy().getMessage().isReliable())
               {
                  i.remove();
                  log.trace("removed non persistent delivery " + info);
               }
            }

            ackInfos = getClientAckList();
         }
         else
         {
            DeliveryInfo autoAck = getAutoAckInfo();
            if (autoAck != null)
            {
               if (!autoAck.getMessageProxy().getMessage().isReliable())
               {
                  // unreliable, discard
                  setAutoAckInfo(null);
               }
               else
               {
                  // reliable
                  ackInfos = new ArrayList();
                  ackInfos.add(autoAck);
               }
            }
         }

         log.trace(this + " retrieved " + ackInfos.size() + " deliveries");
      }
      else
      {
         // Transacted session - we need to get the acks from the resource manager. BTW we have
         // kept the old resource manager.

         ackInfos = rm.getDeliveriesForSession(getSessionID());
      }

      List recoveryInfos = new ArrayList();
      if (!ackInfos.isEmpty())
      {        
View Full Code Here

            log.trace(this + " synchronized failover browser " + browserDelegate);
         }
      }

      ConnectionState connState = (ConnectionState)getParent();
      ResourceManager rm = connState.getResourceManager();

      // We need to failover from one session ID to another in the resource manager
      rm.handleFailover(connState.getServerID(), oldSessionID, newState.sessionID);

      List ackInfos = Collections.EMPTY_LIST;

      if (!isTransacted() || (isXA() && getCurrentTxId() == null))
      {
         // TODO - the check "(isXA() && getCurrentTxId() == null)" shouldn't be necessary any more
         // since xa sessions no longer fall back to non transacted
        
         // Non transacted session or an XA session with no transaction set (it falls back
         // to AUTO_ACKNOWLEDGE)

         log.trace(this + " is not transacted (or XA with no transaction set), " +
                   "retrieving deliveries from session state");

         // We remove any unacked non-persistent messages - this is because we don't want to ack
         // them since the server won't know about them and will get confused

         if (acknowledgeMode == Session.CLIENT_ACKNOWLEDGE)
         {
            for(Iterator i = getClientAckList().iterator(); i.hasNext(); )
            {
               DeliveryInfo info = (DeliveryInfo)i.next();
               if (!info.getMessageProxy().getMessage().isReliable())
               {
                  i.remove();
                  log.trace("removed non persistent delivery " + info);
               }
            }

            ackInfos = getClientAckList();
         }
         else
         {
            DeliveryInfo autoAck = getAutoAckInfo();
            if (autoAck != null)
            {
               if (!autoAck.getMessageProxy().getMessage().isReliable())
               {
                  // unreliable, discard
                  setAutoAckInfo(null);
               }
               else
               {
                  // reliable
                  ackInfos = new ArrayList();
                  ackInfos.add(autoAck);
               }
            }
         }

         log.trace(this + " retrieved " + ackInfos.size() + " deliveries");
      }
      else
      {
         // Transacted session - we need to get the acks from the resource manager. BTW we have
         // kept the old resource manager.

         ackInfos = rm.getDeliveriesForSession(getSessionID());
      }

      List recoveryInfos = new ArrayList();
      if (!ackInfos.isEmpty())
      {        
View Full Code Here

           
      ClientConnectionDelegate del1 = (ClientConnectionDelegate)((JBossConnection)conn1).getDelegate();
     
      ConnectionState state1 = (ConnectionState)del1.getState();
     
      ResourceManager rm1 = state1.getResourceManager();
     
      Connection conn2 = cf.createConnection();     
     
      ClientConnectionDelegate del2 = (ClientConnectionDelegate)((JBossConnection)conn2).getDelegate();
     
      ConnectionState state2 = (ConnectionState)del2.getState();
     
      ResourceManager rm2 = state2.getResourceManager();

      //Two connections for same server should share the same resource manager
     
      assertTrue(rm1 == rm2);
     
View Full Code Here

      {
         if (trace) { log.trace("Session is XA"); }
        
         ConnectionState connState = (ConnectionState)state.getParent();
        
         ResourceManager rm = connState.getResourceManager();
        
         // An XASession should never be closed if there is prepared ack work that has not yet been
         // committed or rolled back. Imagine if messages had been consumed in the session, and
         // prepared but not committed. Then the connection was explicitly closed causing the
         // session to close. Closing the session causes any outstanding delivered but unacked
         // messages to be cancelled to the server which means they would be available for other
         // consumers to consume. If another consumer then consumes them, then recover() is called
         // and the original transaction is committed, then this means the same message has been
         // delivered twice which breaks the once and only once delivery guarantee.
        
         if (rm.checkForAcksInSession(state.getSessionID()))
         {
            throw new IllegalStateException(
               "Attempt to close an XASession when there are still uncommitted acknowledgements!");
         }       
      }
           
      int ackMode = state.getAcknowledgeMode();
 
      //We need to either ack (for auto_ack) or cancel (for client_ack)
      //any deliveries - this is because the message listener might have closed
      //before on message had finished executing
     
      if (ackMode == Session.AUTO_ACKNOWLEDGE || isXAAndConsideredNonTransacted(state))
      {
         //Acknowledge or cancel any outstanding auto ack
       
         DeliveryInfo remainingAutoAck = state.getAutoAckInfo();
        
         if (remainingAutoAck != null)
         {
            if (trace) { log.trace(this + " handleClosing(). Found remaining auto ack. Will ack " + remainingAutoAck); }
           
            try
            {
               ackDelivery(del, remainingAutoAck);
              
               if (trace) { log.trace(this + " acked it"); }              
            }
            finally
            {                       
               state.setAutoAckInfo(null);
            }
         }
      }
      else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
      {
         //Ack any remaining deliveries
                         
         if (!state.getClientAckList().isEmpty())
         {              
            try
            {
               acknowledgeDeliveries(del, state.getClientAckList());
            }
            finally
            {           
               state.getClientAckList().clear();
              
               state.setAutoAckInfo(null);
            }
         }
      }
      else if (ackMode == Session.CLIENT_ACKNOWLEDGE)
      {
         // Cancel any oustanding deliveries
         // We cancel any client ack or transactional, we do this explicitly so we can pass the
         // updated delivery count information from client to server. We could just do this on the
         // server but we would lose delivery count info.
                 
         // CLIENT_ACKNOWLEDGE cannot be used with MDBs (i.e. no connection consumer)
         // so is always safe to cancel on this session                 
        
         cancelDeliveries(del, state.getClientAckList());
        
         state.getClientAckList().clear();
      }
      else if (state.isTransacted() && !state.isXA())
      {
         //We need to explicitly cancel any deliveries back to the server
         //from the resource manager, otherwise delivery count won't be updated
        
         ConnectionState connState = (ConnectionState)state.getParent();
        
         ResourceManager rm = connState.getResourceManager();
        
         List dels = rm.getDeliveriesForSession(state.getSessionID());
        
         cancelDeliveries(del, dels);       
      }

      return invocation.invokeNext();
View Full Code Here

         {
            throw new TransactionInProgressException("Cannot call rollback on an XA session");
         }
        
         ConnectionState connState = (ConnectionState)state.getParent();
         ResourceManager rm = connState.getResourceManager();
         try
         {
            rm.rollbackLocal((LocalTx)state.getCurrentTxId());
         }
         finally
         {
            // start new local tx
            Object xid = rm.createLocalTx();
            state.setCurrentTxId(xid);
         }
  
         return null;
      }
View Full Code Here

           
      ClientConnectionDelegate del1 = (ClientConnectionDelegate)((JBossConnection)conn1).getDelegate();
     
      ConnectionState state1 = (ConnectionState)del1.getState();
     
      ResourceManager rm1 = state1.getResourceManager();
     
      Connection conn2 = cf.createConnection();     
     
      ClientConnectionDelegate del2 = (ClientConnectionDelegate)((JBossConnection)conn2).getDelegate();
     
      ConnectionState state2 = (ConnectionState)del2.getState();
     
      ResourceManager rm2 = state2.getResourceManager();

      //Two connections for same server should share the same resource manager
     
      assertTrue(rm1 == rm2);
     
View Full Code Here

TOP

Related Classes of org.jboss.jms.tx.ResourceManager

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.