acknowledge(m);
if (log.isTraceEnabled()) log.trace("Calling delivered()");   delivered(m);  if (log.isTraceEnabled()) log.trace("Called delivered()");
   public Message receive(long timeout) throws JMSException, InterruptedException   {      long startTimestamp = System.currentTimeMillis();      // make sure the current state allows receiving      synchronized(this)      {         if (listener != null)         {            throw new JBossJMSException("A message listener is already registered");         }         if (receiving)         {            throw new JBossJMSException("Another thread is already receiving");         }         receiving = true;      }      try      {         if (log.isTraceEnabled()) { log.trace("receive, timeout = " + timeout + " ms"); }         receivingThread = Thread.currentThread();         JBossMessage m = null;         while(true)         {            try            {               if (timeout <= 0)               {                  m = (JBossMessage)messages.take();               }               else               {                  m = (JBossMessage)messages.poll(timeout);                  if (m == null)                  {                     // receive expired                     return null;                  }               }            }            catch(InterruptedException e)            {               if (closed)               {                  return null;               }               else               {                  throw e;               }            }            // acknowledge even if the message expired            acknowledge(m);            if (!m.isExpired())            {               return m;            }            // discard the message, adjust timeout and reenter the buffer            timeout -= System.currentTimeMillis() - startTimestamp;         }      }      finally      {         receiving = false;         receivingThread = null;      }   }