private void handshakeFinished() throws IOException {
    // SSLEnginge.getHandshakeStatus is transient and it doesn't record FINISHED status properly.
    // It can move from FINISHED status to NOT_HANDSHAKING after the handshake is completed.
    // Hence we also need to check handshakeResult.getHandshakeStatus() if the handshake finished or not
    if (handshakeResult.getHandshakeStatus() == HandshakeStatus.FINISHED) {
      //we are complete if we have delivered the last package
      handshakeComplete = !netWriteBuffer.hasRemaining();
      //remove OP_WRITE if we are complete, otherwise we still have data to write
      if (!handshakeComplete) {
        key.interestOps(key.interestOps() | SelectionKey.OP_WRITE);
      } else {
        key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE);
        metrics.sslHandshakeCount.inc();
        metrics.sslHandshakeTime.update(time.milliseconds() - handshakeStartTime);
      }

      logger.trace(
          "SSLHandshake FINISHED channelId {}, appReadBuffer pos {}, netReadBuffer pos {}, netWriteBuffer pos {} ",
          getConnectionId(), appReadBuffer.position(), netReadBuffer.position(), netWriteBuffer.position());
    } else {
      throw new IOException("NOT_HANDSHAKING during handshake");
    }
  }
Checks if the handshake status is finished
Sets the interestOps for the selectionKey.
ambry-network/src/main/java/com/github/ambry/network/SSLTransmission.java