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

Print this page




 247                 new SocketOrChannelConnectionImpl(orb, this, socket);
 248             if (orb.transportDebugFlag) {
 249                 dprint(".accept: new: " + connection);
 250             }
 251 
 252             // NOTE: The connection MUST be put in the cache BEFORE being
 253             // registered with the selector.  Otherwise if the bytes
 254             // are read on the connection it will attempt a time stamp
 255             // but the cache will be null, resulting in NPE.
 256 
 257             // A connection needs to be timestamped before putting to the cache.
 258             // Otherwise the newly created connection (with 0 timestamp) could be
 259             // incorrectly reclaimed by concurrent reclaim() call OR if there
 260             // will be no events on this connection then it could be reclaimed
 261             // by upcoming reclaim() call.
 262             getConnectionCache().stampTime(connection);
 263             getConnectionCache().put(this, connection);
 264 
 265             if (connection.shouldRegisterServerReadEvent()) {
 266                 Selector selector = orb.getTransportManager().getSelector(0);




 267                 selector.registerForEvent(connection.getEventHandler());
 268             }

 269 
 270             getConnectionCache().reclaim();
 271 
 272         } catch (IOException e) {
 273             if (orb.transportDebugFlag) {
 274                 dprint(".accept:", e);
 275             }
 276             orb.getTransportManager().getSelector(0).unregisterForEvent(this);


 277             // REVISIT - need to close - recreate - then register new one.
 278             orb.getTransportManager().getSelector(0).registerForEvent(this);
 279             // NOTE: if register cycling we do not want to shut down ORB
 280             // since local beans will still work.  Instead one will see
 281             // a growing log file to alert admin of problem.
 282         }
 283     }

 284 
 285     public void close ()
 286     {
 287         try {
 288             if (orb.transportDebugFlag) {
 289                 dprint(".close->:");
 290             }
 291             Selector selector = orb.getTransportManager().getSelector(0);

 292             selector.unregisterForEvent(this);

 293             if (serverSocketChannel != null) {
 294                 serverSocketChannel.close();
 295             }
 296             if (serverSocket != null) {
 297                 serverSocket.close();
 298             }
 299         } catch (IOException e) {
 300             if (orb.transportDebugFlag) {
 301                 dprint(".close:", e);
 302             }
 303         } finally {
 304             if (orb.transportDebugFlag) {
 305                 dprint(".close<-:");
 306             }
 307         }
 308     }
 309 
 310     public EventHandler getEventHandler()
 311     {
 312         return this;


 463                        + " " + this);
 464             }
 465         } finally {
 466 
 467             // IMPORTANT: To avoid bug (4953599), we force the
 468             // Thread that does the NIO select to also do the
 469             // enable/disable of Ops using SelectionKey.interestOps().
 470             // Otherwise, the SelectionKey.interestOps() may block
 471             // indefinitely.
 472             // NOTE: If "acceptorSocketUseWorkerThreadForEvent" is
 473             // set to to false in ParserTable.java, then this method,
 474             // doWork(), will get executed by the same thread
 475             // (SelectorThread) that does the NIO select.
 476             // If "acceptorSocketUseWorkerThreadForEvent" is set
 477             // to true, a WorkerThread will execute this method,
 478             // doWork(). Hence, the registering of the enabling of
 479             // the SelectionKey's interestOps is done here instead
 480             // of calling SelectionKey.interestOps(<interest op>).
 481 
 482             Selector selector = orb.getTransportManager().getSelector(0);

 483             selector.registerInterestOps(this);

 484 
 485             if (orb.transportDebugFlag) {
 486                 dprint(".doWork<-:" + this);
 487             }
 488         }
 489     }
 490 
 491     public void setEnqueueTime(long timeInMillis)
 492     {
 493         enqueueTime = timeInMillis;
 494     }
 495 
 496     public long getEnqueueTime()
 497     {
 498         return enqueueTime;
 499     }
 500 
 501 
 502     //
 503     // Factory methods.




 247                 new SocketOrChannelConnectionImpl(orb, this, socket);
 248             if (orb.transportDebugFlag) {
 249                 dprint(".accept: new: " + connection);
 250             }
 251 
 252             // NOTE: The connection MUST be put in the cache BEFORE being
 253             // registered with the selector.  Otherwise if the bytes
 254             // are read on the connection it will attempt a time stamp
 255             // but the cache will be null, resulting in NPE.
 256 
 257             // A connection needs to be timestamped before putting to the cache.
 258             // Otherwise the newly created connection (with 0 timestamp) could be
 259             // incorrectly reclaimed by concurrent reclaim() call OR if there
 260             // will be no events on this connection then it could be reclaimed
 261             // by upcoming reclaim() call.
 262             getConnectionCache().stampTime(connection);
 263             getConnectionCache().put(this, connection);
 264 
 265             if (connection.shouldRegisterServerReadEvent()) {
 266                 Selector selector = orb.getTransportManager().getSelector(0);
 267                 if (selector != null) {
 268                     if (orb.transportDebugFlag) {
 269                         dprint(".accept: registerForEvent: " + connection);
 270                     }
 271                     selector.registerForEvent(connection.getEventHandler());
 272                 }
 273             }
 274 
 275             getConnectionCache().reclaim();
 276 
 277         } catch (IOException e) {
 278             if (orb.transportDebugFlag) {
 279                 dprint(".accept:", e);
 280             }
 281             Selector selector = orb.getTransportManager().getSelector(0);
 282             if (selector != null) {
 283                 selector.unregisterForEvent(this);
 284                 // REVISIT - need to close - recreate - then register new one.
 285                 selector.registerForEvent(this);
 286                 // NOTE: if register cycling we do not want to shut down ORB
 287                 // since local beans will still work.  Instead one will see
 288                 // a growing log file to alert admin of problem.
 289             }
 290         }
 291     }
 292 
 293     public void close ()
 294     {
 295         try {
 296             if (orb.transportDebugFlag) {
 297                 dprint(".close->:");
 298             }
 299             Selector selector = orb.getTransportManager().getSelector(0);
 300             if (selector != null) {
 301                 selector.unregisterForEvent(this);
 302             }
 303             if (serverSocketChannel != null) {
 304                 serverSocketChannel.close();
 305             }
 306             if (serverSocket != null) {
 307                 serverSocket.close();
 308             }
 309         } catch (IOException e) {
 310             if (orb.transportDebugFlag) {
 311                 dprint(".close:", e);
 312             }
 313         } finally {
 314             if (orb.transportDebugFlag) {
 315                 dprint(".close<-:");
 316             }
 317         }
 318     }
 319 
 320     public EventHandler getEventHandler()
 321     {
 322         return this;


 473                        + " " + this);
 474             }
 475         } finally {
 476 
 477             // IMPORTANT: To avoid bug (4953599), we force the
 478             // Thread that does the NIO select to also do the
 479             // enable/disable of Ops using SelectionKey.interestOps().
 480             // Otherwise, the SelectionKey.interestOps() may block
 481             // indefinitely.
 482             // NOTE: If "acceptorSocketUseWorkerThreadForEvent" is
 483             // set to to false in ParserTable.java, then this method,
 484             // doWork(), will get executed by the same thread
 485             // (SelectorThread) that does the NIO select.
 486             // If "acceptorSocketUseWorkerThreadForEvent" is set
 487             // to true, a WorkerThread will execute this method,
 488             // doWork(). Hence, the registering of the enabling of
 489             // the SelectionKey's interestOps is done here instead
 490             // of calling SelectionKey.interestOps(<interest op>).
 491 
 492             Selector selector = orb.getTransportManager().getSelector(0);
 493             if (selector != null) {
 494                 selector.registerInterestOps(this);
 495             }
 496 
 497             if (orb.transportDebugFlag) {
 498                 dprint(".doWork<-:" + this);
 499             }
 500         }
 501     }
 502 
 503     public void setEnqueueTime(long timeInMillis)
 504     {
 505         enqueueTime = timeInMillis;
 506     }
 507 
 508     public long getEnqueueTime()
 509     {
 510         return enqueueTime;
 511     }
 512 
 513 
 514     //
 515     // Factory methods.