public void ioProcess()
    {
        int numberOfKeys;
        try {
            numberOfKeys = selector.select(selectTimeout);
        } catch (IOException e) {
            Logger.error("Selector.select error.", e);
            return;
        }
        if (0 == numberOfKeys) {
            return;
        }
        
        Iterator<SelectionKey> keyIter = selector.selectedKeys().iterator(); 
        while (keyIter.hasNext())
        {
            SelectionKey key = keyIter.next();
            Session session = (Session) key.attachment();
            
            long timeMillis = System.currentTimeMillis();
            
            try {
                if (key.isValid() && key.isReadable()) {
                    long start = System.currentTimeMillis();
                    session.callbackRead(key, timeMillis);
                    long end = System.currentTimeMillis();
                    Statistics.updateNioRead(end - start);
                }
                
                if (key.isValid() && key.isWritable()) {
                    long start = System.currentTimeMillis();
                    session.callbackWrite(key, timeMillis);
                    long end = System.currentTimeMillis();
                    Statistics.updateNioWrite(end - start);
                }
                
                if (key.isValid() && key.isAcceptable()) {
                    session.callbackAccept(key, timeMillis);
                }
                
                if (key.isValid() && key.isConnectable()) {
                    session.callbackConnect(key, timeMillis);
                }
            } catch (CancelledKeyException e) {
                Logger.warn("Closed connection {}", session, e);
            } catch (ClosedChannelException e) {
                Logger.warn("Closed connection {}", session, e);
            } catch (IOException e) {
                Logger.warn("Closed connection {}", session, e);
            } catch (Exception e) {
                Logger.error("Exception occurs on {}", session, e);
            }
            
            keyIter.remove();
        }
    }
public void ioProcess()
    {
        int numberOfKeys;
        try {
            numberOfKeys = selector.select(selectTimeout);
        } catch (IOException e) {
            Logger.error("Selector.select error.", e);
            return;
        }
        if (0 == numberOfKeys) {
            return;
        }
        
        Iterator<SelectionKey> keyIter = selector.selectedKeys().iterator(); 
        while (keyIter.hasNext())
        {
            SelectionKey key = keyIter.next();
            Session session = (Session) key.attachment();
            
            long timeMillis = System.currentTimeMillis();
            
            try {
                if (key.isValid() && key.isReadable()) {
                    long start = System.currentTimeMillis();
                    session.callbackRead(key, timeMillis);
                    long end = System.currentTimeMillis();
                    Statistics.updateNioRead(end - start);
                }
                
                if (key.isValid() && key.isWritable()) {
                    long start = System.currentTimeMillis();
                    session.callbackWrite(key, timeMillis);
                    long end = System.currentTimeMillis();
                    Statistics.updateNioWrite(end - start);
                }
                
                if (key.isValid() && key.isAcceptable()) {
                    session.callbackAccept(key, timeMillis);
                }
                
                if (key.isValid() && key.isConnectable()) {
                    session.callbackConnect(key, timeMillis);
                }
            } catch (CancelledKeyException e) {
                Logger.warn("Closed connection {}", session, e);
            } catch (ClosedChannelException e) {
                Logger.warn("Closed connection {}", session, e);
            } catch (IOException e) {
                Logger.warn("Closed connection {}", session, e);
            } catch (Exception e) {
                Logger.error("Exception occurs on {}", session, e);
            }
            
            keyIter.remove();
        }
    }
public void ioProcess ( ) { int numberOfKeys ; try { numberOfKeys = selector . select ( selectTimeout ) ; } catch ( IOException e ) { Logger . error ( "Selector.select error." , e ) ; return ; } if ( 0 == numberOfKeys ) { return ; } Iterator < SelectionKey > keyIter = selector . selectedKeys ( ) . iterator ( ) ; while ( keyIter . hasNext ( ) ) { SelectionKey key = keyIter . next ( ) ; Session session = ( Session ) key . attachment ( ) ; long timeMillis = System . currentTimeMillis ( ) ; try { if ( key . isValid ( ) && key . isReadable ( ) ) { long start = System . currentTimeMillis ( ) ; session . callbackRead ( key , timeMillis ) ; long end = System . currentTimeMillis ( ) ; Statistics . updateNioRead ( end - start ) ; } if ( key . isValid ( ) && key . isWritable ( ) ) { long start = System . currentTimeMillis ( ) ; session . callbackWrite ( key , timeMillis ) ; long end = System . currentTimeMillis ( ) ; Statistics . updateNioWrite ( end - start ) ; } if ( key . isValid ( ) && key . isAcceptable ( ) ) { session . callbackAccept ( key , timeMillis ) ; } if ( key . isValid ( ) && key . isConnectable ( ) ) { session . callbackConnect ( key , timeMillis ) ; } } catch ( CancelledKeyException e ) { Logger . warn ( "Closed connection {}" , session , e ) ; } catch ( ClosedChannelException e ) { Logger . warn ( "Closed connection {}" , session , e ) ; } catch ( IOException e ) { Logger . warn ( "Closed connection {}" , session , e ) ; } catch ( Exception e ) { Logger . error ( "Exception occurs on {}" , session , e ) ; } keyIter . remove ( ) ; } }
Demultiplex IO events
Demultiplex IO events