Package org.jboss.jms.delegate

Examples of org.jboss.jms.delegate.SessionDelegate


         {
            DeliveryInfo info = (DeliveryInfo)acks.get(0);
           
            MessageProxy mp = info.getMessageProxy();
           
            SessionDelegate del = mp.getSessionDelegate();
           
            del.redeliver(acks);
         }
      }
   }
View Full Code Here


      // Create the message handler
      SessionState sessionState =
         (SessionState)((DelegateSupport)invocation.getTargetObject()).getState();
      ConnectionState connectionState = (ConnectionState)sessionState.getParent();
      SessionDelegate sessionDelegate = (SessionDelegate)invocation.getTargetObject();
      ConsumerState consumerState = (ConsumerState)((DelegateSupport)consumerDelegate).getState();
      int consumerID = consumerState.getConsumerID();
      int prefetchSize = consumerState.getBufferSize();
      QueuedExecutor sessionExecutor = sessionState.getExecutor();
      int maxDeliveries = consumerState.getMaxDeliveries();
View Full Code Here

  
   public Object handleClosing(Invocation invocation) throws Throwable
   {
      MethodInvocation mi = (MethodInvocation)invocation;
      SessionState state = getState(invocation);
      SessionDelegate del = (SessionDelegate)mi.getTargetObject();
           
      if (trace) { log.trace("handleClosing()"); }

      //Sanity check
      if (state.isXA())
      {
         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)
      {
         //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
            {
               del.acknowledgeDeliveries(state.getClientAckList());
            }
            finally
            {           
               state.getClientAckList().clear();
              
View Full Code Here

     
      if (ackMode == Session.AUTO_ACKNOWLEDGE)
      {
         // We auto acknowledge.

         SessionDelegate sd = (SessionDelegate)mi.getTargetObject();

         // It is possible that session.recover() is called inside a message listener onMessage
         // method - i.e. between the invocations of preDeliver and postDeliver. In this case we
         // don't want to acknowledge the last delivered messages - since it will be redelivered.
         if (!state.isRecoverCalled())
         {
            DeliveryInfo delivery = state.getAutoAckInfo();
           
            if (delivery == null)
            {
               throw new IllegalStateException("Cannot find delivery to AUTO_ACKNOWLEDGE");
            }
                                
            if (trace) { log.trace(this + " auto acknowledging delivery " + delivery); }
             

            // We clear the state in a finally so then we don't get a knock on
            // exception on the next ack since we haven't cleared the state. See
            // http://jira.jboss.org/jira/browse/JBMESSAGING-852

            //This is ok since the message is acked after delivery, then the client
            //could get duplicates anyway
           
            try
            {
               ackDelivery(sd, delivery);
            }
            finally
            {
               state.setAutoAckInfo(null);              
            }
         }        
         else
         {
            if (trace) { log.trace(this + " recover called, so NOT acknowledging"); }

            state.setRecoverCalled(false);
         }
      }
      else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
      {
         List acks = state.getClientAckList();
        
         if (!state.isRecoverCalled())
         {
            if (acks.size() >= state.getDupsOKBatchSize())
            {
               // We clear the state in a finally
               // http://jira.jboss.org/jira/browse/JBMESSAGING-852
  
               SessionDelegate sd = (SessionDelegate)mi.getTargetObject();
                                         
               try
               {
                  sd.acknowledgeDeliveries(acks);
               }
               finally
               {                 
                  acks.clear();
                  state.setAutoAckInfo(null);
View Full Code Here

    */
   public Object handleAcknowledgeAll(Invocation invocation) throws Throwable
   {   
      MethodInvocation mi = (MethodInvocation)invocation;
      SessionState state = getState(invocation);
      SessionDelegate del = (SessionDelegate)mi.getTargetObject();           
   
      if (!state.getClientAckList().isEmpty())
      {                
         //CLIENT_ACKNOWLEDGE can't be used with a MDB so it is safe to always acknowledge all
         //on this session (rather than the connection consumer session)
         del.acknowledgeDeliveries(state.getClientAckList());
     
         state.getClientAckList().clear();
      }     
       
      return null;
View Full Code Here

      }
     
      if (trace) { log.trace("recovering the session"); }
      
      //Call redeliver
      SessionDelegate del = (SessionDelegate)mi.getTargetObject();
     
      int ackMode = state.getAcknowledgeMode();
     
      if (ackMode == Session.CLIENT_ACKNOWLEDGE)
      {
         List dels = state.getClientAckList();
        
         state.setClientAckList(new ArrayList());
        
         del.redeliver(dels);
      }
      else if (ackMode == Session.AUTO_ACKNOWLEDGE || ackMode == Session.DUPS_OK_ACKNOWLEDGE)
      {
         DeliveryInfo info = state.getAutoAckInfo();
        
         //Don't recover if it's already to cancel
        
         if (info != null)
         {
            List redels = new ArrayList();
           
            redels.add(info);
           
            del.redeliver(redels);
           
            state.setAutoAckInfo(null);           
         }
      }  
       
View Full Code Here

     
      List toRedeliver = (List)mi.getArguments()[0];
      
      if (trace) { log.trace(this + " handleRedeliver() called: " + toRedeliver); }
     
      SessionDelegate del = (SessionDelegate)mi.getTargetObject();
     
      // Need to be redelivered in reverse order.
      for (int i = toRedeliver.size() - 1; i >= 0; i--)
      {
         DeliveryInfo info = (DeliveryInfo)toRedeliver.get(i);
View Full Code Here

      MessageProxy m = (MessageProxy)mi.getArguments()[0];
      int theConsumerID = ((Integer)mi.getArguments()[1]).intValue();
      String queueName = (String)mi.getArguments()[2];
      int maxDeliveries = ((Integer)mi.getArguments()[3]).intValue();
      SessionDelegate connectionConsumerDelegate = ((SessionDelegate)mi.getArguments()[4]);
     
      if (m == null)
      {
         throw new IllegalStateException("Cannot add a null message to the session");
      }
View Full Code Here

      if (trace) { log.trace("run()"); }
     
      MethodInvocation mi = (MethodInvocation)invocation;
           
      //This is the delegate for the session from the pool
      SessionDelegate del = (SessionDelegate)mi.getTargetObject();
     
      SessionState state = getState(invocation);
     
      int ackMode = state.getAcknowledgeMode();
View Full Code Here

      return (SessionState)((DelegateSupport)inv.getTargetObject()).getState();
   }
  
   private void ackDelivery(SessionDelegate sess, DeliveryInfo delivery) throws Exception
   {
      SessionDelegate connectionConsumerSession = delivery.getConnectionConsumerSession();
     
      //If the delivery was obtained via a connection consumer we need to ack via that
      //otherwise we just use this session
     
      SessionDelegate sessionToUse = connectionConsumerSession != null ? connectionConsumerSession : sess;
     
      sessionToUse.acknowledgeDelivery(delivery);     
   }
View Full Code Here

TOP

Related Classes of org.jboss.jms.delegate.SessionDelegate

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.