sp.removeSession(new Integer(id));
   void localClose() throws Throwable   {      if (closed)      {         throw new IllegalStateException("Session is already closed");      }            if (trace) log.trace(this + " close()");                  synchronized (consumers)      {                     for( Iterator i = consumers.values().iterator(); i.hasNext(); )         {            ((ServerConsumerEndpoint)i.next()).localClose();         }                    consumers.clear();      }            synchronized (browsers)      {                     for( Iterator i = browsers.values().iterator(); i.hasNext(); )         {            ((ServerBrowserEndpoint)i.next()).localClose();         }                    browsers.clear();      }            //Now cancel any remaining deliveries in reverse delivery order      //Note we don't maintain order using a LinkedHashMap since then we lose      //concurrency since we would have to lock it exclusively            List entries = new ArrayList(deliveries.entrySet());            //Sort them in reverse delivery id order      Collections.sort(entries,                       new Comparator()                       {                           public int compare(Object obj1, Object obj2)                           {                              Map.Entry entry1 = (Map.Entry)obj1;                              Map.Entry entry2 = (Map.Entry)obj2;                              Long id1 = (Long)entry1.getKey();                              Long id2 = (Long)entry2.getKey();                              return id2.compareTo(id1);                           }                        });      Iterator iter = entries.iterator();                  Set channels = new HashSet();            if (trace) { log.trace("Cancelling " + entries.size() + " deliveries"); }            while (iter.hasNext())      {         Map.Entry entry = (Map.Entry)iter.next();                  if (trace) { log.trace("Cancelling delivery with delivery id: " + entry.getKey()); }                  Delivery del = (Delivery)entry.getValue();                  del.cancel();                  channels.add(del.getObserver());      }            promptDelivery(channels);            deliveries.clear();                  JMSDispatcher.instance.unregisterTarget(new Integer(id));            closed = true;   }            