src/java.corba/share/classes/com/sun/corba/se/impl/transport/SelectorImpl.java

Print this page

        

@@ -24,20 +24,23 @@
  */
 
 package com.sun.corba.se.impl.transport;
 
 import java.io.IOException;
+import java.net.ServerSocket;
 import java.nio.channels.ClosedChannelException;
 import java.nio.channels.SelectableChannel;
+import java.nio.channels.ServerSocketChannel;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Iterator;
 import java.util.List;
 
+
 import com.sun.corba.se.pept.broker.Broker;
 import com.sun.corba.se.pept.transport.Acceptor;
 import com.sun.corba.se.pept.transport.Connection;
 import com.sun.corba.se.pept.transport.EventHandler;
 import com.sun.corba.se.pept.transport.ListenerThread;

@@ -237,10 +240,12 @@
         while (i.hasNext()) {
             ReaderThread readerThread = (ReaderThread) i.next();
             readerThread.close();
         }
 
+       clearDeferredRegistrations();
+
         // Selector
 
         try {
             if (selector != null) {
                 // wakeup Selector thread to process close request

@@ -326,10 +331,55 @@
     /////////////////////////////////////////////////////
     //
     // Implementation.
     //
 
+    private void clearDeferredRegistrations() {
+        synchronized (deferredRegistrations) {
+            int deferredListSize = deferredRegistrations.size();
+            if (orb.transportDebugFlag) {
+                dprint(".clearDeferredRegistrations:deferred list size == " + deferredListSize);
+            }
+            for (int i = 0; i < deferredListSize; i++) {
+                EventHandler eventHandler =
+                    (EventHandler)deferredRegistrations.get(i);
+                if (orb.transportDebugFlag) {
+                    dprint(".clearDeferredRegistrations: " + eventHandler);
+                }
+                SelectableChannel channel = eventHandler.getChannel();
+                SelectionKey selectionKey = null;
+
+                try {
+                    if (orb.transportDebugFlag) {
+                        dprint(".clearDeferredRegistrations:close channel == "
+                                + channel);
+                        dprint(".clearDeferredRegistrations:close channel class == "
+                                + channel.getClass().getName());
+                    }
+                    channel.close();
+                    if (channel instanceof ServerSocketChannel) {
+                        dprint(".clearDeferredRegistrations:close ServerSocketCHannel == "
+                                + channel);
+                        ServerSocket ss = ((ServerSocketChannel) channel)
+                                .socket();
+                        ss.close();
+                        selectionKey = eventHandler.getSelectionKey();
+                        if (selectionKey != null) {
+                            selectionKey.cancel();
+                            selectionKey.attach(null);
+                        }
+                    }
+                } catch (IOException ioEx) {
+                    if (orb.transportDebugFlag) {
+                        dprint(".handleDeferredRegistrations: " + ioEx);
+                    }
+                }
+            }
+            deferredRegistrations.clear();
+        }
+    }
+
     private synchronized boolean isClosed ()
     {
         return closed;
     }