cancelMessage(m);
if (!closed) { cancelMessage(m); }
   public void handleCallback(Callback callback) throws HandleCallbackException   {      if (log.isTraceEnabled()) { log.trace("receiving message " + callback.getParameter() + " from the remoting layer"); }      synchronized (closedLock)      {                  Message m = (Message)callback.getParameter();                  if (closed)         {            log.error("Consumer is closed - ignoring message");            //Note - we do not cancel the message if the handler is closed.            //If the handler is closed then the corresponding serverconsumerdelegate            //is either already closed or about to close, in which case it's deliveries            //will be cancelled anyway.         }                  try         {                                //We attempt to put the message in the Channel            //The call will return false if the message is not picked up the receiving or listening            //thread in which case we need to cancel it                        boolean handled = false;            while (waiting)            {               //channel.offer will *only* return true if there is a thread waiting to take a               //message using take() or poll() hence we can guarantee there is no chance any               //messages can arrive and are left in the channel without being handled -  this is               //why we use a SynchronousChannel :)                              //We do this in a while loop to deal with a possible race condition where               //waiting had been set but the main consumer thread hadn't quite blocked on the call               //to take or poll from the channel                              handled = buffer.offer(m, 0);               if (handled)               {                  break;               }            }                        if (!handled)            {               //There is no-one waiting for our message so we cancel it               cancelMessage(m);            }                       }         catch(InterruptedException e)         {            String msg = "Interrupted attempt to put message in the delivery buffer";            log.error(msg);            throw new HandleCallbackException(msg, e);         }      }   }