Code example for SelectionKey

Methods: attachment, cancel

0
    /** 
     * Do connection-close cleanup on a given SelectionKey. 
     */ 
    protected void cleanupSelectionKey(SelectionKey key) {
      // remove the records from the two maps 
      FrameBuffer buffer = (FrameBuffer) key.attachment();
      if (buffer != null) {
        // close the buffer 
        buffer.close();
      } 
      // cancel the selection key 
      key.cancel();
    } 
  } // SelectThread 
 
  /** 
   * Possible states for the FrameBuffer state machine. 
   */ 
  private enum FrameBufferState { 
    // in the midst of reading the frame size off the wire 
    READING_FRAME_SIZE,