Interface QueryGateway
- All Superinterfaces:
HasLocalHandlers, Namespaced<QueryGateway>
- All Known Implementing Classes:
DefaultQueryGateway
Gateway interface for dispatching queries and receiving responses in Fluxzero.
The QueryGateway provides a high-level API for submitting queries and retrieving
results, either asynchronously or synchronously. It supports rich metadata and integrates with
both local and remote query handlers.
Queries can be sent as raw payloads, Message objects, or Request wrappers for typed responses.
This interface also supports registration of local handlers via HasLocalHandlers.registerHandler(Object).
For message types that are queries, the MessageType.QUERY enum is typically used.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Gracefully shuts down this gateway and releases any held resources.<R> CompletableFuture<R> Sends a typedRequestquery and returns a future representing the result.<R> CompletableFuture<R> Sends a typedRequestquery with additional metadata and returns a future with the result.<R> CompletableFuture<R> Sends the given query asynchronously and returns a future representing the result.<R> List<CompletableFuture<R>> Sends multiple queries asynchronously and returns a list of futures, one for each result.<R> CompletableFuture<R> Sends the given query along with metadata asynchronously and returns a future representing the result.<R> RsendAndWait(Request<R> query) Sends a typedRequestquery and waits for the result.<R> RsendAndWait(Request<R> payload, Metadata metadata) Sends a typedRequestquery with metadata and waits for the result.<R> RsendAndWait(Object query) Sends the given query and waits for the result, blocking the current thread.<R> RsendAndWait(Object payload, Metadata metadata) Sends the given query and metadata, then waits for the result.sendForMessage(Message message) Sends the givenMessageand returns a future representing the resulting message.sendForMessages(Message... messages) Sends multiple queryMessages and returns a list of futures for the raw responses.Methods inherited from interface HasLocalHandlers
hasLocalHandlers, registerHandler, registerHandler, setSelfHandlerFilterMethods inherited from interface Namespaced
forDefaultNamespace, forNamespace
-
Method Details
-
send
Sends the given query asynchronously and returns a future representing the result.If the query is a
Message, it is dispatched as-is. Otherwise, it is wrapped in a new message.- Type Parameters:
R- the expected type of the result- Parameters:
query- the query object- Returns:
- a
CompletableFuturewith the result
-
send
Sends the given query along with metadata asynchronously and returns a future representing the result.- Type Parameters:
R- the expected result type- Parameters:
payload- the query payloadmetadata- additional metadata to attach to the message- Returns:
- a
CompletableFuturecontaining the query result
-
sendForMessage
Sends the givenMessageand returns a future representing the resulting message. This method gives access to the fullMessagereturned by the query handler.- Parameters:
message- the message representing the query- Returns:
- a
CompletableFuturewith the response message
-
send
Sends multiple queries asynchronously and returns a list of futures, one for each result.- Type Parameters:
R- the expected result type for each query- Parameters:
messages- one or more query objects or messages- Returns:
- a list of
CompletableFutures for each query result
-
sendForMessages
Sends multiple queryMessages and returns a list of futures for the raw responses.- Parameters:
messages- one or more messages representing queries- Returns:
- a list of
CompletableFutures containing the result messages
-
sendAndWait
Sends the given query and waits for the result, blocking the current thread.- Type Parameters:
R- the expected result type- Parameters:
query- the query object- Returns:
- the result of the query
-
sendAndWait
-
send
Sends a typedRequestquery and returns a future representing the result.- Type Parameters:
R- the expected result type- Parameters:
query- theRequestquery- Returns:
- a
CompletableFuturecontaining the result
-
send
Sends a typedRequestquery with additional metadata and returns a future with the result.- Type Parameters:
R- the expected result type- Parameters:
payload- theRequestpayloadmetadata- metadata to attach to the request- Returns:
- a
CompletableFuturewith the result
-
sendAndWait
-
sendAndWait
-
close
void close()Gracefully shuts down this gateway and releases any held resources.
-