if (log.isTraceEnabled()) { log.trace("got " + m + " from queue"); }    receivingThread = null;  preDeliver(m); postDeliver(m);
if (log.isTraceEnabled()) { log.trace("got " + m); }
   public Message receive(long timeout, JMSMethodInvocation jmsmi, Interceptor receiverInt)         throws JMSException, InterruptedException   {            long startTimestamp = System.currentTimeMillis();            // make sure the current state allows receiving            synchronized(this)      {         if (isClosed())         {            throw new JBossJMSException("The message handler is closed");         }         if (isListening())         {            throw new JBossJMSException("A message listener is already registered");         }         if (isReceiving())         {            throw new JBossJMSException("Another thread is already receiving");         }         setReceiving(true);      }            try      {         receivingThread = Thread.currentThread();                  clearBuffer();                  // forward the invocation to the server, the server-side consumer delegate needs         // to know it must start accepting messages         forwardToServer(jmsmi, this, receiverInt);         JBossMessage m = null;         while(true)         {            try            {               if (timeout == 0)               {                  if (log.isTraceEnabled()) log.trace("receive with no timeout");                                      m = ((JBossMessage)messages.take());                  if (log.isTraceEnabled()) { log.trace("Got message: " + m); }               }               else if (timeout == -1)               {                  //ReceiveNoWait                  if (log.isTraceEnabled()) { log.trace("receive noWait"); }                                    /*                   * FIXME                   *                    * We have a problem with receive no wait                   * Even if there is a message sitting waiting in the server queue                   * then if we don't wait at all here, there is probably not                   * enough time for the message to get here so the client can receive it                   * So temporarily I have hacked it to wait for a bit, even though it                   * is no wait. !!!!!!!!!!!!                   *                    * What we really need to do is introduce a synchronous                   * "giveMeNextMessage" method on the channel, that gives the first                   * available message that is sitting in the queue, or null if there                   * is none                   * Then we would call that method here.                   *                    *                    *                    */                  m = ((JBossMessage)messages.poll(1000));                                   if (m == null)                  {                     if (log.isTraceEnabled()) { log.trace("No message available"); }                     return null;                  }               }               else               {                  if (log.isTraceEnabled()) { log.trace("receive timeout " + timeout + " ms, blocking poll on queue"); }                  m = ((JBossMessage)messages.poll(timeout));                                                      if (m == null)                  {                     // timeout expired                     if (log.isTraceEnabled()) { log.trace(timeout + " ms timeout expired"); }                     stopServerDelivery();                     return null;                  }               }            }            catch(InterruptedException e)            {               if (log.isTraceEnabled()) { log.trace("Thread was interrupted"); }               stopServerDelivery();               if (isClosed())               {                  if (log.isTraceEnabled()) { log.trace(this + " is closed"); }                  return null;               }               else               {                  throw e;               }            }                        if (log.isTraceEnabled()) { log.trace("got " + m + " from queue"); }                        // notify that the message has been delivered (not necessarily acknowledged though)            receivingThread = null; // Crucial - in case thread is interrupted during pre or postDeliver            preDeliver(m);            postDeliver(m);                        if (!m.isExpired())            {               if (log.isTraceEnabled()) { log.trace("message " + m + " is not expired, returning it to the caller"); }               return m;            }            log.debug("message expired, discarding");            // discard the message, adjust timeout and reenter the buffer            if (timeout != 0)            {               timeout -= System.currentTimeMillis() - startTimestamp;            }         }      }      finally      {         setReceiving(false);         receivingThread = null;      }   }