if (log.isTraceEnabled()){ log.trace(this + " handles " + r + (tx == null ? " non-transactionally" : " in transaction: " + tx) ); }
if (trace){ log.trace(this + " handles " + r + (tx == null ? " non-transactionally" : " in transaction: " + tx) ); }
   public Delivery handle(DeliveryObserver sender, Routable r, Transaction tx)   {                  checkClosed();            if (r == null)      {         return null;      }      if (log.isTraceEnabled()){ log.trace(this + " handles " + r + (tx == null ? " non-transactionally" : " in transaction: " + tx) ); }      // don't even attempt synchronous delivery for a reliable message when we have an      // non-recoverable state that doesn't accept reliable messages. If we do, we may get into the      // situation where we need to reliably store an active delivery of a reliable message, which      // in these conditions cannot be done.      MessageReference ref = ref(r);            try      {                  if (tx == null)         {                  if (r.isReliable() && !state.acceptReliableMessages())            {               log.error("Cannot handle reliable message " + r +                         " because the channel has a non-recoverable state!");               return null;            }                        //This returns true if the ref was added to an empty ref queue            boolean first = state.addReference(ref);                                    //Previously we would call push() at this point to push the reference to the consumer            //One of the problems this had was it would end up leap-frogging messages that were            //already in the queue.            //So now we add the message to the back of the queue and call deliver()                        //In fact we only need to call deliver() if the queue was empty before we added            //the ref.            //If the queue wasn't empty there would be no active waiting receiver, so there            //would be no need to call deliver()            //Once I have improve the locking on the ref queue, this should result in very little (if any)            //lock contention between the thread depositing the message on the queue and the thread            //activating the consumer and prompting delivery.                        if (first)            {               deliver(this, null);                     }         }         else         {               if (log.isTraceEnabled()){ log.trace("adding " + ref + " to state " + (tx == null ? "non-transactionally" : "in transaction: " + tx) ); }                        state.addReference(ref, tx);                  }      }      catch (Throwable t)      {         log.error("Failed to handle message", t);                  ref.release();                  return null;      }      // I might as well return null, the sender shouldn't care      return new SimpleDelivery(sender, ref, true);   }