Interface Request<R>

Type Parameters:
R - the expected response type of the request

public interface Request<R>
Marker interface for request messages (e.g., commands or queries) that expect a response of a specific type.

Implementing this interface allows the Flux Capacitor client to infer the return type of a request, enabling:

  1. Type-safe request invocations (e.g. FluxCapacitor.queryAndWait(Request<T>) returns T)
  2. Compile-time verification that handler methods return a value compatible with the expected response

Example


 @Value
 public class GetUser implements Request<UserProfile> {
     String userId;

     @HandleQuery
     UserProfile handle(GetUser query) {
         return FluxCapacitor.search(UserProfile.class).match(query.getUserId()).fetchFirstOrNull();
     }
 }
 

The responseType() method provides runtime introspection for the expected return type. This is primarily used for generic resolution and handler validation, and relies on reflection to inspect the generic type parameter R declared in Request<R>.

  • Method Summary

    Modifier and Type
    Method
    Description
    default Type
    Returns the expected response type associated with this request instance.
  • Method Details

    • responseType

      default Type responseType()
      Returns the expected response type associated with this request instance.

      This is resolved via reflective analysis of the request's declared generic type (i.e., R in Request<R>). If no concrete type is available, Object.class is returned as a fallback.

      Returns:
      the Type representing the expected response type, or Object.class if unknown