code: public FastSet<ChannelSelectionKey> selectNow() throws IOException {
          FastSet<ChannelSelectionKey> selectedKey = new FastSet<ChannelSelectionKey>();
          selector.selectNow();
          Set<SelectionKey> selection = selector.selectedKeys();
          for (SelectionKey key : selection) {
              ChannelSelectionKey k = (ChannelSelectionKey) key.attachment();
              try {
                  if (key.isValid()) {
                      if (key.isValid() && key.isAcceptable()) {
                          selectedKey.add(k);
                      } else {
  
                          if (key.isValid() && key.isReadable()) {
                              ((ShellChannel) k.channel()).doRead();
                              if (k.isValid() && k.isReadable()) {
                                  selectedKey.add(k);
                              }
                          }
  
                          if (key.isValid() && key.isWritable()) {
                              ((ShellChannel) k.channel()).doWrite();
                              if (k.isValid() && k.isWritable()) {
                                  selectedKey.add(k);
                              }
                          }
                      }
                  } else {
                      // adding invalid channel to allow its removal
                      selectedKey.add(k);
                  }
              } catch (IOException ioe) {
                  throw new ChannelException(k, ioe.getMessage());
              }
          } // for
          selection.clear();
          return selectedKey;
      }
docs: * Selects a set of keys whose corresponding channels are ready for I/O operations.
  
  <p>
  This method performs a non-blocking selection operation. If no channels have become selectable since the previous
  selection operation then this method immediately returns empty selected-key set.
  </p>
  
  @return
  @throws IOException If an I/O error occurs