Class AbstractRequestContent.AbstractSubscription

java.lang.Object
org.eclipse.jetty.client.util.AbstractRequestContent.AbstractSubscription
All Implemented Interfaces:
Request.Content.Subscription
Enclosing class:
AbstractRequestContent

public abstract class AbstractRequestContent.AbstractSubscription extends Object implements Request.Content.Subscription

Partial implementation of Subscription.

Implements the algorithm described in Request.Content.

  • Constructor Details

  • Method Details

    • demand

      public void demand()
      Description copied from interface: Request.Content.Subscription

      Demands more content, which eventually results in Request.Content.Consumer.onContent(ByteBuffer, boolean, Callback) to be invoked.

      Specified by:
      demand in interface Request.Content.Subscription
    • produceContent

      protected abstract boolean produceContent(AbstractRequestContent.Producer producer) throws 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:
      Exception - when content production fails
    • fail

      public void fail(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(ByteBuffer buffer, boolean last, Callback callback)
    • toString

      public String toString()
      Overrides:
      toString in class Object