- Type Parameters:
T- The type of the data passed to the genericon(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 TypeMethodDescriptiondefault voidA generic data callback for handling specific types of callback data, such as STOMP messages or other asynchronous events.default voidonFailure(NewCall call, IOException ex) Called when the request could not be executed due to cancellation, a connectivity problem, or a timeout.default voidCalled when the request fails, including a request ID to differentiate multiple requests.default voidonResponse(NewCall call, Response response) Called when the remote server returns an HTTP response.default voidonResponse(NewCall newCall, Response response, String id) Called when the request is successful, including a request ID to differentiate multiple requests.
-
Method Details
-
onFailure
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
Called when the request fails, including a request ID to differentiate multiple requests. This is an alternative toonFailure(NewCall, IOException)for more specific use cases.- Parameters:
newCall- The call that was executed.exception- The exception that occurred.id- The request identifier.
-
onResponse
Called when the remote server returns an HTTP response.Implementations must close the
Response.bodyto 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
Called when the request is successful, including a request ID to differentiate multiple requests. This is an alternative toonResponse(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
A generic data callback for handling specific types of callback data, such as STOMP messages or other asynchronous events.- Parameters:
data- The callback data.
-