code: public void connectClient(Connection connection) {
      threadContext.checkThread();
  
      // Note we do not use method references here because the "state" variable changes over time.
      // We have to use lambdas to ensure the request handler points to the current state.
      connection.handler(RegisterRequest.class, (Function<RegisterRequest, CompletableFuture<RegisterResponse>>) request -> state.register(request));
      connection.handler(ConnectRequest.class, (Function<ConnectRequest, CompletableFuture<ConnectResponse>>) request -> state.connect(request, connection));
      connection.handler(KeepAliveRequest.class, (Function<KeepAliveRequest, CompletableFuture<KeepAliveResponse>>) request -> state.keepAlive(request));
      connection.handler(UnregisterRequest.class, (Function<UnregisterRequest, CompletableFuture<UnregisterResponse>>) request -> state.unregister(request));
      connection.handler(ResetRequest.class, (Consumer<ResetRequest>) request -> state.reset(request));
      connection.handler(CommandRequest.class, (Function<CommandRequest, CompletableFuture<CommandResponse>>) request -> state.command(request));
      connection.handler(QueryRequest.class, (Function<QueryRequest, CompletableFuture<QueryResponse>>) request -> state.query(request));
  
      connection.onClose(stateMachine.executor().context().sessions()::unregisterConnection);
    }
docs: Handles a connection from a client.