Java Code Examples for java.nio.channels.spi.AbstractSelectableChannel#isOpen()

The following examples show how to use java.nio.channels.spi.AbstractSelectableChannel#isOpen() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VirtualChannelSelectorImpl.java    From BiglyBT with GNU General Public License v2.0 6 votes vote down vote up
public void pauseSelects( AbstractSelectableChannel channel ) {

      //System.out.println( "pauseSelects: " + channel + " - " + Debug.getCompressedStackTrace() );

      if( channel == null ) {
        return;
      }

      SelectionKey key = channel.keyFor( selector );

      if( key != null && key.isValid() ) {
        key.interestOps( key.interestOps() & ~INTEREST_OP );
      }
      else {  //channel not (yet?) registered
        if( channel.isOpen() ) {  //only bother if channel has not already been closed
          try{  register_cancel_list_mon.enter();

            paused_states.put( channel, Boolean.TRUE);  //ensure the op is paused upon reg select-time reg

          }
          finally{  register_cancel_list_mon.exit();  }
        }
      }
    }
 
Example 2
Source File: VirtualChannelSelectorImpl.java    From TorrentEngine with GNU General Public License v3.0 6 votes vote down vote up
public void pauseSelects( AbstractSelectableChannel channel ) {
  
  //System.out.println( "pauseSelects: " + channel + " - " + Debug.getCompressedStackTrace() );
  
  if( channel == null ) {
    return;
  }
  
  SelectionKey key = channel.keyFor( selector );
  
  if( key != null && key.isValid() ) {
    key.interestOps( key.interestOps() & ~INTEREST_OP );
  }
  else {  //channel not (yet?) registered
    if( channel.isOpen() ) {  //only bother if channel has not already been closed
      try{  register_cancel_list_mon.enter();
      
        paused_states.put( channel, new Boolean( true ) );  //ensure the op is paused upon reg select-time reg

      }
      finally{  register_cancel_list_mon.exit();  }
    }
  }
}
 
Example 3
Source File: NioUtils.java    From netcrusher-java with Apache License 2.0 5 votes vote down vote up
public static void close(AbstractSelectableChannel channel) {
    if (channel != null && channel.isOpen()) {
        try {
            channel.close();
        } catch (IOException e) {
            LOGGER.error("Fail to close channel", e);
        }
    }
}