Module org.firebirdsql.jaybird
Package org.firebirdsql.gds.ng.wire

# Interface DeferredAction

public interface DeferredAction
Interface for processing deferred responses from the server.

This interfaces is used in protocol 11 or higher.

Since:
  3.0
Author:
  Mark Rotteveel

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final DeferredAction`
  `NO_OP_INSTANCE`
  An instance of `DeferredAction` which does nothing (uses the default methods of this interface).

- ## Method Summary

  Modifier and Type
  Method
  Description
  `default WarningMessageCallback`
  `getWarningMessageCallback()`
  Warning message callback.
  `default void`
  `onException(Exception exception)`
  Exception received when receiving or processing the response.
  `default void`
  `processResponse(Response response)`
  Steps to process the deferred response.
  `default boolean`
  `requiresSync()`
  Indicates if this deferred action cannot be processed without an explicit sync action (e.g.
  `static <T> DeferredAction`
  `wrapDeferredResponse(DeferredResponse<T> deferredResponse, Function<Response,T> responseMapper, WarningMessageCallback warningMessageCallback, Consumer<Exception> exceptionConsumer, boolean requiresSync)`
  Wraps a `DeferredResponse` in a `DeferredAction`.

- ## Field Details

  - ### NO_OP_INSTANCE

    static final DeferredAction NO_OP_INSTANCE
    An instance of `DeferredAction` which does nothing (uses the default methods of this interface).

- ## Method Details

  - ### processResponse

    default void processResponse(Response response)
    Steps to process the deferred response.

    The default implementation does nothing.

    Parameters:
      `response` - Response object.

  - ### onException

    default void onException(Exception exception)
    Exception received when receiving or processing the response.

    The default implementation only logs the exception on debug level.

    Parameters:
      `exception` - exception received processing the response
    Since:
      5

  - ### getWarningMessageCallback

    default WarningMessageCallback getWarningMessageCallback()
    Warning message callback.

    The default implementation returns `null`.

    Returns:
      warning callback to use when executing this deferred action, `null` signals to use the default

  - ### requiresSync

    default boolean requiresSync()
    Indicates if this deferred action cannot be processed without an explicit sync action (e.g. `op_ping` or `op_batch_sync`). Should also be used for requests which haven't been explicitly flushed.

    Failure to perform such a sync action may result in indefinitely blocking on read.

    Returns:
      `true` if this deferred action requires an explicit sync action
    Since:
      6

  - ### wrapDeferredResponse

    static <T> DeferredAction wrapDeferredResponse(DeferredResponse<T> deferredResponse, Function<Response,T> responseMapper, WarningMessageCallback warningMessageCallback, Consumer<Exception> exceptionConsumer, boolean requiresSync)
    Wraps a `DeferredResponse` in a `DeferredAction`.
    Type Parameters:
      `T` - response type of the deferred response
    Parameters:
      `deferredResponse` - the deferred response to wrap
      `responseMapper` - conversion from a `Response` to the appropriate object (or `null`) to call on `DeferredResponse.onResponse(Object)`
      `warningMessageCallback` - warning message callback to use when receiving the response
      `exceptionConsumer` - action to take for exceptions
    Returns:
      deferred action