void addNewConnections() { ListIterator<EventableSocketChannel> iter = DetachedConnections.listIterator(0); while (iter.hasNext()) { EventableSocketChannel ec = iter.next(); ec.cleanup(); } DetachedConnections.clear(); ListIterator<Long> iter2 = NewConnections.listIterator(0); while (iter2.hasNext()) { long b = iter2.next(); EventableChannel ec = Connections.get(b); if (ec != null) { try { ec.register(); } catch (ClosedChannelException e) { UnboundConnections.add(ec.getBinding()); } } } NewConnections.clear(); }
void close() { try { if (mySelector != null) mySelector.close(); } catch (IOException e) { } mySelector = null; // run down open connections and sockets. Iterator<ServerSocketChannel> i = Acceptors.values().iterator(); while (i.hasNext()) { try { i.next().close(); } catch (IOException e) { } } // 29Sep09: We create an ArrayList of the existing connections, then iterate over // that to call unbind on them. This is because an unbind can trigger a reconnect, // which will add to the Connections HashMap, causing a ConcurrentModificationException. // XXX: The correct behavior here would be to latch the various reactor methods to return // immediately if the reactor is shutting down. ArrayList<EventableChannel> conns = new ArrayList<EventableChannel>(); Iterator<EventableChannel> i2 = Connections.values().iterator(); while (i2.hasNext()) { EventableChannel ec = i2.next(); if (ec != null) { conns.add(ec); } } Connections.clear(); ListIterator<EventableChannel> i3 = conns.listIterator(0); while (i3.hasNext()) { EventableChannel ec = i3.next(); eventCallback(ec.getBinding(), EM_CONNECTION_UNBOUND, null); ec.close(); EventableSocketChannel sc = (EventableSocketChannel) ec; if (sc != null && sc.isAttached()) DetachedConnections.add(sc); } ListIterator<EventableSocketChannel> i4 = DetachedConnections.listIterator(0); while (i4.hasNext()) { EventableSocketChannel ec = i4.next(); ec.cleanup(); } DetachedConnections.clear(); }
void removeUnboundConnections() { ListIterator<Long> iter = UnboundConnections.listIterator(0); while (iter.hasNext()) { long b = iter.next(); EventableChannel ec = Connections.remove(b); if (ec != null) { eventCallback(b, EM_CONNECTION_UNBOUND, null); ec.close(); EventableSocketChannel sc = (EventableSocketChannel) ec; if (sc != null && sc.isAttached()) DetachedConnections.add(sc); } } UnboundConnections.clear(); }