if (!cancels.isEmpty()) {   del.cancelDeliveries(cancels); }
   public Object handleClosing(Invocation invocation) throws Throwable   {      MethodInvocation mi = (MethodInvocation)invocation;      SessionState state = getState(invocation);      SessionDelegate del = (SessionDelegate)mi.getTargetObject();            int ackMode = state.getAcknowledgeMode();        //We need to either ack (for auto_ack) or cancel (for client_ack)      //any deliveries - this is because the message listener might have closed      //before on message had finished executing            if (ackMode == Session.AUTO_ACKNOWLEDGE ||          ackMode == Session.DUPS_OK_ACKNOWLEDGE ||          (state.isXA() && state.getCurrentTxId() == null))      {         //Acknowledge any outstanding auto ack                  DeliveryInfo remainingAutoAck = state.getAutoAckInfo();                  if (remainingAutoAck != null)         {            if (trace) { log.trace(this + " handleClosing(). Found remaining auto ack. Will ack it " + remainingAutoAck.getDeliveryId()); }                        ackDelivery(del, remainingAutoAck);                        if (trace) { log.trace(this + " acked it"); }                        state.setAutoAckInfo(null);         }      }      else if (ackMode == Session.CLIENT_ACKNOWLEDGE)      {         // Cancel any oustanding deliveries         // We cancel any client ack or transactional, we do this explicitly so we can pass the updated         // delivery count information from client to server. We could just do this on the server but         // we would lose delivery count info.                  //CLIENT_ACKNOWLEDGE cannot be used with MDBs so is always safe to cancel on this session                  List cancels = new ArrayList();                  for(Iterator i = state.getClientAckList().iterator(); i.hasNext(); )         {            DeliveryInfo ack = (DeliveryInfo)i.next();                        DefaultCancel cancel = new DefaultCancel(ack.getMessageProxy().getDeliveryId(), ack.getMessageProxy().getDeliveryCount());            cancels.add(cancel);         }                  state.getClientAckList().clear();      }            return invocation.invokeNext();   }