Interface RestResponseHandler


  • public interface RestResponseHandler
    Meant to be the component that handles and routes all outgoing responses.

    The responses are usually submitted by the RestRequestService and sent out via the RestResponseChannel with the RestResponseHandler forming a bridge between them to provide scaling capabilities and non-blocking behaviour.

    Implementations are expected to be thread-safe.

    • Method Detail

      • start

        void start()
            throws java.lang.InstantiationException
        Does startup tasks for the RestResponseHandler. When the function returns, startup is FULLY complete.
        Throws:
        java.lang.InstantiationException - if the RestResponseHandler is unable to start.
      • shutdown

        void shutdown()
        Does shutdown tasks for the RestResponseHandler. When the function returns, shutdown is FULLY complete.

        Any responses queued after shutdown is called might be dropped.

      • handleResponse

        void handleResponse​(RestRequest restRequest,
                            RestResponseChannel restResponseChannel,
                            ReadableStreamChannel response,
                            java.lang.Exception exception)
                     throws RestServiceException
        Submit a response for a request along with a channel over which the response can be sent. If the response building was unsuccessful for any reason, the details should be included in the exception.

        The bytes consumed from the response are streamed out (unmodified) through the restResponseChannel.

        Assumed that at least one of response or exception is null.

        Depending on the implementation, it is possible that the response is not immediately sent but en-queued to be sent at a later time.

        Parameters:
        restRequest - the RestRequest for which the response has been constructed.
        restResponseChannel - the RestResponseChannel to be used to send the response.
        response - a ReadableStreamChannel that represents the response to the restRequest.
        exception - if the response could not be constructed, the reason for the failure.
        Throws:
        RestServiceException - if there is any error while processing the response.