preDeliver(sessionDelegate, consumerID, channelID, m, isConnectionConsumer);
if (!isConnectionConsumer) { sessionDelegate.preDeliver(new DeliveryInfo(m, consumerID, channelID, null));  sessionDelegate.postDeliver(false); }
   public MessageProxy receive(long timeout) throws JMSException   {                      MessageProxy m = null;                  synchronized (mainLock)      {                 if (trace) { log.trace(this + " receiving, timeout = " + timeout); }                  if (closed)         {            // If consumer is closed or closing calling receive returns null            if (trace) { log.trace(this + " closed, returning null"); }            return null;         }                  if (listener != null)         {            throw new JMSException("The consumer has a MessageListener set, cannot call receive(..)");                  }                                receiverThread = Thread.currentThread();                        long startTimestamp = System.currentTimeMillis();                           try         {            while(true)            {                                            if (timeout == 0)               {                  if (trace) { log.trace(this + ": receive, no timeout"); }                                    m = getMessage(0);                                                         if (m == null)                  {                     return null;                  }               }               else if (timeout == -1)               {                  //ReceiveNoWait                  if (trace) { log.trace(this + ": receive, noWait"); }                                    m = getMessage(-1);                                                         if (m == null)                  {                     if (trace) { log.trace(this + ": no message available"); }                     return null;                  }               }               else               {                  if (trace) { log.trace(this + ": receive, timeout " + timeout + " ms, blocking poll on queue"); }                                    m = getMessage(timeout);                                                      if (m == null)                  {                     // timeout expired                     if (trace) { log.trace(this + ": " + timeout + " ms timeout expired"); }                                          return null;                  }               }                                             if (trace) { log.trace("received " + m + " after being blocked on buffer"); }                                      // If message is expired we still call pre and post deliver. This makes sure the               // message is acknowledged so it gets removed from the queue/subscription.               preDeliver(sessionDelegate, consumerID, channelID, m, isConnectionConsumer);                              postDeliver(sessionDelegate, isConnectionConsumer, false);                              if (!m.getMessage().isExpired())               {                  if (trace) { log.trace("message " + m + " is not expired, pushing it to the caller"); }                                    break;               }                              if (trace)               {                  log.trace("message expired, discarding");               }                              // the message expired, so discard the message, adjust timeout and reenter the buffer               if (timeout != 0)               {                  timeout -= System.currentTimeMillis() - startTimestamp;               }                                        }                    }         finally         {            receiverThread = null;                     }      }             //This needs to be outside the lock      if (buffer.isEmpty() && !serverSending)      {         //The server has previously stopped sending because the buffer was full         //but now it is empty, so we tell the server to start sending again         consumerDelegate.more();      }            m.incDeliveryCount();            return m;   }    