Iterator iter2 = state.getToAck().iterator();  if (trace) { log.trace("Removing any np deliveries"); }  while (iter2.hasNext())
if (state.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE)
   private void performClientSideFailover(ClientConnectionDelegate failedConnDelegate,                                          ClientConnectionDelegate newConnDelegate) throws Exception   {      log.debug(this + " performing client side failover");      ConnectionState failedState = (ConnectionState)failedConnDelegate.getState();      ConnectionState newState = (ConnectionState)newConnDelegate.getState();      if (failedState.getClientID() != null)      {         newConnDelegate.setClientID(failedState.getClientID());      }      // Transfer attributes from newDelegate to failedDelegate      failedConnDelegate.copyAttributes(newConnDelegate);      CallbackManager oldCallbackManager = failedState.getRemotingConnection().getCallbackManager();      //We need to update some of the attributes on the state      failedState.copyState(newState);            //Map of old session id to new session state      Map oldNewSessionStateMap = new HashMap();      for(Iterator i = failedState.getChildren().iterator(); i.hasNext(); )      {         SessionState failedSessionState = (SessionState)i.next();                  if (trace) { log.trace("Failed session state has " + failedSessionState.getToAck().size() + " deliveries"); }                  int oldSessionId = failedSessionState.getSessionId();         ClientSessionDelegate failedSessionDelegate =            (ClientSessionDelegate)failedSessionState.getDelegate();         ClientSessionDelegate newSessionDelegate = (ClientSessionDelegate)newConnDelegate.            createSessionDelegate(failedSessionState.isTransacted(),                                  failedSessionState.getAcknowledgeMode(),                                  failedSessionState.isXA());         SessionState newSessionState = (SessionState)newSessionDelegate.getState();                  if (trace) { log.trace("New session state has " + newSessionState.getToAck().size() + " deliveries"); }                  oldNewSessionStateMap.put(new Integer(oldSessionId), failedSessionState);         failedSessionDelegate.copyAttributes(newSessionDelegate);         //We need to update some of the attributes on the state         failedSessionState.copyState(newSessionState);         if (trace) { log.trace("replacing session (" + failedSessionDelegate + ") with a new failover session " + newSessionDelegate); }         List children = new ArrayList();         // TODO Why is this clone necessary?         children.addAll(failedSessionState.getChildren());         for (Iterator j = children.iterator(); j.hasNext(); )         {            HierarchicalStateSupport sessionChild = (HierarchicalStateSupport)j.next();            if (sessionChild instanceof ProducerState)            {               handleFailoverOnProducer((ProducerState)sessionChild, newSessionDelegate);            }            else if (sessionChild instanceof ConsumerState)            {               handleFailoverOnConsumer(failedConnDelegate,                                        (ConsumerState)sessionChild,                                        failedSessionDelegate,                                        oldCallbackManager);            }            else if (sessionChild instanceof BrowserState)            {                handleFailoverOnBrowser((BrowserState)sessionChild, newSessionDelegate);            }         }      }            //First we must tell the resource manager to substitute old session id for new session id      //Note we MUST submit the entire mapping in one operation since there may be overlap between      //old and new session id, and we don't want to overwrite keys in the map            failedState.getResourceManager().handleFailover(oldNewSessionStateMap);            Iterator iter = oldNewSessionStateMap.values().iterator();                  while (iter.hasNext())      {         SessionState state = (SessionState)iter.next();                  List ackInfos = null;                  if (!state.isTransacted() && !state.isXA())         {            //Now we remove any unacked np messages - this is because we don't want to ack them            //since the server won't know about them and will barf                                    Iterator iter2 = state.getToAck().iterator();                        if (trace) { log.trace("Removing any np deliveries"); }            while (iter2.hasNext())            {               DeliveryInfo info = (DeliveryInfo)iter2.next();               if (!info.getMessageProxy().getMessage().isReliable())               {                  iter2.remove();                                    if (trace) { log.trace("Removed np delivery: " + info.getDeliveryId()); }               }            }                        if (trace) { log.trace("Session is not transacted, retrieving deliveries from session state"); }            //Get the ack infos from the list in the session state            ackInfos = state.getToAck();                        if (trace) { log.trace("Retrieved " + ackInfos.size() + " deliveries"); }         }         else         {            //Transacted session - we need to get the acks from the resource manager            //btw we have kept the old resource manager            ResourceManager rm = failedState.getResourceManager();            ackInfos = rm.getDeliveriesForSession(state.getSessionId());         }         if (!ackInfos.isEmpty())         {                                    SessionDelegate newDelegate = (SessionDelegate)state.getDelegate();                        List recoveryInfos = new ArrayList();                        for (Iterator iter2 = ackInfos.iterator(); iter2.hasNext(); )            {               DeliveryInfo info = (DeliveryInfo)iter2.next();                              DeliveryRecovery recInfo =                  new DeliveryRecovery(info.getMessageProxy().getDeliveryId(),                                                                              info.getMessageProxy().getMessage().getMessageID(),                                       info.getChannelId());                              recoveryInfos.add(recInfo);            }                        if (trace) { log.trace(this + " sending delivery recovery info: " + recoveryInfos); }            newDelegate.recoverDeliveries(recoveryInfos);         }         else         {            if (trace) { log.trace(this + " no delivery recovery info to send"); }         }      }      // We must not start the connection until the end      if (failedState.isStarted())      {         failedConnDelegate.start();      }      log.info(this + " completed client-side failover");   }