geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject cvs commit: incubator-geronimo/modules/network/src/java/org/apache/geronimo/network SelectorManager.java
Date Sat, 01 May 2004 23:16:22 GMT
adc         2004/05/01 16:16:22

  Modified:    modules/network/src/java/org/apache/geronimo/network
                        SelectorManager.java
  Log:
  Put in work-around for NPE from NIO impl.
  
  SelectorManager will now not stop when a key is canceled.
  
  Revision  Changes    Path
  1.7       +51 -37    incubator-geronimo/modules/network/src/java/org/apache/geronimo/network/SelectorManager.java
  
  Index: SelectorManager.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/network/src/java/org/apache/geronimo/network/SelectorManager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SelectorManager.java	25 Apr 2004 02:03:37 -0000	1.6
  +++ SelectorManager.java	1 May 2004 23:16:22 -0000	1.7
  @@ -129,49 +129,52 @@
               log.debug("Selector Work thread has started.");
               log.debug("Selector Manager timeout: "+timeout);
               while (running) {
  +                try {
   
  -                synchronized (guard) { /* do nothing */
  -                    log.trace("Waiting for selector to return.");
  -                }
  -                
  -                if (selector.select(timeout) == 0) continue;
  -                
  -                // Get a java.util.Set containing the SelectionKey objects for
  -                // all channels that are ready for I/O.
  -                Set keys = selector.selectedKeys();
  -
  -                // Use a java.util.Iterator to loop through the selected keys
  -                for (Iterator i = keys.iterator(); i.hasNext();) {
  -                    final SelectionKey key = (SelectionKey) i.next();
  -
  -                    if (key.isReadable()) { 
  -                        log.trace("-OP_READ " + key);
  -                        key.interestOps(key.interestOps() & (~SelectionKey.OP_READ));
  -                    }
  -                    if (key.isWritable()) {
  -                        log.trace("-OP_WRITE " + key);
  -                        key.interestOps(key.interestOps() & (~SelectionKey.OP_WRITE));
  -                    }
  -                    if (key.isAcceptable()) {
  -                        log.trace("-OP_ACCEPT " + key);
  -                        key.interestOps(key.interestOps() & (~SelectionKey.OP_ACCEPT));
  +                    synchronized (guard) { /* do nothing */
  +                        log.trace("Waiting for selector to return.");
                       }
   
  -                    threadPool.getWorkManager().execute(new Runnable() {
  -                        public void run() {
  -                            try {
  -                                ((SelectionEventListner) key.attachment()).selectionEvent(key);
  -                            } catch (Throwable e) {
  -                                log.trace("Request Failed.", e);
  -                            }
  +                    if (selector.select(timeout) == 0) continue;
  +
  +                    // Get a java.util.Set containing the SelectionKey objects for
  +                    // all channels that are ready for I/O.
  +                    Set keys = selector.selectedKeys();
  +
  +                    // Use a java.util.Iterator to loop through the selected keys
  +                    for (Iterator i = keys.iterator(); i.hasNext();) {
  +                        final SelectionKey key = (SelectionKey) i.next();
  +
  +                        if (key.isReadable()) {
  +                            log.trace("-OP_READ " + key);
  +                            key.interestOps(key.interestOps() & (~SelectionKey.OP_READ));
  +                        }
  +                        if (key.isWritable()) {
  +                            log.trace("-OP_WRITE " + key);
  +                            key.interestOps(key.interestOps() & (~SelectionKey.OP_WRITE));
                           }
  -                    });
  +                        if (key.isAcceptable()) {
  +                            log.trace("-OP_ACCEPT " + key);
  +                            key.interestOps(key.interestOps() & (~SelectionKey.OP_ACCEPT));
  +                        }
  +
  +                        threadPool.getWorkManager().execute(new Runnable() {
  +                            public void run() {
  +                                try {
  +                                    ((SelectionEventListner) key.attachment()).selectionEvent(key);
  +                                } catch (Throwable e) {
  +                                    log.trace("Request Failed.", e);
  +                                }
  +                            }
  +                        });
   
  -                    i.remove(); // Remove the key from the set of selected keys
  +                        i.remove(); // Remove the key from the set of selected keys
  +                    }
  +                    
  +                } catch (CancelledKeyException e) {
  +                    log.debug("Key has Been Cancelled: "+e);
                   }
               }
  -        } catch (CancelledKeyException e) {
  -            log.debug("Key has Been Cancelled: "+e);
           } catch (IOException e) {
               log.warn("IOException occured.", e);
           } catch (InterruptedException e) {
  @@ -188,12 +191,23 @@
               return key;
           }
       }
  +    public void closeChannel(SelectableChannel selectableChannel) throws IOException {
  +        synchronized (guard) {
  +            selector.wakeup();
  +            selectableChannel.keyFor(selector).cancel();
  +            selectableChannel.close();
  +        }
  +    }
   
       public void addInterestOps(SelectionKey selectorKey, int addOpts) {
           synchronized (guard) {
               selector.wakeup();
               selectorKey.interestOps( selectorKey.interestOps() | addOpts );
           }
  +    }
  +
  +    public void wakeup() {
  +        selector.wakeup();
       }
   
       public void setGBeanContext(GBeanContext context) {
  
  
  

Mime
View raw message