Class AbstractRequestContent.AbstractSubscription

    • Constructor Detail

    • Method Detail

      • produceContent

        protected abstract boolean produceContent​(AbstractRequestContent.Producer producer)
                                           throws java.lang.Exception

        Subclasses implement this method to produce content, without worrying about demand or exception handling.

        Typical implementation (pseudo code):

         protected boolean produceContent(Producer producer) throws Exception
         {
             // Step 1: try to produce content, exceptions may be thrown during production
             //  (for example, producing content reading from an InputStream may throw).
        
             // Step 2A: content could be produced.
             ByteBuffer buffer = ...;
             boolean last = ...;
             Callback callback = ...;
             return producer.produce(buffer, last, callback);
        
             // Step 2B: content could not be produced.
             //  (for example it is not available yet)
             return false;
         }
         
        Parameters:
        producer - the producer to notify when content can be produced
        Returns:
        whether content production should continue
        Throws:
        java.lang.Exception - when content production fails
      • fail

        public void fail​(java.lang.Throwable failure)
        Description copied from interface: Request.Content.Subscription

        Fails the subscription, notifying the content producer to stop producing content.

        Typical failure: a proxy consumer waiting for more content (or waiting to demand content) that is failed by an error response from the server.

        Specified by:
        fail in interface Request.Content.Subscription
        Parameters:
        failure - the reason of the failure
      • notifyContent

        protected void notifyContent​(java.nio.ByteBuffer buffer,
                                     boolean last,
                                     Callback callback)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object