Package org.jboss.jms.client.state

Examples of org.jboss.jms.client.state.SessionState


   }
  
   public Object handlePreDeliver(Invocation invocation) throws Throwable
   {
      MethodInvocation mi = (MethodInvocation)invocation;
      SessionState state = getState(invocation);
     
      int ackMode = state.getAcknowledgeMode();
     
      Object[] args = mi.getArguments();
      DeliveryInfo info = (DeliveryInfo)args[0];
     
      if (ackMode == Session.CLIENT_ACKNOWLEDGE)
      {
         // We collect acknowledgments in the list
        
         if (trace) { log.trace(this + " added to CLIENT_ACKNOWLEDGE list delivery " + info); }
        
         // Sanity check
         if (info.getConnectionConsumerSession() != null)
         {
            throw new IllegalStateException(
               "CLIENT_ACKNOWLEDGE cannot be used with a connection consumer");
         }
                 
         state.getClientAckList().add(info);
      }
      else if (ackMode == Session.AUTO_ACKNOWLEDGE)
      {
         // We collect the single acknowledgement in the state.
                          
         if (trace) { log.trace(this + " added " + info + " to session state"); }
        
         state.setAutoAckInfo(info);        
      }
      else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
      {
         if (trace) { log.trace(this + " added to DUPS_OK_ACKNOWLEDGE list delivery " + info); }
        
         state.getClientAckList().add(info);
        
         //Also set here - this would be used for recovery in a message listener
         state.setAutoAckInfo(info);
      }
      else
      {            
         Object txID = state.getCurrentTxId();
  
         if (txID != null)
         {
            // the session is non-XA and transacted, or XA and enrolled in a global transaction. An
            // XA session that has not been enrolled in a global transaction behaves as a
            // transacted session.
           
            ConnectionState connState = (ConnectionState)state.getParent();
  
            if (trace) { log.trace("sending acknowlegment transactionally, queueing on resource manager"); }
  
            // If the ack is for a delivery that came through via a connection consumer then we use
            // the connectionConsumer session as the session id, otherwise we use this sessions'
            // session ID
           
            ClientSessionDelegate connectionConsumerDelegate =
               (ClientSessionDelegate)info.getConnectionConsumerSession();
           
            int sessionId = connectionConsumerDelegate != null ?
               connectionConsumerDelegate.getID() : state.getSessionID();
           
            connState.getResourceManager().addAck(txID, sessionId, info);
         }       
      }
     
View Full Code Here


   }
  
   public Object handlePostDeliver(Invocation invocation) throws Throwable
   {
      MethodInvocation mi = (MethodInvocation)invocation;
      SessionState state = getState(invocation);
     
      int ackMode = state.getAcknowledgeMode();
     
      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);
               }
            }   
         }
         else
         {
            if (trace) { log.trace(this + " recover called, so NOT acknowledging"); }

            state.setRecoverCalled(false);
         }
         state.setAutoAckInfo(null);
                 
      }

      return null;
   }
View Full Code Here

    * Used for client acknowledge.
    */
   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("recover called"); }
     
      MethodInvocation mi = (MethodInvocation)invocation;
           
      SessionState state = getState(invocation);
     
      if (state.isTransacted())
      {
         throw new IllegalStateException("Cannot recover a transacted session");
      }
     
      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);           
         }
      }  
       
      state.setRecoverCalled(true);
     
      return null
   }
View Full Code Here

    *
    */
   public Object handleRedeliver(Invocation invocation) throws Throwable
   {           
      MethodInvocation mi = (MethodInvocation)invocation;
      SessionState state = getState(invocation);           
           
      // We put the messages back in the front of their appropriate consumer buffers
     
      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);
         MessageProxy proxy = info.getMessageProxy();       
        
         MessageCallbackHandler handler = state.getCallbackHandler(info.getConsumerId());
             
         if (handler == null)
         {
            // This is ok. The original consumer has closed, so we cancel the message
           
View Full Code Here

      return null
   }
  
   public Object handleCommit(Invocation invocation) throws Throwable
   {
      SessionState state = getState(invocation);

      if (!state.isTransacted())
      {
         throw new IllegalStateException("Cannot commit a non-transacted session");
      }

      if (state.isXA())
      {
         throw new TransactionInProgressException("Cannot call commit on an XA session");
      }

      ConnectionState connState = (ConnectionState)state.getParent();
      ConnectionDelegate conn = (ConnectionDelegate)connState.getDelegate();
 
      try
      {
         connState.getResourceManager().commitLocal((LocalTx)state.getCurrentTxId(), conn);
      }
      finally
      {
         //Start new local tx
         Object xid = connState.getResourceManager().createLocalTx();

         state.setCurrentTxId(xid);
      }
     
      //TODO on commit we don't want to ACK any messages that have exceeded the max delivery count OR

      return null;
View Full Code Here

      return null;
   }

   public Object handleRollback(Invocation invocation) throws Throwable
   {
      SessionState state = getState(invocation);

      if (!state.isTransacted())
      {
         throw new IllegalStateException("Cannot rollback a non-transacted session");
      }

      if (state.isXA())
      {
         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

      return null;
   }
  
   public Object handleSend(Invocation invocation) throws Throwable
   {
      SessionState state = getState(invocation);
      Object txID = state.getCurrentTxId();

      if (txID != null)
      {
         // the session is non-XA and transacted, or XA and enrolled in a global transaction, so
         // we add the message to a transaction instead of sending it now. An XA session that has
         // not been enrolled in a global transaction behaves as a non-transacted session.

         ConnectionState connState = (ConnectionState)state.getParent();
         MethodInvocation mi = (MethodInvocation)invocation;
         Message m = (Message)mi.getArguments()[0];

         if (trace) { log.trace("sending message " + m + " transactionally, queueing on resource manager txID=" + txID + " sessionID= " + state.getSessionID()); }

         connState.getResourceManager().addMessage(txID, state.getSessionID(), (JBossMessage)m);

         // ... and we don't invoke any further interceptors in the stack
         return null;
      }
View Full Code Here

      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();

      LinkedList msgs = state.getASFMessages();
     
      while (msgs.size() > 0)
      {
         AsfMessageHolder holder = (AsfMessageHolder)msgs.removeFirst();

         if (trace) { log.trace("sending " + holder.msg + " to the message listener" ); }
        
         MessageCallbackHandler.callOnMessage(del, state.getDistinguishedListener(), holder.consumerID,
                                              holder.queueName, false,
                                              holder.msg, ackMode, holder.maxDeliveries,
                                              holder.connectionConsumerDelegate);                         
      }
     
View Full Code Here

      cons.receive();
      sess.commit();
     
      ClientSessionDelegate del = (ClientSessionDelegate)((JBossSession)sess).getDelegate();
     
      SessionState state = (SessionState)del.getState();
      ConnectionState cState = (ConnectionState)state.getParent();
     
      Object xid = state.getCurrentTxId();
      assertNotNull(xid);
      assertNotNull(cState.getResourceManager().getTx(xid));
     
      //Now close the session
      sess.close();
     
      //Session should be removed from resource manager
      xid = state.getCurrentTxId();
      assertNotNull(xid);
      assertNull(cState.getResourceManager().getTx(xid));
     
      conn.close();
     
View Full Code Here

TOP

Related Classes of org.jboss.jms.client.state.SessionState

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.