if (!wantReference())
if (log.isTraceEnabled()) { log.trace("Delivering ref " + reference.getMessageID()); }  Delivery delivery = null; Message message = reference.getMessage();  boolean accept = this.accept(message); if (!accept)
   public Delivery handle(DeliveryObserver observer, Routable reference, Transaction tx)   {      //Check if we're ready to handle this reference      //We do the check outside of the synchronized block for performance reasons      //Then we do the check again once we are inside the block      //We don't want a lot of threads blocking on the mutex      if (!wantReference())      {         return null;      }            //Serialize delivery for this consumer      synchronized (deliveryLock)      {         //Need to check again - the state may have changed         //while a thread was blocked on the mutex                  if (!wantReference())         {            return null;         }                  try         {            Delivery delivery = null;            Message message = reference.getMessage();               try            {               message = JBossMessage.copy((javax.jms.Message)message);               if (log.isTraceEnabled()) { log.trace("dereferenced message: " + message); }            }            catch(JMSException e)            {               // TODO - review this, http://jira.jboss.org/jira/browse/JBMESSAGING-132               String msg = "Cannot make a copy of the message";               log.error(msg, e);               throw new java.lang.IllegalStateException(msg);            }               boolean accept = this.accept(message);            if (!accept)            {               if (log.isTraceEnabled()) { log.trace("consumer DOES NOT accept the message"); }               return null;            }               if (reference.isRedelivered())            {               message.setRedelivered(true);               if (log.isTraceEnabled()) { log.trace("set the redelivered flag to true"); }            }               delivery = new SimpleDelivery(observer, (MessageReference)reference);            deliveries.add(delivery);                        if (!grabbing)            {               //We want to asynchronously deliver the message to the consumer               //deliver the message on a different thread than the core thread that brought it here                              try               {                  if (log.isTraceEnabled()) { log.trace("queueing message " + message + " for delivery to client"); }                  threadPool.execute(new DeliveryRunnable(this.sessionEndpoint.connectionEndpoint, callbackHandler, message));               }               catch (InterruptedException e)               {                  log.warn("Thread interrupted", e);               }            }            else            {               //The message is being "grabbed" and returned for receiveNoWait semantics               toGrab = message;            }               return delivery;         }         finally         {            //we set 'ready' to false since the consumer can only deal with messages one at a time            // i.e. we don't buffer them on the client side            ready = false;         }      }   }