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

Print this page

        

*** 24,43 **** --- 24,47 ---- */ 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.nio.channels.ClosedSelectorException; 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;
*** 109,120 **** --- 113,133 ---- SelectionKeyAndOp keyAndOp = new SelectionKeyAndOp(selectionKey, ehOps); synchronized(interestOpsList) { interestOpsList.add(keyAndOp); } // tell Selector Thread there's an update to a SelectorKey's Ops + try { + if (selector != null) { + // wakeup Selector thread to process close request selector.wakeup(); } + } catch (Throwable t) { + if (orb.transportDebugFlag) { + dprint(".close: selector.close: " + t); + } + } + } else { wrapper.selectionKeyInvalid(eventHandler.toString()); if (orb.transportDebugFlag) { dprint(".registerInterestOps: EventHandler SelectionKey not valid " + eventHandler); }
*** 184,194 **** --- 197,209 ---- selectionKey = eventHandler.getSelectionKey(); } if (selectionKey != null) { selectionKey.cancel(); } + if (selector != null) { selector.wakeup(); + } return; } switch (eventHandler.getInterestOps()) { case SelectionKey.OP_ACCEPT :
*** 237,246 **** --- 252,263 ---- while (i.hasNext()) { ReaderThread readerThread = (ReaderThread) i.next(); readerThread.close(); } + clearDeferredRegistrations(); + // Selector try { if (selector != null) { // wakeup Selector thread to process close request
*** 259,269 **** // public void run() { setName("SelectorThread"); ! while (!closed) { try { int n = 0; if (timeout == 0 && orb.transportDebugFlag) { dprint(".run: Beginning of selection cycle"); } --- 276,286 ---- // public void run() { setName("SelectorThread"); ! while (!isClosed()) { try { int n = 0; if (timeout == 0 && orb.transportDebugFlag) { dprint(".run: Beginning of selection cycle"); }
*** 273,290 **** n = selector.select(timeout); } catch (IOException e) { if (orb.transportDebugFlag) { dprint(".run: selector.select: " + e); } ! } ! if (closed) { ! selector.close(); if (orb.transportDebugFlag) { ! dprint(".run: closed - .run return"); } ! return; } /* if (timeout == 0 && orb.transportDebugFlag) { dprint(".run: selector.select() returned: " + n); } if (n == 0) { --- 290,308 ---- n = selector.select(timeout); } catch (IOException e) { if (orb.transportDebugFlag) { dprint(".run: selector.select: " + e); } ! } catch (ClosedSelectorException csEx) { if (orb.transportDebugFlag) { ! dprint(".run: selector.select: ", csEx); } ! break; } + if (isClosed()) { + break; + } /* if (timeout == 0 && orb.transportDebugFlag) { dprint(".run: selector.select() returned: " + n); } if (n == 0) {
*** 319,335 **** --- 337,411 ---- if (orb.transportDebugFlag) { dprint(".run: ignoring", t); } } } + try { + if (selector != null) { + if (orb.transportDebugFlag) { + dprint(".run: selector.close "); } + selector.close(); + } + } catch (Throwable t) { + if (orb.transportDebugFlag) { + dprint(".run: selector.close: ", t); + } + } + } + ///////////////////////////////////////////////////// // // 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; }