BaseFutureLiveConnection
Java-friendly base for implementing a LiveConnection: override the ...Async methods, which return a CompletableFuture, and receiveJava, which returns a Publisher of one model turn. The base maps these to LiveConnection's calls and also enforces two of its rules, one receive collector at a time and a closeSession that is safe to call again; apply its content rules yourself. Return a new future from each call, because the base cancels a send's future when its caller is cancelled, and a new publisher from each receiveJava call; return each promptly, with any blocking work inside it, and fail a future rather than cancel it.
Functions
Blocks until the close finishes, so never call it from a thread that the future from closeSessionAsync needs in order to complete. It is final, so a subclass cannot swap the graceful close for an abrupt one: put teardown in closeSessionAsync.
Closes the connection; collectors of receive complete normally.
The model's responses for the current turn, completing when the turn ends; collect it again for the next turn. A collection that completes with no response means the connection has ended. Unlike Model.generateContent, where each collection makes its own request, every collection here reads the same open connection, so only one is allowed at a time: implementations reject a concurrent one with IllegalStateException.
Sends user content, which completes the turn and prompts a response unless partial is true.
Seeds the session with prior conversation; Model.connect does not call it, so the caller invokes it at most once, right after connecting and before any other send. The model responds only if the last content is from the user, and otherwise waits for new input.
Sends realtime input: a chunk of media, or a signal marking the edge of user activity.