Module bus.http

Interface Callback<T>

Type Parameters:
T - The type of the data passed to the generic on(Object) callback.
All Known Implementing Classes:
FileCallback, TextCallback

public interface Callback<T>
A generic callback interface for asynchronous operations.

This interface defines callback methods for handling successful and failed operations, particularly for HTTP requests, enabling asynchronous response processing. Implementations must ensure that resources like the response body are properly closed and handle potential exceptions.

Since:
Java 17+
Author:
Kimi Liu
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    on(T data)
    A generic data callback for handling specific types of callback data, such as STOMP messages or other asynchronous events.
    default void
    Called when the request could not be executed due to cancellation, a connectivity problem, or a timeout.
    default void
    onFailure(NewCall newCall, Exception exception, String id)
    Called when the request fails, including a request ID to differentiate multiple requests.
    default void
    onResponse(NewCall call, Response response)
    Called when the remote server returns an HTTP response.
    default void
    onResponse(NewCall newCall, Response response, String id)
    Called when the request is successful, including a request ID to differentiate multiple requests.
  • Method Details

    • onFailure

      default void onFailure(NewCall call, IOException ex)
      Called when the request could not be executed due to cancellation, a connectivity problem, or a timeout.

      Because networks can fail during an exchange, it is possible that the remote server accepted the request before the failure.

      Parameters:
      call - The call that was executed.
      ex - The exception that occurred.
    • onFailure

      default void onFailure(NewCall newCall, Exception exception, String id)
      Called when the request fails, including a request ID to differentiate multiple requests. This is an alternative to onFailure(NewCall, IOException) for more specific use cases.
      Parameters:
      newCall - The call that was executed.
      exception - The exception that occurred.
      id - The request identifier.
    • onResponse

      default void onResponse(NewCall call, Response response) throws IOException
      Called when the remote server returns an HTTP response.

      Implementations must close the Response.body to release resources. Note that a transport-level success (e.g., a 200 OK) does not guarantee an application-level success (e.g., a 404 or 500 status code).

      Parameters:
      call - The call that was executed.
      response - The response from the server.
      Throws:
      IOException - If an error occurs while processing the response.
    • onResponse

      default void onResponse(NewCall newCall, Response response, String id)
      Called when the request is successful, including a request ID to differentiate multiple requests. This is an alternative to onResponse(NewCall, Response) for more specific use cases.
      Parameters:
      newCall - The call that was executed.
      response - The response from the server.
      id - The request identifier.
    • on

      default void on(T data)
      A generic data callback for handling specific types of callback data, such as STOMP messages or other asynchronous events.
      Parameters:
      data - The callback data.