if (!toCancel.isEmpty()) {   SessionDelegate del = (SessionDelegate)mi.getTargetObject(); del.cancelDeliveries(toCancel); }
   public Object handleRedeliver(Invocation invocation) throws Throwable   {      if (trace) { log.trace("redeliver called"); }            MethodInvocation mi = (MethodInvocation)invocation;      SessionState state = getState(invocation);                  // We put the messages back in the front of their appropriate consumer buffers and set      // JMSRedelivered to true.            List toRedeliver = (List)mi.getArguments()[0];      LinkedList toCancel = new LinkedList();            // Need to be recovered in reverse order.      for (int i = toRedeliver.size() - 1; i >= 0; i--)      {         DeliveryInfo info = (DeliveryInfo)toRedeliver.get(i);         MessageProxy proxy = info.getMessageProxy();                          MessageCallbackHandler handler = state.getCallbackHandler(info.getConsumerId());                       if (handler == null)         {            // This is ok. The original consumer has closed, this message wil get cancelled back            // to the channel.            Cancel cancel = new Cancel(info.getMessageProxy().getDeliveryId(), info.getMessageProxy().getDeliveryCount());            toCancel.addFirst(cancel);         }         else         {            handler.addToFrontOfBuffer(proxy);         }                                          }            if (!toCancel.isEmpty())      {         // Cancel the messages that can't be redelivered locally                  SessionDelegate del = (SessionDelegate)mi.getTargetObject();         del.cancelDeliveries(toCancel);      }                  return null;     }