Class AbstractAsyncResponseConsumer<T>

    • Field Detail

      • completed

        private final java.util.concurrent.atomic.AtomicBoolean completed
      • result

        private volatile T result
      • ex

        private volatile java.lang.Exception ex
    • Constructor Detail

      • AbstractAsyncResponseConsumer

        public AbstractAsyncResponseConsumer()
    • Method Detail

      • onResponseReceived

        protected abstract void onResponseReceived​(HttpResponse response)
                                            throws HttpException,
                                                   java.io.IOException
        Invoked when a HTTP response message is received. Please note that the onContentReceived(ContentDecoder, IOControl) method will be invoked only if the response messages has a content entity enclosed.
        Parameters:
        response - HTTP response message.
        Throws:
        HttpException - in case of HTTP protocol violation
        java.io.IOException - in case of an I/O error
      • onContentReceived

        protected abstract void onContentReceived​(ContentDecoder decoder,
                                                  IOControl ioControl)
                                           throws java.io.IOException
        Invoked to process a chunk of content from the ContentDecoder. The IOControl interface can be used to suspend input events if the consumer is temporarily unable to consume more content.

        The consumer can use the ContentDecoder.isCompleted() method to find out whether or not the message content has been fully consumed.

        Parameters:
        decoder - content decoder.
        ioControl - I/O control of the underlying connection.
        Throws:
        java.io.IOException - in case of an I/O error
      • onEntityEnclosed

        protected abstract void onEntityEnclosed​(HttpEntity entity,
                                                 ContentType contentType)
                                          throws java.io.IOException
        Invoked if the response message encloses a content entity.
        Parameters:
        entity - HTTP entity
        contentType - expected content type.
        Throws:
        java.io.IOException - in case of an I/O error
      • buildResult

        protected abstract T buildResult​(HttpContext context)
                                  throws java.lang.Exception
        Invoked to generate a result object from the received HTTP response message.
        Parameters:
        context - HTTP context.
        Returns:
        result of the response processing.
        Throws:
        java.lang.Exception - in case of an abnormal termination.
      • releaseResources

        protected abstract void releaseResources()
        Invoked to release all system resources currently allocated.
      • onClose

        protected void onClose()
                        throws java.io.IOException
        Invoked when the consumer is being closed.
        Throws:
        java.io.IOException - may be thrown by subclassses
        Since:
        4.3
      • cancel

        public final boolean cancel()
        Description copied from interface: Cancellable
        Cancels the ongoing operation or process.
        Specified by:
        cancel in interface Cancellable
        Returns:
        true if the operation or process has been cancelled as a result of this method call or false if it has already been cancelled or not started.
      • failed

        public final void failed​(java.lang.Exception ex)
        Description copied from interface: HttpAsyncResponseConsumer
        Invoked to signal that the response processing terminated abnormally.
        Specified by:
        failed in interface HttpAsyncResponseConsumer<T>
        Parameters:
        ex - exception
      • close

        public final void close()
                         throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException